67
.index = CLOCK_REALTIME,
67
.index = HRTIMER_BASE_MONOTONIC,
68
.clockid = CLOCK_MONOTONIC,
69
.get_time = &ktime_get,
70
.resolution = KTIME_LOW_RES,
73
.index = HRTIMER_BASE_REALTIME,
74
.clockid = CLOCK_REALTIME,
68
75
.get_time = &ktime_get_real,
69
76
.resolution = KTIME_LOW_RES,
72
.index = CLOCK_MONOTONIC,
73
.get_time = &ktime_get,
74
.resolution = KTIME_LOW_RES,
77
.index = CLOCK_BOOTTIME,
79
.index = HRTIMER_BASE_BOOTTIME,
80
.clockid = CLOCK_BOOTTIME,
78
81
.get_time = &ktime_get_boottime,
79
82
.resolution = KTIME_LOW_RES,
84
static int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
87
static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
85
88
[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
86
89
[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
87
90
[CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
196
199
struct hrtimer_cpu_base *new_cpu_base;
197
200
int this_cpu = smp_processor_id();
198
201
int cpu = hrtimer_get_target(this_cpu, pinned);
199
int basenum = hrtimer_clockid_to_base(base->index);
202
int basenum = base->index;
202
205
new_cpu_base = &per_cpu(hrtimer_bases, cpu);
626
* Retrigger next event is called after clock was set
628
* Called with interrupts disabled via on_each_cpu()
630
static void retrigger_next_event(void *arg)
632
struct hrtimer_cpu_base *base;
633
struct timespec realtime_offset, wtm, sleep;
635
if (!hrtimer_hres_active())
638
get_xtime_and_monotonic_and_sleep_offset(&realtime_offset, &wtm,
640
set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
642
base = &__get_cpu_var(hrtimer_bases);
644
/* Adjust CLOCK_REALTIME offset */
645
raw_spin_lock(&base->lock);
646
base->clock_base[HRTIMER_BASE_REALTIME].offset =
647
timespec_to_ktime(realtime_offset);
648
base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
649
timespec_to_ktime(sleep);
651
hrtimer_force_reprogram(base, 0);
652
raw_spin_unlock(&base->lock);
656
* Clock realtime was set
658
* Change the offset of the realtime clock vs. the monotonic
661
* We might have to reprogram the high resolution timer interrupt. On
662
* SMP we call the architecture specific code to retrigger _all_ high
663
* resolution timer interrupts. On UP we just disable interrupts and
664
* call the high resolution interrupt code.
666
void clock_was_set(void)
668
/* Retrigger the CPU local events everywhere */
669
on_each_cpu(retrigger_next_event, NULL, 1);
673
* During resume we might have to reprogram the high resolution timer
674
* interrupt (on the local CPU):
676
void hres_timers_resume(void)
678
WARN_ONCE(!irqs_disabled(),
679
KERN_INFO "hres_timers_resume() called with IRQs enabled!");
681
retrigger_next_event(NULL);
685
628
* Initialize the high resolution related parts of cpu_base
661
* Retrigger next event is called after clock was set
663
* Called with interrupts disabled via on_each_cpu()
665
static void retrigger_next_event(void *arg)
667
struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
668
struct timespec realtime_offset, xtim, wtm, sleep;
670
if (!hrtimer_hres_active())
673
/* Optimized out for !HIGH_RES */
674
get_xtime_and_monotonic_and_sleep_offset(&xtim, &wtm, &sleep);
675
set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
677
/* Adjust CLOCK_REALTIME offset */
678
raw_spin_lock(&base->lock);
679
base->clock_base[HRTIMER_BASE_REALTIME].offset =
680
timespec_to_ktime(realtime_offset);
681
base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
682
timespec_to_ktime(sleep);
684
hrtimer_force_reprogram(base, 0);
685
raw_spin_unlock(&base->lock);
718
689
* Switch to high resolution mode
720
691
static int hrtimer_switch_to_hres(void)
722
int cpu = smp_processor_id();
693
int i, cpu = smp_processor_id();
723
694
struct hrtimer_cpu_base *base = &per_cpu(hrtimer_bases, cpu);
724
695
unsigned long flags;
737
708
base->hres_active = 1;
738
base->clock_base[HRTIMER_BASE_REALTIME].resolution = KTIME_HIGH_RES;
739
base->clock_base[HRTIMER_BASE_MONOTONIC].resolution = KTIME_HIGH_RES;
740
base->clock_base[HRTIMER_BASE_BOOTTIME].resolution = KTIME_HIGH_RES;
709
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
710
base->clock_base[i].resolution = KTIME_HIGH_RES;
742
712
tick_setup_sched_timer();
763
733
static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
734
static inline void retrigger_next_event(void *arg) { }
765
736
#endif /* CONFIG_HIGH_RES_TIMERS */
739
* Clock realtime was set
741
* Change the offset of the realtime clock vs. the monotonic
744
* We might have to reprogram the high resolution timer interrupt. On
745
* SMP we call the architecture specific code to retrigger _all_ high
746
* resolution timer interrupts. On UP we just disable interrupts and
747
* call the high resolution interrupt code.
749
void clock_was_set(void)
751
#ifdef CONFIG_HIGH_RES_TIMERS
752
/* Retrigger the CPU local events everywhere */
753
on_each_cpu(retrigger_next_event, NULL, 1);
755
timerfd_clock_was_set();
759
* During resume we might have to reprogram the high resolution timer
760
* interrupt (on the local CPU):
762
void hrtimers_resume(void)
764
WARN_ONCE(!irqs_disabled(),
765
KERN_INFO "hrtimers_resume() called with IRQs enabled!");
767
retrigger_next_event(NULL);
768
timerfd_clock_was_set();
767
771
static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
769
773
#ifdef CONFIG_TIMER_STATS
1234
1241
void hrtimer_interrupt(struct clock_event_device *dev)
1236
1243
struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
1237
struct hrtimer_clock_base *base;
1238
1244
ktime_t expires_next, now, entry_time, delta;
1239
1245
int i, retries = 0;
1257
1263
cpu_base->expires_next.tv64 = KTIME_MAX;
1259
base = cpu_base->clock_base;
1261
1265
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
1266
struct hrtimer_clock_base *base;
1267
struct timerqueue_node *node;
1262
1268
ktime_t basenow;
1263
struct timerqueue_node *node;
1270
if (!(cpu_base->active_bases & (1 << i)))
1273
base = cpu_base->clock_base + i;
1265
1274
basenow = ktime_add(now, base->offset);
1267
1276
while ((node = timerqueue_getnext(&base->active))) {
1525
1533
struct timespec __user *rmtp;
1528
hrtimer_init_on_stack(&t.timer, restart->nanosleep.index,
1536
hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid,
1529
1537
HRTIMER_MODE_ABS);
1530
1538
hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
1578
1586
restart = ¤t_thread_info()->restart_block;
1579
1587
restart->fn = hrtimer_nanosleep_restart;
1580
restart->nanosleep.index = t.timer.base->index;
1588
restart->nanosleep.clockid = t.timer.base->clockid;
1581
1589
restart->nanosleep.rmtp = rmtp;
1582
1590
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);