1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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>
29#include <asm/io.h>
30
31static int pm_tmr_ioport = 0;
32
33
34static u32 read_pmtmr(void)
35{
36 u32 v1=0,v2=0,v3=0;
37
38
39
40
41
42 do {
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));
48
49
50 return (v2 & 0xFFFFFF);
51}
52
53static int __init cpufreq_test_tsc(void)
54{
55 u32 now, then, diff;
56 u64 now_tsc, then_tsc, diff_tsc;
57 int i;
58
59
60
61
62
63 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
64
65 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
66 ACPI_ADR_SPACE_SYSTEM_IO)
67 return 0;
68
69 pm_tmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
70
71
72
73
74
75 if (!pm_tmr_ioport)
76 pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block;
77 } else {
78
79 pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block;
80 }
81
82 printk(KERN_DEBUG "start--> \n");
83 then = read_pmtmr();
84 then_tsc = rdtsc();
85 for (i=0;i<20;i++) {
86 mdelay(100);
87 now = read_pmtmr();
88 now_tsc = rdtsc();
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);
92 then = now;
93 then_tsc = now_tsc;
94 }
95 printk(KERN_DEBUG "<-- end \n");
96 return -ENODEV;
97}
98
99static void __exit cpufreq_none(void)
100{
101 return;
102}
103
104module_init(cpufreq_test_tsc)
105module_exit(cpufreq_none)
106
107
108MODULE_AUTHOR("Dominik Brodowski");
109MODULE_DESCRIPTION("Verify the TSC cpufreq notifier working correctly -- needs ACPI-enabled system");
110MODULE_LICENSE ("GPL");
111