Skip to content

Commit 48cf76f

Browse files
torbenh33KAGA-KOKO
authored andcommitted
time: Provide get_xtime_and_monotonic_offset()
The hrtimer code accesses timekeeping variables under xtime_lock. Provide a sensible accessor function and use it. [ tglx: Removed the conditionals, unused variable, fixed codingstyle and massaged changelog ] Signed-off-by: Torben Hohn <torbenh@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: johnstul@us.ibm.com Cc: yong.zhang0@gmail.com Cc: hch@infradead.org LKML-Reference: <20110127145905.23248.30458.stgit@localhost> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent fbad1ea commit 48cf76f

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎include/linux/time.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct timespec current_kernel_time(void);
127127
struct timespec __current_kernel_time(void); /* does not take xtime_lock */
128128
struct timespec __get_wall_to_monotonic(void); /* does not take xtime_lock */
129129
struct timespec get_monotonic_coarse(void);
130+
void get_xtime_and_monotonic_offset(struct timespec *xtim, struct timespec *wtom);
130131

131132
#define CURRENT_TIME (current_kernel_time())
132133
#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 })

‎kernel/hrtimer.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,8 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
8585
{
8686
ktime_t xtim, tomono;
8787
struct timespec xts, tom;
88-
unsigned long seq;
8988

90-
do {
91-
seq = read_seqbegin(&xtime_lock);
92-
xts = __current_kernel_time();
93-
tom = __get_wall_to_monotonic();
94-
} while (read_seqretry(&xtime_lock, seq));
89+
get_xtime_and_monotonic_offset(&xts, &tom);
9590

9691
xtim = timespec_to_ktime(xts);
9792
tomono = timespec_to_ktime(tom);
@@ -612,15 +607,11 @@ static void retrigger_next_event(void *arg)
612607
{
613608
struct hrtimer_cpu_base *base;
614609
struct timespec realtime_offset, wtm;
615-
unsigned long seq;
616610

617611
if (!hrtimer_hres_active())
618612
return;
619613

620-
do {
621-
seq = read_seqbegin(&xtime_lock);
622-
wtm = __get_wall_to_monotonic();
623-
} while (read_seqretry(&xtime_lock, seq));
614+
get_xtime_and_monotonic_offset(&realtime_offset, &wtm);
624615
set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
625616

626617
base = &__get_cpu_var(hrtimer_bases);

‎kernel/time/timekeeping.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,3 +958,19 @@ void do_timer(unsigned long ticks)
958958
update_wall_time();
959959
calc_global_load(ticks);
960960
}
961+
962+
/**
963+
* get_xtime_and_monotonic_offset() - get xtime and wall_to_monotonic
964+
* @xtim: pointer to timespec to be set with xtime
965+
* @wtom: pointer to timespec to be set with wall_to_monotonic
966+
*/
967+
void get_xtime_and_monotonic_offset(struct timespec *xtim, struct timespec *wtom)
968+
{
969+
unsigned long seq;
970+
971+
do {
972+
seq = read_seqbegin(&xtime_lock);
973+
*xtim = xtime;
974+
*wtom = wall_to_monotonic;
975+
} while (read_seqretry(&xtime_lock, seq));
976+
}

0 commit comments

Comments
 (0)