Friday, June 08, 2007

Worse is worse

Last week I presented my work on the ZeroBUGS debugger at Amazon.com. I started my talk by saying that the debugging support in Linux is in line with the worse is better principle: the building blocks are rudimentary for the sake of keeping the implementation simple.

For example, there is no native BreakpointEvent notification. Rather, the debugger implementer needs to keep track of all breakpoints; if a SIGTRAP occurs at the address where an active breakpoint exists, then it is most likely because the said breakpoint was hit.

Another solution is to use PTRACE_GETSIGINFO (available since kernel 2.3.99) and inspect the siginfo_t structure:

struct siginfo_t {
int si_signo; /* Signal number */
int si_errno; /* An errno value */
int si_code; /* Signal code */
pid_t si_pid; /* Sending process ID */
uid_t si_uid; /* Real user ID of sending process */
int si_status; /* Exit value or signal */
clock_t si_utime; /* User time consumed */
clock_t si_stime; /* System time consumed */
sigval_t si_value; /* Signal value */
int si_int; /* POSIX.1b signal */
void *si_ptr; /* POSIX.1b signal */
void *si_addr; /* Memory location which caused fault */
int si_band; /* Band event */
int si_fd; /* File descriptor */
}


For a SIGTRAP signal, the si_code field may be TRAP_BRKPT, in which case we know that the program hit a breakpoint.

At any rate, it is up to the debugger application to create higher-level abstractions, based on signals and ptrace notifications.

Linux is not the easiest nor most pleasant system to program on, but the implementation is so simple a child could understand it. Ahem.


Thursday, May 24, 2007

Oops. I Did It Again

Yesterday I spoke at the Northwest C++ Users Group, presenting my work on the ZeroBUGS Debugger for Linux. This in itself isn't that remarkable (I basically reused the presentation I did at Google's Kirkland offices back in March and spiced it up with some humor and C++ code).

I projected my slides off a Powerbook. Not so remarkable either, even considering that the topic was a Linux-based project.

The Northwest C++ Users Group meetings are currently hosted by Microsoft. So I did a Linux gig in the Lion's lair, and I lived to talk about it. Pleasantly remarkable.

Sunday, April 15, 2007

Mini Me

I turned one year older since my last blog entry. I usually get depressed at this time of the year (a trend that begun the day I turned thirty).

But this time around it is different: my birthday came with a fresh feeling of renewal, brought by newborn son, Nick.

There's always hope when version 2.0 comes out.

Tuesday, April 03, 2007

Limericks

There was a lady from Bombay
Her breasts looked as if made of clay.
She was short and hairy
And her brow was scary.
But otherwise she was okay.


There was a beast on Noah's Ark
Whose testes glowed red in the dark.
The species is now long extinct:
Such trait (although distinct)
Makes for great a hunter's mark.


There was a guy from Romania,
Who had a limerick mania...

Darn!

Thursday, March 22, 2007

How Do I Bake a Cake Shaped Like the Internet?


When I first saw this xkcd cartoon I did not get it at all. I fancy myself as an independent thinker more than a corporate pawn.

But today I gave a tech talk on debugger architecture at Google's Kirkland office. The experience was... how should I describe it? I arrived there, and had my ten-year old Camry valet parked. Then, my host took me to lunch (to the Google cafeteria). I avoided filling my plate because I imagined that in between him and I, someone was going to pay for it. Darn, Jeez Gosh! Nobody warned me that they do get free lunches over there! And pretty yummy too.

And people arrived on time, were very polite, the logistics worked flawlessly, and nobody made me feel like being surrounded by Super Humans. I even had the fine pleasure of seeing familiar faces from my old Amazon days!

XKCD dude, I see your point. Now: how do you bake that Internet-shaped cake?

Sunday, March 11, 2007

Keep it Cool

Last week I fixed some breakpoint management logic in my debugger for Linux, and also reduced the memory footprint for debug symbols and stuff.

Walter Bright is fixing his D compiler back end for Linux, so now the DWARF source line info appears to be almost correct. Once complete, these fixes will mark a huge milestone for debugging D on Linux. And then I will have no excuses left for not adding more D support in ZeroBUGS... oh wait: Our first baby is due on April 5th.

