Frankenstein or The Modern Prometheus

I never thought that I would see such a thing in my life. It is only from a story teller, right!. I was completly wrong, and it is not the first time I was ...

Specially in large scale software(s), it is pivotal that it is designed with care. Otherwise, only the orignal designer could perhaps come to rescue.  I was poking thru one such software, and found how much of a design problem is there. There are deadlocks, exceptions, and other stuff.... I've been debugging softwares written by others on and off for quite sometime. So I do have an uncanny knack of criticizing vital defects in software design...

This lead me to talk about asynchronous processing. What is it? Where the heck it came from? What's the use of it? And a host of other questions your wandering mind might have.

Most of the computer architecture are sequential in nature.It simply performs one instruction at a time and in sequence. It was found early in the history of computing that saturating the CPU bandwidth are almost always a rarity than common use of a CPU, and I/O processing is essential to make computing exciting. Think about one case, where you are to solve a bunch of partial differential equations ( if you know what it is :-), or to run a pobabilistic sampling on the memory bitness , to find out what is the probablity that your memory has more one bits than zero bits. These are not  really  very interesting unless you can convey your result in one or other form to your audience. So the I/O processing came as a vital part of computing. But I/O processing could be slower than your CPU. You really can not waste CPU time just by waiting for the I/O to finish and give you intermediate or final result. So what we do now?  Well device interrupt technology came to rescue us from it. We send a command or two to a device, and we could go ahead to do our business until we get a notice that the request is done or there is a device error. Now how and when the device going to let the CPU know that a request is done?. The answer to when is that when the device is ready to let CPU know. So if the CPU continues working sequentially, it needs to be stopped from what it is doing and look at the result of the request. This is where asychronous processing comes into play, since the CPU needs to halt what it is doing and start looking at the interruption.  How it is going to notify CPU is the mechanism to handle interruption from external devices.

Now suppose we have a situation that the CPU should halt executing our current steps of computation, since we are depending on the result from the device. In this case, we should try to use the CPU for something else. Here the OS tries to put the current task to go on sleep, and gets another task to run. In this case we can see how the computer resouce is being shared by differnt computations. And we achieve a pseudo parallelism.

Today these concepts are available to programmers who are not directly involved with OS development. For example, threading is one. If we have more than one completely disjoint computations, we can do by creating seprate thread of computation, and it is easy enough!. But if we have some dependencies among several thread of computations, we will have to be very careful. These things brings up, race conditions, deadlocks, data corruption etc.

When the design is not well thought out, it becomes a very difficult software to understand...

 

Posted on Sunday, March 18, 2007 at 06:31PM by Registered CommenterProkash Sinha | CommentsPost a Comment

What you assume is what you may get !

Assumption is really a key concept in daily life. Can we really eliminate assumption altogether? That's a question I fight with almost everyday, though not for daily chores outside my profession. In programming, it is extreemly important to know what is/are known and what are not. Hopes sometime lead us to assume ( or belief) about some situation, some context that bite us back later. A very good book to read on this is "How to solve it" by Polya. In almost all science and engineering we contradict hypothesis. And that is to test our hypothethis.

Here is an example of how bad assumptions could be in math -

We were taught that infinity divided by infinity is not one. Since infinity has a mathematical symbol ( often more than one symbol, but that is a different topics altogether) like any other number why it is not true that infinity by infinity equals one. So lets assume that it is one, then contradict it to see what we were taught is indeed true or not.

We know that sum of all natural numbers is infinity. Sum of all even numbers is infinity. Sum of all odd numbers is ... Sum of all numbers that are multiple of something is again infinity.

Now we can argue that sum of all odd numbers and sum of all even numbers must be equal to sum of all numbers, since a number could either be odd or even.

So take inifinity by infinity equals 1, and substitute accordingly you will see 1 is equal to 2, 3 equal to 7, or whatever you imagination drives to.

In windows kernel mode programming, there are lot of places you can not readily assume anything. For example, user context is one. Accessibility of your own allocated memory is another one. In another topic I touched upon process context.

Here, for example if you allocate memory from paged pool, you  have to remember that particular memory will not be accessible all the time. It could be paged out by the systems, and if you happen to be in a high irql, and the system thinks your memory is invalid ( i.e. from the paging point of view), it would not be able to page in your memory, and you know what is next... So is the story for any code or data you define for your windows kernel mode programming. By default, all the data and code you write for drivers ( or other kernel module by a third party ) are from non-paged pool. But when you allocate memory from kernel heap, you have a choice to allocate from paged or non-paged pool. If you are not sure how the memory would be access, it is safe and perhaps little bad design, allocate your memory from non-paged pool. Also note that non-paged pool is a limited resources.

Since code sizes are not very dynamic, and it is not very large for kernel modules, it is perhaps okay to have them in non-paged area. Dyanmic memory allocation is different though, so use of judment is essential. Experts often uses several techniques to allocate memory from paged pool, and if there is a need for access at a higher IRQL when makes the request as an work item and queues to be processed at a lower IRQL when paging is allowed.

 

Posted on Friday, March 16, 2007 at 07:48PM by Registered CommenterProkash Sinha | CommentsPost a Comment

SUN sets at 4:30PM !

How else can I spend an week end evening when there was plenty to wine and dine, and chat-away couple hours whose end result could very well be zero?

Couple weeks ago, I had to be in a gathering, since I had been gradually becoming very unsocial. Couple friends got together. One from SUN, another from veritas(symantec), another one from san disk and myself. We saw our friend from SUN is little depressed, so I threw an honest question ... What caused SUN to go down the path? Please tell us something, without getting into Marketing, Management, and other things that needs for a company to be successful. In particular, what machine(s) and OS(s) are eating away server market of SUN.

