Archive for the ‘Linux’ Category

Filed Under (Geekstuff, Linux, My Music) by Sean on March-3-2008

This is a follow up to the previous post located here.

Well I finally decided to get down and dirty once again and dive into the innards of real time kernel tuning. As I reported last time, I was getting some latency which was evident through the sound card as a very nasty buzzing sound. Here I’ll report some basic findings which hopefully will help anyone attempting to set up a real time system set up for use as a DAW.

My system is running Ubuntu Gutsy Gibbon. You may recall where I had some serious trouble installing the Ubuntu Studio real time Ubuntu kernel; the initrd image was severely anemic to the point where I couldn’t even boot up. Instead, I decided to download the latest kernel source and roll my own so I knew everything would be just the way I wanted.

Before I go into the step by step process of how that was done, allow me to report some updated findings that may clear up some confusion. One issue is deciding what method to use to grant realtime scheduling to users (so you don’t have to run programs as root, which is a very bad idea). The old way of doing things was to use the realtime-lsm kernel patch and module. The problem I was running into with this method along with the latest 2.6.24 kernels is the fact that you can no longer configure your kernel with CONFIG_SECURITY_CAPABILITIES as a module! The kernel maintainers have decided that it introduces some serious security vulnerabilities, so the only options now are built into the kernel or not at all. This is a serious problem when using realtime-lsm since presumably the capability module does not support stacking and needs to be unloaded when the realtime-lsm module is loaded. This is not completely true as pointed out by the Debian Kernel Team, but the realtime-lsm module patches I was using have not been modified to correct this. In any case, realtime-lsm has been deprecated in favor of the newer PAM rlimits method of granting realtime scheduling priority to userspace programs. It is important to note that realtime-lsm will still give you superior performance over the rlimits method for really heavy multimedia work, but in 99% of cases the rlimits method should suit most users just fine. The rlimits method works by configuring priority scheduling limits in /etc/security/limits.conf.

Let’s get to the meat of how I configured my system. I’m going to list all the steps in order with a very brief explanation of each.

First we get the latest kernel source tarball. In my case this was 2.6.24.3.

wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.xx.tar.bz2

Then we get the latest realtime kernel patch. Make sure the patch version matches your kernel version above. Get the latest rt version if there is more than one for your kernel. In my case this was patch-2.6.24.3-rt3.bz2.

wget http://kernel.org/pub/linux/kernel/projects/rt/patch-2.6.xx-rt.bz2

Copy the files to your kernel source tree, un-tarball them and patch the kernel. Be sure to use the proper version numbers below in place of these as applicable from your download.

cd /usr/src/

tar zjfv ~/linux-2.6.24.3.tar.bz2 linux-2.6.24.3 .

ln -s linux-2.6.24.3 linux

cd linux

bzcat ~/patch-2.6.24.3-rt3.bz2 | patch -p1

Get your current working config if you have one.

zcat /proc/config.gz > .config

or

cp /usr/src/linux-`uname -r`/.config ./.config

From the existing .config, if you have one, update the settings from it. If there are any new features from the last config file, you may be asked some configuration questions.

make oldconfig

Get your favorite editor out and modify the config file to match the following settings. If they don’t exist just add them to the end of the config file. Another option is to make menuconfig (or xconfig, gconfig, config, etc.) and set the values that way.

vi .config

HIGH_RES_TIMERS=y

PREEMPT_RT=y

HZ_1000=y

RTC=y

SND_RTCTIMER=y

SND_SEQ_RTCTIMER_DEFAULT=y

Now we can recompile and install our kernel. Below is the Debian/Ubuntu way of doing it. You can use the old school make && make modules && make modules_install technique as well. The Debian way does it all for you and packages the kernel image and headers as .deb packages in /usr/src and even installs the new kernel into GRUB!

make-kpkg --initrd --append-to-version=-rt_custom kernel_image kernel_headers

