John Dvorak and Office

I love John Dvorak. You gotta appreciate the man - no one writes such nonsense and gets so much attention.

For example, his latest outburst on Microsoft Office. I love how it starts

"It's been 20 years since I first heard that Microsoft was freaked out over its dependence on Office..."

Wow John -you heard about Office some 10 year before it even existed. That's what I call clairvoyance!

 

Getting hired

I was inspired enough by Gopal's story to document my own. This is not about me getting a job at Microsoft. This is about me before I got a job at Microsoft.

Around May 2005 or so was a nasty time to be me or any of my batchmates. We had just entered the final year of engineering college and everyone was obsessed with getting a job. A 'job' meant being one of the thousands hired each year by one of the services companies. At that time, Microsoft was far, far away for me - I just wanted to get hired by somebody, anybody, as badly as anyone else.

I had a problem. Though my marks were decent, they were not stellar. I was also haunted by a failed Maths exam two years before.1 Like vultures swooping in for the kill, one by one, the large Indian IT service companies came to my college for 'placement'.

These events were funny, if you were fortunate enough not to have to take part in them. Around a week before the 'big day', you'll get to know who's eligible and who isn't. If you don't have any outstanding arrears, you're good to go. Of course, you don't have to know anything about computers - these companies are so desperate that they would hire any body off the street.

I skipped the first two companies for I had heard bad reviews of them from people who were working there. I decided to attend the third, more out of fear of missing the boat rather than anything else.

The day before the 'big day', we had a 'pre-placement' talk at another college. This is where employees and HR from the company would talk about what you need to have to get hired - and what they would pay you if you did get hired. I walked into the main hall where this pre-placement talk was being held and did a double-take.

The hall was overflowing with almost twice its maximum capacity - there were close to a 1000 people all packed in, all eagerly waiting to hear what they would make if they got a job. People speak of 'aha' moments. I had what I believe is the opposite - a 'Oh my God' moment. I was disappointed, saddened to be part of such a ... herd of people. I felt as if I was part of a huge meat market - albeit one where all the meat had engineering degrees attached.

After a couple of hours of incredibly boring videos 2, we learnt that the 'big day' would be the next day, and that we would need to carry a host of documents - marksheets all the way back to 10th standard!

The Written Test

Since there were so many of us who were eligible, we were put through a written exam. This was a huge farce - most of the people in the room copied in one form or another and the questions were brain-dead. Surprisingly, there was not even a single computer related question. After a couple of hours of waiting, I learnt that I was one of the few hundred who qualified.

I felt relieved more than anything else - I just wanted to get this done with and go home.

The Big Day

I was optimistic about doing well. I'm not sure where this confidence came from - was it from belief in my coding skills or in the lack of thereof in the people around me? I'm really not sure.

I walked into the classroom where the interview was to be held. Each interview was a 30 minute affair with one employee 3.Having spent the previous night on interview websites which uniformly preached the virtues of cheerfulness, I said a cheerful 'Hi' a cheerleader would have been proud of and walked in.

My interviewer (let's call him 'Grumpy' - for obvious reasons) grunted a welcome and motioned me to take a seat. With another grunt (obviously, vocabulary wasn't his forte), he asked for my marksheets.

Things got off to a bad start almost instantly.

He pointed to my Maths failure in second year and asked me about it. I stammered out a reply of how I was badly unprepared and cracked a joke of how much I hate Maths. Which he didn't laugh at. Crap.

After a few more uncomfortable minutes, he asked me my first question. He drew a molecular structure and asked me to identify it.

Oh oh. You see, I was not that hot at chemical compounds either. I peered closely - but I had no chance. I sheepishly told him I had no clue.

He grunted again. I wasn't sure whether it meant "Don't worry" or it meant "You're so dead". Anyway, it was time for question 2.

Question 2 was as bad as the one preceding it. I was asked to prove a Maths theorem. Well, there's a higher probability of me going out on a date with Jessica Alba than there is of me cracking Maths theorems.

The next 20 minutes were equally bad. Believe it or not, I did't answer a *single* question - almost all of them were mathematical or about some arcane aspect of physics or chemistry.I had lost all hopes of getting hired and was just waiting for the ordeal to end. If this were a boxing match, the referee would have called off the bout long back.

To wrap things up,I think he decided to throw in a computer science question, surely positive that I wouldn't answer it. Well, he thought wrong. By this time, my ego had been so badly damaged that I was just waiting for an opportunity to show off. The question was 'What is a garbage collector?'. The answer he got in return was a ten minute lecture from me on everything from copying collectors all the way to the CLR's generational mechanisms. I was just happy to be given a chance to speak on something I knew about - Maths I may not know, but GCs, I do know!

