Skip to content

Commit ab0e08f

Browse files
committed
x86: hpet: Cleanup the clockevents init and register code
No need to recalculate the frequency and the conversion factors over and over. Calculate the frequency once and use the new config/register interface and let the core code do the math. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: John Stultz <john.stultz@linaro.org> Reviewed-by: Ingo Molnar <mingo@elte.hu> Link: http://lkml.kernel.org/r/%3C20110518210136.646482357%40linutronix.de%3E
1 parent 61ee9a4 commit ab0e08f

File tree

1 file changed

+16
-56
lines changed

1 file changed

+16
-56
lines changed

arch/x86/kernel/hpet.c

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void hpet_reserve_platform_timers(unsigned int id) { }
217217
/*
218218
* Common hpet info
219219
*/
220-
static unsigned long hpet_period;
220+
static unsigned long hpet_freq;
221221

222222
static void hpet_legacy_set_mode(enum clock_event_mode mode,
223223
struct clock_event_device *evt);
@@ -232,7 +232,6 @@ static struct clock_event_device hpet_clockevent = {
232232
.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
233233
.set_mode = hpet_legacy_set_mode,
234234
.set_next_event = hpet_legacy_next_event,
235-
.shift = 32,
236235
.irq = 0,
237236
.rating = 50,
238237
};
@@ -289,29 +288,13 @@ static void hpet_legacy_clockevent_register(void)
289288
/* Start HPET legacy interrupts */
290289
hpet_enable_legacy_int();
291290

292-
/*
293-
* The mult factor is defined as (include/linux/clockchips.h)
294-
* mult/2^shift = cyc/ns (in contrast to ns/cyc in clocksource.h)
295-
* hpet_period is in units of femtoseconds (per cycle), so
296-
* mult/2^shift = cyc/ns = 10^6/hpet_period
297-
* mult = (10^6 * 2^shift)/hpet_period
298-
* mult = (FSEC_PER_NSEC << hpet_clockevent.shift)/hpet_period
299-
*/
300-
hpet_clockevent.mult = div_sc((unsigned long) FSEC_PER_NSEC,
301-
hpet_period, hpet_clockevent.shift);
302-
/* Calculate the min / max delta */
303-
hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF,
304-
&hpet_clockevent);
305-
/* Setup minimum reprogramming delta. */
306-
hpet_clockevent.min_delta_ns = clockevent_delta2ns(HPET_MIN_PROG_DELTA,
307-
&hpet_clockevent);
308-
309291
/*
310292
* Start hpet with the boot cpu mask and make it
311293
* global after the IO_APIC has been initialized.
312294
*/
313295
hpet_clockevent.cpumask = cpumask_of(smp_processor_id());
314-
clockevents_register_device(&hpet_clockevent);
296+
clockevents_config_and_register(&hpet_clockevent, hpet_freq,
297+
HPET_MIN_PROG_DELTA, 0x7FFFFFFF);
315298
global_clock_event = &hpet_clockevent;
316299
printk(KERN_DEBUG "hpet clockevent registered\n");
317300
}
@@ -549,7 +532,6 @@ static int hpet_setup_irq(struct hpet_dev *dev)
549532
static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu)
550533
{
551534
struct clock_event_device *evt = &hdev->evt;
552-
uint64_t hpet_freq;
553535

554536
WARN_ON(cpu != smp_processor_id());
555537
if (!(hdev->flags & HPET_DEV_VALID))
@@ -571,24 +553,10 @@ static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu)
571553

572554
evt->set_mode = hpet_msi_set_mode;
573555
evt->set_next_event = hpet_msi_next_event;
574-
evt->shift = 32;
575-
576-
/*
577-
* The period is a femto seconds value. We need to calculate the
578-
* scaled math multiplication factor for nanosecond to hpet tick
579-
* conversion.
580-
*/
581-
hpet_freq = FSEC_PER_SEC;
582-
do_div(hpet_freq, hpet_period);
583-
evt->mult = div_sc((unsigned long) hpet_freq,
584-
NSEC_PER_SEC, evt->shift);
585-
/* Calculate the max delta */
586-
evt->max_delta_ns = clockevent_delta2ns(0x7FFFFFFF, evt);
587-
/* 5 usec minimum reprogramming delta. */
588-
evt->min_delta_ns = 5000;
589-
590556
evt->cpumask = cpumask_of(hdev->cpu);
591-
clockevents_register_device(evt);
557+
558+
clockevents_config_and_register(evt, hpet_freq, HPET_MIN_PROG_DELTA,
559+
0x7FFFFFFF);
592560
}
593561

594562
#ifdef CONFIG_HPET
@@ -792,7 +760,6 @@ static struct clocksource clocksource_hpet = {
792760
static int hpet_clocksource_register(void)
793761
{
794762
u64 start, now;
795-
u64 hpet_freq;
796763
cycle_t t1;
797764

798765
/* Start the counter */
@@ -819,24 +786,7 @@ static int hpet_clocksource_register(void)
819786
return -ENODEV;
820787
}
821788

822-
/*
823-
* The definition of mult is (include/linux/clocksource.h)
824-
* mult/2^shift = ns/cyc and hpet_period is in units of fsec/cyc
825-
* so we first need to convert hpet_period to ns/cyc units:
826-
* mult/2^shift = ns/cyc = hpet_period/10^6
827-
* mult = (hpet_period * 2^shift)/10^6
828-
* mult = (hpet_period << shift)/FSEC_PER_NSEC
829-
*/
830-
831-
/* Need to convert hpet_period (fsec/cyc) to cyc/sec:
832-
*
833-
* cyc/sec = FSEC_PER_SEC/hpet_period(fsec/cyc)
834-
* cyc/sec = (FSEC_PER_NSEC * NSEC_PER_SEC)/hpet_period
835-
*/
836-
hpet_freq = FSEC_PER_SEC;
837-
do_div(hpet_freq, hpet_period);
838789
clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
839-
840790
return 0;
841791
}
842792

@@ -845,7 +795,9 @@ static int hpet_clocksource_register(void)
845795
*/
846796
int __init hpet_enable(void)
847797
{
798+
unsigned long hpet_period;
848799
unsigned int id;
800+
u64 freq;
849801
int i;
850802

851803
if (!is_hpet_capable())
@@ -883,6 +835,14 @@ int __init hpet_enable(void)
883835
if (hpet_period < HPET_MIN_PERIOD || hpet_period > HPET_MAX_PERIOD)
884836
goto out_nohpet;
885837

838+
/*
839+
* The period is a femto seconds value. Convert it to a
840+
* frequency.
841+
*/
842+
freq = FSEC_PER_SEC;
843+
do_div(freq, hpet_period);
844+
hpet_freq = freq;
845+
886846
/*
887847
* Read the HPET ID register to retrieve the IRQ routing
888848
* information and the number of channels

0 commit comments

Comments
 (0)