MLUG: Re: [MLUG] Linux time command -- "kernel mode" and "user mode"
Re: [MLUG] Linux time command -- "kernel mode" and "user mode"
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Disclaimer: It's been a long time since I had Operating Systems, so the following may all be nonsense, but I'm sure someone will point it out if it is. ;)

* User time is total CPU time spent in "user mode" (doing "safe" operations like arithmetic on its own variables).
* System time is total CPU time spent in "kernel mode" (doing system calls, like I/O operations, memory allocation, etc. I think time spent handling page faults -- swapping, in Unix parlance -- are counted here as well, but don't quote me on that).


What you need to realize, though, is that CPU time does NOT include time in which the process is waiting on interrupt-driven I/O requests like disk access. During this time, the process essentially goes to sleep (meaning it is never scheduled on the CPU) until the kernel gets an interrupt signaling the completion of the request. So CPU time alone is not necessarily a good performance measure for I/O-bound applications, because it fails to count time spent waiting on reads and writes to/from disk, network, and any other I/O device.

Under Linux, the "iostat" command will give you a category called "iowait" that tells you what percentage of CPU time is being spent waiting on I/O, but only for the system as a whole (or each CPU, on an SMP system). It doesn't appear that there's anyway to get this information on a per-process basis, which seems unfortunate, since ultimately what you want to know is basically user+sys+iowait.

So for an I/O-bound application, your best strategy might simply be to make sure the system load is light and use "real" as your performance measure. But of course here you get into some issues with disk caching that could make comparison slightly tricky. (A quick Google search turns up several indications that the only way to flush the disk read cache under Linux is to umount/remount the file system you're reading from.)

HTH,
Adam



Mike Miller wrote:
We have written a program in C++ and we have also written it with a slightly different algorithm in Python. We want to see how much slower the Python program is than the C++ program. We get these results:

Python:
------
real    10m43.357s
user    9m51.050s
sys     0m23.420s

C++:
------
real    8m16.668s
user    5m38.360s
sys     2m37.780s

The thing I'm trying to understand is what the differences are in the three kinds of timings. "real" is pretty easy to understand, but it is the least useful of the three times because it depends heavily on system load. This was extracted from "man time" on GNU/Linux:

  When the -p option is given the (portable) output format
     real %e
     user %U
     sys %S
  is used.

  %E  Elapsed real time (in [hours:]minutes:seconds).

  %e  (Not in tcsh.) Elapsed real time (in seconds).

  %S  Total number of CPU-seconds that the process spent in kernel mode.

  %U  Total number of CPU-seconds that the process spent in user mode.

Now I just need a more thorough understanding of "kernel mode" and "user mode" -- know any references?

What I'm really interested in knowing is how the programs would compare in elapsed time under optimal conditions -- no other process competing for CPU, disk, etc. What would come closest to answering my question? Should I just add together the %S and %U times (kernel-mode seconds plus user-mode seconds)? Does that seem right?

Any tips will be appreciated.  Thanks.

Mike

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members


_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members