[Python-checkins] r46505 -python/trunk/Tools/pybench/systimes.py

Tim Peters tim.peters at gmail.com
Fri Jun 2 18:23:33 CEST 2006


[Marc-Andre]
>>> Using your code I now see non-zero values as well - perhaps
>>> KernelTime refers to calls being made to the win32 APIs ?!

[Fredrik]
>> huh?  what else would it refer to ?

[Marc-Andre]
> Not sure, that's why I'm asking. The MS docs say: "A pointer to a
> FILETIME structure that receives the amount of time that the process has
> executed in kernel mode.".

My understanding is that the docs are correct there, and "kernel mode"
could just as well (perhaps better) be called "privileged mode".  The
OS kernel runs at a higher privilege level, which is partly enforced
by modern CPU hardware.  For example, code triggered by HW interrupts
runs in privileged mode, and can execute instructions that the HW
refuses to execute in "user mode", and access the entirety of physical
RAM directly.  Device drivers usually run in privileged/kernel mode
too.  This isn't the same as "Win32 API call", neither is it the same
as anything else that can make instant sense to a non-OS hacker.  More
here:

    http://en.wikipedia.org/wiki/CPU_modes
    http://en.wikipedia.org/wiki/Architecture_of_the_Windows_NT_operating_system_line

In any case, distinguishing between user time and system time is
pretty much pointless in most benchmarks.  I want to know how long the
code takes, and couldn't care less how much of it runs with some CPU
privilege bit set (unless, as mentioned before, I'm running on a
timesharing mainframe and get charged different rates for user time
than for system time).

BTW, it may be the case that time waiting for a page fault to get
resolved from disk doesn't get charged against "user time" or "kernel
time" (depends on OS details).  But if a code change is made that
significantly increases or decreases page faults, that's certainly
something a benchmarker wants to know about.  A high-resolution
wall-clock timer is typically the only way to approach measuring that
kind of thing directly.

Example:  I ran this on WinXP just now:

"""
i = 0
d = {}
while True:
    i += 1
    d[i] = 1
    if i % 1000000 == 0:
        print i
"""

It quickly brought my box to its knees, but _total_ system-wide "user
time" and "kernel time" essentially stopped increasing.  The paging
time wasn't getting charged to anything.  Likewise after hitting
Ctrl-C, the time required to swap all of the dict back in from disk
(in order to decref millions of int objects) didn't appear to be
charged to anything either.  The CPU was simply idle most of that
time, waiting for disk traffic.


More information about the Python-checkins mailing list