Linus Torvalds Quote of the Week

April 9th, 2014 subogero No comments

How can a cursing, politically incorrect, rude man lead a project of Linux’ size. This is how:

On Wed, Apr 2, 2014 at 4:28 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> Could be done per-fd: put a struct ratelimit_state into struct
> devkmsg_user.

Yeah, what Andrew said. My suggestion of per-task or per-cred is
obviously moronic in comparison.

                Linus "hangs head in shame" Torvalds
Categories: Uncategorized Tags:

The (semi) Ultimate YouTube Party

February 7th, 2014 subogero No comments

screenshot-1391729480793

YouTube parties have a few flaws. Five to ten people gather around a small laptop, an even smaller tablet or a tiny smartphone. Nobody can see the screen really well. It’s no biggie, actually, as nobody cares for videos someone else wants to show. You only want to show off yours. And here is the problem:

You have to wait until the end of that lame boring clip, just to start the search for that brilliant masterpiece you’ve come across last night.

And that’s where remotepi and youtube-dl come for the help of the party, to fix the small problem and the big problem. First, the actual video is played on your huge flatscreen TV by the Raspberry Pi. Second, everyone can search for the next clip on their mobile phones in the meantime!

Head to the homepage or github.com/subogero/remotepi to solve your YouTube problems.

And why semi-ultimate? Erm, a few small problems. The omxd playlist daemon may or may not work properly with the freshest omxplayer. Also, a few video URLs can’t be played by the latter, probably due to authentication problems. But give it a try, anyway.

Categories: Uncategorized Tags: , ,

My Raspberry Pi Media Player Suite

September 26th, 2013 subogero No comments
RemotePi screenshot

RemotePi browsing music

My Raspberry Pi media player suite has reached a generally usable level. At the bottom of the stack there is omxplayer, then the omxd playlist daemon, the rpi.fm command-line internet radio player and, finally, RemotePi the remote control web-app, optimized for smart-phone screens.

Check out its home page.

Why Not XBMC?

I admit I suffer from severe NIH (Not Invented Here) symptoms. But this time, I actually tried to install XBMC from Michael Gorven’s Debian package. But what do I see?

I need to get 44 MB of archives. 120 MB additional disk space will be used. RemotePi, rpi.fm and omxd are 3 MB including all sources, all binaries and all git repositories.

And lo and behold, who are among the dependencies?

  • qt3
  • mysql-common
  • samba-common-bin

Come on! I never use my Raspberry’s GUI. All the GUI RemotePi has is a web-app.

MySQL? Probably a sign of a nice tag-based media library which, in real life, is an absolute pain in the neck to use. You have a DJ-set album, from all sorts of different artists, and a tag-based player just refuses to play it in the order intended by the DJ. I’ll stick to my files and directories, thank you very much.

Samba? I’m one of those smug Penguinistas whose home is Windows-free. So no thanks.

Redmine Command Line Interface – redlist

May 27th, 2013 subogero No comments

redupload, redupdate, redshow, and now redlist. The new one prints the list of issues in plain text, project-wise or globally.

$ redlist -p test localhost/redmine
# Tracker Status      Subject      Assignee      Due date   
2 Feature In Progress Test Feature Szabó Gergely            
1 Bug     In Progress Test Issue   Szabó Gergely 2013-05-26

Uploading files? Check.
Creating or updating issues? Check.
Showing issue details? Check.
Listing issues? Check.

Redlist uses the CSV export feature of Redmine. As Text::CSV is not part of the standard Perl library, I decided to write my own CSV parser. It seemed easy until I tried it on an old mine, 0.9.3 to be precise. In which case it fell apart as the bastard puts each and every existing attribute into the CSV, including the multiline Description. What started with two simple regular expressions, ended up with five, plus a state-machine.

There was some trouble with encoding too. For best results, set your terminal’s locale to utf-8, as well as Redmine’s csv-encoding. On Debian, the yml files are in /usr/share/redmine/config/locales/ for each language. Look for

   general_csv_encoding: UTF-8

Bot the old mine’s output is still too wide for a terminal. Until you define your personal filters, that is. Create ~/.redgit and add

[redlist]
Created
Updated
Description
Parent task
Estimated time

Whatever. It’s still on Github: http://github.com/subogero/redgit

HP Laserjet P1102 on Raspberry Pi

May 22nd, 2013 subogero 3 comments

Printing is evil. Back in the day this evilness sparked even Richard Stallman’s ire and so the Free Software Movement was born. It was 1980 and the new Xerox 9700 laser printer’s proprietary software could not be modified to add an email notification feature.

