Friday, October 24, 2008

code musings

MinWin and the NT Kernel

Lately Slashdot has been discussing Windows 7 and MinWin, but its coverage sucks. I don't know if people don't understand the architecture of Windows NT, or they don't understand operating systems in general, or they just don't care so long as it's Microsoft bashing.

The first thing that bugs me is all this talk about the "MinWin" project. Ever since this posting ran on Slashdot, there's been all kinds of discussion about MinWin, what it means for Windows 7, and so on. The thing is, lots of people seem to think that MinWin represents a completely different kernel. It's not: it's still NT. MinWin is just a stripped-down Windows NT installation - the essential components for booting up an NT system. The suggestion that MinWin should be "added" to Windows 7 doesn't make any sense; what people really mean is that they want all of Windows' "features" to be removed.

This just leads into the next misconception, which is this idea that the Windows "kernel" is big, bloated, ancient, monolithic, and filled with compatibility hacks. This is perpetuated by an error-filled article in the New York Times, no less.

Let's take a breather and take a step back. First of all, is the Windows NT kernel monolithic? Most references refer to it as a "hybrid" kernel. My opinion is that this is more an issue of nomenclature than of implementation. While the kernel might be compartmentalized, as long as its components and device drivers share address space and full supervisor privileges, they are effectively dealing with the same issues that a monolithic kernel might have. The primary result is the fact that a crash in one component of the kernel (or in a device driver) can take down the entire kernel as a whole.

The bigger question though: Is a monolithic NT kernel at all relevant to the notion that Windows is bloated? The correct answer here is, "No." It is not fair to imply that a monolithic kernel consists of "bloated layers we don't use." As stated above, that's not really what it means to be monolithic; the issues outlined above, not bloat, are among the main drawbacks of a monolithic kernel. Unfortunately Slashdot and the Times seem to believe otherwise. I think that I know why, and the reason is historical.

Back in the day, Windows consisted of three core modules: USER.EXE, GDI.EXE, and KERNEL.EXE (or KRNL[23]86.EXE depending on the operating mode that the hardware could support). USER was the window manager, GDI was the graphics library, and KERNEL handled, well, the kernel-ish functionality. I say "kernel-ish" because the 16-bit Windows kernel would sometimes "suck the brains out of DOS" and implement its own system calls, and other times it would just end up issuing DOS syscalls itself. When NT came along it was designed to support multiple subsystems in user-mode, so that the NT kernel could run OS/2 programs or POSIX programs (recall that NT was originally supposed to be a portable, "new technology" implementation of OS/2). Once the decision was made to make NT a Windows product, the OS/2 subsystem was replaced by another subsystem for 32-bit Windows programs that we now know as Win32.

Win32 consists of USER32.DLL, KERNEL32.DLL, and GDI32.DLL (of course there are now other components, but those are extraneous to my argument). These DLLs have similar names to the old core modules of Windows 3.x, and many of the APIs that these DLLs export are 32-bit counterparts to the old 16-bit APIs. Note, however, that just because one of the Win32 DLLs is still named KERNEL32, it doesn't mean that that library implements the kernel of a NT system!

I think that what these writers are really getting at is that they are fed up with the Win32 subsystem. They keep whining about the kernel because they've seen a core module named KERNEL since Windows 1.0 came out in 1985. The NT kernel itself is no older than Linux or Mach, the very kernels that NT is being compared to!

I think that the most absurd part of that Times coverage was that they proceed to compare the Win32 subsystem to microkernels. We're talking apples versus oranges here. The article then claims that because OS X was written on Mach that it became portable enough to run on the iPhone. This is probably true in comparison to the classic Mac OS, but for NT portability was an original design goal. IA-32 was not the first architecture that NT was written for; the Intel i860, a RISC chip, was the original platform. Further note that there were several RISC versions of NT that were available for many years. Itanium and AMD64 versions of NT sprung up rather quickly as well because of this portability. There are many more important factors that affect portability than the type of kernel that is involved; both NT and Linux are testaments to that.

The article also ignores the separate evolution of the DOS-based and NT-based code bases prior to Windows XP. In another instance of ignoring the fact that NT uses subsystems, the article suggests that the NT architecture isn't compartmentalized enough to change. If NT could switch from an OS/2 API to Win32, why couldn't it be switched to something else? I'm not saying that Microsoft would do this, but it certainly isn't a technical limitation.

I'm not defending monolithic kernels, and I'm not defending Microsoft either. As a matter of fact, I've personally been involved with writing two microkernels. I also just happen to have done lots of Windows programming over the past dozen years. What I am arguing for is some correctness in this armchair discussion of both the design and the future of Windows.

Saturday, October 11, 2008


A New Take on Running with Scissors?

I just saw a kid across the alleyway jumping on a trampoline while holding a pair of pruning shears.

The sad part is that his dad was out there "supervising."

Thursday, October 09, 2008

OhmsBlog storytime

Resistance: The Team Ohms Story

