]> git.hungrycats.org Git - linux/commit
[PATCH] Posix compliant cpu clocks
authorChristoph Lameter <clameter@sgi.com>
Wed, 20 Oct 2004 01:31:19 +0000 (18:31 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Wed, 20 Oct 2004 01:31:19 +0000 (18:31 -0700)
commitbb82e8a53042a91688fd819d0c475a1c9a2b982a
tree8c29236a024454ac71021a8f96524f6a4e9d5a67
parent2e3aca172bf49849a131c2c7b856bbbb22462fec
[PATCH] Posix compliant cpu clocks

POSIX clocks are to be implemented in the following way according
to V3 of the Single Unix Specification:

1. CLOCK_PROCESS_CPUTIME_ID

  Implementations shall also support the special clockid_t value
  CLOCK_PROCESS_CPUTIME_ID, which represents the CPU-time clock of the
  calling process when invoking one of the clock_*() or timer_*()
  functions. For these clock IDs, the values returned by clock_gettime() and
  specified by clock_settime() represent the amount of execution time of the
  process associated with the clock.

2. CLOCK_THREAD_CPUTIME_ID

  Implementations shall also support the special clockid_t value
  CLOCK_THREAD_CPUTIME_ID, which represents the CPU-time clock of the
  calling thread when invoking one of the clock_*() or timer_*()
  functions. For these clock IDs, the values returned by clock_gettime()
  and specified by clock_settime() shall represent the amount of
  execution time of the thread associated with the clock.

These times mentioned are CPU processing times and not the time that has
passed since the startup of a process. Glibc currently provides its own
implementation of these two clocks which is designed to return the time
that passed since the startup of a process or a thread.

Moreover Glibc's clocks are bound to CPU timers which is problematic when the
frequency of the clock changes or the process is moved to a different
processor whose cpu timer may not be fully synchronized to the cpu timer
of the current CPU. This patchset results in a both clocks working reliably.

The patch also implements the access to other the thread and process clocks
of linux processes by using negative clockid's:

1. For CLOCK_PROCESS_CPUTIME_ID: -pid
2. For CLOCK_THREAD_CPUTIME_ID: -(pid + PID_MAX_LIMIT)

This allows

clock_getcpuclockid(pid) to return -pid

and

pthread_getcpuiclock(pid) to return -(pid + PID_MAX_LIMIT)

to allow access to the corresponding clocks.

Todo:
- The timer API to generate events by a non tick based timer is not
  usable in its current state. The posix timer API seems to be only
  useful at this point to define clock_get/set. Need to revise this.
- Implement timed interrupts in mmtimer after API is revised.

The mmtimer patch is unchanged from V6 and stays as is in 2.6.9-rc3-mm2.
But I expect to update the driver as soon as the interface to setup hardware
timer interrupts is usable.

Single Thread Testing
  CLOCK_THREAD_CPUTIME_ID=          0.494140878 resolution= 0.000976563
 CLOCK_PROCESS_CPUTIME_ID=          0.494140878 resolution= 0.000976563
Multi Thread Testing
Starting Thread: 0 1 2 3 4 5 6 7 8 9
 Joining Thread: 0 1 2 3 4 5 6 7 8 9
0 Cycles=      0 Thread=  0.000000000ns Process=  0.495117441ns
1 Cycles=1000000 Thread=  0.140625072ns Process=  2.523438792ns
2 Cycles=2000000 Thread=  0.966797370ns Process=  8.512699671ns
3 Cycles=3000000 Thread=  0.806641038ns Process=  7.561527309ns
4 Cycles=4000000 Thread=  1.865235330ns Process= 12.891608163ns
5 Cycles=5000000 Thread=  1.604493009ns Process= 11.528326215ns
6 Cycles=6000000 Thread=  2.086915131ns Process= 13.500983475ns
7 Cycles=7000000 Thread=  2.245118337ns Process= 13.947272766ns
8 Cycles=8000000 Thread=  1.604493009ns Process= 12.252935961ns
9 Cycles=9000000 Thread=  2.160157356ns Process= 13.977546219ns

Clock status at the end of the timer tests:
          Gettimeofday() = 1097084999.489938000
           CLOCK_REALTIME= 1097084999.490116229 resolution= 0.000000040
          CLOCK_MONOTONIC=        177.071675109 resolution= 0.000000040
 CLOCK_PROCESS_CPUTIME_ID=         13.978522782 resolution= 0.000976563
  CLOCK_THREAD_CPUTIME_ID=          0.497070567 resolution= 0.000976563
          CLOCK_SGI_CYCLE=        229.967982280 resolution= 0.000000040
PROCESS clock of 1 (init)=          4.833986850 resolution= 0.000976563
 THREAD clock of 1 (init)=          0.009765630 resolution= 0.000976563

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/posix-timers.h
include/linux/time.h
kernel/posix-timers.c