Fast forward 33 years. The HP Laserjet P1102 has a proprietary driver plugin. It’s freely available for the hp-setup program on Linux. Except, that HP does not compile it for the armv6 architecture. So my home print server, a Raspberry Pi, did not work with my new shiny P1102.

Until I found Rick Richardson’s foo2jzs driver, that is. Instructions and download on http://foo2zjs.rkkda.com.

Morale of the story: free software has nothing to do with communism. On the contrary: it promotes private property rights. The communist, a.k.a. thief, is HP. I bought their printer with my own money, but the tricky bastards did not allow me to use it. A classic case of “redistribution of wealth”. It was Rick’s opens source driver that saved my day.

rpi.fm My Stations

May 20th, 2013 subogero No comments

The Raspberry Pi kicks ass as a media player. Thanks to, among others, rpi.fm, my and my friends’ favourite internet radio player.

Ladies and Gentlemen!

Upon popular user request, I hereby present its new “My Stations” function. rpi.fm now remembers whenever you choose a station. It builds a list from them, ranked by how often you’ve chosen each, and offers a new command “m” to access them.

Enjoy. But only after you’ve updated rpi.fm form Github.

For those in the know:

cd rpi.fm
git pull origin master
sudo make install
rpi.fm

For rpi.fm Noobs:

git clone https://github.com/subogero/rpi.fm
cd rpi.fm
sudo make install
rpi.fm

Redmine Command Line Interface – redupdate

May 19th, 2013 subogero No comments

We love Redmine. It’s everyone’s favourite integrated bug-tracker-wiki-gantt-roadmap-web-app running on Rails. It has everything. Except a decent command line interface.

There are some half-baked attempts on the internet, usually having suffered a few years’ time of bitrot and featuring loads of undocumented Ruby-related dependencies, so-called gems in Ruby-speak. I tried to install a few, but not being a hard-core Rubyist, I had to give up.

Long ages of desperation followed. Until I looked into Redmine’s email interface. Which, it turns out, is a command-line interface in disguise. I decided to leave Exim4 well alone, and write a user friendly command line wrapper around the obvious

/usr/share/redmine/extra/mail_handler/rdm-mailhandler.rb

My first attempt was a server-side only shell-script. But then I realized that any self-respecting person who uses the command-line has some sort of shell access to the Redmine server anyway, which also accommodates the central-ish git repos. So I added an option to run via SSH.

Ladies and Gentlemen: redupdate

Please find it on Github along with a few other scripts:
https://github.com/subogero/redgit

The other scripts include:

  • redupload: upload files to Redmine
  • redshow: view issues in plain text format
  • gitcreate: create bare repo, add HTTP access, optional email notification upon pushes

Lured into Linux Real Time

April 13th, 2013 subogero No comments

The support period of the Lucid Lynx on the Asus UL20A is about to end in May, so I was looking for a new OS. I gave a try to Debian Testing, or Linux Mint Debian Edition, to be precise. But not Pangolin. Sorry.

It was my smoothest Linux install ever. All hardware worked out of the box. Volume and brightness buttons? Check. Wifi? Check. Two-finger scrolling? Check. I also applied the usual MATE fixes for mutt and the power-button. Debian comes with a 486-kernel by default, so it handles only one processor core. One can upgrade manually to a multi-core 686-kernel with apt-get.

aptitude search linux-image

And what do I find?

linux-image-rt-686-pae

A PREEMPT_RT patched kernel, kindly compiled by Debian. Time to plunge into real-time again!

I put together a Linux syscall tutorial project a year ago (see github) which contained a small program performing a periodic real-time task and printing statistics like average/min/max dt and its standard deviation. It’s called rt and uses the setitimer() system call to generate periodic SIGALRM signals. Time to measure latencies of a 1ms periodic task on a RT kernel!

To my utter disappointment, performance was fine, until the tapeta daemon changed my wallpaper, that is. At which point a 300% latency appeared. That’s right, period time 4ms instead of 1ms. Same as earlier, without an RT kernel. What’s wrong?

I was not using real-time scheduling, that’s what. It turned out Linux processes run at static priority zero by default, where the actual scheduling priorities are dynamic, depending on interactivity, nice level, sleep/runtime, etc. This is called the SCHED_OTHER policy. In other words, one is at the mercy of the Completely Fair Scheduler.

On the other hand, a process’ static priority can be increased, and the scheduling policy can be changed to SCHED_FIFO with the sched_setscheduler() system call. In this case the only one whose mercy we are at, is another SCHED_FIFO or SCHED_RR (Round Robin) scheduled process with equal or higher static priority, lurking in the background somewhere. Important to note, though, a process needs to run as root to be able to change its own or another process’ scheduling. There is also a command line utility called chrt, to change the scheduling policy of processes.

