30 Jun 2007

More WPA2 debugging

Tonight I was debugging more wireless and it seems that driver does not report that AP is using better encryption than WEP. Wpa_supplicant seems to look for WPA IE and/or RSN IE data so I need to find out where to get that or do I need to bake it somehow (or can I bake it). Having no documentation for gelic is making it a bit hard to guess, but it would seem that this AP's IE information is not available from it. Need to study this more later on. I also implemented some ioctl's so that user space can query and set those values, wpa_supplicant was giving some warnings about those. Though I am still wondering should those values be used in driver itself and not just to provide storage helper ;). Hacked wpa_supplicant to accept my AP without whining about missing WPA, it went a bit further leaved scanning mode to another but then again failed. It looks like it sets wrong encryption session settings or something like that as it didn't get it from driver on those IE fields. Need to study this more too...

28 Jun 2007

WPA problems with PS3 Linux


I was getting annoyed that WPA2 didn't work out of the box in Yellow Dog Linux, so I started to diagnose what is the problem. First I setuped seperate Linux kernel module building environment so I could compile newest ps3_gelic module in isolation. After long hours of debugging I think that ps3_gelic or gelic_wireless is working correctly. The problem is either Linux Wireless Extension userspace glue or with userspace applications. After all this seems to be problem with 64 bitness and inability of the tools to handle it correctly. I think there might be some hacks on x86-64 to get it working but those are probably not present on Cell (or powerpc arch within Linux kernel).

25 Jun 2007

Some thoughts about realtime buffers

One of the problems I have faced many times before is how can I avoid doing much locking in real time software. This is not an easy task, and failure to do it properly can cause obscure problems. While reading recent Dr. Dobb's Journal issue I though I could write something about on subject, when to use locking and when it can be avoided (or minimized). I will assume that reader has at least some idea why in multi threaded application there should be some locking :)

One of the principles of parallel programming is that if some resource is shared, its access should be synchronized or algorithm should be defined in a way that there are no sharing problems (like one writing to data that is being read elsewhere and incorrect result is being retrieved).

One of the problems with synchronizing access is that it usually needs some locking to be made like in following pseudo code:
read()
lock resource X
tmp = resource X
unlock resource X
return tmp

write(new value)
lock resource X
resource X = new value
unlock resource X

Otherwise fine algorithm, safe to use but in some cases excessive locking can be a problem. If there are lots of read's and write's per second locking is starting to take lots of time and in some applications this is not favorable situation. Problem comes from fact that locking usually needs context switches which is usually quite expensive. One of the possible solutions for multicore (or multiple) processors is to use spinlocks - try to acquire lock multiple times before switching thread to sleep.

One approach is to use algorithms that require lesser amount of locking. Perhaps most classical algorithm is ring buffer. Caveat here is that system must support atomic reading & writing of needed data types used to store buffer status - or otherwise some locking must be implemented in here too. Though the access time can be smaller as lock is needed only for small period of time.

Algorithm proposed in Dr. Dobb's article was called Spin Buffers. Basically it has multiple buffers (minimum of 3) set up as a ring. One buffer can only be owned by one party. Algorithm works like following. When writing new data: put data to current buffer and then if next buffer is free, switch to it for future writes, mark old buffer as free. When reading data, read current read buffer until it is empty, if next buffer is free, switch to it and mark old buffer as free. Reason why this algorithm needs at least 3 buffers is that it tries to always allow reading of written data, and if reader is not fast enough, writer can always write new data to current buffer (until its full). If reading and writing is not balanced it is possible that writer does not have possibility to switch to another buffer until next write is issued. Eg. issue many writes to fill all buffers so it will have to queue items to last buffer (before read buffer), then writer decides to go to sleep for some time. During this time write buffer pointer can't be incremented as it is reserved for writer only. Now reader wakes up and reads all data until there are no free buffers to be consumed, only buffer having data is write buffer and it cannot be accessed as it is reserved for writer. This situation can be unlocked only by waking up writer to switch to next free buffer.

17 Jun 2007

Using Eclipse for GRUB 2 development


As I have been using Eclipse for some time now I decided to give forthcoming Eclipse Europa release a try. Eclipse Europa is still in release candidate state (rc4) but it should be stable enough to be used. Final release of Europa should be within this month.

I am currently using Ubuntu 7.04 for my GRUB 2 development activities so I needed to download GTK+ version of the Europa SDK. I also like to use Sun's Java so I also installed several sun-java6 packages from Ubuntu's package manager. After this, rest was quite easy. Extracted Europa SDK under /opt and gave access rights to my normal user to that directory so I could install additional plug-ins.

After starting up Eclipse I installed CDT 4.0 (C/C++ Development Tools) from Europa repository. All went nicely without an issue. I noticed that they finally added this automatic mirror selection functionality to Eclipse! I have been waiting for this feature for a looooong time.

Setting up a GRUB project was quite easy. First I downloaded up to date version from grub's developer ssh. Then I copied it to under my workspace and created a C project for it. While configuring C project, I noticed that Linux version of the Eclipse doesn't have managed build support at all. Well for this project it is not issue, but would be nice addition in future. I don't really like to play with makefiles or such, sometimes they are necessary evil. After running configure for grub2 all was ready from source for development activities. From Eclipse side, first I configured project settings (seems that they have changed how CDT's preferences looks) and added grub2's include directory to include search path. Then I added make target for building 'all'. I noticed that CVS team synchronization worked out of the box as .cvs folders was present. Tried up team synchronization, needed to add couple of folders and files to ignore to make list of files clean. All seems to be OK, so I tries to build all target. Surprisingly everything seems to work nicely. I event got warnings and errors list populated correctly. Now that those GRUB2's build files would reside on own directory......

Starting up my development blog

I decided to start blogging about my open source and other development activities. In this blog I will tell what I am currently working on and possibly even give some hints and tips. You are free to give comments and perhaps you could event influence what I write here.