Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 234621
b: refs/heads/master
c: e06383d
h: refs/heads/master
i:
  234619: 9bdde77
v: v3
  • Loading branch information
John Stultz committed Feb 21, 2011
1 parent 56d5e31 commit f8bc2a9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: db1c1cce4a653dcbe6949c72ae7b9f42cab1b929
refs/heads/master: e06383db9ec591696a06654257474b85bac1f8cb
6 changes: 5 additions & 1 deletion trunk/include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ struct hrtimer_clock_base {
#endif
};

#define HRTIMER_MAX_CLOCK_BASES 2
enum hrtimer_base_type {
HRTIMER_BASE_REALTIME,
HRTIMER_BASE_MONOTONIC,
HRTIMER_MAX_CLOCK_BASES,
};

/*
* struct hrtimer_cpu_base - the per cpu clock bases
Expand Down
40 changes: 27 additions & 13 deletions trunk/kernel/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@
/*
* The timer bases:
*
* Note: If we want to add new timer bases, we have to skip the two
* clock ids captured by the cpu-timers. We do this by holding empty
* entries rather than doing math adjustment of the clock ids.
* This ensures that we capture erroneous accesses to these clock ids
* rather than moving them into the range of valid clock id's.
* There are more clockids then hrtimer bases. Thus, we index
* into the timer bases by the hrtimer_base_type enum. When trying
* to reach a base using a clockid, hrtimer_clockid_to_base()
* is used to convert from clockid to the proper hrtimer_base_type.
*/
DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
{
Expand All @@ -77,6 +76,14 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
}
};

static int hrtimer_clock_to_base_table[MAX_CLOCKS];

static inline int hrtimer_clockid_to_base(clockid_t clock_id)
{
return hrtimer_clock_to_base_table[clock_id];
}


/*
* Get the coarse grained time at the softirq based on xtime and
* wall_to_monotonic.
Expand All @@ -90,8 +97,8 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)

xtim = timespec_to_ktime(xts);
tomono = timespec_to_ktime(tom);
base->clock_base[CLOCK_REALTIME].softirq_time = xtim;
base->clock_base[CLOCK_MONOTONIC].softirq_time =
base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim;
base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time =
ktime_add(xtim, tomono);
}

Expand Down Expand Up @@ -179,10 +186,11 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,
struct hrtimer_cpu_base *new_cpu_base;
int this_cpu = smp_processor_id();
int cpu = hrtimer_get_target(this_cpu, pinned);
int basenum = hrtimer_clockid_to_base(base->index);

again:
new_cpu_base = &per_cpu(hrtimer_bases, cpu);
new_base = &new_cpu_base->clock_base[base->index];
new_base = &new_cpu_base->clock_base[basenum];

if (base != new_base) {
/*
Expand Down Expand Up @@ -618,7 +626,7 @@ static void retrigger_next_event(void *arg)

/* Adjust CLOCK_REALTIME offset */
raw_spin_lock(&base->lock);
base->clock_base[CLOCK_REALTIME].offset =
base->clock_base[HRTIMER_BASE_REALTIME].offset =
timespec_to_ktime(realtime_offset);

hrtimer_force_reprogram(base, 0);
Expand Down Expand Up @@ -716,8 +724,8 @@ static int hrtimer_switch_to_hres(void)
return 0;
}
base->hres_active = 1;
base->clock_base[CLOCK_REALTIME].resolution = KTIME_HIGH_RES;
base->clock_base[CLOCK_MONOTONIC].resolution = KTIME_HIGH_RES;
base->clock_base[HRTIMER_BASE_REALTIME].resolution = KTIME_HIGH_RES;
base->clock_base[HRTIMER_BASE_MONOTONIC].resolution = KTIME_HIGH_RES;

tick_setup_sched_timer();

Expand Down Expand Up @@ -1112,6 +1120,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
enum hrtimer_mode mode)
{
struct hrtimer_cpu_base *cpu_base;
int base;

memset(timer, 0, sizeof(struct hrtimer));

Expand All @@ -1120,7 +1129,8 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS)
clock_id = CLOCK_MONOTONIC;

timer->base = &cpu_base->clock_base[clock_id];
base = hrtimer_clockid_to_base(clock_id);
timer->base = &cpu_base->clock_base[base];
hrtimer_init_timer_hres(timer);
timerqueue_init(&timer->node);

Expand Down Expand Up @@ -1156,9 +1166,10 @@ EXPORT_SYMBOL_GPL(hrtimer_init);
int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
{
struct hrtimer_cpu_base *cpu_base;
int base = hrtimer_clockid_to_base(which_clock);

cpu_base = &__raw_get_cpu_var(hrtimer_bases);
*tp = ktime_to_timespec(cpu_base->clock_base[which_clock].resolution);
*tp = ktime_to_timespec(cpu_base->clock_base[base].resolution);

return 0;
}
Expand Down Expand Up @@ -1705,6 +1716,9 @@ static struct notifier_block __cpuinitdata hrtimers_nb = {

void __init hrtimers_init(void)
{
hrtimer_clock_to_base_table[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME;
hrtimer_clock_to_base_table[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC;

hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
(void *)(long)smp_processor_id());
register_cpu_notifier(&hrtimers_nb);
Expand Down

0 comments on commit f8bc2a9

Please sign in to comment.