8/08/2009

NT architecture: What is...an Architecture?

Windows is a well known OS from the user point of view ( tell me your first game played wasn't winemine or solitaire under any of the Windows versions), also thanks to some interesting books as "Windows Internals 4th or 5th Edition" now you can begin understanding the internal behavior of Windows.

ReactOS is an operating system which aims to have the same internal behavior than Windows, following this target,ReactOS will be able to load/run Applications and Drivers designed for Windows.

Windows,Gnu-Linux,ReactOS or any other OS has just one objective from the User point of view: Run Apps.From the developing point of view: Create the fastest/reliable way of connecting Applications with Hardware, processing and returning results.

But "Windows" is just an easy name to remember.The way an OS behaves,the way an OS processes the information,how the app is "processed" and how it is connected with the hardware(to show results in the LCD screen) is called Architecture, by the way "Windows" has followed different architectures.The last one is called "NT architecture".

What´s an Architecture?

I like the idea of comparing any OS architecture with the architecture of the buildings. Imagine you are an architect, imagine you can make a building with the shape you want but you have to give room for 100 people. You can decide creating a building of 10 floors and each floor creating 10 flats, or you can decide creating a skytower of 100 floors and just one flat on each floor. They are different Architectures, but they are valid solutions. In the same way you may have different OS Architectures, in this case the requirement is "processing and connecting the Software with the Hardware", so you can find: Nt architecture, Mac OS X architecture, Linux kernel...

And the Best Architecture is...

Let´s return to the idea of the buildings. Deciding making a skytower or a 10-floors building will make you facing different problems to solve.

Let´s study the skytower: you will have one neighboor in each floor, that means that each neighboor just will have a direct relation with the neighboor it has over his head and the one under his feet. So the flats are quite silence.That is a nice thing if you are the architect but also the owner who wants to rent the flats. "Silence full-floor flats": nice advertisement.

But of course it has some drawbacks, the first one: If the guy of the first floor wants to go to the roof will need some sandwiches to arrive to the roof if there isnt any direct elevator.

The 10floors-Architecture is a nice approach, it is much less expensive to construct, but there are much more noise in each floor and a lot of relations(which in a neighborhood can lead to problems) are created. Let's count the relations: each guy of the 5th floor will have 9 neighboors and 10 neighboors over his head and another 10 under his feet.Total: 29 direct relations. This is EACH guy. Try to calculate the number of total relations and compare with the number of the total relations with the Skytower approach.

Now, we can indeed invent a new architecture called: 1-Floor. An odd "building" which just have one enormous floor and 100 neighboors. Could you calculate the number of possible direct relations?Yes, a lot. But ey!They can arrive to the roof quite easy, withour any Elevator!!Wowww..(*ehem*)

Ok,Ok. Why am I talking about roofs,neighboors,floors?

The Translation...

An OS architecture can be studied as a number of superposed layers, as a building can be studied as a number of superposed floors. So we can have an architecture with 100 layers or an architecture with just 1 layer.This doesnt say too much, but let´s following. Each layer is usually divided in different structures,as a floor can be divided in 10 flats.And each flat(sorry, structure) has its own task inside the Architecture. One flat(sorry structure) processes the graphics , other flat talks with the hardware,other flat talk with the application, other flat talks with flat2 because flat3 is angry with the latter one...

So lets go to the skytower example again:

On the top(the Roof) of the Skytower there is an Application, in the basement of the building there is the Hardware, and theflats have to create "a way" for the app to reach the hardware.(Anything ends in the microprocessor,right?or accessing the HDD, or printing info in the Screen)

The skytower is the typical example of a too much layered OS.A too-much layered has some advantages, you as a programmer dont have to create a lot of direct relations between the structures(neighboors) in this skytower just 2 direct relations.So seems to be easier to control, but..you face one main issue: Slowness. The "call" has to go through 100 floors.No,there isn't a fast elevator.Maybe the "call" doesn't need to be processed in the floor number 63, but it has to go through it to reach the floor number 62.

What happens with a 1-Floor architecture? This is a non-layered-at-all architecture. Layers are nice since they reduce the number of direct relations (if you didn't calculate,please do it now :3.It´s huge )but they introduce extra time if you layered the architecture too much. A non layered architecture is huge in direct relations, and it is a full mess since you will be seeing the call going to the flat number #1 which later goes to the number #35 then going back to #12 and then to #98 and all this happening in ONE floor.

Of course an App makes different "calls"("ways"). A "call" which calculates 2+2 isnt the same that a "call" which reproduces music.This means that a call which calculates 2+2 needs to go through some flats but maybe different(some could be commun) that the flats which the "sound call" goes through.

In a 1-Floor architecture (thanks to be all the flats in the same floor), the calls just have to go in and out from the desired flats and ending in the basement.Now,imagine the skytower again: both calls will go through the 100 Flats(because in skytower flat and floor is the same)!!!

Look carefully the two pictures : There are 2 calls represented, but in different architectures(Skytower vs 10-Floors).

Call1:(Orange) This one has to visit Flat98, Flat4 before reaching the hardware

Call2:(Pink)This one has to visit 20,19,3.

As you can see in a Skytower architecture the calls have to go through all the Floors, to reach the desired flats. Something like calling to the door and saying: "Hi, I want to go into your flat but just because i need to reach your neighboor who is under your feet. My apologies"

In the 10-Floors, this happens much less, but you can find also calls (look Call1) which goes through layers without visiting any of the flats, just to arrive a flat which is placed in a layer below.

Look also that the call #100 to #98 doesnt need to go through 99. This is possible because Direct Relations inside the layer. Same with #19 and #3. Of course it´s just a developing decission if ALL the flats inside a layer have direct relations, or if it isn't needed(easier to code).

Look the call #20,#19,#3: It´s possible that 20 and 3 doesnt have a Direct Relation so the call needs to go through 19 (like in the Skytower) or maybe it goes through 19 because it needs to "do something" inside.

"So it´s better a 1-Floor architecture...":

Well,not really. Imagine that the 100% of the time you need at least going inside 2 flats(call1: flat #1,flat #13; call2: flat#3,flat#11,flat#7;call3: flat #1, flat#7,flat #14...and others 2 or more flats combinations).Then it´s obvious that if you create a 2-Floor architecture (remember you can place the flats inside this 2 Floors as you wish:you are the architect)you arent going to lose extra time!

So yes, you have to find the balance between number of direct relations(easier,clear and cleaner code as possible) with the performance of the OS(not too much layers).And also it depends of the objective of the OS: a real-time OS cant be quite layered or it will "lose a lot of time" from a Real-time OS point of view(any nanosecond counts).

So each OS tries to give its own solution to this balance problem, and that is why there are different architectures. ReactOS follows the NT architecture and its layers are placed in the same way Nt does.

And yes: We are going to try to explain the ReactOS (NT) architecture..Are you ready? ;)

See you next week :)

1 comment:

  1. Thanks for writing this article this is useful stuff!

    For future people who want to join in on the fun visit here:

    http://www.reactos.org/forum/viewtopic.php?f=13&t=7349&sid=c21794f08d5ec40ed2d93e0fddfcfc42

    ReplyDelete