After my monologue, he stared at me for a second. After a couple more seconds of this uncomfortable silence,  he grunted that I could leave the room.

A few hours later, I found out that I had been hired. I also found out how some of the other interviews had gone. People were asked to show their marksheets alone and was hired based on their getting full marks in some subject back in 12th grade. Others were asked to sing and dance (literally!).

Me, I was just relieved that the ordeal was over. I was also relieved that I didn't have to go through one of these experiences again, that I was now officially part of the IT boom.

 

I hated the entire experience. I hated the fact that computer skills were the last thing they looked for in a coding job. I hated the fact that I was treated with so little respect. I hated the fact that my work with computers was ignored, that the only thing that mattered was me having failed Maths. I was also dreading having to write code in a company that hires people based on their knowledge of physics.

Post Script

Well, as you know, I eventually wound up getting interviewed by Microsoft and joined the B0rg straight out of college in May 2005. Interestingly enough, I got a letter from the company I had been hired for sometime in December 2005 asking me to report for work - whole 6 months after I had finished college. A lot of my classmates were forced to twiddle their thumbs at home for even longer, just because these companies couldn't find enough spots to stuff them in.

For the record, Microsoft never asked me for my marks or my marksheet. To this date, I don't think whether my manager's manager knows whether I've finished college or not. 

Notes

1. People who know me know how much I detest Maths. And almost all subjects which don't involve computers or literature.

2. When I joined Microsoft, I worked with our HR to generate high quality videos to show colleges. Even though I'm not completely happy with the outcome, if you attend a Microsoft campus pre-placement talk, you'll hopefully hear me and others talk about *why* we like working for Microsoft. Stuff like hacking on stuff you like, working on stuff that will change millions of people's lives. None of that BS about 'synergy across verticals' that I heard at some IT services companies' PP talks.

3.Who invariably looked bored and dis-interested - I imagined that the bad employees were punished by being sent to colleges like ours)


 

A Tale of Two Schedulers: Windows NT and Windows CE

Operating system kernels have been the object of my attention for the last few days. I'm really not sure of the reason behind this new found affection for everything ring-0 - but it's sure been fun.

However, unlike most folks, my adventures in kernel-mode have all been in Windows kernels - in specific, the WinCE kernel and the Windows NT kernel. For Windows CE, I'm using the source code that ships with Platform Builder (and is also available as a free download under shared source licensing).

For NT, I've been using the code from the Windows Research Kernel effort. This surprises people - why use that when I have access to the current Windows source tree? Well, for the simple reason that the WRK is a whole lot easier to build! Besides, since it contains only the stuff required to build the kernel itself, it suits my needs perfectly. Also, this lets me demo any kernel mode work in academia. Showing the live NT code on stage would be a quick route to getting fired :-)

The best part of the Windows Research Kernel offering, more than the source code, is access to the original NT specs, written by Dave Cutler, Lou Perrazoli, Kimura and others. I recently laid my hands on them internally and felt a sense of awe when reading through them. How many people get to write the specifications for such an insanely successful product?

This (and the following blog posts) are an attempt to document my wanderings through the kernel sources. In this post, I'll walk through the schedulers of the 2 kernels and try to guess at what they do and why they do things differently. For a thorough description of the NT scheduler, see this article from Mark Russinovich

Schedulers

Schedulers, in essence, 'schedule' time on your operating system (Duh!)). If you want to learn more about the fundamentals behind how these beasts work, I suggest reading a good operating systems book - like the one from Tannenbaum.

Before I dig into the internals of the NT scheduler, let's define some terms

Thread - Basic unit of execution on NT or CE. Corresponds 1:1 to what you get when you make a CreateThread call. When you create a process, you get a thread for free

Process - Corresponds to one or more threads. More importantly, it usually corresponds to an executable on your machine (e.g iexplore.exe, firefox.exe, etc). Note that I said 'mostly'. The default process (called 'System' by task manager) loosely corresponds to ntoskrnl.exe.

Quantum - A unit of scheduling time for which a thread is given control over the processor. Usually expressed in 3 * clock ticks. Ranges between 10 milliseconds to 120 milliseconds. Why does it vary? We'll see that below.