Two days ago I received a call from one of my sisters telling me that the famous Medicine Hat rumour mill was churning out a story that Mr. Weatherhead, my grade 12 physics teacher, had passed away. Perpetually searching for truth and justice, I was hesitant to believe such a tale. Unfortunately I later received confirmation from more credible sources.

I have often wondered why people feel the way they do about death. Certainly there's the obvious reasons: the deceased individual is no longer with us, and will not be with us in the future. Perhaps he or she contributed heavily to somebody's life. At the last funeral I attended, I made the observation that another, more subtle reason we mourn is because the people in our lives share experiences with us. When somebody dies, his memories and his perspectives about those shared events are lost. In a way, for the rest of us, part of our lives has been lost too.

It's been almost nine years since I was taught by Mr. Weatherhead, and though the memories have begun to fade, I decided that once I got my thoughts organized I'd tell a few stories about my experiences as his student. In many ways, the time spent in his class established much of the mythology that many of my friends still share on a regular basis. We would not have a Team Ohms (or a teamohms.org domain, or a blog named the "OhmsBlog") if it weren't for those five months of the first semester of the 1999-2000 school year at Medicine Hat High School.

I had heard stories about Mr. Weatherhead from my peers, but my first experience with him was when I was taking Physics 20. Mr. Grad was actually my teacher for this class, but Weatherhead was known to drop in once in a while, mainly for harassment purposes. He walked in and pulled out this wooden facsimile of a switchblade. It looked like it was made out of balsa wood; it wasn't a real weapon by any stretch of the imagination. It did have a rubber band that would extend the wooden "blade" when some kind of release mechanism was pressed. Mr. Weatherhead demonstrated this device, and then declared that it was a "Redcliff switchblade." (People who aren't from the Medicine Hat area won't get the joke, sorry.) Then he just turned around and left the room.