Also I implied that Microsoft servers market has been growing quite fast lately. If you remember, in the earlier days of NT now windows, people used to talk about SUN servers are so good, and MS were not ready at that time.

The veritas guy and san disk guys immediately threw me out of the picture, saying no it is not Windows server. It is the linux server on intel machines are eating away SUNs market.

Finally the SUN guy started. BYW, he has been with SUN for quite sometime. As usual, he is also not too keen about these business aspect. But whatever information he had, it is Power PC machnes from IBM with AIX or Linux or whatever...

Well, we have to trust horse's mouth. Then he iterated that SUN is reshaping.

So I guess, Sun does not set at 4:30Pm all the time.

Posted on Wednesday, March 14, 2007 at 07:47PM by Registered CommenterProkash Sinha | CommentsPost a Comment

Can you spare a quater ...?

I meant to say quater of an hour...

Recently I was bumped into two discussions . One was about windows operating systems context switching, another one was about 64bit machine.

For the context switching, someone was thinking that as soon as a user request comes to the kernel land, there is a context switch. There were few things that I started thinking about. What does the person mean by context switching. If I could recall, in a process based os when a processor is switched ( assigned ) to another process for execution we call it a context switch. In windows schedulable enitities are threads, so it might be that the person was talking about thread switching.

 Whatever that switchable entity is, it does not make sense... Remember that user space data can be accessed directly from top level kernel mode component. If there were a process context switch as soon as the process goes to kernel mode, there is a security and protection problem. So it means the context was not switched as soon as it gets to the kernel mode. Then the next question is when there could be a context switch while we are in the caller process context and in kernel mode. Some obvious ones are if the time quantum for the process is used up, or if the process goes to kernel mode wait. Since windows is, as far as I know, is thread based, the switching is supposed to be light-weight, and it could still be in the same process context, only the threads were switched. But if none of the current process's threads are ready to be scheduled, a process context switch has to happen. One fine point I missed here in my assumption. If you happen to know the meaning of topLevel kernel component in windows terminology, quite often we think about kernel mode driver that is a top level component. Which usually implies a file system or file system filter driver. But in most cases  there are a lot of processing goes on in the kernel mode before even hitting top level driver ( kernel component that we are thinking here ), and during that processing if there is no outside influence to change context, would there still be a context switch. Or specifically if nothing extraneous influence changes process or thread context, is the kernel mode execution path before toplevel component would change contex?.  I don't see why it would do that ...  I don't see any need for it.

So it's not necessary that the context would be different as soon as it enters kernel mode. Then what exactly happens when the process goes to kernel mode. From a very high level point of view, the processor has to be in privilage mode. And for stack space sanity, arguments, flags, and other stuff gets copied to kernel stack, and execution continues in the kernel mode. This is at a concept level. For detail, look at available lituratures on windows internals and / or start digging deep with debugger.

At this point I would like ask  - What is an operating system?

 It is a program that allows other programs to share computer resources. How does it do, how fair it is, how efficient it is, how general purpose it is ...  are basically the questions whose answer belong to the policy enforcement algorithms.

Second discussion I was invoved with was about 64bit systems, and its performance is going to be better than 32bit machine. The question came from an experienced software engineer with proper computer science back ground. My answer was at first purely based on intuition. And I said sure it is going to be faster, graphics would be snappier, blah, blah. His answer was that he can only see it is faster when massive numerical processing is done. Other than that it was beyond him. Is it a neive or logical thought?

That got me to a point of thinking that if one has to show that 64bit is better performing machine ( wiht 64 bit windows), what that person need to do?.  Perhaps there are bench marks that do not try to compare apple and orange. But how could you go about doing it? Remember you need to convince a bonafied computer engineer that 64bit systems are better performing !. Also you might have to prove if someone needs it or not.

For a moment, I was also stumbled by the question. Is it really just futuristic? Can I really show that it is better performing? This needs a no or hardly any perturbation on two systems: One 32 bit, and another 64bit. And eliminating as much of baggages as possible. For example networking, since it can have non determistic delays...

Frankly, it is an interesting question, and I don't have answer to it. I can probably point at lot of technical discussion that would show how larger address space is going to help. Perhaps the system cache sizes are larger, and perhaps the block level i/o gets to fetch or write with a larger chunks etc., etc. But the basic question is - User perception. Lets take vista 32bit and vista 64bit, make sure apple and oranges are not compared, so the system should be as identical as possible from users perspective ( same amount of RAM, same type and capacity of Hard disk etc...).

Posted on Monday, March 12, 2007 at 08:22PM by Registered CommenterProkash Sinha | CommentsPost a Comment

Bedouins are back in bay area !

Recently, I was skimming thru San francisco Chronicle. And found an interesting article about some small startups or private companies without any office. They hang out in Starbuck or other cafe or resturants, gets internet access, work for 10 or 12 or 14 hours a day. Their main theme is independence. They have flexible hours, they don't need to call their business garage.com when it flies.

Statistically speaking, very few of those see success. But it is really an interesting idea. There is a wave of creation and hopefully make a business out of it. During the dot.com fallout, lot of these thing were vanished. Now it is coming back again...

I wonder how many more Bedouins would surface when alternative energy becomes more interesting. Already there seems to be acute interest in that space ...

 

 

Posted on Monday, March 12, 2007 at 07:45PM by Registered CommenterProkash Sinha | CommentsPost a Comment