Search Results: "dom"

8 February 2006

Uwe Hermann: How to detect and defeat hardware backdoors and wiretaps?

A network card How nice. The FCC wants "a "back door" be built into all Internet-communications hardware and software to provide access for law enforcement agencies". This and similar horror scenarios for the freedom and privacy of the people are nothing unusual these days. A more general (and more paranoid) question: How do we know whether our software or hardware is backdoored/wiretapped? We all know that using a certain OS from Redmond opens a lot of security holes in itself. Add to that all the now-public attempts of agencies and companies ranging from the FBI, NSA, Sony to antivirus-software vendors who install backdoors on your PC, and you've got some very good reasons to never trust any closed-source software again. This is not a problem for most of us using Free Software and free operating systems (Linux, *BSD, etc.). Theoretically, we can read the source code of almost every single instruction being executed on our hardware, and verify that the software doesn't do any funny things like phoning home, logging keystrokes, opening backdoors and so on. However, how can we know whether or not our hardware has been backdoored/wiretapped/trojaned (or whatever you want to call it)? Given that almost all devices we own nowadays (PDA, iPod, cell phone, hardware VOIP phone, and all the other gadgets) as well as most parts of our PCs and laptops have some sort of microcontrollers on them, how can we be sure that there is no secret code hidden in there which spies on us or provides hidden backdoors to them (whoever that may be)? With some devices you can dump the firmware and analyze that, but most parts are probably not easily analyzable by mere mortals. Think network cards, builtin wireless cards, sound cards, bluetooth chips and so on. IMHO, a good first step in the right direction are things like OpenBIOS (Free Software firmware/BIOS) and OpenEZX (Free Software GSM phones). Alas, I think DRM will pose a major threat here in future, as we probably cannot easily replace custom firmware/software anymore if DRM in the worst form becomes reality. So, how would you go about to ensure that your hardware has not been backdoored? How can we detect such things? How can we defend against such things? How can we remove backdoors if we find any? Do you know of any relevant research, papers, documents, HOWTOs? Any cases you know of where such things happened? Any practical tips or advice?

Joe Wreschnig: An Open Letter: Notification of copyright infringement to Abaakouk Mehdi

Update: The Listen website has been temporarily taken down, and Abaakouk Mehdi is in the process of fixing the copyright notices. I am very grateful for this. In my mind, this issue is finished; we’ll soon see a new release of Listen, with intact copyright notices, and everyone wins. Also, so people don’t take my opinion as anything other than solely mine - Eduardo Gonzalez and Michael Urman, the other Quod Libet developers who had their copyrights infringed, have also commented on the issue with slightly different views. (But first second, a brief open letter to people who leave anonymous comments calling me an ass: The only tool free software developers have to defend themselves is their copyright. Copyright infringement is not a “minor problem” but the single largest mistake you can make when writing free software. When you take my work, and strip my name from it, and plasters yours all over it, I have every legal and ethical right to be as pissed about it as I want. I love it when people use my code. I see no reason to love it when people misrepresent my code. Without the ability to pursue copyright infringement, I might as well be writing public domain code, and in that case, I might as well be getting paid for helping software hoarders, and screw you all. Abaakouk screwed up, really badly, but you guys who don’t want me to enforce my license are a real threat to free software.) Dear Abaakouk Mehdi, author of “Listen, just listen,” Your program is ugly. But beyond that, it’s infringing upon my copyright and that of my friends. Your mmkey support, on-screen display, config.py, stock.py, much of your utils.py, and probably more but because I’m already angry enough I’m going to stop looking, is taken directly from my audio player, Quod Libet. Normally, that’s fine. It’s free software. Enjoy the source. You didn’t credit any of our work on the website. That’s fine; it just makes you an asshole, albeit a law-abiding one. But you had to go one step further and rip off most of the copyright notices. You also licensed all the code under “GNU GPL v2 or later”. You can’t do that. Quod Libet’s source is released under the GNU GPL, version 2. My one consolation is your complete incompetence. I mean, it’s really obvious from your screenshots that you ripped off our OSD, and you even left in the horrendous Python style guideline violations that we’ve since fixed. You copied and didn’t use a lot of our utility functions (and you didn’t copy and reimplemented improperly a few others). You left in half my comments, but then translated some docstrings. And to cap it off, you authenticate yourself to leoslyrics.com as auth=QuodLibet. Remove my code from your release, until you can learn how to properly, and legally, credit people.

7 February 2006

Zak B. Elep: Whirlwind < 48h Manila Tour

Heh, its been more than a day now since I got back from Manila after the Ubuntu AsiaBusinessTour, and even then I have some stuff to do here (both IRL and IOL work) before I could find some time to blog ;) Here are the highlights of my trip: I’ve adopted opendchub, rccp, and xshisen from Grzegorz Prokopski too :D Heh, I’ll be quite busy this coming week…

