You are not logged in.

#1 2008-01-03 03:08:46

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

[solved] What monitors the kernel?

I'm trying to understand how my computer works.

The kernel manages how CPU cycles are time-shared between running applications. To do this, it has to be 'running', therefore using up cycles itself. But then every system call has to go through the kernel... so the kernel must have a big 'share' of the cpu time. What kind of sharing goes on? Does it slice very tiny slices, running in every other slice? How does it do it? How does the kernel manage itself?

Last edited by peets (2008-01-16 23:11:16)

Offline

#2 2008-01-03 04:15:42

vitalstatistix
Member
Registered: 2007-01-31
Posts: 28

Re: [solved] What monitors the kernel?

I know this question, at first glance, seems easy but few can answer it conclusively. I too have wondered how the kernel scheduler works and recently, there has been much controversy as to what scheduler should be used. So investigating how the kernel scheduler (currently called CFS for Completely Fair Scheduler), works could be a start. There's a wealth of information online about it - wikipedia comes to mind first. Anyway, let us know what you find out and post a response that is palatable.

Offline

#3 2008-01-03 14:46:26

dawei
Member
From: China
Registered: 2007-05-02
Posts: 29

Re: [solved] What monitors the kernel?

I know nothing about the kernel, but I am an EE student, here is my guess.

The computer is a causal system, it runs because you push the power button. And since then, all the codes on the computer begin to execute. The kernel is the first real program being executed, so it takes control of the CPU. After the kernel is loaded into RAM, it begins to run application by loading the binary file into RAM, reading the needed bits into CPU to make them executed. If you know assembly language, you should know what is going on in CPU.

English is not my first language, I don't know if you can understand me.

Offline

#4 2008-01-03 14:53:12

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [solved] What monitors the kernel?

For a bit more info, see supervisor mode.

Offline

#5 2008-01-03 19:17:28

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: [solved] What monitors the kernel?

This is the best thread I've seen on the forums in ages!

And yet, I don't know how to answer your question. I will tell you, however, that I first learned all these concepts regarding scheduling, time slices, etc via VMS manuals. If you have those laying around (hah) they might be worth a read.

I would, however, speculate one thing here: the kernel lies. It, most likely, does use a lot of CPU time, but it's not recorded under some magical "kernel" process, because the kernel doesn't "run". It actually defines what a process is, so kinda can't be a process itself. While a system call may go *through* the kernel, that time slice is, likely, 'owned' by the calling process.

Offline

#6 2008-01-03 21:29:39

sjb933
Member
Registered: 2007-01-18
Posts: 113

Re: [solved] What monitors the kernel?

Well, I'm a CS major and have begun touching on low-level hardware and kernels, so I will try to describe it to the best of my abilities.

The Kernel is just a program like any other.  It is written very low level,  C and Assembly for linux and then compiled specifically to the hardware on which it runs.  X86, Sparc, PPC, etc.

Writing low level like that can give you precise control over the instruction set architecture, and thus give you access to all that the hardware has made available.  The Kernel will run in what is considered "supervisor mode" as described above.  This is physically wired into processors, and gives the program in supervisor mode access to the hardware directly.  Other programs executed (user-level programs) will be run with user-level permissions and will not have direct access to hardware level Interrupt Requests and peripheals etc.

Now, this supervisor/user-level coded in the hardware is not to be confused with root permissions in linux.  Root permissions in linux provides access to parts of the file system otherwise not available.. But this is a much higher level and further abstracted idea, as this is all within the kernel program, not the hardware of the computer.

So the kernel is running in supervisor mode, and has direct access and control over all the hardware the computer has available.  This means that if another program... say Open Office (running in user-mode) needs to print than it must make the request to print through the kernel.  Such operations are called TRAP requests.  It's when a user-level program makes a System Call to the operating system/kernel to take care of any needs of the hardware.  These system calls are available to all user-level programs, some of which in linux will require root level privileges.  NOTE: This is a security decision made by the programmers of the kernel.  All OS's do this is some fashion or another.

In addition to managing peripherals and what not, the kernel has precise control over both the memory and the CPU.  Keep in mind that the CPU is simply doing simple instructions one after another at a rate of say... 1 billion instructions per second (1 Ghz).  Each of these instructions as said is usually fairly simple, but doing so many so quickly can give the illusion of complexity.  On the memory side of things, the Kernel will manage it's own location in memory, making it off-limits to user-level programs.  This prevents programs from inserting their own code into off-limit locations in memory.  The only kernel instructions that user-level programs are able to Jump to are those TRAP Vectors (System Calls) as mentioned above.

As far as the rest of the memory goes, the kernel will have very sophisticated memory management that decides where in memory to place any user-executed programs and will also manage shared memories (such as the clipboard).  It will attempt to keep the memory as de-fragmented as possible, which in itself could be discussed in an entirely different post.  It will initially give programs a small amount of memory, but one of the TRAP requests a user-program can make is for access to more memory.  This is if the HEAP in the running program has become too small for the data they are trying allocate.

Another issue to touch on is the STACK.  This is another memory ideology that could require it's own post, but it is important to not that there is both a user-stack (each running program has one) and a system stack (used by the kernel).

Well, I know I just barely touched on memory, but as I said it can be a long discussion in and of itself.  Best practices are constantly debated and changed (same goes for process management).  One thing i personally have not learned about yet is pipelining/multithreading.  I understand how to code for it, but not how the hardware handles it yet.  We've only been learning the concepts i discussed above on a simple single-procedure processor, the LC-3.

So erm... I hope this helps, I haven't even re-read this so I suspect i'll be making edits.  If it's unclear feel free to ask for clarification.

Regards,
Shane

Last edited by sjb933 (2008-01-03 23:11:23)

Offline

#7 2008-01-03 23:14:44

sjb933
Member
Registered: 2007-01-18
Posts: 113

Re: [solved] What monitors the kernel?

Also if you're really curious I would recommend this book: http://www.amazon.com/Introduction-Comp … 0072467509

I know it's a text book and all, but it's very well written and covers all the low-level computing basics.  You'll learn a ton.

Shane

Offline

#8 2008-01-16 23:10:53

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: [solved] What monitors the kernel?

Somehow I didn't realize anyone had replied to this question. Today I randomly found some school text that pretty much answered what I was after (even though I worded it all wrong). It's pretty basic, and your answers show that these problems have no decisive solution yet; but I'm happy with just the basic ideas.

My intuition was not so far off actually. The kernel/OS is just another program. It gets called when interrupts happen. There are timed interrupts every now and then, and after a few of them, the current program stops and the kernel runs. So basically, the kernel runs in-between every other program, and it's also called through an interrupt when a system call is made. So I guess most of the cpu time is spent executing kernel code!

Shane: I'm guessing you wrote that while on vacation --you seem like a motivated student! Keep it up.

Thanks all for your answers.

Offline

#9 2008-01-19 17:40:52

sjb933
Member
Registered: 2007-01-18
Posts: 113

Re: [solved] What monitors the kernel?

Well sorta -- wrote it at work wink  I'm a Systems Administrator for ARM Inc.

Thanks though smile I am rather motivated in at least my CS classes.

Regards,
Shane

Offline

Board footer

Powered by FluxBB