timekeeping: optimized ktime_get[_ts] for GENERIC_TIME=y
authorMartin Schwidefsky <schwidefsky@de.ibm.com>
Tue, 7 Jul 2009 09:27:28 +0000 (11:27 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 7 Jul 2009 10:47:33 +0000 (12:47 +0200)
commit951ed4d36b77ba9fe1ea08fc3c59d8bb6c9bda32
tree870456aff2c513c00608f5416d1b7b440fa5f963
parentfaf80d62e44dc627efb741f48db50c1858d1667c
timekeeping: optimized ktime_get[_ts] for GENERIC_TIME=y

The generic ktime_get function defined in kernel/hrtimer.c is suboptimial
for GENERIC_TIME=y:

 0)               |  ktime_get() {
 0)               |    ktime_get_ts() {
 0)               |      getnstimeofday() {
 0)               |        read_tod_clock() {
 0)   0.601 us    |        }
 0)   1.938 us    |      }
 0)               |      set_normalized_timespec() {
 0)   0.602 us    |      }
 0)   4.375 us    |    }
 0)   5.523 us    |  }

Overall there are two read_seqbegin/read_seqretry loops and a lot of
unnecessary struct timespec calculations. ktime_get returns a nano second
value which is the sum of xtime, wall_to_monotonic and the nano second
delta from the clock source.

ktime_get can be optimized for GENERIC_TIME=y. The new version only calls
clocksource_read:

 0)               |  ktime_get() {
 0)               |    read_tod_clock() {
 0)   0.610 us    |    }
 0)   1.977 us    |  }

It uses a single read_seqbegin/readseqretry loop and just adds everthing
to a nano second value.

ktime_get_ts is optimized in a similar fashion.

[ tglx: added WARN_ON(timekeeping_suspended) as in getnstimeofday() ]

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Acked-by: john stultz <johnstul@us.ibm.com>
LKML-Reference: <20090707112728.3005244d@skybase>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
kernel/hrtimer.c
kernel/time/timekeeping.c