10 #include <linux/timex.h>
24 #ifdef ARCH_HAS_READ_CURRENT_TIMER
31 #define DELAY_CALIBRATION_TICKS ((HZ < 100) ? 1 : (HZ/100))
32 #define MAX_DIRECT_CALIBRATION_RETRIES 5
34 static unsigned long __cpuinit calibrate_delay_direct(
void)
36 unsigned long pre_start,
start, post_start;
37 unsigned long pre_end,
end, post_end;
38 unsigned long start_jiffies;
39 unsigned long timer_rate_min, timer_rate_max;
40 unsigned long good_timer_sum = 0;
41 unsigned long good_timer_count = 0;
42 unsigned long measured_times[MAX_DIRECT_CALIBRATION_RETRIES];
69 for (i = 0; i < MAX_DIRECT_CALIBRATION_RETRIES; i++) {
82 DELAY_CALIBRATION_TICKS)) {
88 timer_rate_max = (post_end - pre_start) /
89 DELAY_CALIBRATION_TICKS;
90 timer_rate_min = (pre_end - post_start) /
91 DELAY_CALIBRATION_TICKS;
97 if (start >= post_end)
99 "timer_rate as we had a TSC wrap around"
100 " start=%lu >=post_end=%lu\n",
102 if (start < post_end && pre_start != 0 && pre_end != 0 &&
103 (timer_rate_max - timer_rate_min) < (timer_rate_max >> 3)) {
105 good_timer_sum += timer_rate_max;
106 measured_times[
i] = timer_rate_max;
107 if (max < 0 || timer_rate_max > measured_times[max])
109 if (min < 0 || timer_rate_max < measured_times[min])
112 measured_times[
i] = 0;
120 while (good_timer_count > 1) {
121 unsigned long estimate;
122 unsigned long maxdiff;
125 estimate = (good_timer_sum/good_timer_count);
126 maxdiff = estimate >> 3;
129 if ((measured_times[max] - measured_times[min]) < maxdiff)
134 good_timer_count = 0;
135 if ((measured_times[max] - estimate) <
136 (estimate - measured_times[
min])) {
138 "min bogoMips estimate %d = %lu\n",
139 min, measured_times[min]);
140 measured_times[
min] = 0;
144 "max bogoMips estimate %d = %lu\n",
145 max, measured_times[max]);
146 measured_times[
max] = 0;
150 for (i = 0; i < MAX_DIRECT_CALIBRATION_RETRIES; i++) {
151 if (measured_times[i] == 0)
154 good_timer_sum += measured_times[
i];
155 if (measured_times[i] < measured_times[min])
157 if (measured_times[i] > measured_times[max])
164 "estimate for loops_per_jiffy.\nProbably due to long platform "
165 "interrupts. Consider using \"lpj=\" boot option.\n");
169 static unsigned long __cpuinit calibrate_delay_direct(
void) {
return 0;}
183 static unsigned long __cpuinit calibrate_delay_converge(
void)
186 unsigned long lpj, lpj_base,
ticks, loopadd, loopadd_base, chop_limit;
187 int trials = 0, band = 0, trial_in_band = 0;
198 if (++trial_in_band == (1<<band)) {
210 loopadd_base = lpj * band;
211 lpj_base = lpj * trials;
215 loopadd = loopadd_base;
222 while (loopadd > chop_limit) {
238 if (lpj + loopadd * 2 == lpj_base + loopadd_base * 2) {
247 static DEFINE_PER_CPU(
unsigned long, cpu_loops_per_jiffy) = { 0 };
268 if (
per_cpu(cpu_loops_per_jiffy, this_cpu)) {
269 lpj =
per_cpu(cpu_loops_per_jiffy, this_cpu);
271 pr_info(
"Calibrating delay loop (skipped) "
272 "already calibrated this CPU");
276 pr_info(
"Calibrating delay loop (skipped) "
278 }
else if ((!printed) &&
lpj_fine) {
280 pr_info(
"Calibrating delay loop (skipped), "
281 "value calculated using timer frequency.. ");
284 }
else if ((lpj = calibrate_delay_direct()) != 0) {
286 pr_info(
"Calibrating delay using timer "
287 "specific routine.. ");
290 pr_info(
"Calibrating delay loop... ");
291 lpj = calibrate_delay_converge();
293 per_cpu(cpu_loops_per_jiffy, this_cpu) = lpj;
295 pr_cont(
"%lu.%02lu BogoMIPS (lpj=%lu)\n",
297 (lpj/(5000/
HZ)) % 100, lpj);