Friday, November 28, 2008

Understanding PER_CPU_LOCKED

per_cpu variables is one of the type of synchronization primitive available in the linux kernel.
As the name suggests, it it used by those data structures that need elements equal to the number of processor available.

This helps avoid contention and faster access due to cache coherency as the element of the per_cpu data structure accessed correponds "only" to the processor on which the kernel thread is running on.This obviously means preemption be disabled before accessing the per_cpu variables.

Now, in the realtime linux kernel (PREEMPT_RT patchset) the aim is to be as preemptible as possible so as to allow high priority tasks to preempt anyone and everyone. Hence the above assumption that preemption is disabled prior to accessing per_cpu variables breaks.
This happens because, usually spinlocks are used to disable preemption but in realtime linux, all these spinlocks are converted to rt-mutexes . rt-mutexes does not disable preemption and puts the process to sleep instead of spinning.

A task put to sleep, would not know on which processor it will wake up on. Hence, a task can be preempted while accessing a per_cpu var and scheduled on another processor. The value eventually read can be corrupted or illegal.

The solution is to declare variables as PER_CPU_LOCKED (DEFINE_PER_CPU_LOCKED, DECLARE_PER_CPU_LOCKED) instead of just PER_CPU DEFINE_PER_CPU, DECLARE_PER_CPU).

This new macro, associates a per-cpu sleeping lock (rt-mutex) with the per-cpu variable. So, even if a kernel thread accessing a per-cpu variable is scheduled on another cpu, this lock will ensure that the data read is correct.

The implication of this new macro is a performance hit, as the per-cpu variable being read on one processor could well be for some other processor.

This performance hit is alright as in "realtime" we care more about "latency" and "determinism" than "overall system performance".





Wednesday, November 26, 2008

Installing Amarok 2 Beta/RC on Fedora 9


Installing Amarok 2 Beta/RC is pretty straight forward except that the steps on the Amarok wiki are incomplete.

First you need to install cmake


# yum install cmake


After that, try compiling with


# cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` -DCMAKE_BUILD_TYPE=debugfull



On a typical Fedora 9 setup, you'd instantly hit errors. Thats because multiple devel packages are missing.


# yum install -y kdelibs phonon* libgpod-devel prce



Another package that needs to be installed is libtags. Installing it via yum didnot solve the problem for me. So I had to download the code and install it from here
You will need libmtp. But the ones available in Fedora 9 won't help. Take ones from Fedora 10 repo from here and here

During make i hit a problem, amarok couldn't file libprce and libprceposix, even though they were installed.


# ln -s /usr/lib/libpcreposix.so.0 /usr/lib/libpcreposix
# ln -s /lib/libpcre.so.0 /usr/lib/libpcre.so



Phew!
After all of this, trying compiling amarok again.This time everything should go smooth.
Then do a make and make install.
The make step takes a lot of time.
You should be all set to use the latest and greatest Music Player i.e Amarok 2 RC1 (pun intended!)


The easy way to do this just install the rpm. Grab the beta rpm from here


# yum localinstall amarok-1.90-1.fc9.i386.rpm


The above will resolve all the necessary dependencies and install amarok 2 beta 1


Powered by ScribeFire.

Sunday, November 16, 2008

Custom Search in Firefox

Firefox allows users to custom search (Top Right Corner) certain websites which have built in search capabilities like Wikipedia, Amazon etc.

How does one go about adding a custom search to a site without inherent search capabilities like eg. lkml.org ?

Assuming you are in your home directory.


[cheezo@phaedrus ~]$ pwd
/home/cheezo
[cheezo@phaedrus ~]$ cd `find .mozilla/ -name 'searchplugins' `

[cheezo@phaedrus searchplugins]$ ls
goosh.xml imdb.xml linkedin.xml lkml.xml


Here there are already some xml files for those custom search engines.
lkml.xml is the file of our interest, lets have a look


[cheezo@phaedrus searchplugins]$ cat lkml.xml

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Google</ShortName>
<Description>Google Search
<InputEncoding>UTF-8
<Url type="application/x-suggestions+json" method="GET" template="http://www.google.com/custom?sitesearch=lkml.org&;client=firefox&hl={moz:locale}&q={searchTerms}"/>
<Url type="text/html" method="GET" template="http://www.google.com/search">
<Param name="q" value="{searchTerms}"/>
<Param name="ie" value="utf-8"/>
<Param name="oe" value="utf-8"/>
<Param name="aq" value="t"/>

<Param name="rls" value="{moz:distributionID}:{moz:locale}:{moz:official}"/>
<MozParam name="client" condition="defaultEngine" trueValue="firefox-a" falseValue="firefox"/>
</Url>
<SearchForm>http://www.google.com/firefox
</SearchPlugin>



On the 5th line, we have template="http://www.google.com/custom?sitesearch=site_name". Here site_name = lkml.org. Incase you want to search any other site, replace site_name with that site.

Other terms are self-explanatory.
To ensure a new search engine option shows in Firefox; Firefox needs to be rebooted.

Note:This is my first post which experiments with Cascading Style Sheets (CSS).

Powered by ScribeFire.

Saturday, November 15, 2008

Finding out processor topology

The other day Varun and I were discussing about how we could find out the system multi-threaded/multi-core topology. We looked at /proc/cpuinfo and got our answer. So the following fields in the cpuinfo file would need to be consulted to understand the topology of the system:

physical id: physical package id of the CPU

siblings: number of processors, present in the same physical package. This counts both hardware threads and cores

core id: Core id of the processor

cpu cores: number of cores in the physical package

Also, the flags field contains a flag called "ht", to indicate if hardware multi-threading is supported by the processor

So, if for a physical package, the number of siblings is equal to the number of cores and both are greater than 2, it would mean that it has multiple cores and does not support hardware threads. If the number of siblings is greater than 2 but the number of cores is one, then that would imply that there is only a single core in one package and that there is support for hardware threads. Some systems could have processors that are both, multi-threaded and ulti-core. For these, the number of siblings and the number of cores in a physical package would be more than one.

The topology information can be very useful. It can be used to bind certain application or kernel threads, and/or irqs to particular cpus, to improve throughput by reducing resource contention and aid the scheduler in making better load balancing decisions.

Tuesday, November 4, 2008

Funny Pull Request @ netdev

From: "John W. Linville" 
Date: Fri, 31 Oct 2008 19:37:35 -0400

> Here is a spooky Halloween pull request for wireless bits intended for
> 2.6.29 -- Boo! Are you scared?

Best pull request ever :-)

> There is a ton of stuff here.  The good news is that it has been cooking
> in wireless-testing for a while and it seems OK. :-) There are some
> warning in the build like "‘__IEEE80211_CONF_SHORT_SLOT_TIME’ is
> deprecated". Don't worry, I already have more patches cooking in
> wireless-testing that will take care of those warnings in the next
> round.
>
> Please let me know if there are problems!

Pulled, thanks a lot!