diff options
Diffstat (limited to 'kernel/time/jiffies.c')
-rw-r--r-- | kernel/time/jiffies.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index a470154e0408..6629bf7b5285 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c | |||
@@ -37,7 +37,7 @@ | |||
37 | * requested HZ value. It is also not recommended | 37 | * requested HZ value. It is also not recommended |
38 | * for "tick-less" systems. | 38 | * for "tick-less" systems. |
39 | */ | 39 | */ |
40 | #define NSEC_PER_JIFFY ((u32)((((u64)NSEC_PER_SEC)<<8)/ACTHZ)) | 40 | #define NSEC_PER_JIFFY ((NSEC_PER_SEC+HZ/2)/HZ) |
41 | 41 | ||
42 | /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier | 42 | /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier |
43 | * conversion, the .shift value could be zero. However | 43 | * conversion, the .shift value could be zero. However |
@@ -95,3 +95,33 @@ struct clocksource * __init __weak clocksource_default_clock(void) | |||
95 | { | 95 | { |
96 | return &clocksource_jiffies; | 96 | return &clocksource_jiffies; |
97 | } | 97 | } |
98 | |||
99 | struct clocksource refined_jiffies; | ||
100 | |||
101 | int register_refined_jiffies(long cycles_per_second) | ||
102 | { | ||
103 | u64 nsec_per_tick, shift_hz; | ||
104 | long cycles_per_tick; | ||
105 | |||
106 | |||
107 | |||
108 | refined_jiffies = clocksource_jiffies; | ||
109 | refined_jiffies.name = "refined-jiffies"; | ||
110 | refined_jiffies.rating++; | ||
111 | |||
112 | /* Calc cycles per tick */ | ||
113 | cycles_per_tick = (cycles_per_second + HZ/2)/HZ; | ||
114 | /* shift_hz stores hz<<8 for extra accuracy */ | ||
115 | shift_hz = (u64)cycles_per_second << 8; | ||
116 | shift_hz += cycles_per_tick/2; | ||
117 | do_div(shift_hz, cycles_per_tick); | ||
118 | /* Calculate nsec_per_tick using shift_hz */ | ||
119 | nsec_per_tick = (u64)NSEC_PER_SEC << 8; | ||
120 | nsec_per_tick += (u32)shift_hz/2; | ||
121 | do_div(nsec_per_tick, (u32)shift_hz); | ||
122 | |||
123 | refined_jiffies.mult = ((u32)nsec_per_tick) << JIFFIES_SHIFT; | ||
124 | |||
125 | clocksource_register(&refined_jiffies); | ||
126 | return 0; | ||
127 | } | ||