How much processor time is wasted doing OS stuff

yelo333

Senior member
Dec 13, 2003
990
0
71
see title...
I'm talking handling the different threads, watching the memory, etc.
say it takes your computer 1 minute to convert an mp3. without all the os stuff(I.E. the mp3 is now in one location in ram, the place for teh converted mp3 is set up in a different location, and the mp3 converter WAS the OS, so, it had absolutely nothing else to do)
could it now take more like 40 seconds?

just pure wondering out loud.to put it another way, how much cpu time is actually spent by the os while you are doing something else?
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Well, depends on your definition of "OS stuff". If you mean system calls (putting things on the screen, opening/closing/reading/writing files, using network connections, then quite a bit depending on the app. Of course, if you didn't use system calls, you'd end up doing the same work anyway.

If you mean really low level stuff (drivers, virtual memory stuff, etc), it's going to be much less. You can actually look at kernel vs user time in "top" or using "time" on unix and with the windows NT task manager (performance tab, check the "Show Kernel Times" item in the View menu).

For a very cpu-intensive task like encoding an MP3, the vast majority of time is spent doing work, and only a few microseconds every few milliseconds shoudl be spent on stuff like context switches.
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
I tend to think that if you wanted all processor resources dedicated to doing something like an encoding task, then do it in DOS or a Command Line style interface. No need to update the screen for all the "OS stuff" like updating the clock, progress bars, the rest of the GUI. Even better, make sure the OS doesn't multi-task. Don't have to handle task/program scheduling either.

I think it is not too significant an amount of resources that is required by the rest of the operating system (or if the encoding program was badly written for that matter). By definition though, whatever the processor does isn't wasted. When the processor IS NOT doing anything, THAT is wasted.
 

glugglug

Diamond Member
Jun 9, 2002
5,340
1
81
Modern OSes are pretty good about keeping context switch times low.

However, on a single CPU system, if you run 2 CPU intensive apps simultaneously it will often be slower than running one after the other completes. This is because the 2 processes will purge each other's data out of cache, and the overhead of pulling data back into cache can be a significant portion of each timeslice.
 

GoHAnSoN

Senior member
Mar 21, 2001
732
0
0
humn.... with all those gigahertz cpu around, i think OS is a piece of cake for cpu.
the problem is how those process are scheduled to do more usefull stuff first. that's y we have those priority stuff for all processes.
we should care on how cpu time is utilized; no cpu time is accually wasted if the cpu is constantly doing stuff.
hence no time is accually wasted.
 

Matthew Daws

Member
Oct 19, 1999
31
0
0
I would agree: for your 60 second MP3 encoding, maybe you could get it down to 59 seconds, but not much less. On the linux box I'm on, the OS seems to take less than 1% of the CPU time, as reported by top.

However, glugglug makes a good point that multi-tasking OSes do, I don't know, "complicate" the issue. Running two CPU intensive tasks is bad. As is pressing the amount of available memory, at least in older OSes. For example, I had a very memory intesive app which I wrote running on a 128MB, Win98 box. It needed something like 100MB of memory, and this caused massive amounts of disk activity for virtual memory. However, I found that if I added some code to my program so that it made itself run at high priority, then the disk activitiy dropped and the program ran a lot quicker. This seems a little paradoxical, as I wasn't running anything else except the baggage which comes with Win98, so there seemed to be no reason for the OS to keep swapping stuff to disk (if swapping was absolutely neccessary, then why would moving to high priority make such a difference?) Thus by moving to high priority, the OS was doing a lot better job of keeping in physical ram the areas of memory my program needed.

I suspect that for applications like this, you might see a significant gain if one wrote a "custom" OS. Then again, perhaps I could have done a better job of memory handling in the program, so that Win98 didn't get so confused about which bits of memory to keep off the disk.

--Matt
 

buleyb

Golden Member
Aug 12, 2002
1,301
0
0
glugglug and Daws have good points. Trashing cache and having contention over the I/O devices will kill any number of apps performance. But no matter how much you trim off your OS, you'll still have do some of those tasks (like I/O), and do all your number crunching as well.

As far as improving performance in CPU intensive apps, algorithm improvements and architectural specific enhancements will buy you more than optimising your OS.
 

Chu

Banned
Jan 2, 2001
2,911
0
0
Originally posted by: yelo333
see title...
I'm talking handling the different threads, watching the memory, etc.
say it takes your computer 1 minute to convert an mp3. without all the os stuff(I.E. the mp3 is now in one location in ram, the place for teh converted mp3 is set up in a different location, and the mp3 converter WAS the OS, so, it had absolutely nothing else to do)
could it now take more like 40 seconds?

just pure wondering out loud.to put it another way, how much cpu time is actually spent by the os while you are doing something else?

In windows, Task Manager -> Performance. View -> Show Kernal Times. This will show you %CPU Usage and %CPU Usage by system calls. You might be surprised at how CPU time is divided between system and user calls for some apps . . .

-Chu