~ubuntu-branches/ubuntu/trusty/linux-armadaxp/trusty

« back to all changes in this revision

Viewing changes to tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c

  • Committer: Package Import Robot
  • Author(s): Michael Casadevall, Bryan Wu, Dann Frazier, Michael Casadeall
  • Date: 2012-03-10 15:00:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120310150054-flugb39zon8vvgwe
Tags: 3.2.0-1600.1
[ Bryan Wu ]
* UBUNTU: import debian/debian.env and debian.armadaxp

[ Dann Frazier ]
* ARM: Armada XP: remove trailing '/' in dirnames in mvRules.mk

[ Michael Casadeall ]
* tools: add some tools for Marvell Armada XP processor
* kernel: timer tick hacking from Marvell
* kernel: Sheeva Errata: add delay on Sheeva when powering down
* net: add Marvell NFP netfilter
* net: socket and skb modifications made by Marvell
* miscdevice: add minor IDs for some Marvell Armada drivers
* fs: introduce memory pool for splice()
* video: EDID detection updates from Marvell Armada XP patchset
* video: backlight: add Marvell Dove LCD backlight driver
* video: display: add THS8200 display driver
* video: framebuffer: add Marvell Dove and Armada XP processor onchip LCD controller driver
* usbtest: add Interrupt transfer testing by Marvell Armada XP code
* usb: ehci: add support for Marvell EHCI controler
* tty/serial: 8250: add support for Marvell Armada XP processor and DeviceTree work
* rtc: add support for Marvell Armada XP onchip RTC controller
* net: pppoe: add Marvell ethernet NFP hook in PPPoE networking driver
* mtd: nand: add support for Marvell Armada XP Nand Flash Controller
* mtd: maps: add Marvell Armada XP specific map driver
* mmc: add support for Marvell Armada XP MMC/SD host controller
* i2c: add support for Marvell Armada XP onchip i2c bus controller
* hwmon: add Kconfig option for Armada XP onchip thermal sensor driver
* dmaengine: add Net DMA support for splice and update Marvell XOR DMA engine driver
* ata: add support for Marvell Armada XP SATA controller and update some quirks
* ARM: add Marvell Armada XP machine to mach-types
* ARM: oprofile: add support for Marvell PJ4B core
* ARM: mm: more ARMv6 switches for Marvell Armada XP
* ARM: remove static declaration to allow compilation
* ARM: alignment access fault trick
* ARM: mm: skip some fault fixing when run on NONE SMP ARMv6 mode during early abort event
* ARM: mm: add Marvell Sheeva CPU Architecture for PJ4B
* ARM: introduce optimized copy operation for Marvell Armada XP
* ARM: SAUCE: hardware breakpoint trick for Marvell Armada XP
* ARM: big endian and little endian tricks for Marvell Armada XP
* ARM: SAUCE: Add Marvell Armada XP build rules to arch/arm/kernel/Makefile
* ARM: vfp: add special handling for Marvell Armada XP
* ARM: add support for Marvell U-Boot
* ARM: add mv_controller_num for ARM PCI drivers
* ARM: add support for local PMUs, general SMP tweaks and cache flushing
* ARM: add Marvell device identifies in glue-proc.h
* ARM: add IPC driver support for Marvell platforms
* ARM: add DMA mapping for Marvell platforms
* ARM: add Sheeva errata and PJ4B code for booting
* ARM: update Kconfig and Makefile to include Marvell Armada XP platforms
* ARM: Armada XP: import LSP from Marvell for Armada XP 3.2 kernel enablement

Show diffs side-by-side

added added

removed removed

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