Skip to content

Commit 76f4108

Browse files
hrtimer: Cleanup hrtimer accessors to the timekepeing state
Rather then having two similar but totally different implementations that provide timekeeping state to the hrtimer code, try to unify the two implementations to be more simliar. Thus this clarifies ktime_get_update_offsets to ktime_get_update_offsets_now and changes get_xtime... to ktime_get_update_offsets_tick. Signed-off-by: John Stultz <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent e06fde3 commit 76f4108

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

include/linux/hrtimer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,12 @@ extern ktime_t ktime_get_real(void);
331331
extern ktime_t ktime_get_boottime(void);
332332
extern ktime_t ktime_get_monotonic_offset(void);
333333
extern ktime_t ktime_get_clocktai(void);
334-
extern ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot,
335-
ktime_t *offs_tai);
336-
334+
extern ktime_t ktime_get_update_offsets_tick(ktime_t *offs_real,
335+
ktime_t *offs_boot,
336+
ktime_t *offs_tai);
337+
extern ktime_t ktime_get_update_offsets_now(ktime_t *offs_real,
338+
ktime_t *offs_boot,
339+
ktime_t *offs_tai);
337340
DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
338341

339342

include/linux/time.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ unsigned long get_seconds(void);
133133
struct timespec current_kernel_time(void);
134134
struct timespec __current_kernel_time(void); /* does not take xtime_lock */
135135
struct timespec get_monotonic_coarse(void);
136-
void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim,
137-
struct timespec *wtom, struct timespec *sleep);
138136
void timekeeping_inject_sleeptime(struct timespec *delta);
139137

140138
#define CURRENT_TIME (current_kernel_time())

kernel/time/hrtimer.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,18 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
114114
*/
115115
static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
116116
{
117-
ktime_t xtim, mono, boot;
118-
struct timespec xts, tom, slp;
119-
s32 tai_offset;
117+
ktime_t xtim, mono, boot, tai;
118+
ktime_t off_real, off_boot, off_tai;
120119

121-
get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &slp);
122-
tai_offset = timekeeping_get_tai_offset();
120+
mono = ktime_get_update_offsets_tick(&off_real, &off_boot, &off_tai);
121+
boot = ktime_add(mono, off_boot);
122+
xtim = ktime_add(mono, off_real);
123+
tai = ktime_add(xtim, off_tai);
123124

124-
xtim = timespec_to_ktime(xts);
125-
mono = ktime_add(xtim, timespec_to_ktime(tom));
126-
boot = ktime_add(mono, timespec_to_ktime(slp));
127125
base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim;
128126
base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono;
129127
base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot;
130-
base->clock_base[HRTIMER_BASE_TAI].softirq_time =
131-
ktime_add(xtim, ktime_set(tai_offset, 0));
128+
base->clock_base[HRTIMER_BASE_TAI].softirq_time = tai;
132129
}
133130

134131
/*
@@ -673,7 +670,7 @@ static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
673670
ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
674671
ktime_t *offs_tai = &base->clock_base[HRTIMER_BASE_TAI].offset;
675672

676-
return ktime_get_update_offsets(offs_real, offs_boot, offs_tai);
673+
return ktime_get_update_offsets_now(offs_real, offs_boot, offs_tai);
677674
}
678675

679676
/*

kernel/time/timekeeping.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,37 +1581,47 @@ void do_timer(unsigned long ticks)
15811581
}
15821582

15831583
/**
1584-
* get_xtime_and_monotonic_and_sleep_offset() - get xtime, wall_to_monotonic,
1585-
* and sleep offsets.
1586-
* @xtim: pointer to timespec to be set with xtime
1587-
* @wtom: pointer to timespec to be set with wall_to_monotonic
1588-
* @sleep: pointer to timespec to be set with time in suspend
1584+
* ktime_get_update_offsets_tick - hrtimer helper
1585+
* @offs_real: pointer to storage for monotonic -> realtime offset
1586+
* @offs_boot: pointer to storage for monotonic -> boottime offset
1587+
* @offs_tai: pointer to storage for monotonic -> clock tai offset
1588+
*
1589+
* Returns monotonic time at last tick and various offsets
15891590
*/
1590-
void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim,
1591-
struct timespec *wtom, struct timespec *sleep)
1591+
ktime_t ktime_get_update_offsets_tick(ktime_t *offs_real, ktime_t *offs_boot,
1592+
ktime_t *offs_tai)
15921593
{
15931594
struct timekeeper *tk = &timekeeper;
1594-
unsigned long seq;
1595+
struct timespec ts;
1596+
ktime_t now;
1597+
unsigned int seq;
15951598

15961599
do {
15971600
seq = read_seqcount_begin(&timekeeper_seq);
1598-
*xtim = tk_xtime(tk);
1599-
*wtom = tk->wall_to_monotonic;
1600-
*sleep = tk->total_sleep_time;
1601+
1602+
ts = tk_xtime(tk);
1603+
1604+
*offs_real = tk->offs_real;
1605+
*offs_boot = tk->offs_boot;
1606+
*offs_tai = tk->offs_tai;
16011607
} while (read_seqcount_retry(&timekeeper_seq, seq));
1608+
1609+
now = ktime_set(ts.tv_sec, ts.tv_nsec);
1610+
now = ktime_sub(now, *offs_real);
1611+
return now;
16021612
}
16031613

16041614
#ifdef CONFIG_HIGH_RES_TIMERS
16051615
/**
1606-
* ktime_get_update_offsets - hrtimer helper
1616+
* ktime_get_update_offsets_now - hrtimer helper
16071617
* @offs_real: pointer to storage for monotonic -> realtime offset
16081618
* @offs_boot: pointer to storage for monotonic -> boottime offset
16091619
* @offs_tai: pointer to storage for monotonic -> clock tai offset
16101620
*
16111621
* Returns current monotonic time and updates the offsets
16121622
* Called from hrtimer_interrupt() or retrigger_next_event()
16131623
*/
1614-
ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot,
1624+
ktime_t ktime_get_update_offsets_now(ktime_t *offs_real, ktime_t *offs_boot,
16151625
ktime_t *offs_tai)
16161626
{
16171627
struct timekeeper *tk = &timekeeper;

0 commit comments

Comments
 (0)