6 February 2006

Lars Wirzenius: Debian: What kind of DPL?

The nomination period for the Debian Project Leader is on again. This means that the Finnish winter is at its worst, and indeed, as I write this, it is -22 degrees Celsius outside. The sun went down about six hours ago; I woke up quite late, so I only saw half the sunset. Back in November, while vacationing, I spent some time thinking about what the role of the DPL is, and now seems a good time to say it. The actual work of developing and maintaining Debian is done by package maintainers, translators, a handful of infrastructure teams or other special purpose teams, bug reporters, and others. It is not the job of the DPL (in their role as DPL) to take charge of the actual development: the DPL is not expected to administer debian.org machines, to fix RC bugs themselves, or to make decisions about release management. Instead, the DPL's job is to help everyone else do those things. If some part of project isn't working well due to resource shortage, or personality conflicts, or other issues, it is ultimately the DPL who needs to facilitate, mediate, or otherwise deal with it. This is not uniquely the DPL's job: any Debian member could step into a situation and help, but the project does need someone whose job it is to do that if no-one else will or succeeds. Another important job of the leader (again not uniquely) is to provide inspiration. Our leaders in the past few years have provided fairly little of that. I would like us to have a DPL that inspires the project into setting and achieving goals that make us happy and make Debian the best operating system ever. The important thing is to inspire, not to force, cajole, or otherwise unilaterally decide. Not quite sure now how that should happen. Perhaps the Finnish military saying that "leading is best done at the front" is applicable: an inspiring DPL is one who by his own work, and his own behavior, shows by example what a good, productive member of the Debian development community is like. A third important job of the leader is to be the project's public face to the rest of humanity. Again, not uniquely, we have other members who are often prominently in the public eye, such as release managers or security people, but the DPL is the main such public face. And finally, the fourth important job of the leader is to do the tasks assigned to him in the Debian Constitution. These are not daily tasks, but they're important, and these, at least, are uniquely the DPL's domain.

Enrico Zini: Italian screen reading