By the way. I’m not using threads. Threads are evil. People who use them mostly condemn themselves to a thousand hells of corrupted data, deadlocks and, at the end of the day, slower performance, thanks to cache misses and dirty cache lines. And the uClibc library in many embedded systems does not support POSIX threads. Thank goodness. I’m particularly angry with threads, as every damn RT-Linux tutorial you look at, spends 75% with setting up the bloody things. And you even have to worry about which thread your signals will be delivered to. What about learning fork() and pipe() instead? KEEP IT SIMPLE STUPID!

But enough of my rants and dodgy theories, let’s see the practice. First let’s see, how the skeleton of a periodic task looks like.

#include <unistd.h>
#include <signal.h>
#include <sys/time.h>

/* Periodic SIGALRM handler routine: everything happens here */
void periodic(int signal)
{
    ... /* do your periodic stuff */
    if (continue_running)
        signal(SIGALRM, periodic);
    else
        exit(0);
}

int main(int argc, char *argv[])
{
    ... /* initialize your stuff */
    struct itimerval period = {
        { 0, 1000, }, /* 1st signal in [s], [us] */
        { 0, 1000, }, /* period time   [s], [us] */
    };
    signal(SIGALRM, periodic);       /* install periodic() to handle SIGALRM */
    setitimer(ITIMER_REAL, &period, NULL); /* start periodic SIGALRM signals */
    /* Main idle loop: everything done by the signal handler */
    while (1)
        pause();
    return 0;
}

Next, how to set up real-time scheduling. Add this code to main(), before the setup of the periodic stuff. Remember to run your program as root for the below code to take effect.

#include <sched.h>
...
int main(int argc, char *argv[])
{
    ...
    struct sched_param schedp;
    schedp.sched_priority = 1;
    sched_setscheduler(0, SCHED_FIFO, &schedp);
    ...
}

And now let’s see what happens when a process becomes real-time. I’m measuring latencies of a 1ms task on Raspberry Pi, actually without a PREEMPT_RT kernel. I start rt as a normal process, then change its scheduling to SCHED_FIFO with chrt. See the code of rt on github.

szg@og314 ~/syscalls $ ./rt 1000
Real time child process PID 3368
------------------------------------------------------------------------
     n  Mean [us]       [us] SD  [%]      [us] Min [%]      [us] Max [%]
------------------------------------------------------------------------
   982   1017.502    246.148  24.615        67  93.300      4449 344.900
   985   1015.249    247.086  24.709        71  92.900      4865 386.500
   975   1025.625    300.905  30.091        63  93.700      4669 366.900
   989   1011.116    162.667  16.267       181  81.900      2682 168.200
   986   1014.260    155.867  15.587       259  74.100      2506 150.600
   989   1011.115    163.982  16.398        51  94.900      2674 167.400
   983   1017.492    189.123  18.912        59  94.100      2803 180.300
   983   1017.102    199.678  19.968        74  92.600      3985 298.500
   985   1015.169    214.607  21.461        62  93.800      3938 293.800
   978   1022.632    267.480  26.748        83  91.700      4355 335.500
   988   1012.008    165.071  16.507        84  91.600      2707 170.700
   991   1009.079    222.581  22.258        72  92.800      6762 576.200
  1000   1000.001     18.526   1.853       769  23.100      1218  21.800
  1000   1000.040     16.464   1.646       834  16.600      1163  16.300
  1000    999.958     12.861   1.286       924   7.600      1086   8.600
  1000   1000.002     17.503   1.750       809  19.100      1223  22.300
  1000   1000.014     20.984   2.098       793  20.700      1212  21.200
  1000   1000.035     24.159   2.416       827  17.300      1175  17.500
  1000    999.998     26.596   2.660       795  20.500      1246  24.600
  1000    999.962     18.433   1.843       844  15.600      1152  15.200
  1000    999.989     34.235   3.424       716  28.400      1314  31.400
  1000   1000.003     18.630   1.863       849  15.100      1214  21.400
  1000   1000.001     22.666   2.267       717  28.300      1268  26.800
  1000    999.996     20.419   2.042       799  20.100      1196  19.600
  1000   1000.051     15.729   1.573       831  16.900      1159  15.900
  1000    999.951     13.385   1.339       920   8.000      1109  10.900
  1000   1000.000     18.562   1.856       830  17.000      1210  21.000
  1000   1000.002     28.782   2.878       812  18.800      1222  22.200
  1000   1000.039     19.713   1.971       763  23.700      1239  23.900
  1000    999.964     25.291   2.529       907   9.300      1118  11.800
     1   1035.000     35.000   3.500      1035  -3.500      1035   3.500
