2 * test module to check whether the TSC-based delay routine continues
3 * to work properly after cpufreq transitions. Needs ACPI to work
6 * Based partly on the Power Management Timer (PMTMR) code to be found
7 * in arch/i386/kernel/timers/timer_pm.c on recent 2.6. kernels, especially
8 * code written by John Stultz. The read_pmtmr function was copied verbatim
11 * (C) 2004 Dominik Brodowski
14 * 1.) pass clock=tsc to the kernel on your bootloader
15 * 2.) modprobe this module (it'll fail)
16 * 3.) change CPU frequency
17 * 4.) modprobe this module again
18 * 5.) if the third value, "diff_pmtmr", changes between 2. and 4., the
19 * TSC-based delay routine on the Linux kernel does not correctly
20 * handle the cpufreq transition. Please report this to
21 * linux-pm@vger.kernel.org
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/acpi.h>
31 static int pm_tmr_ioport
= 0;
33 /*helper function to safely read acpi pm timesource*/
34 static u32
read_pmtmr(void)
37 /* It has been reported that because of various broken
38 * chipsets (ICH4, PIIX4 and PIIX4E) where the ACPI PM time
39 * source is not latched, so you must read it multiple
40 * times to insure a safe value is read.
43 v1
= inl(pm_tmr_ioport
);
44 v2
= inl(pm_tmr_ioport
);
45 v3
= inl(pm_tmr_ioport
);
46 } while ((v1
> v2
&& v1
< v3
) || (v2
> v3
&& v2
< v1
)
47 || (v3
> v1
&& v3
< v2
));
49 /* mask the output to 24 bits */
50 return (v2
& 0xFFFFFF);
53 static int __init
cpufreq_test_tsc(void)
56 u64 now_tsc
, then_tsc
, diff_tsc
;
59 /* the following code snipped is copied from arch/x86/kernel/acpi/boot.c
62 /* detect the location of the ACPI PM Timer */
63 if (acpi_gbl_FADT
.header
.revision
>= FADT2_REVISION_ID
) {
65 if (acpi_gbl_FADT
.xpm_timer_block
.space_id
!=
66 ACPI_ADR_SPACE_SYSTEM_IO
)
69 pm_tmr_ioport
= acpi_gbl_FADT
.xpm_timer_block
.address
;
71 * "X" fields are optional extensions to the original V1.0
72 * fields, so we must selectively expand V1.0 fields if the
73 * corresponding X field is zero.
76 pm_tmr_ioport
= acpi_gbl_FADT
.pm_timer_block
;
79 pm_tmr_ioport
= acpi_gbl_FADT
.pm_timer_block
;
82 printk(KERN_DEBUG
"start--> \n");
89 diff
= (now
- then
) & 0xFFFFFF;
90 diff_tsc
= now_tsc
- then_tsc
;
91 printk(KERN_DEBUG
"t1: %08u t2: %08u diff_pmtmr: %08u diff_tsc: %016llu\n", then
, now
, diff
, diff_tsc
);
95 printk(KERN_DEBUG
"<-- end \n");
99 static void __exit
cpufreq_none(void)
104 module_init(cpufreq_test_tsc
)
105 module_exit(cpufreq_none
)
108 MODULE_AUTHOR("Dominik Brodowski");
109 MODULE_DESCRIPTION("Verify the TSC cpufreq notifier working correctly -- needs ACPI-enabled system");
110 MODULE_LICENSE ("GPL");