cpufreq-test_tsc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * test module to check whether the TSC-based delay routine continues
  3. * to work properly after cpufreq transitions. Needs ACPI to work
  4. * properly.
  5. *
  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
  9. * from that file.
  10. *
  11. * (C) 2004 Dominik Brodowski
  12. *
  13. * To use:
  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. * cpufreq@vger.kernel.org
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <asm/io.h>
  28. #include <acpi/acpi_bus.h>
  29. #include <acpi/acpi_drivers.h>
  30. static int pm_tmr_ioport = 0;
  31. /*helper function to safely read acpi pm timesource*/
  32. static u32 read_pmtmr(void)
  33. {
  34. u32 v1=0,v2=0,v3=0;
  35. /* It has been reported that because of various broken
  36. * chipsets (ICH4, PIIX4 and PIIX4E) where the ACPI PM time
  37. * source is not latched, so you must read it multiple
  38. * times to insure a safe value is read.
  39. */
  40. do {
  41. v1 = inl(pm_tmr_ioport);
  42. v2 = inl(pm_tmr_ioport);
  43. v3 = inl(pm_tmr_ioport);
  44. } while ((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1)
  45. || (v3 > v1 && v3 < v2));
  46. /* mask the output to 24 bits */
  47. return (v2 & 0xFFFFFF);
  48. }
  49. static int __init cpufreq_test_tsc(void)
  50. {
  51. u32 now, then, diff;
  52. u64 now_tsc, then_tsc, diff_tsc;
  53. int i;
  54. /* the following code snipped is copied from arch/x86/kernel/acpi/boot.c
  55. of Linux v2.6.25. */
  56. /* detect the location of the ACPI PM Timer */
  57. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
  58. /* FADT rev. 2 */
  59. if (acpi_gbl_FADT.xpm_timer_block.space_id !=
  60. ACPI_ADR_SPACE_SYSTEM_IO)
  61. return 0;
  62. pm_tmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
  63. /*
  64. * "X" fields are optional extensions to the original V1.0
  65. * fields, so we must selectively expand V1.0 fields if the
  66. * corresponding X field is zero.
  67. */
  68. if (!pm_tmr_ioport)
  69. pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block;
  70. } else {
  71. /* FADT rev. 1 */
  72. pm_tmr_ioport = acpi_gbl_FADT.pm_timer_block;
  73. }
  74. printk(KERN_DEBUG "start--> \n");
  75. then = read_pmtmr();
  76. rdtscll(then_tsc);
  77. for (i=0;i<20;i++) {
  78. mdelay(100);
  79. now = read_pmtmr();
  80. rdtscll(now_tsc);
  81. diff = (now - then) & 0xFFFFFF;
  82. diff_tsc = now_tsc - then_tsc;
  83. printk(KERN_DEBUG "t1: %08u t2: %08u diff_pmtmr: %08u diff_tsc: %016llu\n", then, now, diff, diff_tsc);
  84. then = now;
  85. then_tsc = now_tsc;
  86. }
  87. printk(KERN_DEBUG "<-- end \n");
  88. return -ENODEV;
  89. }
  90. static void __exit cpufreq_none(void)
  91. {
  92. return;
  93. }
  94. module_init(cpufreq_test_tsc)
  95. module_exit(cpufreq_none)
  96. MODULE_AUTHOR("Dominik Brodowski");
  97. MODULE_DESCRIPTION("Verify the TSC cpufreq notifier working correctly -- needs ACPI-enabled system");
  98. MODULE_LICENSE ("GPL");