Now, there is one fundamental difference between how the Windows* kernels work when compared to most other kernels. Both NT and CE schedule *threads* rather than processes i.e, the scheduler schedules the processor between threads rather than the processes which own these threads. One side effect of this that a process with more threads will tend to hog more of the CPU - there is no concept of 'fairness' between processes, only threads 1

NT

Let's look at the NT kernel first. Most of the scheduler was written by Dave Cutler himself and until a week ago, he was still the owner of all the scheduling related code.2

Priority

Threads have different priorities. Theoretically, NT has 32 priorities but in practice, only 31 as priority 0 is reserved for the thread that zeroes out memory. Normal threads have priorities between 1 and 15. Priorities above 15 are called 'realtime' and are meant for time critical stuff. The realtime threads are also interesting in that they don't get boosted or some of the other special treatment that normal threads too. Of course, they don't need this special treatment given that they get so much preference in the processor.

When threads are created, they start off at the priority mapping to the priority class of their process. If you have access to the WRK, you can look at the gory details for yourself in base/ntos/ke/thredobj.c (KeStartThread)

Picking a thread to run

The entire section below comes from base/ntos/ke/thredsup.c and balmgr.c

Threads are assigned quantums - the unit of time for which they can run on a processor. At the end of the quantum, the kernel needs to decide which thread to run next. This is not the only time the kernel needs to decide - the kernel needs to make similar scheduling decisions when a thread is waiting on something and that something becomes available. Or if the thread or some other thread decide to play around with thread priorities.

The kernel makes this scheduling decision based on a datastructure called the the 'Dispatcher Ready List'. Shown below, the DRL basically lets the kernel do a weighted-round-robin algorithm. With multiple processors, there is one DRL per processor. The kernel stores the list heads of the individual thread queues in in the processor control block (PRCB).

The DRL is basically a 32 element array whose elements are the heads of a set of linked lists. These linked lists contain the list of ready threads at that particular priority. Below, you see 2 threads ready to execute at priority 1.

[Update: I updated this blogpost to reflect that the array contains the list heads themselves rather than pointers to the list heads. Therefore, the diagram below is incorrect (the priority 1 box should be a node too and the circular link list should cycle back to that node. Will update the image sometime]

Dispatcher Ready List

If you want to write some scheduler code and iterate through the DRLs, you would want to do something like this.

PRLIST_ENTRY ListHead;
PRLIST_ENTRY NextEntry;

for(int Priority=1; Priority<32;Priority++)
{
ListHead = &Prcb->DispatcherReadyListHead[Priority];
NextEntry = ListHead->Flink;

do
{

//
// Do something interesting with the thread.Implement your new super-cool scheduling algorithm
//

NextEntry = NextEntry->Flink;

}while(NextEntry!=ListHead);

}

NT picks the highest priority thread which is ready to run. Sounds simple and efficient doesn't it? Well, it is - except that this doesn't work out so well in some cases.

Boosting

To make sure your operating system acts all snappy in such situations, NT uses a concept of 'boosting' and 'decay' to vary thread priorities at runtime. Note that thread priorities can only be varied if it is in the dynamic range (<=15). If your thread is above 15, then it's like a kid at a party who has already got his share of the birthday cake but wants more - it doesn't get any more special treatment.

NT boosts threads when an event happens. An event could be a mouse input or keyboard input. A few versions back, NT used to boost the threads of the foreground applications. However, that has now been switched to increasing the quantum of the foreground threads. They won't run at higher priority - they'll just run longer without interruption (possibly).

There's still a problem here. What if you're part of a background thread merrily doing some work and not getting any events? Do you wither away in a corner of the processor due to lack of scheduler time? This is where the balance set manager comes into the picture. One among its tasks is to come to the rescue of all such neglected threads.

The Balance Set Manager (see balmgr.c) is a kernel component that ensures fairness in the realm of the kernel. Once every second, it looks through the dispatcher ready lists for any thread that hasn't run in around 4 seconds or so.3 . When it finds one such thread, it assigns it the highest dynamic priority available throughout the realm and puts it at the front of the ready list for that priority (priority 15). This pretty much ensures that the execution of that thread next in the absence of real-time threads. The balance set manager also helps to avoid priority inversion this way.

In a multiprocessor scenario, the decision-making process is slightly more complicated.

Win CE

The Windows CE kernel is an entirely different beast altogether. It has a completely different set of requirements when compared to the NT kernel. NT runs on desktops and serves with oodles of processor and RAM. WinCE runs on tiny devices with very little RAM, slow processors and needs to be 'more' real-time than the NT kernel when needed.

The Windows CE code is also available under a Shared Source license for academia. If you have Platform Builder installed, you already have the source on your machine. All the interesting stuff for this blogpost is under %_WINCEROOT%\private\winceos\coreos\nk\kernel\schedule.c .

The CE scheduler is similar to the NT scheduler in that it schedules threads instead of processes. However, there are a lot of differences, some of them quite subtle

However, unlike the NT kernel, it doesn't do the same amount of boosting. It does boosting to some extent to avoid priority inversion, but it doesn't have a balance set manager equivalent.

The reasoning is obvious - it makes sense to keep the CE code smaller given the more restricted hardware it runs on. Especially given the limited cache on these machines, you don't want your scheduler code to cause cache misses!

But given that modern Windows Mobile operating systems are moving closer to the desktop model and with mobile processors becoming faster and with more RAM, it might make sense to bring more desktop scheduling concepts down on to Windows CE. This might be an interesting research project for the operating systems enthusiasts out there :-)