So far, it has been a fairly happy hacking day. I wanted to see how far I could go to make a Linux desktop accessible for the blind. Platform of choice is Breezy because:
  • it uses gnome, which is the most accessible stuff at the moment;
  • it's the distribution with the least amount of raw edges at the moment;
  • its gnome accessibility stuff is more up to date than the stuff in sid (I got in touch with Mario Lang and I'll see if I can help)
Step number 1: installing a fully working Breezy chroot inside my sid
  1. lvcreate -L2G -n breezy vg
  2. mkfs.jfs /dev/vg/breezy
  3. mount /dev/vg/breezy /chroot/breezy
  4. debootstrap --arch i386 breezy /chroot/breezy http://archive.ubuntu.com/ubuntu/
  5. chroot /chroot/breezy
  6. dpkg-reconfigure locales
  7. tzconfig
  8. base-config new
  9. fixed gdm configuration to work along with the sid X server
  10. fixed /etc/fstab, resolv.conf and /etc/hosts
  11. reduced the lart-delay of /etc/rcS.d/S04udev from 60 to 5 seconds
  12. "booted" the Breezy system running /etc/rcS and /etc/rc 2
Believe it or not, it works. I have another gdm login screen, I login and I hear the Ubuntu startup music. A couple of warnings about ACPI and HAL not working... well, I can imagine why. gnome-panel would refuse to show the menus. It turned out to be connected to Gnome bug #323064 (debian bug #338438) and I found out that Alt+F2 (run) and then killall gam_server would be enough to stay displayed.
Step number 2: getting the screen reader to work Note: the menu names might be incorrect as my system is localised in Italian and I'm now translating back to English.
  1. Install gnopernicus
  2. Go into Desktop/Preferences/Audio and disable the sound server
  3. Go into Desktop/Preferences/Assistive technology, enable assistive technology and screen reader
  4. Logout and in again
Now, coolness ubercoolness, the desktop starts to speak with the voice of a depressed 40 years old dude from the USA. Thanks to Luke Yelavich of ubuntu-accessibility for supporting me and for explaining me that if esd is running then the voice tends to disappear because esd steals the sound device to festival. He also explained me that if one tries to run festival through esd then it works, but since esd is a mixer then one starts hearing various voices for different events all mixed together. Now, the English speech engine often mentions the "barra dei sacramenti". In local Italian it means "toolbar for blaspheme curses". Time to move on to step 3.
Step number 3: getting the screen reader to work in Italian I'm very proud of the Italian speech engine that recently entered Debian thanks to Riccardo Vestrini and the Debian Italian Maintainers Task Force, I've already put it to good use in the past and have great plans about it for the future. It's now a good moment to turn the knowledge previously acquired with creative timewasting into something serious. So, on to work:
  1. get the italian festival voice packages from sid (the packages are festlex-ifd, festvox-itapc16k and festvox-italp16k)
  2. install them all in Breezy
  3. sudo patch /usr/share/festival/languages.scm /usr/share/doc/festlex-ifd/languages.scm.patch (and ping again Matthias Urlichs for a fix for bug#335845)
  4. log out
  5. kill all the festival servers, drivers and whatnot (need to do it when logged out, but one can just install the voices before starting gnopernicus for the first time)
  6. log in again
  7. go into gnopernicus configuration and select the new voices.
It SO WORKS! I configured some voices a bit at random, so now according to what I do the desktop speaks like the depressed dude, Adriano Celentano or the Italian dubbing of the Enterprise computer (without reverb effect). An extra cool unexpected side effect of this chroot setup is that now I can go back to my Sid X session and the Breezy X session will keep talking in the background, so I can even keep an ear on what happens in the other Virtual Console. Now, on to the applications. The menus, work. Abiword works, but I couldn't find out how to read the things I type on the editing area (not so useful until that one is solved). OpenOffice2 does not work. Firefox 1.5 works. gnome-terminal works. gedit works. It could be better, but I was fearing much worse. Now, gnopernicus has various powerful features accessible using the numeric keypad, but I haven't found a way to activate them in my laptop. It may be that with the keypad functions abiword becomes readable. I'm quite satisfied today.

5 February 2006

Andreas Metzler: clueless

I am pretty sure this cluelessness at its best:
m26s25:~# swaks -s spam-is-theft.sput.nl. -f'<>' -t rob@sput.nl -q rcpt
[...]
-> RCPT TO:<rob@sput.nl>
<** 550 Host name is listed in abuse.rfc-ignorant.org. Get yourself another ISP.
According to the web interface the host 83.151.30.59 is definitely not listed on abuse.rfc-ignorant.org. Anyway, should you read this, the answer to your question is: It has been reported before bug 326160 and is suppposed to be documented (although I fail to parse right now, due to being slightly tired) perhaps unknown_in_list should be added to log_selector. Just finished reading: Jane Austen's Pride and Prejudice which was a pleasure to me.

Andreas Metzler: exim4.conf for *.debian.org II

Following up on the previous entry I have now got a exim4.conf that has survived basic testing. I have checked exim4 -bt for all major routers and found and fixed a fair number of bugs in the initial version. Any further changes I would (like to) make would result in different behavior than the current exim v3 setup, so I am not wasting time on that until somebody from debian-admin says they want me to. Conservative suggestions include copying the "deny local_parts = funky characters" settings from the default configuration, disabling domain-literals (or at least accepting only incoming postmaster@[local.ip] instead of only outgoing), and perhaps recipient verification.

Adam Rosi-Kessel: Pit Bulls and Profiling

Malcolm Gladwell· (probably best known as the pop-sociologist author of The Tipping Point·) has an excellent piece in this week’s New Yorker· on what pit bulls can teach us about profiling·. The argument boils down to one about common tendencies in misinterpreting data and drawing the wrong (or “unstable”) generalizations from apparently recurrent phenomena. Everyone’s favorite security guru Bruce Schneier· has made similar arguments in the past·, but Gladwell’s style in this case is more compelling. I particularly liked this passage about The Godfather:
In July of last year, following the transit bombings in London, the New York City Police Department announced that it would send officers into the subways to conduct random searches of passengers’ bags. On the face of it, doing random searches in the hunt for terrorists — as opposed to being guided by generalizations — seems like a silly idea. As a columnist in New York wrote at the time, “Not just ‘most’ but nearly every jihadi who has attacked a Western European or American target is a young Arab or Pakistani man. In other words, you can predict with a fair degree of certainty what an Al Qaeda terrorist looks like. Just as we have always known what Mafiosi look like — even as we understand that only an infinitesimal fraction of Italian-Americans are members of the mob.” But wait: do we really know what mafiosi look like? In “The Godfather,” where most of us get our knowledge of the Mafia, the male members of the Corleone family were played by Marlon Brando, who was of Irish and French ancestry, James Caan, who is Jewish, and two Italian-Americans, Al Pacino and John Cazale. To go by “The Godfather,” mafiosi look like white men of European descent, which, as generalizations go, isn’t terribly helpful. Figuring out what an Islamic terrorist looks like isn’t any easier. Muslims are not like the Amish: they don’t come dressed in identifiable costumes. And they don’t look like basketball players; they don’t come in predictable shapes and sizes. Islam is a religion that spans the globe.

Jesus Climent: The right to critizise.

I can't agree more with Per-Arne Hellarvik. Globalization is making this whole thing of personal offenses a ridiculous thing: for every sentence I write in my blog, which might reach every corner in this planet, someone, somewhere, might feel offended. As I have stated before, it offends me that my life is affected everyday in many ways by people's believes in god(s). Yet I don't go around burning churches and killing the offenders. Note to anyone offended by this post: live your life, that I will take care of living mine. PS: Demonstrators in London claimed: "The government must control the media". I thoght one of the purposes of the media was to keep the government under control. And interestingly enough, the countries dubbed as offenders are listed on top of the countries with more freedom of speach in press, while Syria is 145.

4 February 2006

Per-Arne Hellarvik: The burning of an embassy.

Tonight I find myself regretting to be openminded about religion and believes.
Islamic followers has burned the Danish and the Norwegian embassy in Syriah.
This seems to me like a direct treath to my way of thinking and the single most important right I as a human beeing have: The freedom of speech. You might say that even though you have freedom of speech you cannot harras people and their believes. This is not true, I can and I will speak up against any form of belief or religion which underminds my rights as a human to ridicule religions which are oppressing other humans and are decreasing my right to choose whichever religion I'm to follow.

As some demonstrants stated to the media in London: "The government must control the media".
And haven't we "non-believers" been called "sons of whores", dogs and pigs from the same people which demands respect?

This is _not_ right, this is madness........

2 February 2006

Kevin Rosenberg: Encrypted Root Filesystem Revisited

The hard disk on my notebook computer developed a number of bad sectors so I replaced it with a new 7200rpm 100GB drive. I've discussed my experience and gave details about using an encrypted root and LVM filesystem using the Linux 2.6 device mapper. While I found the disk speed acceptable using the encrypted filesystem, I did note that it was subjectively slower than using an unencrypted filesystem. This time, I used the bonnie++ disk benchmark to test the new disk. Raw disk benchmark
       ------Sequential Output------ --Sequential Input- --Random-
        -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
  Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
    4G 30299  98 47348  13 20552   6 29947  91 44758   5 137.3   0
       ------Sequential Create------ --------Random Create--------
        -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
  files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
     16  3545  21 +++++ +++  3863  42  3350  20 +++++ +++   867   6
Encrypted disk benchmark
       ------Sequential Output------ --Sequential Input- --Random-
        -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
   Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
     4G 18861  60 40812   9 10534   2 18530  58 30641   4 143.6   0
       ------Sequential Create------ --------Random Create--------
        -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
  files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
     16  3150  87 +++++ +++  3510  92  2919  86 +++++ +++   900  35
While there is an overhead using the encrypted file system (which is likely magnified by using a 4-year old CPU, a 2GHz Pentium 4-M), the overall speed with the 7200rpm drive is acceptable and will be a boost compared to the old 5400rpm drive. While my notebook previously ran Debian Sarge, I thought I'd try something slightly different, the Debian offshoot Ubuntu Breezy. I found a few issues that had to be resolved to use the encrypted filesystems. After those bits of additional configuration, the encrypted root filesystem and encrypted LVM physical volume is working very well. Additionally, I'm using an encrypted swap partition, but there was no additional configuration required beyond what I previously described.

1 February 2006

Jos Parrella: auto-eject-cdrom 0.3

Today my boss asked me for a method to clearly umount and afterwards eject a CDROM media on the event of trying to eject the tray using the drive button. I googled around a bit and found auto-eject-cdrom, in the public domain, and originally written by Jens Axboe, from SuSe, and Peter Willis, in 2001 and 2005 respectively. The problem with this little application is that it was unable to eject both my boss drive and mine. It did umount the filesystem but did not eject the tray. So I dig into the code and found that it used plain, old cdrom events, handled by the cdrom kernel module. The event was, in fact, defined in <linux/cdrom.h> as:
#define CDROMEJECT 0×5309 /* Ejects the cdrom media */ I found out that using system (”eject”); as my quick and dirty solution after the umount was working ok, but I was losing performance because eject is used for ejecting floppy disks, tapes and several other media. In fact, eject can figure out which media is he working with so he selects the proper method of ejecting, but I was bitten by the curiosity. So I implemented both the cdrom commands and the SCSI commands for ejecting the tray, in two functions, copypasted from the eject.c, previously apt-get source‘ed and I’m putting this interesting piece of code to the public domain (most likely it should go with a GPL license, since I used GPL’ed code on it) here: auto-eject-cdrom v0.3. A relevant and important piece of code goes now:
        /* Here I use two different methods for ejecting the CDROM. This is for fun only,
           since I could use system(\"eject\"); but this is the dirty hack. Here I use the only
           two CDROM-related eject functions from the eject.c file of the eject program
           by Jeff Tranter (tranter@pobox.com) - Note by Jose Parrella  */
Installing is just a matter of compiling and copying to /usr/local/sbin and running it as auto-eject-cdrom &. I hope it’s useful for those of you who can not afford to use one of the keys of your keyboard to assign the eject command to it. Enjoy!

31 January 2006

Wouter Verhelst: nbd-tester-client

Prompted by #350357, I did something I've planned to do a long time already, but had so, so far, failed to do: I wrote an nbd-tester-client. All it does currently is a sequential read of the entire block device, but it's written in such a manner that it should be easy to add additional tests—say, random reads, or write-read-verify cycles. Not that I actually needed such an application to identify and fix the bug (which boils down to a forgotten return 0 somewhere halfway the code; upload on the way), but it's a good thing none the less. It even pointed out one problem with nbd-server: that it will do write() calls without select, thus allowing for a deadlock if both the client and the server have a full write queue. I'll fix that for NBD 2.9 (might be too intrusive for 2.8, and I'm not sure whether the kernel actually writes without waiting for its write queue to be emptied). The code is in CVS HEAD, if you want it.

Axel Beckert: Can the spam problem be solved?

Many have tried to solve spam problem, even Micrsoft (with a quite strange solution ;-), but except personal solutions like well working and well-kept spam filters, no well-working general technical solution has been found yet. Although I really would like to see a technical solution and often think about this problem, I currently believe that this primarily is a social problem which cannot be solved solely with technic. UserFriendly’s Erwin seems to see it the same way and proposed today a quite drastical solution. There are good ideas out there (e.g. SPF, RBL, Greylisting and Teergrubing), but all seem to have their problems, too. Especially RBL often have administrative problems, i.e. if an entry is justified or not. Greylisting simply can be bypassed by being SMTP conform and trying again, so it’s usefulness will decrease permanently. And against Lutz Donnerhacke’s teergrubing, spammers seem to have found workarounds quite quickly. Haven’t heard much about it in the last years. (I just can’t remember what the drawback of SPF was.) For myself I’ve solved the spam problem with a learning SpamAssassin and sorting mail by spam-level into several mailboxes. The higher the spam-level of such an inbox, the more seldom I look into it. Works fine. For me. No general solution though, since the SpamAssassin needs to be fed with fresh spam regularly.

Joey Hess: random tip: redirecting alsa to usb sound card

This took a bit too much work to figure out so here it is. If you're like me and had to buy a usb sound card (nearly as sensible a name as a cable modem) since the laptop's onboard headphone jack broke, and would like to have that card used by default when it's plugged in, but otherwise have builtin card be used, create an /etc/udev/rules.d/00_local.rules containing:
# Default to using additional (USB) sound cards when they are available.
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$$ K#pcmC ; K=$$ K%%D* ; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"
Only programs started after the sound card is plugged in will use it of course, and this might not work if you have it plugged in while booting.

30 January 2006

Antti-Juhani Kaijanaho: Counting lines

Insipired by Daniel Burrows’ tests, I decided to do mine. The object is to come up with a Haskell program that performs the job of wc -l as efficiently as possible. My test material is a randomly generated file with all lines less than 80 characters long. Summary: my final idiomatic version is twice as slow as wc -l, and my final nonidiomatic version is as fast as wc -l, or at least within the margin of error. First, the baseline:
$ time wc -l testfile
7798137 testfile
real    0m12.127s
user    0m0.765s
sys     0m0.399s
Then the most idiomatic program. Honestly, I expect it to suck performance-wise:
main = getContents >>= print . length . lines
And it does:
$ time ./wcl1.hs < testfile
7798137
real    1m14.993s
user    0m54.182s
sys     0m0.573s
But only by a factor of six. My first hypothesis is that garbage collection is the culprit. And, indeed:
$ time ./wcl1.hs +RTS -sstderr -RTS < testfile
./wcl1.hs +RTS -sstderr
7798137
25,236,174,340 bytes allocated in the heap
5,070,193,924 bytes copied during GC
117,484 bytes maximum residency (3750 sample(s))
96274 collections in generation 0 ( 26.36s)
3750 collections in generation 1 (  0.74s)
2 Mb total memory in use
INIT  time    0.00s  (  0.00s elapsed)
MUT   time   27.17s  ( 42.72s elapsed)
GC    time   27.10s  ( 33.72s elapsed)
EXIT  time    0.00s  (  0.00s elapsed)
Total time   54.27s  ( 76.44s elapsed)
%GC time      49.9%  (44.1% elapsed)
Alloc rate    928,824,966 bytes per MUT second
Productivity  50.1% of total user, 35.5% of total elapsed
real    1m16.616s
user    0m54.278s
sys     0m0.700s
As you can see, GC takes half of the processing time. Unfortunately, minimizing GC time does not have as big an effect as I hoped:
$ time ./wcl1.hs +RTS -H100M  -RTS  < testfile
7798137
real    1m1.354s
user    0m44.371s
sys     0m1.171s
Here, I’m effectively telling it to use a 100-megabyte heap. A separate GC profiling run tells me that GC time has dropped from 50 % to 1 %. The memory problem seems to be a red herring. What we’re doing here is creating four separately allocated memory cells for each character in the input. Of course, the cells are generated lazily, that is, a cell pair is allocated when the lines function demands another character; it then creates another cell pair to denote the same character in a list of lines. As soon as each line has been counted, the four cells become garbage. This sounds like a lot of work! But apparently it isn’t; I tried a few variations that did away with the stream of input altogether, not much unlike what Daniel did in his tests. Surprisingly, the performance worsened a lot. The lesson: functional programming language implementations, unlike typical imperative ones, are built on the assumption that you’ll be doing a lot of allocation. What I suspect is taking a lot of the time is arithmetic. Haskell’s Int is boxed, and lazy by default, adding a lot of overhead. I hand-fused length and line, yielding a tail-recursive countLines function, and I added the command-line switch -funbox-strict-fields, which enables a few significant optimizations of the laziness of Int. The results were nice:
ajk@kukkamaljakko:~/scratch$ cat wcl4.hs
module Main (main) where
main :: IO ()
main = getContents >>= print . countLines 0
countLines :: Int -> String -> Int
countLines n ('n':r) = countLines (n + 1) r
countLines n (_:r) = countLines n r
countLines n [] = n
ajk@kukkamaljakko:~/scratch$ ghc -O -Wall -funbox-strict-fields --make wcl4.hs -o wcl4
Chasing modules from: wcl4.hs
Compiling Main             ( wcl4.hs, wcl4.o )
Linking ...
ajk@kukkamaljakko:~/scratch$ time ./wcl4 < testfile
7798137
real    0m37.961s
user    0m29.853s
sys     0m0.495s
ajk@kukkamaljakko:~/scratch$ time ./wcl4 +RTS -H100M < testfile
7798137
real    0m25.153s
user    0m13.497s
sys     0m0.803s
ajk@kukkamaljakko:~/scratch$
With a large heap, the program is only twice as slow as the baseline. This is pretty good, considering that the code is still idiomatically functional. The following rather ugly, imperative program does away with the lazy stream and carefully avoids any laziness without doing any too dirty tricks:
ajk@kukkamaljakko:~/scratch$ cat wcl7.hs
module Main (main) where
import Data.Word
import Data.Array.IO
import IO (stdin)
count :: Int -> (Int, Int) -> IOUArray Int Word8 -> IO Int
count 0 _ _   False = undefined -- force ac evaluation
count ac (l,u) _   l > u = return ac
count ac (l,u) ar
    = do a < - readArray ar l
         let ac' = case a of 10 -> ac + 1
                             _  -> ac
         count ac’ (l+1, u) ar
maxn :: Int
maxn = 4096
main :: IO ()
main = do
  arr < - newArray (0,maxn) 0
  let loop :: Int -> IO Int
      loop acc = do n < - hGetArray stdin arr maxn
                    if n == 0
                       then return acc
                       else do acc' <- count acc (0,n) arr
                               loop acc'
  res <- loop 0
  print res
ajk@kukkamaljakko:~/scratch$ ghc -O  -Wall -funbox-strict-fields --make wcl7.hs -o wcl7
Chasing modules from: wcl7.hs
Compiling Main             ( wcl7.hs, wcl7.o )
Linking ...
ajk@kukkamaljakko:~/scratch$ time ./wcl7 < testfile
7798137
real    0m13.431s
user    0m10.342s
sys     0m0.467s
Of course, this program is not Haskell 98, but the nonstandard things it uses are fairly common. As can be seen, this version’s performance is, considering the margin of error, equal to the baseline. The compiler used in this test is The Glorious Glasgow Haskell Compilation System, version 6.4.1, as packaged in Debian sid.

Daniel Burrows: How much speed are you willing to give up for pretty code?

After experimenting a bit with Haskell and using it for some toy projects, I decided to see if there was any chance it could be used for a non-toy task; i.e., one where it might one day be necessary to actually have fast code. As a proxy for this, I decided to try a very simple task: counting the number of lines in a file. As input, I generated a file with a million lines of random data and an average of 40 bytes per line; all the Haskell programs were compiled with the current GHC in Debian unstable and with optimizations enabled.

The baseline is, of course, our friend "wc":

real    0m0.084s
user 0m0.043s
sys 0m0.040s


(this and all other timing data was taken after "cat /tmp/testwc.txt > /dev/null" to ensure that the file was cached) Now, it's probably too much to hope that a Haskell program will run as fast as a C program does, since the C program can run in a tight loop. But it seems reasonable that it should be possible for Haskell to be competitive with the trivial Python implementation of this program -- after all, Python is interpreted and Haskell is compiled.

import sys
n = 0
for line in sys.stdin:
n += 1
print n


Running this simple Python program under "time" produces the following statistics, a bit less than 10 times slower than the C version:

real    0m0.698s
user 0m0.643s
sys 0m0.050s


The trivial Haskell program to count the lines of its input is:

main = do c <- getContents ; print $ length $ lines c


Note that this is basically identical to the Python program, but expressed in a functional style. Pretty, but how does it stack up?

real    0m6.744s
user 0m6.426s
sys 0m0.213s


OW! Ten times slower than the Python code, and a good 80 times faster than "wc"! The gap can be lowered to "only" 50 times with the following program --

do c <- getContents; print $ length $ elemIndices '\n' c


-- but surely it's possible to do better. I'd expect that the expense here is in the use of lazy streams for IO; eliminating them gives us the following code:

wc :: Handle -> IO Int
wc h = do a <- mallocArray bufSize :: IO (Ptr Word8)
loop a 0
where loop a n = do amt <- hGetBuf h a bufSize
elts <- peekArray amt a
(if amt == 0
then return n
else loop a $! n + nlCount elts)


At this point, we're basically using Haskell as a (bad) imperative language. This function allocates a buffer, repeatedly reads into it, and counts the number of newlines in the buffer (I dropped some auxillary code to keep the post short). The $! is important; without it, even though this routine is tail-recursive, Haskell will still allocate an unbounded amount of memory to store the return value. (because, of course, it's terribly important to remember that you're actually returning "1+2+3", not "6")

So, how does this unreadable, hand-optimized version of the code perform?

real    0m1.980s
user 0m1.757s
sys 0m0.094s


That's right -- I've eliminated most uses of higher-level functional techniques, and the Haskell version is still two times slower than an ultra-high-level interpreted language, while also being uglier and harder to read! Ouch. It appears the old performance albatross of functional languages is not quite dead yet.

28 January 2006

Holger Levsen: Kernel 2.4 for etch or not

This is a blog entry I wanted to write for about six weeks now, but I was busy with other stuff. In December 2005 I got curious why 2.4.32 wasn't packaged for Debian and investigated the situation a bit.

There are several reasons why 2.4 is still interesting:

- Kernel 2.6 is still a moving target...

- Some hardware is only supported with 2.4, for example older laptops which need APM and don't work with ACPI. Also some non-i386 machines.

- According to popcon, 6-7% of the i386 users have a kernel-2.4 image installed.

Unfortunatly, nobody from the kernel team is really interested in working on 2.4 anymore. They do security fixes for the 2.4 kernels in woody and sarge, for which I'm very thankful, but that's about it.

Even though 2.4 is moving very slowly nowadays (mostly security updates, very seldom new drivers are including), this is more work than needed, because every fix needs to be backported to 2.4.27 (and 2.4.18 for woody).

Of course there are some issues which need to be taken into consideration when thinking about whether it's worthwhile to have 2.4.3x in Etch:

- it needs gcc-3.3 to compile, gcc-4.0 won't work. Period. So gcc-3.4 also needs to supported during etch's lifetime - which will be something like 2009 when etch+1 will become oldstable (by current release cycles)...

- it's not sensible to have powerpc and amd64 flavors, and probably others. So this kernel package will not be arch any. (Which is not really a problem, but unusual.)

- Both kernel 2.4 and 2.6 contain non-free firmware and drivers. I seriously doubt people want to deal with this issue and solve it for 2.4. For 2.6 it will be done, but for 2.4 ? As I see it, this is the biggest showstopper for 2.4 in etch, I would be happy to be proven wrong. As a starting point, you can look at this investigation by Bill Allombert about the the situation in 2.4.25.

Removing those files would be an option, but maybe we can also "borrow a better solution" from 2.6...?!

- if 2.4.32 or .33 shall be used in d-i/g-i, work on this integration needs to be started real soon now.

I have done some work on creating a linux-2.4.32 package which is based on the new kernel packaging. I got busy with videos for debconf-es2, so I didn't finish and commit this.

Horms made a presentation about the kernel packaging in debian for LCA and gave two options: a.) support and backport fixes for 2.4.27 or b.) go with 2.4.32. Somehow he did not consider the option of dropping 2.4 even if he calls it legacy ;-)