------------------------------------------------------------------------
     n  Mean [us]       [us] SD  [%]      [us] Min [%]      [us] Max [%]
------------------------------------------------------------------------
 29815   1006.212    136.875  13.687        51  94.900      6762 576.200

A line of statistics is printed after every second with the following columns: n (number of events), Mean dt, SD (standard deviation), and Min/Max dt. Whilst the program was running, after the 12th line of data above, I changed rt’s scheduling with the command below.

root@og314 ~ # chrt -f -p 1 3368  # -f : SCHED_FIFO, 1 : static priority 1

The effect was truly dramatic. With normal scheduling I was missing about 2% of the events, with an average latency of 20% (0.2ms), in the worst case up to 600% (6ms). After changing to real-time scheduling, not a single event went lost, average latency dropped to 2% (0.02ms!), and the worst case delay dropped to 31% (0.31ms).

All this is causing 7-8 % processor load on a Raspberry Pi running two ssh sessions and omxplayer playing an internet radio. Single core, no PREEMPT_RT kernel. You probably need the latter in a production system which must not miss a beat for weeks.

So Linux is definitely able to run an ECU. That’s where my new ARIA25 board will excel. After someone designs an ECU for me…

Raspberry Pi Internet Radio

December 22nd, 2012 subogero 2 comments

I’ve mentioned already that the Raspberry has become a rather integral part of my flat. And now I mention that I’m a great consumer of ska, reggae, soul, house, samba, sambass, funk and liquid funk.

And that’s where internet radios come into the picture. But it’s been so awkward so far. Hook up the phone to the stereo’s AUX cable? Start an entire desktop session on a laptop to play them in a browser and hook it up to the stereo’s AUX cable?

But now the Raspberry is in place, and it’s permanently connected to both the TV and the stereo. So I had to find a way to play internet radio stations from the command line. The internet did not reveal definitive answers, so I wrote a little Perl program.

It does some data-mining on www.internet-radio.com and presents an extremely simple interactive command line interface to choose genres and stations, start playback on the audio-jack or on HDMI, to play or pause, to quit or quit but continue playback in the background.

It’s very easy to use. I ssh sometimes into the Raspberry to change the station, and then it plays LiquidBass.net or something else all day long.

It’s called rpi.fm. Please find it on GitHub.

I tested it on Raspbian Wheezy. It uses omxplayer for playback. Important: the user must be in the “audio” group. The default user “pi” is, for new users edit /etc/group as root:

audio:x:29:pulse,pi,youruser

Next project: web-app for the same thing. And then the phone can be used as a remote control.

Raspberry Ping

December 10th, 2012 subogero No comments

My long awaited Raspberry Pi has arrived about 2 weeks ago. I’ve ordered some accessories along with it, like an SD card, a HDMI cable and a power supply. What was missing though, was any kind of input device. I flashed the Raspbian image to the SD, hooked it to the TV and go.

It booted! And then waited hopelessly for me to log in.

Fortunately my flat has built-in Ethernet everywhere, so I connected the Pi, and tried to ssh into it from an Ubuntu laptop. Success! I typed “startx” and an orphaned LXDE session popped up on the TV. Rather useless without a mouse.

But then I remembered the so called X-server, which has to be the largest program that does nothing for you according to Ken Thompson. Except that it does. Unix GUI programs don’t talk to the screen/keyboard/mouse directly, but through an X-server that handles these. And my Ubuntu had one already running. And the GUI-X communication can run over a network as well. So…

foo@bar$ ssh -X pi@raspberry  # ssh into the RPi allowing X communication
pi@raspberry$ lxsession       # start an LXDE desktop session on the RPi

and what popped up was the proof for the superiority of this weird, unfriendly, minimalistic thing called Unix:

Ubuntu & Raspberry on same screen

Ubuntu & Raspberry on same screen

Ladies and gentlemen: 2 full desktop environments running on 1 screen! And that was it for the first weekend with the Pi.

For the second weekend, I bought some more accessories: Logitech K400 wireless keyboard with built-in touchpad, 1 TB USB hard-disk and a powered USB-hub. Time to build my low-power home server. Built into the hidden recesses of my desk.

Home server

Home server

Then I turned my USB printer into a network-printer installing CUPS on the Raspberry. The last adventure so far was setting up an FTP-server on said fruit. Vsftpd. VS probably means very secure, which usually stands for totally unusable. And yes, it was a bloody nightmare to set up. At the end it turned out you have to comment out nearly all lines in the bloody /etc/pam.d/vsftpd file. Oh well.

Linux desktops on a desktop

Linux desktops on a desktop

Categories: Uncategorized Tags: , , ,