Skip to content

Commit 398ca17

Browse files
committed
hrtimer: Get rid of the resolution field in hrtimer_clock_base
The field has no value because all clock bases have the same resolution. The resolution only changes when we switch to high resolution timer mode. We can evaluate that from a single static variable as well. In the !HIGHRES case its simply a constant. Export the variable, so we can simplify the usage sites. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Preeti U Murthy <preeti@linux.vnet.ibm.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Link: http://lkml.kernel.org/r/20150414203500.645454122@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent d9f0acd commit 398ca17

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

‎include/linux/hrtimer.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ struct hrtimer_sleeper {
137137
* timer to a base on another cpu.
138138
* @clockid: clock id for per_cpu support
139139
* @active: red black tree root node for the active timers
140-
* @resolution: the resolution of the clock, in nanoseconds
141140
* @get_time: function to retrieve the current time of the clock
142141
* @softirq_time: the time when running the hrtimer queue in the softirq
143142
* @offset: offset of this clock to the monotonic base
@@ -147,7 +146,6 @@ struct hrtimer_clock_base {
147146
int index;
148147
clockid_t clockid;
149148
struct timerqueue_head active;
150-
ktime_t resolution;
151149
ktime_t (*get_time)(void);
152150
ktime_t softirq_time;
153151
ktime_t offset;
@@ -295,11 +293,15 @@ extern void hrtimer_peek_ahead_timers(void);
295293

296294
extern void clock_was_set_delayed(void);
297295

296+
extern unsigned int hrtimer_resolution;
297+
298298
#else
299299

300300
# define MONOTONIC_RES_NSEC LOW_RES_NSEC
301301
# define KTIME_MONOTONIC_RES KTIME_LOW_RES
302302

303+
#define hrtimer_resolution LOW_RES_NSEC
304+
303305
static inline void hrtimer_peek_ahead_timers(void) { }
304306

305307
/*

‎kernel/time/hrtimer.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,28 @@
6666
*/
6767
DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
6868
{
69-
7069
.lock = __RAW_SPIN_LOCK_UNLOCKED(hrtimer_bases.lock),
7170
.clock_base =
7271
{
7372
{
7473
.index = HRTIMER_BASE_MONOTONIC,
7574
.clockid = CLOCK_MONOTONIC,
7675
.get_time = &ktime_get,
77-
.resolution = KTIME_LOW_RES,
7876
},
7977
{
8078
.index = HRTIMER_BASE_REALTIME,
8179
.clockid = CLOCK_REALTIME,
8280
.get_time = &ktime_get_real,
83-
.resolution = KTIME_LOW_RES,
8481
},
8582
{
8683
.index = HRTIMER_BASE_BOOTTIME,
8784
.clockid = CLOCK_BOOTTIME,
8885
.get_time = &ktime_get_boottime,
89-
.resolution = KTIME_LOW_RES,
9086
},
9187
{
9288
.index = HRTIMER_BASE_TAI,
9389
.clockid = CLOCK_TAI,
9490
.get_time = &ktime_get_clocktai,
95-
.resolution = KTIME_LOW_RES,
9691
},
9792
}
9893
};
@@ -478,6 +473,8 @@ static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base)
478473
* High resolution timer enabled ?
479474
*/
480475
static int hrtimer_hres_enabled __read_mostly = 1;
476+
unsigned int hrtimer_resolution __read_mostly = LOW_RES_NSEC;
477+
EXPORT_SYMBOL_GPL(hrtimer_resolution);
481478

482479
/*
483480
* Enable / Disable high resolution mode
@@ -660,7 +657,7 @@ static void retrigger_next_event(void *arg)
660657
*/
661658
static int hrtimer_switch_to_hres(void)
662659
{
663-
int i, cpu = smp_processor_id();
660+
int cpu = smp_processor_id();
664661
struct hrtimer_cpu_base *base = &per_cpu(hrtimer_bases, cpu);
665662
unsigned long flags;
666663

@@ -676,8 +673,7 @@ static int hrtimer_switch_to_hres(void)
676673
return 0;
677674
}
678675
base->hres_active = 1;
679-
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
680-
base->clock_base[i].resolution = KTIME_HIGH_RES;
676+
hrtimer_resolution = HIGH_RES_NSEC;
681677

682678
tick_setup_sched_timer();
683679
/* "Retrigger" the interrupt to get things going */
@@ -820,8 +816,8 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
820816
if (delta.tv64 < 0)
821817
return 0;
822818

823-
if (interval.tv64 < timer->base->resolution.tv64)
824-
interval.tv64 = timer->base->resolution.tv64;
819+
if (interval.tv64 < hrtimer_resolution)
820+
interval.tv64 = hrtimer_resolution;
825821

826822
if (unlikely(delta.tv64 >= interval.tv64)) {
827823
s64 incr = ktime_to_ns(interval);
@@ -963,7 +959,7 @@ int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
963959
* timeouts. This will go away with the GTOD framework.
964960
*/
965961
#ifdef CONFIG_TIME_LOW_RES
966-
tim = ktime_add_safe(tim, base->resolution);
962+
tim = ktime_add_safe(tim, ktime_set(0, hrtimer_resolution));
967963
#endif
968964
}
969965

@@ -1193,12 +1189,8 @@ EXPORT_SYMBOL_GPL(hrtimer_init);
11931189
*/
11941190
int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
11951191
{
1196-
struct hrtimer_cpu_base *cpu_base;
1197-
int base = hrtimer_clockid_to_base(which_clock);
1198-
1199-
cpu_base = raw_cpu_ptr(&hrtimer_bases);
1200-
*tp = ktime_to_timespec(cpu_base->clock_base[base].resolution);
1201-
1192+
tp->tv_sec = 0;
1193+
tp->tv_nsec = hrtimer_resolution;
12021194
return 0;
12031195
}
12041196
EXPORT_SYMBOL_GPL(hrtimer_get_res);

‎kernel/time/timer_list.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ static void
127127
print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
128128
{
129129
SEQ_printf(m, " .base: %pK\n", base);
130-
SEQ_printf(m, " .index: %d\n",
131-
base->index);
132-
SEQ_printf(m, " .resolution: %Lu nsecs\n",
133-
(unsigned long long)ktime_to_ns(base->resolution));
130+
SEQ_printf(m, " .index: %d\n", base->index);
131+
132+
SEQ_printf(m, " .resolution: %u nsecs\n", (unsigned) hrtimer_resolution);
133+
134134
SEQ_printf(m, " .get_time: ");
135135
print_name_offset(m, base->get_time);
136136
SEQ_printf(m, "\n");

0 commit comments

Comments
 (0)