Another thing that happened that year (and I repeat this anecdote merely as an observer, not a participant) was on April Fools Day, 1999. Mr. Weatherhead's Physics 30 class talked Mr. Grad into unlocking Mr. Weatherhead's classroom early in the morning (I'm sure Mr. Grad was happy to oblige). The class went into that classroom and took every poster, every picture, every piece of paper that was stuck up on those walls, and turned them upside down. A mountain of desks had been constructed in the room, the chairs arranged around the perimeter. It was also wrapped in toilet paper. Apparently the look on Weatherhead's face when he came into the room and turned the lights on was priceless. Doug and I were both in the yearbook club, so when we caught wind of what happened we raced over there with a camera to take pictures. (See page 51 of the 1999 MHHS yearbook, if you can find it!) Mr. Weatherhead was a very gracious prank victim. He was quite amused, and commented that it was well done. I remember that Mr. Hider popped in and asked Weatherhead if this was his idea of higher learning. Mr. Weatherhead just laughed. He still made his first period class clean up the mess, though!

When 12th Grade came along, many of us were excited to be entering our final year of high school. We were also excited to finally be registered in Mr. Weatherhead's infamous Physics 30 class. Unfortunately for Mr. Weatherhead, we were perhaps a little bit too excited. I know that every teacher has students that are trouble, but unfortunately there were some of us in that class that made teaching it a bit more complicated. The funny thing is, these people were the ones that you'd least expect to be a problem! Myself, Wayne, Mark, and Titsing ended up being the riff raff in that class. We also had a few other supporting characters to help us out.

How bad were we? I guess it's all relative. Titsing (whom Weatherhead commonly referred to as "Tits") decided one day that every time Weatherhead said "Bohr" (as in Neils Bohr), the four of us should loudly yell "Bohr" back at him in unison, and pound our desks with our fists. Later on, this antic evolved into doing the same thing for "Ohm." Eventually it progressed to the point where every day when the ball rang at the end of class, one of us would ask (in an outdoor voice of course), "What's the unit for resistance?"

We would then all respond at once: "OHMS!"

And thus Team Ohms was born.

The mythology only expanded from there. When discussing relativity, Mr. Weatherhead was introducing the Lorentz transformation. Wayne and Mark had this Sean Connery thing going at that time where they would try to pronounce words as Sir Sean would. For example, "yes" became "yesshhh." My memory is a bit weak on this one, but if I recall correctly, Mark decided that he wanted to rearrange the formula around a bit to make the calculation more convenient. He referred to this rearranged formula as "Connery's Law." Sean Connery then became our mascot. It suited us quite nicely. [It also suited us that Connery was the original James Bond, and that in recent Bond movies the preferred timepiece was the Omega watch. It dovetailed quite nicely with our Team Ohms theme.]

Another day we decided to spontaneously pretend that everybody in our row of desks was riding a roller coaster. We all threw our hands up in the air and bobbed left and right in unison. Yes, many times that semester Mr. Weatherhead would just hold his head in his hands and sigh. Loudly.

Brett was another student who was in our class. He had recently got a haircut, and his hair was short, spiky, and dyed blond. Weatherhead took to calling him "Vanilla Ice." Of course, we caught on to that one in a hurry: from that day forward, every time Brett walked into physics class, at least one of us would break into an a capella rendition of "Ice Ice Baby," much to Weatherhead's amusement.

Speaking of hair, around that time Mr. Weatherhead had added yellowish highlights to his own. Unfortunately for him, Brock, another student at Hat High, had a hairstyle that was identical. Even funnier was the fact that Brock used to talk to Mr. Weatherhead all the time, and they could often be seen near each other in the classroom or in the hallway. When Wayne and I would walk by the two of them in the halls, Wayne used to pretend that he couldn't tell which one was Brock and which one was Mr. Weatherhead. Sometimes Wayne would intentionally reverse their names when addressing them just to rile them up - he'd continue doing it even when they'd start pushing him around!

The Mr. Weatherhead experience was never complete for any student without a story about the taser. The guy actually kept a taser locked in a filing cabinet in his classroom. Depending on his mood, and depending on what people said to him that day (sometimes you really had to piss him off, other times all you had to do was ask), he'd pull out his keys, walk over to the cabinet, and pull out the taser.

I had heard a rumour that the best way to foil the taser was to just grab onto it and hold tight. The initial shock hurt, but after that you were fine. Furthermore, your finger was electrified and could be used to shock Weatherhead back. We explained this to Darcy, another student in our class, and he decided that he was determined to find out if it worked. He somehow goaded Mr. Weatherhead into pulling out the taser and turning it on. Sure enough, Darcy grabbed onto the taser and held on tight. The funniest thing about doing this is that Mr. Weatherhead obviously didn't want to let go of the taser, but on the other hand he still needed to dodge his opponent's electric finger. The only way that he could get out of that situation was to unplug it.

The other taser story is that Mr. Weatherhead would bring the taser into contact with conductors that the students were least expecting. For example, he'd stick the taser onto the leg of a student's chair. The leg would conduct the current up through the bolts in the seat of the chair and give the student an unforgettable jolt in the ass!

Mr. Weatherhead was also infamous for the abuse that he inflicted on those fake babies that they make students taking health class carry around. If they started crying during one of his classes, he'd inflict all kinds of damage upon them. The funniest anecdote that I ever heard about them was that he tore the crying voice box out of a baby and hid it on top of a girder that was just outside the door of Mr. McFarlane's classroom.

My major Weatherhead classroom disturbance was the time that I decided to take advantage of my membership in the yearbook club. I signed out one of their SLR cameras and took it to Physics. I also asked Josh, a friend of ours who was not actually a member of our Physics class, to show up to our class wearing a dress. I told him that I'd pay him $5 if he'd walk up to Mr. Weatherhead in the middle of his teaching and put his arm around Weatherhead for long enough that I could get a picture. Josh went through with it, but unfortunately Weatherhead's reaction time was too quick. "Holy shit!" Mr. Weatherhead yelled as he tried to get away. I took the photo, but he had ducked out of frame just in time.

I was also one of the students responsible for the 2000 April Fool's Day prank. The other participants know who they are, and I'll leave it to them to come forward. Many members of the MHHS physics class of 2000 weren't sure how to top the April Fool's shenanigans from the previous year. We decided that a prank against Mr. Weatherhead would be done at his house, instead of his classroom. [Ah, nothing like youthful exuberance!] This would be carried out at midnight on April 1, 2000. We had planned a four-pronged approach:
  1. "The Goop," a mysterious substance1;
  2. A 20 pound bag of rice;
  3. Some chocolate-covered bananas and a container of Grecian Formula; and
  4. Toilet paper.
The Goop was poured onto his car, and then it was toilet papered. The rice bag was sliced open and then dragged across his grass in a lawnmower pattern. The bananas and the Grecian Formula were left on the front step. His trees and the front of his house were also toilet papered. Somebody took photos, which I am sure are still in existence. Finally, somebody rang his doorbell and we all ran like hell. He never had proof of the assailants (though I think we were definitely on his suspect list), though he did remark that they were very fortunate that The Goop did not damage his car.

For the first year or two after I left high school, I would still drop by and visit some of the teachers there. The last couple of times that I saw Mr. Weatherhead were during these visits. The first time was at Christmas, 2000. He was teaching class at the time, but Jason and I went and pressed our faces obnoxiously against the glass. I gave Mr. Weatherhead the finger, much to the delight of his class. Despite all the shenanigans that we put him through during the previous year, he invited us in and asked us what we were up to and how we were doing. The last time I saw him, I stuck my head through his open classroom door and yelled at the top of my lungs, "HI MR. WEATHERHEAD!" and then walked away. His wide-eyed response? "JESUS CHRIST!"

So here's to the indelible mark that Mr. Weatherhead made on Team Ohms, Medicine Hat High School and the hundreds of students that he taught. The place won't be the same without him. What's the unit for resistance?

1 "The Goop" actually consisted of the following ingredients (at least that I can remember): Water, oatmeal, leftover pasta, red food colouring, and corn starch. We boiled the water before adding the other stuff. It smelled terrible, was pink coloured, and was fairly thick in viscosity.

Release 7.0; Copyright © 1996-2012 Aaron Klotz. All Rights Reserved.