Notes:

1. So what does process priority mean in NT (the column you see in task manager, the flags to CreateProcess , etc)? Process priority determines the priority class of the process. To over-simplify, it determines what priority the threads within the process start off with.

2. Now that he is moving over to the Live effort, I'm not sure whether he'll continue to own the code.

3. This '4' second limit is hard coded into the kernel. I'm not sure of the logic behind this number. My bet is that the number was arrived at after some empirical analysis


 

10 things I want to do

In no particular order. If you can't understand it, well, that's by design ;-)

1. Write an operating system

2. Wash my clothes. Don't ask.

3. Travel more. As much as this guy or this guy

4. Meet Dave Cutler.

5. Blog regularly

6. Sleep and get up on time. Everyday

7. Go to the gym. Preferably more than once in 4 months

8. Not forget to call up/spend time with the people I care about.

9. Learn COM

10. Develop the same kind of RDF that Steve Jobs has. Develop something as successful as an iPod in the process :-)

And since I just couldn't finish in 10

11. Spend more time doing nothing. Absolutely nothing at all.


 

Tata Indicom Broadband - Heights of incompetence

I'm writing this in anger after yet another long phone call with Tata Indicom Broadband - the ISP i'm unfortunate enough to be saddled with.

Here's my problem. It has been almost 2 weeks since the Government of India clarified the ban on a few URLs under blogspot.com and typepad.com and so on. But my stupid ISP somehow doesn't seem to have got the message.

I've called up multiple times and everytime I've to go through multiple levels of clueless call center support people. And the outcome is always the same -

"Sorry, we haven't received communication from the government about the lifting of the ban" "Why can't you guys ask the DoT yourself?"
"Sorry, Sir, we don't have any communication from the government"

I'm at my wits end. I can't switch to any other ISP due to my where my house is. I've been using anonymizers and proxies and so on, but it is a pain to remember to do so everytime.

Does anyone have any suggestions as to how I can get through to these people? Help!



 

DaveC leaves NT

If you've read this, you would already know about this. Dave Cutler - arguably Microsoft (if not the century's) greatest programmer is moving from working on the NT kernel to the Live initiative.

I finished reading Showstopper just a few days ago - and for those of you who've read it, you can imagine how big a move this is for Dave. If you haven't read it, I strongly recommend that you do so - it changes your opinion of Microsoft and NT and software development in general. I've been hoping to meet Dave for a long time but I'm not sure how to arrange such a meeting (meeting Bill Gates seems to be an easier task!)

I've spent the last few days looking through the NT kernel code - especially the scheduler and related areas. Frankly, it is the most beautiful C code I've ever seen in my life. In fact, I told a friend "You feel like hugging and kissing it - it is so beautiful". It takes quite a programmer who can write code which is both insanely fast, robust but also so simple that someone new to kernel mode like me can still understand it (I even make half intelligent statements like "Ah..so that's how we pick which thread to run next").

I really don't know anything more than what is written in that article (we got a nice long mail from Kevin Johnson this morning ). This shows how seriously the company is taking the entire Live initiative. This is something we're in for the long haul.

The day DaveC left NT. Wow.

For folks unfamiliar with Dave Cutler and his work, let's just say that this would be like Linus Torvalds leaving kernel development to go do something completely different.



Archives

November 2004   January 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006   January 2007   February 2007   March 2007   April 2007   May 2007   June 2007   July 2007   August 2007   September 2007   October 2007   December 2007   January 2008   February 2008   March 2008