dpkg -i ../*deb

Now we grant realtime scheduling to the user group audio. Be sure your user account is part of this group. Here we set a max priority of 99 (RT), nice value of -10 (not very nice :) ) and memlock value of 512MB.
sudo cat "@audio - rtprio 99" >> /etc/security/limits.conf
sudo cat "@audio - nice -10" >> /etc/security/limits.conf
sudo cat "@audio - memlock 512000" >> /etc/security/limits.conf

Verify everything looks good in GRUB and reboot. Verify you’re running the new kernel. Look for PREEMPT RT in the version.

uname -ar

Linux ubuntu 2.6.24.3-rt3-rt_custom #1 SMP PREEMPT RT Sun Mar 2 22:06:11 CST 2008 i686 GNU/Linux

Great! Now you can run qtjackctl and select the appropriate realtime setting. You can launch your other studio applications with these settings as well and modify them in real time using the chrt command. You can check on the status of a process with ps -eo rtprio,comm.

ps -eo rtprio,comm | grep jack

chrt -p 99 <process id>

I will follow up with some more details and howtos regarding working with your DAW. Feel free to comment below if you have any questions or email me using the email icon at the top of the page. Enjoy!



Filed Under (Geekstuff, Linux) by Sean on February-26-2008

No, I’m not talking about the strings from theoretical physics here, just plain old strings in computer programming.

So, let’s say you need to generate a truly random string for a password, encryption key salt, or some other purpose. For this purpose the best thing is to use the /dev/random or /dev/urandom device on your computer. If your system doesn’t have a hardware random number generator (e.g., palm devices, phones, embedded systems), you can use alternative techniques such as using Lava Lamps, WiFi background noise, Space or live Keno results from Vegas to generate truly random data.

Computers cannot, by themselves, generate truly random data. Most random algorithms are based on pseudo-random number generation, which are basically data that appear random but are actually generated from a completely deterministic process, making them not random at all by definition. The /dev/random device, which first appeared in Linux, uses environmental noise to generate its entropy pool from which random data can be created. Environmental noise includes keyboard and mouse use, device driver interrupt timing, and other non-deterministic data. The generator also stores the number of bits of noise that exist within the entropy pool. Thus when accessing /dev/random, if there isn’t sufficient entropy, the device will block until entropy is available. For example, if you call for a specific length string, and there isn’t sufficient entropy, it will generate what it can and wait for more entropy. You can generate entropy by using your computer’s mouse and keyboard (or do what I do and write a blog post or send out a tweet on twitter). If you cannot wait for the entropy pool to fill back up, the /dev/urandom device is available which is non-blocking since it reuses bits from the entropy pool to generate pseudo random bits (however sufficiently random for cryptographic use).

How do we create a random string then? Let’s say you need a 12 character string consisting of alpha numeric characters. This is the command I would use at a shell prompt (only type bold characters):

linux$ od -a -A n /dev/random | head -1 | tr -d ' ' | tr -d '\n' | sed 's/[^a-zA-Z0-9]//g' | awk '{print substr($0,1,12)}'
stxeG5GyIack

You can replace /dev/random with /dev/urandom if you don’t need truly random data. If you need a longer string, you should increase the number used with the head command and modify the number in the substring (substr) function. Additionally, you can include symbols and other non-alphanumeric characters by eliminating the sed statement. If you need just numbers, you can use a different argument to od. Here are some examples of these in order:

linux$ od -a -A n /dev/random | head -30 | tr -d ' ' | tr -d '\n' | sed 's/[^a-zA-Z0-9]//g' | awk '{print substr($0,1,256)}'
DhtBMcsiusdeltackeotbssyn7nakUsYhNuZnOhtspdVescdc4Xsili2CLkeoth8subnuleothtDackw
Sdc4bel2canSackdleSUsietb8Kdc3ynuleenqdc2ijbetb1euCMoTIXzemVyUFxketb69sdc1uQffD
subvjHGrlZpdc2AsinaknulSUrs7dc2nulnul4Gusus3vsp1GB025Kx3dc3xBddc40dleetxhrdc1yH
zu2usjffXMbswhtcaN

linux$ od -a -A n /dev/random | head -1 | tr -d ' ' | tr -d '\n' | awk '{print substr($0,1,12)}'
J+O\amescIen

linux$ od -d -A n /dev/random | head -1 | tr -d ' ' | tr -d '\n' | awk '{print substr($0,1,12)}'
140396406633

I hope you find this information informative. By typing this post, I’ve succeeded in filling back up my entropy pool!