At any rate, I believe future historians will categorize this dawn of the computer's era into BC ("before C"), BC++, and AD ("after D").

But speaking of babies. My wife and I are taking all kinds of classes these days, related to car seat safety, childbirth, feeding, etc. Aside from learning more about female anatomy than I ever cared to know, I also decided that:

  • When I am done with computers I will seek a career as lactation consultant, and

  • those drawings of aliens with huge heads on very thin, wiry bodies are bull, unless alien women have no pelvic bone

  • I have also concluded that all what is holding back the human race is that darned pelvic bone. That's why we can't get bigger brains, and get smarter about war and peace, and the meaning of life.

    A friend of mine argues that size is irrelevant, since the existing neurons could become more efficient by developing more connexions. I believe that there's a problem with developing more synapses: there will be lots of interference in our heads, resulting in loss of focus and did you see the latest xkcd comics? Oops, my neuron miss fired.

    So we need bigger heads, but the hole is not getting any bigger. But there's hope. Soon, with the help of brain-computer interface technologies we will overcome our limitations with more RAM from Radio Shack.

    And that will change how we feel. The purpose of emotions, from an evolutionary point of view, is the same as for database indexing. Can you imagine our ancestors out there in Africa, with a very slow and small memory, performing a linear search: I wonder... I have seen this big cat 'round here before, if only I could 'member what did I do the last time? ... oh wait! of course! I ran for my life!

    So we have developed emotions which act as a big red tab in the thick book of memories: adrenaline kicks in, and the monkey is thumbing its nose to the lion (from a safe distance).

    But with a brain connected to fast memory, and maybe with some additional CPU power and decision-making software thrown in the mix, I could weasel my way out of almost any difficult situation, while keeping my cool.

    Tuesday, February 20, 2007

    Debugger Breakpoints

    An overview of breakpoints, as implemented in the ZeroBugs debugger for Linux.

    Breakpoints are central to the ZeroBugs debugger engine layer. Breakpoints can be set by the user, or by the debugger for internal purposes (such as detecting the creation of new threads).

    Physical vs. Logical


    Breakpoints can be classified in several ways. One categorization distinguishes between "logical breakpoints" and "physical breakpoints". What this means is that not all the breakpoints that you have inserted in the program are physically there, but the debugger will support the illusion that they are; reality is the realm of physical breakpoints, and logic is derived off perception. So if you perceive a breakpoint as being inserted in the debugged process, it is logically there, even though, physically, the debuggee has not been affected.

    Let's consider a couple of examples, to help bring the discussion out of the philosophical realm:

    1. The user inserts a breakpoint at the beginning of a function that is not loaded into memory yet, because it lives in a shared library that has not been mapped into the debugge's memory space (just yet). The debugger nicely shields the user from knowing such details, and may say: "OK. I don't know what the address in memory of function `abc' is; but I know that it is implemented inside the dynamic library libabc.so; I will keep this in mind, so that if I later detect that libabc.so is loded, I will insert the breakpoint. "



    2. Another case may be that the debugger has inserted a breakpoint at the beginning of the pthread_create() function, to internally keep track of newly created threads. The user wants to insert a breakpoint at the same address, and does not need to know that a physical breakpoint is already there. The debugger associates two logical actions with the same physical breakpoint: one that internally updates the list of debugged threads, and another one that initiates an interaction with the user.



    The logical breakpoints are implemented as actions associated with physical breakpoints. Each physical breakpoint maintains a list of actions. An action may be temporary (or once-only), which means that it gets discarded after being executed once. Once-only actions are similar to UNIX System V signal handlers. Non-temporary actions are executed each time the physical breakpoint is hit -- similar to BSD signal handlers.

    Algorithm for executing breakpoint actions




    // Execute actions on given thread
    void BreakPoint::execute_actions(Thread* thread)
    {
    // The list of actions associated with this
    // breakpoint may change during
    // the execution of actions, and thus the
    // iterators may be invalidated:
    // make a copy of the actions and cycle thru
    // the copy, to be safe.
    ActionList tmp(this->actions_);
    ActionList::iterator i = tmp.begin();
    for (size_t d = 0; i != tmp.end(); ++d) {
    if (is_disabled(*i)) {
    ++i; continue;
    }
    // a temporary action returns false
    if ((*i)->execute(thread, this)) {
    ++i;
    }
    else {
    // remove it from the master list
    ActionList::iterator j = actions_.begin();
    advance(j, d); actions_.erase(j);
    // remove it from tmp as well so that
    // destruction is not delayed
    i = tmp.erase(i);
    }
    }
    }



    Software vs. Hardware



    The Intel 386/486/585/686 family of chips offers support for debugging, including breakpoints. The CPU has 6 debug registers: 4 for addresses, one for control, and one for status. Each of the first 4 can hold a memory address that causes a hardware fault when accessed.

    In Intel's lingo, a "fault" is a hardware notification, or event, that happens when the CPU is about to access a memory address -- that is, before the access happens. An "exception" is a similar notification, only that it happens after the access has occurred.

    Remember: Hardware breakpoints are faults, software breakpoints are exceptions.

    The control register holds some flags that specify the type of access (read, read-write, execute) and some other bits; the status register is helpful for determining which breakpoint was hit, when handling a system fault.

    Thanks to Operating System magic, the hardware breakpoints are multiplexed, so we can have as many as N times 4 hardware breakpoints per program, where N is the number of threads in the program.Hardware breakpoints have the advantage of being non-intrusive -- the debugged program is not modified. Another advantage is that they can be set to monitor data as well as code. A debugger may use a hardware breakpoint to detect that a memory location is being accessed.

    Software breakpoints are implemented as a special opcode (INT 0x3) that is inserted in the code at location to be monitored.

    Nicely enough, Intel has a dedicated opcode for breakpoints. Other CPUs (PowerPC, for example) do not have a special opcode; on those platforms software breakpoints are implemented by inserting an invalid code at the desired location.

    Software breakpoints have the main drawbacks of being slow and intrusive. The debugged program has to be modified, and the debugger needs to memorize the original opcode at the modified location, so that the debuggee's code is restored when the breakpoint is removed. When a software breakpoint is hit, the instruction pointer needs to be decremented, and the original opcode restored. Then the debugged program has to be stepped out of the breakpoint. After the breakpoint is handled, the breakpoint opcode is reinserted.

    On UNIX derivatives (such as Linux), a debugger does not manipulate the debugged program directly; rather, it uses the operating system as a middle man (via the ptrace or /proc API). This implies that every time the debugger reads or writes into the debuggee's memory space, a context switch from user mode to kernel mode happens.

    Another disadvantage of soft breakpoints is that they can only monitor code. Software breakpoints cannot be used for watching data accesses.

    What makes software breakpoints indispensable is that there's no limit to how many can be inserted. Hardware breakpoints are a very scarce resource (you can run out of the 4 of them quite fast); software breakpoints are intrusive and slower, but can be used abundantly.

    The design decision in my debugger is to use software breakpoints for user-specified breakpoints, and prefer hardware breakpoints for internal purposes. Watchpoints (breakpoints that monitor data access) are implemented as hardware breakpoints.

    An example of breakpoints maintained by the debugger internally is stepping over function calls. A breakpoint is inserted at the location where the function returns, and control is given to the debuggee to run at full speed until the breakpoint is hit. The breakpoint is removed once it is hit, and the hardware resource can then be reused.

    As a rule of thumb, the debugger employs the hardware support for cases where breakpoints are expected to be released after relatively short amounts of time. If no hardware registers are avaialable, the debugger falls back to using a software breakpoint.

    Global vs. Per-Thread


    Another categorization of breakpoints is by the what threads they affect in a multi-threaded program. A global breakpoint causes the program to stop, regardless of what thread has hit it. Per-thread breakpoints will stop the program only when reached by a given thread. Because all threads share the same code segment, a software breakpoint is also a global breakpoint, since
    any thread that reaches the break opcode will stop.

    The operating system creates the illusion of each thread running on its own CPU, therefore a hardware breakpoint may be private to a given thread.

    A bit in the debug control register of the 386 chip can be used to control the global/per-task behavior of hardware breakpoints.

    A thread ID can be added to the data structure or class that represents a software breakpoint. When the breakpoint is hit, the thread ID in the structure may be compared against the ID of the current thread. The behavior of a per-thread breakpoint can be emulated this way.

    The debugger uses emulated breakpoints when it needs a hardware breapoint and none of the 4 debug registers is available.

    Consider the case where the debugger uses a breakpoint for quickly stepping over function calls. The debugged program must stop only if the breakpoint at the function's return address is hit by the same thread that was current when the user gave the "step over" command.

    Sunday, February 11, 2007

    pszGulasz: PULONG_LONG, PULARGE_INTEGER

    I am a big fan of Mac computers and even use the word Mac as synonym for coolness (or lack thereof), as in "There is no mac in emacs".

    The other day I made a typo in the attempt of e-mailing a link to this blog to someone: oh my! I used a slash instead of a dot: the-free-meme/blogspot.com

    Firefox somehow read through the clutter in my head and took me to the right place (in spite of the error). By contrast Internet Explorer just sat there impotently, summoning up to mind this quote from the Hitchhiker's Guide To The Galaxy: [...] the incredstupid but equally dangerous and ravenous Bug Blatter Beast of Traal. This incredibly stupid monster thinks that if you can't see it, it can't see you!

    I dream of a day when humans will be able to talk to computers in fuzzy terms, and the machines pick up the correct message. Think about it: why should we adjust to the demands of the machine, and appease it by addressing it in very precise, unequivocal ways? The human brain is able to understand the meaning of an article in spite of typos; more so, it can detect subtle changes of context, satirical undertones, and so on. Machines? Not so much.

    As the song goes, you may think I'm a dreamer, but I am not the only one. I read that the genius who came up with Hungarian notation seems to be harboring similar thoughts. Why do I think this is funny?

    Regardless of what camp you are in, both strong-typed languages and dynamic-typed languages strive towards a similar goal: the programmer should not be burdened with the intellectual overhead of remembering the types of the variables. In strong-typed languages the compiler enforces the correct types at... compile-time, and with most dynamic-typed languages the runtime takes care of the needed conversions under the hood.

    By contrast, the HN is designed to help the poor programmer remember the types of the data; something you should not care much about in the first place. Instead of going after the root of the problem (i.e. some fuzziness in the C language wrt types), Microsoft went for the quick-and-dirty solution of making developers adjust to the idiosynchrasies of their machines, and scarred them for life: to this day there are some darned souls in Redmond who are still using HN.

    And the hidden joke is that HN and Romanian Language don't mix well.

    Monday, February 05, 2007

    The Show Must Go On

    I have never missed someone so much since my late father died in April of 2001.

    I do miss Seattle Jazz Icon Floyd Standifer. His gig at The New Orleans kept me sane through many a grim Seattle winter. My wife Juliet and I have a nice Wednesday nights dating ritual since we first started going out together. I used to work for Amazon.com when we first met, and after long, crazy hours of laboring over the ordering system code, I used to call her at home: "Hey Babe, I am walking down Jackson street, see you at the New Orleans in a few?"

    I have taken close friends there to share the Floyd Experience, and family, and people from out of town (Andra and Cristian who visited us from Spain last year had a blast). The staff at the New Orleans is friendly, and the band casual. Clarence Acox reminds me of James Earl Jones, only cooler: he can roll. And the Garfield kids that he coaches are amazing.

    Jim Wilke, John Gilbreath, Bud Young and many many others gathered tonight at Seattle's First Baptist Church to honor Floyd.

    As an immigrant to this Great Country, I cannot but stand by one of the participants' quote: "You cannot talk about America, without talking about Jazz".

    And viceversa. I am lucky to be here.

    Friday, February 02, 2007

    Genuinely Numb

    Does it matter if your copy of Windows is genuine? According to Microsoft, yes. If I understand correctly the gist of what they are saying, genuine Windows is less dangerous to its users.

    It actually appears that the world is awash in counterfeit products. In Russia alone, 43,000 people die annually as a direct consequence of drinking counterfeit alcohol. Tragically enough, the fake beverages also cause losses estimated to $300 million!

    And counterfeit cigarettes were reported to have "75% more tar, 28% more nicotine and about 63% more carbon monoxide" than genuine cigarettes in the UK market.

    For Goodness sake, please make sure your smokes are genuine!

    Oddly enough, I haven't heard of a genuine Apple computer yet.

    And genuine Linux comes with ABSOLUTELY NO WARRANTY.

    Monday, January 29, 2007

    A Ghost in Fremont

    What follows is an essay that I wrote in the Summer of 2004 after listening to a talk by Andrei Codrescu. For those of you who didn't know: there IS a statue of Lenin in Fremont, Seattle, United States of North America, Planet Earth.


    Last night J. and I went to the Rialto Theater in Tacoma to listen to The Writer’s ruminations on Woolworth, on escaping from the Stalinist East and the aroma of strudel in old Hermannstadt.

    I don’t know where he pulled this strudel business from; the city did definitely smell of many things, but apple pie was not one of them, as I recall from back when I was stationed there (drafted by a communist army at age eighteen); yet I share some of his Transylvanian nostalgia. Only I reminisce drinking beer in smoky cellars, places such as “La Bolta Veche”, with the entrance mischievously winking at the old cathedral, and the cobble stone alley that lead to it; the alley narrowed as it spiraled downhill, descending into the outer circles of the Inferno. The cellar with its many corridors could have as well been a real place of torture, back in medieval times; I always wondered if there was some sort of vertical secret passage, a shaft to connect it with the cathedral above. Sinners would have been thrown down through a secret trap in the confessional’s floor.

    Later, The Writer signed for me a copy of his book and I was standing there, shaking and feeling dumb, so much intimidated by the proximity of one of my favorite Romanians; he is also Jewish and therefore related to God: one more reason for me to be shy. He asked what I was doing in the States and I could only utter: “I hang out in Redmond, like many others do these days” – since I assumed that everyone knows that Microsoft’s headquarters are in Redmond, and that makes it the Capital of the Software industry, which made me a programmer.

    The Writer talked about Woolworth and I was thinking about The Waffle House (a favorite hangout back in my Atlanta days); one generation apart, we had different hangouts, different experiences. Yet somehow I felt as the only person in the theater that could see The Ghosts. I mean, how could one expect those nice Tacoma bourgeois ladies and gents to grasp the paranoia I breathed while growing up? Of course, as fine intellectuals with a cult for Freedom, they read Soljenitsin and Codrescu.

    Yet one might think that all the descriptions of the life behind the Iron Curtain are but the fabrication of a sick mind's exercises in exploring the absurd, rhinoceroses metamorphosed into giant roaches. The reality of suburbia, the hard evidence of the two-car garage, and the proof of the barbecue in the backyard all strongly dismiss such aberrations. “Yeah, they say life in the Eastern Block was tough, but that was just an excuse for drinking vodka and seeking asylum in the West”. The Ghosts of the past, I have to live with; I gave up explaining how the communists used to shut down the power in winter, several hours a day, how the children and the elderly had to wait in line for bread, while the working adults went to jobs where they had to listen to propaganda, and spy on each other, to make sure that no one else spies on them on behalf of the government. There was a secret police that watched over the other secret police, making sure that they are loyal to the regime and promptly sent to jail anyone who seemed to display any sign of discontent with the government. The “suspects” used to disappear as if through a secret trap in the floor.


    When I moved to Seattle a few years ago, I almost bumped into one of the Ghosts while walking on the street in plain daylight. I was strolling through Fremont on a sunny Saturday afternoon. It was spring and people were out everywhere, enjoying the first day with blue sky in six months or so. The colorful mass of yuppies wearing shorts and flip-flops flowed slowly by the souvenir and coffee shops, by the Greek restaurant in the corner, some even ventured downstairs in the old Dusty Strings music store.

    I was going with the flow, absent-minded, smiling at the sun, when I saw the statue: a two stories high bronze monument of no one else but the father of communism, the root of all evils, the Mummy. I froze; time bent for a while, slowed down, then came to a full stop: the colors of the crowd, and its noise blurred away. Hypnotized, I couldn’t take my eyes off Lenin, afraid that he might actually move. I quickly examined the possibility that I had come upon a breach in time, where the Universe, in some Carl Sagan-esque sort of stunt bent over backwards, stuck its head up the Milky Way’s butt, and opened a Stargate passage to the Soviets world of the Fifties. I kept looking at Vladimir Ilich, terrified at the thought that some tanks and soldiers with 7.62-mills may rush through the secret opening, through some sort of reversed shaft, ascending from the Inferno back into the gothic cathedral of our daily lives.

    Then, my heart, and time with it, slowly resumed back to their normal beat, and I glanced at the people around: do they see what I see? Are they running in terror? The street was filled with chatter: passers by seemed to ignore the statue of Lenin; the taco place was full of customers. Was I the only one that could see The Ghost (as I would, few years later, in the Tacoma Rialto Theater)?

    And then, paying closer attention to the crowd, I realized that most of the kids out there in the street were generations and thousands of miles apart from the Iron Curtain.

    With the long coat, the visor cap, and the daring beard, the statue could as well pay tribute to a local fishing boat captain who sunk up by Alaska.

    “Vladimir Ilich” – in Russian prose all characters are addressed by their both names, which in a funny way ties Georgia to the other Georgia, “Vladimir Ilich”, I chuckled, “none of these good folks strolling here know who you are. Maybe not even the fool who rescued your statue from the ashes of the dieing U.S.S.R. knew very well who you were.

    “You see, my dear Vladimir Ilich, this is your epitaph: small time fishing boat Captain Anonymous, sunk into The Oblivion Sea, west of Bering. And that is History’s revenge; it’s blessing, it’s curse: a very short memory”.

    Saturday, January 27, 2007

    I Do Not Like Hungarian...

    ... oh... not because I am Romanian and we have a millenium old feud over Transylvania with these folks. No. The beauty of their women (which have a soft spot for Romanian men) totally makes up for it.

    What I was going to say is that I do not like the Hungarian Notation which is complete crap, and I am puzzled that the guy who invented it receives so much praise, to date.

    I read in the New York Times today that he is going to visit the Space Station in a Soyuz rocket. Ok, Mr Wile E. Coyote, bon voyage and good riddance. Too bad the control systems for that rocket don't run on Microsoft software.

    Thursday, January 25, 2007

    The Steve Yegge Factor

    Who is Steve Yegge? Oh, just some guy I did not meet while I was working for Amazon, either because my short (two and a half years, from April 2001 to November 03) tenure has not overlapped with his, or maybe just because I do not seek the benevolent companionship of self-appointed software rock stars. Who knows?

    While I agree with some of his views on the Agile Process, I am not sure that I fancy his style, for several reasons:

    I know from experience that blogging and participating in forums while enjoying a glass of wine inevitably leads to my offending someone needlessly (I have done it more times than I would like to admit, and trust me: I love my reds).

    Arguing over development processes (and programming languages, and OS-es) gets people so worked up to the point it becomes a huge time sink, a distraction from what I like doing best, which is writing code. Sometimes I would rather not say what I truly think.

    Agile is a necessary evil because it keeps management happy and deluded, thinking they have a grip over the development process (and thus less dangerous).

    And finally, why tell people the truth on Agile? Society needs dumb people. If everybody smartens up overnight, then who's gonna pick the garbage? Not Pinocchio, I hear he wants to be a real boy now.

    Tuesday, January 23, 2007

    So Long, Floyd...

    The other night we lost Floyd Standifer. What can I say more? I will miss (like many others) the weekly performances at The New Orleans... but I am sure there must be a great gig in Heavens coming up Wednesday night. Play on, sir.

    Sunday, January 21, 2007

    I Wanna Kick Some Ass. But Whose?

    So I have been having more "fun", trying to get Linux to work on my new Pavilion box.

    Redhat Enterprise Linux AS 64bit gives this error when booting on the HP Pavilion a1600n:

    ...MP-BIOS bug: 8254 timer not connected to IO-APIC

    I got past that by booting with noapic, but I cannot partition the disc, since it is not seen by the kernel.

    On the other hand, Suse 9.3 boots but does not recognize the DVD drive after that.

    As of now the bets are on Suse 10.2... Fingers crossed... It is installing...

    Seems to me that Linux distros are quite challenged in the 64-bit space. It could've been worse though, better be bitter for spending $500 on a piece of hardware that Linux does not support well rather than spending $3000... But the worst thing is that I want to frigging yell at someone, call them names, and... I do not know who the culprit is? HP? The given distros that I am trying to install?

    Here's an interesting business idea: open a call center in Romania, hire some cave men to answer the phone, but not give any customer support, just listen while they are being yelled at and insulted.

    Last edit: the network card on the Pavilion a1600n died last night, a mere week in service. Conclusion: I am taking it back to FRYS and have them make lemonade.
    AMD64 Dual Core, HP, Linux and VMWARE

    How nice (if at all) to the above play with each other?

    I work two jobs. I program using C++ on Windows as my day job, and I am working on my own Linux-based startup at night (doubles as my hobby, too). In both worlds, 64-bit computing is the growing trend. But while at work the Windows 2003 Server 64-bit edition runs happily on the dependable Opteron-based workstation from HP, my private experience is not as successful.

    I have a Pavilion a810n that I bought in January of 2005 (added 512 MRam since) and it runs Fedora Core 5, x86_64 edition. So far, so good. Stable as a rock. On top of it, I run VMWare so that I can simulate 32-bit environments running Fedora 4, 5, and 6, respectively. All stable and fun.

    But I cannot run a 64-bit machine in the VMWare, because the CPU is not "version D, or later"... whatever the heck that means, it is not related to the D Programming Language (which I hope to fully support in Zero, one day).


    [cristiv@newfoundland ~]$ cat /proc/cpuinfo
    processor : 0
    vendor_id : AuthenticAMD
    cpu family : 15
    model : 12
    model name : AMD Athlon(tm) 64 Processor 3300+
    stepping : 0
    cpu MHz : 2400.000
    cache size : 256 KB
    fpu : yes
    fpu_exception : yes
    cpuid level : 1
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow up
    bogomips : 4823.30
    TLB size : 1024 4K pages
    clflush size : 64
    cache_alignment : 64
    address sizes : 40 bits physical, 48 bits virtual
    power management: ts fid vid ttp


    So I hit the coffers and bought a dual core laptop, to build my product on it (I just want to support as many distros as possible). Mandriva 2007 is the only distro that runs without hanging randomly on my HP dv6000z lappy. So far, point for French Engineering, and bad bad karma for Fedora and Ubuntu (which utterly suck on said laptop, both hanging tight as a drum).

    VMWare seems to emulate 32-bit architectures fine on top of Mandriva on the HP dv6000z laptop, but 64-bit architectures hang badly during install (tried tweaking the Options, did not work). I had consistently bad results while trying several versions of Open SUSE and one RHEL 4 AS 64-bit.

    Because I am trying really hard to get out a build of the Zero Debugger for the x86_64 versions of Suse, I bit the bullet one more time, went to FRYS this Sunday and got a HP Pavilion a1600n... Between waiting for AMD's Barcelona chip to come out and getting an unexpensive machine that will become obsolete the next month, I chose the later.

    While I am ranting here, the jury is still out, running memory tests:) I am anxious to see how well 64-bit Suse installs natively on this machine.

    Thursday, January 11, 2007

    Tell HP Your Opinion

    Over the last two years or so, I have switched from using Dell computers to HP, mainly because I was interested in 64-bit computing, and for a while Dell did not sell any computers with AMD64 chips. They seem to have shifted away from the Intel-only policy but as far as I am concerned, it is too late.

    Besides, I like the sturdiness of HP machines better (I own an Pavilion desktop and a DV6000z laptop). Great hardware.

    They also work great with Linux, which brings me to the point of this post. We do not use Windows at home, yet anytime I buy a new machine, I have to pay for Winblows. There's no way to find a bare-bones HP machine. I sent them an email to express my frustration, and I invite you to do the same.

    They are already being sued in Europe (http://www.itworld.com/Comp/1214/061215frenchhp/) and I hope it sends them the right signal.

    Wednesday, January 10, 2007

    Counting Bits

    This code is a solution to the problem of counting the "1" bits in a variable of integral type. It uses recursive templates to generate a table of precalculated values for 0 through 255, then breaks the input value into bytes that are looked up into the table:

    #include <cassert>
    #include <cstdlib>

    // Recursive template, computes the number of bits set
    // in an integer (e.q. Bits<127>::count == 7)
    template<int N>
    struct Bits
    {
    static const unsigned count = (N & 1) + Bits<(N >> 1)>::count;
    };
    template<> struct Bits<0>
    {
    static const unsigned count = 0;
    };
    // This template recursively generates a constructor
    // that will populate a table of 256 entries
    template<int N>
    struct Table : public Table<N - 1>
    {
    Table<N>()
    {
    this->bitcount_[N - 1] = Bits<N - 1>::count;
    }
    };
    template<> struct Table<0>
    {
    unsigned bitcount_[256];
    };

    static const size_t BYTE_SIZE = 8;
    static Table<256> table;

    template<typename T>
    unsigned count_bits(T value)
    {
    size_t result = 0;
    for (size_t i = 0;
    value && (i != sizeof(T));
    ++i, value >>= BYTE_SIZE)
    {
    result += table.bitcount_[value & 0xff];
    }
    return result;
    }
    unsigned count_bits(unsigned char value)
    {
    return table.bitcount_[value];
    }
    unsigned count_bits(char value)
    {
    return count_bits(static_cast<unsigned char>(value));
    }

    // test
    int main()
    {
    assert(Bits<127>::count == 7);
    assert(count_bits(0) == 0);
    assert(count_bits(1) == 1);
    assert(count_bits(-1) == 32);
    assert(count_bits((char)-1) == 8);
    assert(count_bits(3) == 2);
    assert(count_bits(127) == 7);
    assert(count_bits(1023) == 10);
    assert(count_bits(1025) == 2);
    return 0;
    }


    Monday, January 08, 2007

    Zero Debugger News


    The latest version of the Zero Debugger includes fixes for a couple of bugs reported by Christoph Borgolte (thank you, sir) and optimizations of the memory usage in symbol tables.

    I have also played some more with the graphical installer script for Redhat 9 / RHEL (see installer.py in http://zero-bugs.com/8001/builds/zero-i686.010807.tgz).

    Santa brought a license of the Intel Compiler 9.1, so I ran the test suite with it. The results are very satisfactory: Zero Debugger works great on binaries compiled with icc! The only (minor) quirk I found so far is with functions returning long double on the x86_64 platform, which require a special compiler command line flag to work correctly.

    Thursday, December 21, 2006

    UI Python Source for ZeroBugs Opened

    As the song goes, when I was younger, so much younger than today...
    [...] I found my code in tons of trouble,
    Friends and colleagues came to me,
    Speaking words of wisdom:
    "Write in C."

    But that was in the 90s. Today, as somewhat hinted by one of the Mac commercials, C++ GUI Programming is boring, unproductive and uncool. Using a scripting language like Python for UI development gets the job done faster.

    But C++/Python hybrid programming is fucking awesome. And hybrid is the mantra of the decade.

    This is the project that I was talking about in an older post, "Protoyping with Python".
    Download the code archive here.

    Why did I chose Python as the scripting language for ZeroBugs? My first thought was to use a well-known, popular language, and what won me over was the boost python library, which makes integration with C++ a breeze. The documentation at boost.org is very clear and easy to follow. By contrast, SWIG is a pig.