Besides technical reasons (security fixes handled by upstream, some driver updates and very few new ones) I think we should not forget that most people have no idea that 2.4.27 in debian is far closer to 2.4.32 than to .27, and therefore will think debian ships an outdated 2.4 kernel. So I think we should simply go for 2.4.3x, if it is sensible to support 2.4 in etch at all.

It "just" needs to be done, and I volunteer to do it (with the help of the kernel team, the porters and anybody else who wants to join), if this work will not be in vain.

Please send comments to the debian-kernel-mailinglist, where I posted this blog entry before. Thanks.

Uwe Hermann: Al Gore Speech on Unlawful Wiretapping, Imprisonment, and Torture by US President Bush

Al Gore Al Gore, former vice president of the US, has given a very, very interesting and impressing speech on Martin Luther King Day a few days ago. He states very clearly a huge number of (unlawful, illegal, or immoral) things the current US president Bush and/or his administration have done. For example: A quote of Al Gore, from a small Reuters summary of the speech:
We still have much to learn about the NSA's domestic surveillance. What we do know about this pervasive wiretapping virtually compels the conclusion that the president of the United States has been breaking the law repeatedly and insistently.
Transscripts are available from The Raw Story and the Washington Post, and there's also a full audio recording of the speech (MP3, 48 MB). Although I'm not very political usually (or at least I don't write too much about it), this is really something I highly recommend listening to. I cannot imagine why a president of a democratic country can still be in charge, after all these things have become publically known... (via Tim Pritlove)

Gunnar Wolf: Frustration comes on ISO/OSI layer 2 (or: On one of the ways 3Com sucks)

Over one month ago, I truly hoped an evasive network misbehavior issue was solved. In the institute, we had a strange situation which caused a (seemingly random) stack of switches to go out to lunch and leave one of the floors without network access until it decided to restore itself (usually power-cycling it was not enough). The equipment, ten 4200 SuperStack switches, is new, we got it ~September, so I expected 3Com to give me at least some support on the issue. The behavior was apparently random, and I could not track it down, only (thanks to the very nice Cacti) prove it existed.
December 5 was terrible. The whole building's network refused to work. Switches were able to reply to my pings for no more than a minute after booting before they got flooded with "Spanning Tree CTRL MAC PAUSE: Quanta 65535" (according to another great tool, the Ethereal protocol analyzer).
I had been bugging the support people at 3Com for at least three weeks before this incident, they kept promising they would come soon to help us track the cause of the ellusive problem - We threatened to send the switches back and pursue reimbursement through whatever means we could (we had much better stability and performance with our old 10Mbps hubs, so my boss insisted on replacing them), so we got them to come. The answer they gave me? Upgrade your firmware to version 2.50 (not available at their website, of course) and disable spanning tree functionality at the switches.
I have to admit the big problem immediately ceased. This is not to say I was pleased with the response time or with the switches' software quality, but at least we could work.
Happily, ~7 weeks passed by with no major outages (although with a few small ones).
Yesterday, we got back the complete chaotic conditions. This time, though, I was able to get a good and useful tcpdump snapshot, passed it through Ethereal, and actually got something interesting (available to whoever requests it to me if it sounds interesting). In short: Something happens that confuses a switch (I guess it's a faulty NIC), and makes it request to all of the neighbouring switches (via spanning tree protocol - Yes, it's disabled, but still) for their complete ARP tables. But somehow, this noise or whatever keeps confusing it, so the spanning tree requests start repeating every two seconds for slightly over one minute. Then, the same switch which requested this information gets tired of too many ARP tables being thrown at it, and sends out a storm of packets (one each 0.04 seconds) asking every other switch _not_ to send updates anymore. This is broadcasted to all of each of the switches' ports, and the network dies.
My grudge against 3Com is: How come this frigging noise (at least that's what I assume it to be) on one of the ports kill all of the network? If a switch is supposed to be smart, would it be too much for it just to disable the misbehaving port?
Anyway... One and a half days went down the drain trying to find the cause for the problem, sending the report to the 3Com guy (who is very nice in person, yes, but that's by far not enough!), running up and down the stairs to reset different switches, lock down on the source of distress... And as my 3Com contact was busy with another client (who presumably had not yet given them money), I never got a call back from them.
All my good intentions to spend a nice quiet time coding for three projects we currently need to have ready soon (one of them is in production and many of you have used, my dear Comas conference management system, but requires heavy tinkering to be able to extend it) were stuck at that: Good intentions.
I seem to have locked down the problem in one of three computers (that is, network seems stable again once I disconnected them). I insist it must be a faulty NIC. My boss bets it's an ber-contaminated Windows machine. My boss' boss insists we should get the switches double-grounded just to be sure that's not the reason for failure. I am tired, bad mooded, and -again- bored you to death with a too-long blog entry.
Blame it all on 3Com.

Next.

Previous.