All pastes #82236 Raw Edit

Untitled

public text v1 · immutable
·published 2006-07-08 05:42 UTC
rendered paste body
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/init.h>

#include <asm/timex.h>

static unsigned long preset_lpj;
static int __init lpj_setup(char *str)
{
	preset_lpj = simple_strtoul(str,NULL,0);
	return 1;
}

__setup("lpj=", lpj_setup);

#ifdef ARCH_HAS_READ_CURRENT_TIMER

#define DELAY_CALIBRATION_TICKS			((HZ < 100) ? 1 : (HZ/100))
#define MAX_DIRECT_CALIBRATION_RETRIES		5

static unsigned long __devinit calibrate_delay_direct(void)
{

	if (read_current_timer(&pre_start) < 0 )
		return 0;

	for (i = 0; i < MAX_DIRECT_CALIBRATION_RETRIES; i++) {
		pre_start = 0;
		read_current_timer(&start);
		start_jiffies = jiffies;
		while (jiffies <= (start_jiffies + 1)) {
			pre_start = start;
			read_current_timer(&start);
		}
		read_current_timer(&post_start);

		pre_end = 0;
		end = post_start;
		if (pre_start != 0 && pre_end != 0 &&
		    (tsc_rate_max - tsc_rate_min) < (tsc_rate_max >> 3)) {
			good_tsc_count++;
			good_tsc_sum += tsc_rate_max;
		}
	}

	if (good_tsc_count)
		return (good_tsc_sum/good_tsc_count);

	printk(KERN_WARNING "calibrate_delay_direct() failed to get a good "
	       "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n");
	return 0;
}

#define LPS_PREC 8

void __devinit calibrate_delay(void)
{
	unsigned long ticks, loopbit;
	int lps_precision = LPS_PREC;

	if (preset_lpj) {
		loops_per_jiffy = preset_lpj;
		printk("Calibrating delay loop (skipped)... "
			"%lu.%02lu BogoMIPS preset\n",
			loops_per_jiffy/(500000/HZ),
			(loops_per_jiffy/(5000/HZ)) % 100);
	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
		printk("Calibrating delay using timer specific routine.. ");
		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
			loops_per_jiffy/(500000/HZ),
			(loops_per_jiffy/(5000/HZ)) % 100,
			loops_per_jiffy);
	} else {
		loops_per_jiffy = (1<<12);

		printk(KERN_DEBUG "Calibrating delay loop... ");

		loops_per_jiffy >>= 1;
		loopbit = loops_per_jiffy;
		while (lps_precision-- && (loopbit >>= 1)) {
			loops_per_jiffy |= loopbit;
			ticks = jiffies;
			while (ticks == jiffies)
				/* nothing */;
			ticks = jiffies;
			__delay(loops_per_jiffy);
			if (jiffies != ticks)	/* longer than 1 tick */
				loops_per_jiffy &= ~loopbit;
		}

		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
			loops_per_jiffy/(500000/HZ),
			(loops_per_jiffy/(5000/HZ)) % 100,
			loops_per_jiffy);
	}

}