• Roland McGrath's avatar
    [PATCH] posix-timers: high-resolution CPU clocks for POSIX clock_* syscalls · a78331f2
    Roland McGrath authored
    This patch provides support for thread and process CPU time clocks in the
    POSIX clock interface.  Both the existing utime and utime+stime information
    (already available via getrusage et al) can be used, as well as a new
    (potentially) more precise and accurate clock (which cannot distinguish user
    from system time).  The clock used is that provided by the `sched_clock'
    function already used internally by the scheduler.  This gives a way for
    platforms to provide the highest-resolution CPU time tracking that is
    available cheaply, and some already do so (such as x86 using TSC).  Because
    this clock is already sampled internally by the scheduler, this new tracking
    adds only the tiniest new overhead to accomplish the bookkeeping.
    
    Some notes:
    
    This allows per-thread clocks to be accessed only by other threads in the same
    process.  The only POSIX calls that access these are defined only for
    in-process use, and having this check is necessary for the userland
    implementations of the POSIX clock functions to robustly refuse stale
    clockid_t's in the face of potential PID reuse.
    
    This makes no constraint on who can see whose per-process clocks.  This
    information is already available for the VIRT and PROF (i.e.  utime and stime)
    information via /proc.  I am open to suggestions on if/how security
    constraints on who can see whose clocks should be imposed.
    
    The SCHED clock information is now available only via clock_* syscalls.  This
    means that per-thread information is not available outside the process. 
    Perhaps /proc should show sched_time as well?  This would let ps et al show
    this more-accurate information.
    
    When this code is merged, it will be supported in glibc.  I have written the
    support and added some test programs for glibc, which are what I mainly used
    to test the new kernel code.  You can get those here:
    
    	http://people.redhat.com/roland/glibc/kernel-cpuclocks.patchSigned-off-by: default avatarRoland McGrath <roland@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    a78331f2
Makefile 1.99 KB