diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
| commit | f2006e27396f55276f24434f56e208d86e7f9908 (patch) | |
| tree | 71896db916d33888b4286f80117d3cac0da40e6d /tools | |
| parent | e399eb56a6110e13f97e644658648602e2b08de7 (diff) | |
| parent | 9903883f1dd6e86f286b7bfa6e4b423f98c1cd9e (diff) | |
Merge branch 'linus' into timers/urgent
Get upstream changes so we can apply fixes against them
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'tools')
30 files changed, 899 insertions, 120 deletions
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h index f4912e2668ba..84c17d836578 100644 --- a/tools/include/tools/be_byteshift.h +++ b/tools/include/tools/be_byteshift.h | |||
| @@ -1,68 +1,68 @@ | |||
| 1 | #ifndef _TOOLS_BE_BYTESHIFT_H | 1 | #ifndef _TOOLS_BE_BYTESHIFT_H |
| 2 | #define _TOOLS_BE_BYTESHIFT_H | 2 | #define _TOOLS_BE_BYTESHIFT_H |
| 3 | 3 | ||
| 4 | #include <linux/types.h> | 4 | #include <stdint.h> |
| 5 | 5 | ||
| 6 | static inline __u16 __get_unaligned_be16(const __u8 *p) | 6 | static inline uint16_t __get_unaligned_be16(const uint8_t *p) |
| 7 | { | 7 | { |
| 8 | return p[0] << 8 | p[1]; | 8 | return p[0] << 8 | p[1]; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | static inline __u32 __get_unaligned_be32(const __u8 *p) | 11 | static inline uint32_t __get_unaligned_be32(const uint8_t *p) |
| 12 | { | 12 | { |
| 13 | return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; | 13 | return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | static inline __u64 __get_unaligned_be64(const __u8 *p) | 16 | static inline uint64_t __get_unaligned_be64(const uint8_t *p) |
| 17 | { | 17 | { |
| 18 | return (__u64)__get_unaligned_be32(p) << 32 | | 18 | return (uint64_t)__get_unaligned_be32(p) << 32 | |
| 19 | __get_unaligned_be32(p + 4); | 19 | __get_unaligned_be32(p + 4); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | static inline void __put_unaligned_be16(__u16 val, __u8 *p) | 22 | static inline void __put_unaligned_be16(uint16_t val, uint8_t *p) |
| 23 | { | 23 | { |
| 24 | *p++ = val >> 8; | 24 | *p++ = val >> 8; |
| 25 | *p++ = val; | 25 | *p++ = val; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static inline void __put_unaligned_be32(__u32 val, __u8 *p) | 28 | static inline void __put_unaligned_be32(uint32_t val, uint8_t *p) |
| 29 | { | 29 | { |
| 30 | __put_unaligned_be16(val >> 16, p); | 30 | __put_unaligned_be16(val >> 16, p); |
| 31 | __put_unaligned_be16(val, p + 2); | 31 | __put_unaligned_be16(val, p + 2); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | static inline void __put_unaligned_be64(__u64 val, __u8 *p) | 34 | static inline void __put_unaligned_be64(uint64_t val, uint8_t *p) |
| 35 | { | 35 | { |
| 36 | __put_unaligned_be32(val >> 32, p); | 36 | __put_unaligned_be32(val >> 32, p); |
| 37 | __put_unaligned_be32(val, p + 4); | 37 | __put_unaligned_be32(val, p + 4); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | static inline __u16 get_unaligned_be16(const void *p) | 40 | static inline uint16_t get_unaligned_be16(const void *p) |
| 41 | { | 41 | { |
| 42 | return __get_unaligned_be16((const __u8 *)p); | 42 | return __get_unaligned_be16((const uint8_t *)p); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static inline __u32 get_unaligned_be32(const void *p) | 45 | static inline uint32_t get_unaligned_be32(const void *p) |
| 46 | { | 46 | { |
| 47 | return __get_unaligned_be32((const __u8 *)p); | 47 | return __get_unaligned_be32((const uint8_t *)p); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static inline __u64 get_unaligned_be64(const void *p) | 50 | static inline uint64_t get_unaligned_be64(const void *p) |
| 51 | { | 51 | { |
| 52 | return __get_unaligned_be64((const __u8 *)p); | 52 | return __get_unaligned_be64((const uint8_t *)p); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | static inline void put_unaligned_be16(__u16 val, void *p) | 55 | static inline void put_unaligned_be16(uint16_t val, void *p) |
| 56 | { | 56 | { |
| 57 | __put_unaligned_be16(val, p); | 57 | __put_unaligned_be16(val, p); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | static inline void put_unaligned_be32(__u32 val, void *p) | 60 | static inline void put_unaligned_be32(uint32_t val, void *p) |
| 61 | { | 61 | { |
| 62 | __put_unaligned_be32(val, p); | 62 | __put_unaligned_be32(val, p); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static inline void put_unaligned_be64(__u64 val, void *p) | 65 | static inline void put_unaligned_be64(uint64_t val, void *p) |
| 66 | { | 66 | { |
| 67 | __put_unaligned_be64(val, p); | 67 | __put_unaligned_be64(val, p); |
| 68 | } | 68 | } |
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h index c99d45a68bda..8fe9f2488ec7 100644 --- a/tools/include/tools/le_byteshift.h +++ b/tools/include/tools/le_byteshift.h | |||
| @@ -1,68 +1,68 @@ | |||
| 1 | #ifndef _TOOLS_LE_BYTESHIFT_H | 1 | #ifndef _TOOLS_LE_BYTESHIFT_H |
| 2 | #define _TOOLS_LE_BYTESHIFT_H | 2 | #define _TOOLS_LE_BYTESHIFT_H |
| 3 | 3 | ||
| 4 | #include <linux/types.h> | 4 | #include <stdint.h> |
| 5 | 5 | ||
| 6 | static inline __u16 __get_unaligned_le16(const __u8 *p) | 6 | static inline uint16_t __get_unaligned_le16(const uint8_t *p) |
| 7 | { | 7 | { |
| 8 | return p[0] | p[1] << 8; | 8 | return p[0] | p[1] << 8; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | static inline __u32 __get_unaligned_le32(const __u8 *p) | 11 | static inline uint32_t __get_unaligned_le32(const uint8_t *p) |
| 12 | { | 12 | { |
| 13 | return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; | 13 | return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | static inline __u64 __get_unaligned_le64(const __u8 *p) | 16 | static inline uint64_t __get_unaligned_le64(const uint8_t *p) |
| 17 | { | 17 | { |
| 18 | return (__u64)__get_unaligned_le32(p + 4) << 32 | | 18 | return (uint64_t)__get_unaligned_le32(p + 4) << 32 | |
| 19 | __get_unaligned_le32(p); | 19 | __get_unaligned_le32(p); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | static inline void __put_unaligned_le16(__u16 val, __u8 *p) | 22 | static inline void __put_unaligned_le16(uint16_t val, uint8_t *p) |
| 23 | { | 23 | { |
| 24 | *p++ = val; | 24 | *p++ = val; |
| 25 | *p++ = val >> 8; | 25 | *p++ = val >> 8; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static inline void __put_unaligned_le32(__u32 val, __u8 *p) | 28 | static inline void __put_unaligned_le32(uint32_t val, uint8_t *p) |
| 29 | { | 29 | { |
| 30 | __put_unaligned_le16(val >> 16, p + 2); | 30 | __put_unaligned_le16(val >> 16, p + 2); |
| 31 | __put_unaligned_le16(val, p); | 31 | __put_unaligned_le16(val, p); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | static inline void __put_unaligned_le64(__u64 val, __u8 *p) | 34 | static inline void __put_unaligned_le64(uint64_t val, uint8_t *p) |
| 35 | { | 35 | { |
| 36 | __put_unaligned_le32(val >> 32, p + 4); | 36 | __put_unaligned_le32(val >> 32, p + 4); |
| 37 | __put_unaligned_le32(val, p); | 37 | __put_unaligned_le32(val, p); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | static inline __u16 get_unaligned_le16(const void *p) | 40 | static inline uint16_t get_unaligned_le16(const void *p) |
| 41 | { | 41 | { |
| 42 | return __get_unaligned_le16((const __u8 *)p); | 42 | return __get_unaligned_le16((const uint8_t *)p); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static inline __u32 get_unaligned_le32(const void *p) | 45 | static inline uint32_t get_unaligned_le32(const void *p) |
| 46 | { | 46 | { |
| 47 | return __get_unaligned_le32((const __u8 *)p); | 47 | return __get_unaligned_le32((const uint8_t *)p); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static inline __u64 get_unaligned_le64(const void *p) | 50 | static inline uint64_t get_unaligned_le64(const void *p) |
| 51 | { | 51 | { |
| 52 | return __get_unaligned_le64((const __u8 *)p); | 52 | return __get_unaligned_le64((const uint8_t *)p); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | static inline void put_unaligned_le16(__u16 val, void *p) | 55 | static inline void put_unaligned_le16(uint16_t val, void *p) |
| 56 | { | 56 | { |
| 57 | __put_unaligned_le16(val, p); | 57 | __put_unaligned_le16(val, p); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | static inline void put_unaligned_le32(__u32 val, void *p) | 60 | static inline void put_unaligned_le32(uint32_t val, void *p) |
| 61 | { | 61 | { |
| 62 | __put_unaligned_le32(val, p); | 62 | __put_unaligned_le32(val, p); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static inline void put_unaligned_le64(__u64 val, void *p) | 65 | static inline void put_unaligned_le64(uint64_t val, void *p) |
| 66 | { | 66 | { |
| 67 | __put_unaligned_le64(val, p); | 67 | __put_unaligned_le64(val, p); |
| 68 | } | 68 | } |
diff --git a/tools/lguest/Makefile b/tools/lguest/Makefile index 0ac34206f7a7..97bca4871ea3 100644 --- a/tools/lguest/Makefile +++ b/tools/lguest/Makefile | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | # This creates the demonstration utility "lguest" which runs a Linux guest. | 1 | # This creates the demonstration utility "lguest" which runs a Linux guest. |
| 2 | # Missing headers? Add "-I../../../include -I../../../arch/x86/include" | ||
| 3 | CFLAGS:=-m32 -Wall -Wmissing-declarations -Wmissing-prototypes -O3 -U_FORTIFY_SOURCE | 2 | CFLAGS:=-m32 -Wall -Wmissing-declarations -Wmissing-prototypes -O3 -U_FORTIFY_SOURCE |
| 4 | 3 | ||
| 5 | all: lguest | 4 | all: lguest |
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c index 07a03452c227..68f67cf3d318 100644 --- a/tools/lguest/lguest.c +++ b/tools/lguest/lguest.c | |||
| @@ -42,14 +42,6 @@ | |||
| 42 | #include <pwd.h> | 42 | #include <pwd.h> |
| 43 | #include <grp.h> | 43 | #include <grp.h> |
| 44 | 44 | ||
| 45 | #include <linux/virtio_config.h> | ||
| 46 | #include <linux/virtio_net.h> | ||
| 47 | #include <linux/virtio_blk.h> | ||
| 48 | #include <linux/virtio_console.h> | ||
| 49 | #include <linux/virtio_rng.h> | ||
| 50 | #include <linux/virtio_ring.h> | ||
| 51 | #include <asm/bootparam.h> | ||
| 52 | #include "../../include/linux/lguest_launcher.h" | ||
| 53 | /*L:110 | 45 | /*L:110 |
| 54 | * We can ignore the 43 include files we need for this program, but I do want | 46 | * We can ignore the 43 include files we need for this program, but I do want |
| 55 | * to draw attention to the use of kernel-style types. | 47 | * to draw attention to the use of kernel-style types. |
| @@ -65,6 +57,15 @@ typedef uint16_t u16; | |||
| 65 | typedef uint8_t u8; | 57 | typedef uint8_t u8; |
| 66 | /*:*/ | 58 | /*:*/ |
| 67 | 59 | ||
| 60 | #include <linux/virtio_config.h> | ||
| 61 | #include <linux/virtio_net.h> | ||
| 62 | #include <linux/virtio_blk.h> | ||
| 63 | #include <linux/virtio_console.h> | ||
| 64 | #include <linux/virtio_rng.h> | ||
| 65 | #include <linux/virtio_ring.h> | ||
| 66 | #include <asm/bootparam.h> | ||
| 67 | #include "../../include/linux/lguest_launcher.h" | ||
| 68 | |||
| 68 | #define BRIDGE_PFX "bridge:" | 69 | #define BRIDGE_PFX "bridge:" |
| 69 | #ifndef SIOCBRADDIF | 70 | #ifndef SIOCBRADDIF |
| 70 | #define SIOCBRADDIF 0x89a2 /* add interface to bridge */ | 71 | #define SIOCBRADDIF 0x89a2 /* add interface to bridge */ |
| @@ -177,7 +178,8 @@ static struct termios orig_term; | |||
| 177 | * in precise order. | 178 | * in precise order. |
| 178 | */ | 179 | */ |
| 179 | #define wmb() __asm__ __volatile__("" : : : "memory") | 180 | #define wmb() __asm__ __volatile__("" : : : "memory") |
| 180 | #define mb() __asm__ __volatile__("" : : : "memory") | 181 | #define rmb() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") |
| 182 | #define mb() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") | ||
| 181 | 183 | ||
| 182 | /* Wrapper for the last available index. Makes it easier to change. */ | 184 | /* Wrapper for the last available index. Makes it easier to change. */ |
| 183 | #define lg_last_avail(vq) ((vq)->last_avail_idx) | 185 | #define lg_last_avail(vq) ((vq)->last_avail_idx) |
| @@ -676,6 +678,12 @@ static unsigned wait_for_vq_desc(struct virtqueue *vq, | |||
| 676 | errx(1, "Guest moved used index from %u to %u", | 678 | errx(1, "Guest moved used index from %u to %u", |
| 677 | last_avail, vq->vring.avail->idx); | 679 | last_avail, vq->vring.avail->idx); |
| 678 | 680 | ||
| 681 | /* | ||
| 682 | * Make sure we read the descriptor number *after* we read the ring | ||
| 683 | * update; don't let the cpu or compiler change the order. | ||
| 684 | */ | ||
| 685 | rmb(); | ||
| 686 | |||
| 679 | /* | 687 | /* |
| 680 | * Grab the next descriptor number they're advertising, and increment | 688 | * Grab the next descriptor number they're advertising, and increment |
| 681 | * the index we've seen. | 689 | * the index we've seen. |
| @@ -695,6 +703,12 @@ static unsigned wait_for_vq_desc(struct virtqueue *vq, | |||
| 695 | i = head; | 703 | i = head; |
| 696 | 704 | ||
| 697 | /* | 705 | /* |
| 706 | * We have to read the descriptor after we read the descriptor number, | ||
| 707 | * but there's a data dependency there so the CPU shouldn't reorder | ||
| 708 | * that: no rmb() required. | ||
| 709 | */ | ||
| 710 | |||
| 711 | /* | ||
| 698 | * If this is an indirect entry, then this buffer contains a descriptor | 712 | * If this is an indirect entry, then this buffer contains a descriptor |
| 699 | * table which we handle as if it's any normal descriptor chain. | 713 | * table which we handle as if it's any normal descriptor chain. |
| 700 | */ | 714 | */ |
diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index d875a74a3bdf..cbfec92af327 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile | |||
| @@ -128,10 +128,12 @@ UTIL_OBJS = utils/helpers/amd.o utils/helpers/topology.o utils/helpers/msr.o \ | |||
| 128 | utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \ | 128 | utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \ |
| 129 | utils/helpers/pci.o utils/helpers/bitmask.o \ | 129 | utils/helpers/pci.o utils/helpers/bitmask.o \ |
| 130 | utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \ | 130 | utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \ |
| 131 | utils/idle_monitor/hsw_ext_idle.o \ | ||
| 131 | utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ | 132 | utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ |
| 132 | utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ | 133 | utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ |
| 133 | utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ | 134 | utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ |
| 134 | utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o | 135 | utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \ |
| 136 | utils/cpuidle-set.o | ||
| 135 | 137 | ||
| 136 | UTIL_SRC := $(UTIL_OBJS:.o=.c) | 138 | UTIL_SRC := $(UTIL_OBJS:.o=.c) |
| 137 | 139 | ||
diff --git a/tools/power/cpupower/man/cpupower-monitor.1 b/tools/power/cpupower/man/cpupower-monitor.1 index e01c35d13b6e..914cbb9d9cd0 100644 --- a/tools/power/cpupower/man/cpupower-monitor.1 +++ b/tools/power/cpupower/man/cpupower-monitor.1 | |||
| @@ -110,13 +110,21 @@ May work poorly on Linux-2.6.20 through 2.6.29, as the \fBacpi-cpufreq \fP | |||
| 110 | kernel frequency driver periodically cleared aperf/mperf registers in those | 110 | kernel frequency driver periodically cleared aperf/mperf registers in those |
| 111 | kernels. | 111 | kernels. |
| 112 | 112 | ||
| 113 | .SS "Nehalem" "SandyBridge" | 113 | .SS "Nehalem" "SandyBridge" "HaswellExtended" |
| 114 | Intel Core and Package sleep state counters. | 114 | Intel Core and Package sleep state counters. |
| 115 | Threads (hyperthreaded cores) may not be able to enter deeper core states if | 115 | Threads (hyperthreaded cores) may not be able to enter deeper core states if |
| 116 | its sibling is utilized. | 116 | its sibling is utilized. |
| 117 | Deepest package sleep states may in reality show up as machine/platform wide | 117 | Deepest package sleep states may in reality show up as machine/platform wide |
| 118 | sleep states and can only be entered if all cores are idle. Look up Intel | 118 | sleep states and can only be entered if all cores are idle. Look up Intel |
| 119 | manuals (some are provided in the References section) for further details. | 119 | manuals (some are provided in the References section) for further details. |
| 120 | The monitors are named after the CPU family where the sleep state capabilities | ||
| 121 | got introduced and may not match exactly the CPU name of the platform. | ||
| 122 | For example an IvyBridge processor has sleep state capabilities which got | ||
| 123 | introduced in Nehalem and SandyBridge processor families. | ||
| 124 | Thus on an IvyBridge processor one will get Nehalem and SandyBridge sleep | ||
| 125 | state monitors. | ||
| 126 | HaswellExtended extra package sleep state capabilities are available only in a | ||
| 127 | specific Haswell (family 0x45) and probably also other future processors. | ||
| 120 | 128 | ||
| 121 | .SS "Fam_12h" "Fam_14h" | 129 | .SS "Fam_12h" "Fam_14h" |
| 122 | AMD laptop and desktop processor (family 12h and 14h) sleep state counters. | 130 | AMD laptop and desktop processor (family 12h and 14h) sleep state counters. |
diff --git a/tools/power/cpupower/utils/builtin.h b/tools/power/cpupower/utils/builtin.h index c10496fbe3c6..2284c8ea4e2a 100644 --- a/tools/power/cpupower/utils/builtin.h +++ b/tools/power/cpupower/utils/builtin.h | |||
| @@ -5,6 +5,7 @@ extern int cmd_set(int argc, const char **argv); | |||
| 5 | extern int cmd_info(int argc, const char **argv); | 5 | extern int cmd_info(int argc, const char **argv); |
| 6 | extern int cmd_freq_set(int argc, const char **argv); | 6 | extern int cmd_freq_set(int argc, const char **argv); |
| 7 | extern int cmd_freq_info(int argc, const char **argv); | 7 | extern int cmd_freq_info(int argc, const char **argv); |
| 8 | extern int cmd_idle_set(int argc, const char **argv); | ||
| 8 | extern int cmd_idle_info(int argc, const char **argv); | 9 | extern int cmd_idle_info(int argc, const char **argv); |
| 9 | extern int cmd_monitor(int argc, const char **argv); | 10 | extern int cmd_monitor(int argc, const char **argv); |
| 10 | 11 | ||
diff --git a/tools/power/cpupower/utils/cpuidle-info.c b/tools/power/cpupower/utils/cpuidle-info.c index 8145af5f93a6..75e66de7e7a7 100644 --- a/tools/power/cpupower/utils/cpuidle-info.c +++ b/tools/power/cpupower/utils/cpuidle-info.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | static void cpuidle_cpu_output(unsigned int cpu, int verbose) | 23 | static void cpuidle_cpu_output(unsigned int cpu, int verbose) |
| 24 | { | 24 | { |
| 25 | int idlestates, idlestate; | 25 | unsigned int idlestates, idlestate; |
| 26 | char *tmp; | 26 | char *tmp; |
| 27 | 27 | ||
| 28 | printf(_ ("Analyzing CPU %d:\n"), cpu); | 28 | printf(_ ("Analyzing CPU %d:\n"), cpu); |
| @@ -31,10 +31,8 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose) | |||
| 31 | if (idlestates == 0) { | 31 | if (idlestates == 0) { |
| 32 | printf(_("CPU %u: No idle states\n"), cpu); | 32 | printf(_("CPU %u: No idle states\n"), cpu); |
| 33 | return; | 33 | return; |
| 34 | } else if (idlestates <= 0) { | ||
| 35 | printf(_("CPU %u: Can't read idle state info\n"), cpu); | ||
| 36 | return; | ||
| 37 | } | 34 | } |
| 35 | |||
| 38 | printf(_("Number of idle states: %d\n"), idlestates); | 36 | printf(_("Number of idle states: %d\n"), idlestates); |
| 39 | printf(_("Available idle states:")); | 37 | printf(_("Available idle states:")); |
| 40 | for (idlestate = 0; idlestate < idlestates; idlestate++) { | 38 | for (idlestate = 0; idlestate < idlestates; idlestate++) { |
| @@ -50,10 +48,14 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose) | |||
| 50 | return; | 48 | return; |
| 51 | 49 | ||
| 52 | for (idlestate = 0; idlestate < idlestates; idlestate++) { | 50 | for (idlestate = 0; idlestate < idlestates; idlestate++) { |
| 51 | int disabled = sysfs_is_idlestate_disabled(cpu, idlestate); | ||
| 52 | /* Disabled interface not supported on older kernels */ | ||
| 53 | if (disabled < 0) | ||
| 54 | disabled = 0; | ||
| 53 | tmp = sysfs_get_idlestate_name(cpu, idlestate); | 55 | tmp = sysfs_get_idlestate_name(cpu, idlestate); |
| 54 | if (!tmp) | 56 | if (!tmp) |
| 55 | continue; | 57 | continue; |
| 56 | printf("%s:\n", tmp); | 58 | printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : ""); |
| 57 | free(tmp); | 59 | free(tmp); |
| 58 | 60 | ||
| 59 | tmp = sysfs_get_idlestate_desc(cpu, idlestate); | 61 | tmp = sysfs_get_idlestate_desc(cpu, idlestate); |
| @@ -98,21 +100,13 @@ static void cpuidle_general_output(void) | |||
| 98 | static void proc_cpuidle_cpu_output(unsigned int cpu) | 100 | static void proc_cpuidle_cpu_output(unsigned int cpu) |
| 99 | { | 101 | { |
| 100 | long max_allowed_cstate = 2000000000; | 102 | long max_allowed_cstate = 2000000000; |
| 101 | int cstates, cstate; | 103 | unsigned int cstate, cstates; |
| 102 | 104 | ||
| 103 | cstates = sysfs_get_idlestate_count(cpu); | 105 | cstates = sysfs_get_idlestate_count(cpu); |
| 104 | if (cstates == 0) { | 106 | if (cstates == 0) { |
| 105 | /* | 107 | printf(_("CPU %u: No C-states info\n"), cpu); |
| 106 | * Go on and print same useless info as you'd see with | ||
| 107 | * cat /proc/acpi/processor/../power | ||
| 108 | * printf(_("CPU %u: No C-states available\n"), cpu); | ||
| 109 | * return; | ||
| 110 | */ | ||
| 111 | } else if (cstates <= 0) { | ||
| 112 | printf(_("CPU %u: Can't read C-state info\n"), cpu); | ||
| 113 | return; | 108 | return; |
| 114 | } | 109 | } |
| 115 | /* printf("Cstates: %d\n", cstates); */ | ||
| 116 | 110 | ||
| 117 | printf(_("active state: C0\n")); | 111 | printf(_("active state: C0\n")); |
| 118 | printf(_("max_cstate: C%u\n"), cstates-1); | 112 | printf(_("max_cstate: C%u\n"), cstates-1); |
diff --git a/tools/power/cpupower/utils/cpuidle-set.c b/tools/power/cpupower/utils/cpuidle-set.c new file mode 100644 index 000000000000..c78141c5dfac --- /dev/null +++ b/tools/power/cpupower/utils/cpuidle-set.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <ctype.h> | ||
| 8 | |||
| 9 | #include <getopt.h> | ||
| 10 | |||
| 11 | #include "cpufreq.h" | ||
| 12 | #include "helpers/helpers.h" | ||
| 13 | #include "helpers/sysfs.h" | ||
| 14 | |||
| 15 | static struct option info_opts[] = { | ||
| 16 | { .name = "disable", .has_arg = required_argument, .flag = NULL, .val = 'd'}, | ||
| 17 | { .name = "enable", .has_arg = required_argument, .flag = NULL, .val = 'e'}, | ||
| 18 | { }, | ||
| 19 | }; | ||
| 20 | |||
| 21 | |||
| 22 | int cmd_idle_set(int argc, char **argv) | ||
| 23 | { | ||
| 24 | extern char *optarg; | ||
| 25 | extern int optind, opterr, optopt; | ||
| 26 | int ret = 0, cont = 1, param = 0, idlestate = 0; | ||
| 27 | unsigned int cpu = 0; | ||
| 28 | |||
| 29 | do { | ||
| 30 | ret = getopt_long(argc, argv, "d:e:", info_opts, NULL); | ||
| 31 | if (ret == -1) | ||
| 32 | break; | ||
| 33 | switch (ret) { | ||
| 34 | case '?': | ||
| 35 | param = '?'; | ||
| 36 | cont = 0; | ||
| 37 | break; | ||
| 38 | case 'd': | ||
| 39 | if (param) { | ||
| 40 | param = -1; | ||
| 41 | cont = 0; | ||
| 42 | break; | ||
| 43 | } | ||
| 44 | param = ret; | ||
| 45 | idlestate = atoi(optarg); | ||
| 46 | break; | ||
| 47 | case 'e': | ||
| 48 | if (param) { | ||
| 49 | param = -1; | ||
| 50 | cont = 0; | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | param = ret; | ||
| 54 | idlestate = atoi(optarg); | ||
| 55 | break; | ||
| 56 | case -1: | ||
| 57 | cont = 0; | ||
| 58 | break; | ||
| 59 | } | ||
| 60 | } while (cont); | ||
| 61 | |||
| 62 | switch (param) { | ||
| 63 | case -1: | ||
| 64 | printf(_("You can't specify more than one " | ||
| 65 | "output-specific argument\n")); | ||
| 66 | exit(EXIT_FAILURE); | ||
| 67 | case '?': | ||
| 68 | printf(_("invalid or unknown argument\n")); | ||
| 69 | exit(EXIT_FAILURE); | ||
| 70 | } | ||
| 71 | |||
| 72 | /* Default is: set all CPUs */ | ||
| 73 | if (bitmask_isallclear(cpus_chosen)) | ||
| 74 | bitmask_setall(cpus_chosen); | ||
| 75 | |||
| 76 | for (cpu = bitmask_first(cpus_chosen); | ||
| 77 | cpu <= bitmask_last(cpus_chosen); cpu++) { | ||
| 78 | |||
| 79 | if (!bitmask_isbitset(cpus_chosen, cpu)) | ||
| 80 | continue; | ||
| 81 | |||
| 82 | switch (param) { | ||
| 83 | |||
| 84 | case 'd': | ||
| 85 | ret = sysfs_idlestate_disable(cpu, idlestate, 1); | ||
| 86 | if (ret == 0) | ||
| 87 | printf(_("Idlestate %u disabled on CPU %u\n"), idlestate, cpu); | ||
| 88 | else if (ret == -1) | ||
| 89 | printf(_("Idlestate %u not available on CPU %u\n"), | ||
| 90 | idlestate, cpu); | ||
| 91 | else if (ret == -2) | ||
| 92 | printf(_("Idlestate disabling not supported by kernel\n")); | ||
| 93 | else | ||
| 94 | printf(_("Idlestate %u not disabled on CPU %u\n"), | ||
| 95 | idlestate, cpu); | ||
| 96 | break; | ||
| 97 | case 'e': | ||
| 98 | ret = sysfs_idlestate_disable(cpu, idlestate, 0); | ||
| 99 | if (ret == 0) | ||
| 100 | printf(_("Idlestate %u enabled on CPU %u\n"), idlestate, cpu); | ||
| 101 | else if (ret == -1) | ||
| 102 | printf(_("Idlestate %u not available on CPU %u\n"), | ||
| 103 | idlestate, cpu); | ||
| 104 | else if (ret == -2) | ||
| 105 | printf(_("Idlestate enabling not supported by kernel\n")); | ||
| 106 | else | ||
| 107 | printf(_("Idlestate %u not enabled on CPU %u\n"), | ||
| 108 | idlestate, cpu); | ||
| 109 | break; | ||
| 110 | default: | ||
| 111 | /* Not reachable with proper args checking */ | ||
| 112 | printf(_("Invalid or unknown argument\n")); | ||
| 113 | exit(EXIT_FAILURE); | ||
| 114 | break; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | return EXIT_SUCCESS; | ||
| 118 | } | ||
diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c index 52bee591c1c5..7efc570ffbaa 100644 --- a/tools/power/cpupower/utils/cpupower.c +++ b/tools/power/cpupower/utils/cpupower.c | |||
| @@ -17,12 +17,6 @@ | |||
| 17 | #include "helpers/helpers.h" | 17 | #include "helpers/helpers.h" |
| 18 | #include "helpers/bitmask.h" | 18 | #include "helpers/bitmask.h" |
| 19 | 19 | ||
| 20 | struct cmd_struct { | ||
| 21 | const char *cmd; | ||
| 22 | int (*main)(int, const char **); | ||
| 23 | int needs_root; | ||
| 24 | }; | ||
| 25 | |||
| 26 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) | 20 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) |
| 27 | 21 | ||
| 28 | static int cmd_help(int argc, const char **argv); | 22 | static int cmd_help(int argc, const char **argv); |
| @@ -43,10 +37,17 @@ int be_verbose; | |||
| 43 | 37 | ||
| 44 | static void print_help(void); | 38 | static void print_help(void); |
| 45 | 39 | ||
| 40 | struct cmd_struct { | ||
| 41 | const char *cmd; | ||
| 42 | int (*main)(int, const char **); | ||
| 43 | int needs_root; | ||
| 44 | }; | ||
| 45 | |||
| 46 | static struct cmd_struct commands[] = { | 46 | static struct cmd_struct commands[] = { |
| 47 | { "frequency-info", cmd_freq_info, 0 }, | 47 | { "frequency-info", cmd_freq_info, 0 }, |
| 48 | { "frequency-set", cmd_freq_set, 1 }, | 48 | { "frequency-set", cmd_freq_set, 1 }, |
| 49 | { "idle-info", cmd_idle_info, 0 }, | 49 | { "idle-info", cmd_idle_info, 0 }, |
| 50 | { "idle-set", cmd_idle_set, 1 }, | ||
| 50 | { "set", cmd_set, 1 }, | 51 | { "set", cmd_set, 1 }, |
| 51 | { "info", cmd_info, 0 }, | 52 | { "info", cmd_info, 0 }, |
| 52 | { "monitor", cmd_monitor, 0 }, | 53 | { "monitor", cmd_monitor, 0 }, |
diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c index 38ab91629463..5cdc600e8152 100644 --- a/tools/power/cpupower/utils/helpers/sysfs.c +++ b/tools/power/cpupower/utils/helpers/sysfs.c | |||
| @@ -89,6 +89,33 @@ int sysfs_is_cpu_online(unsigned int cpu) | |||
| 89 | 89 | ||
| 90 | /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ | 90 | /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ |
| 91 | 91 | ||
| 92 | |||
| 93 | /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */ | ||
| 94 | |||
| 95 | /* | ||
| 96 | * helper function to check whether a file under "../cpuX/cpuidle/stateX/" dir | ||
| 97 | * exists. | ||
| 98 | * For example the functionality to disable c-states was introduced in later | ||
| 99 | * kernel versions, this function can be used to explicitly check for this | ||
| 100 | * feature. | ||
| 101 | * | ||
| 102 | * returns 1 if the file exists, 0 otherwise. | ||
| 103 | */ | ||
| 104 | unsigned int sysfs_idlestate_file_exists(unsigned int cpu, | ||
| 105 | unsigned int idlestate, | ||
| 106 | const char *fname) | ||
| 107 | { | ||
| 108 | char path[SYSFS_PATH_MAX]; | ||
| 109 | struct stat statbuf; | ||
| 110 | |||
| 111 | |||
| 112 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", | ||
| 113 | cpu, idlestate, fname); | ||
| 114 | if (stat(path, &statbuf) != 0) | ||
| 115 | return 0; | ||
| 116 | return 1; | ||
| 117 | } | ||
| 118 | |||
| 92 | /* | 119 | /* |
| 93 | * helper function to read file from /sys into given buffer | 120 | * helper function to read file from /sys into given buffer |
| 94 | * fname is a relative path under "cpuX/cpuidle/stateX/" dir | 121 | * fname is a relative path under "cpuX/cpuidle/stateX/" dir |
| @@ -121,6 +148,40 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate, | |||
| 121 | return (unsigned int) numread; | 148 | return (unsigned int) numread; |
| 122 | } | 149 | } |
| 123 | 150 | ||
| 151 | /* | ||
| 152 | * helper function to write a new value to a /sys file | ||
| 153 | * fname is a relative path under "../cpuX/cpuidle/cstateY/" dir | ||
| 154 | * | ||
| 155 | * Returns the number of bytes written or 0 on error | ||
| 156 | */ | ||
| 157 | static | ||
| 158 | unsigned int sysfs_idlestate_write_file(unsigned int cpu, | ||
| 159 | unsigned int idlestate, | ||
| 160 | const char *fname, | ||
| 161 | const char *value, size_t len) | ||
| 162 | { | ||
| 163 | char path[SYSFS_PATH_MAX]; | ||
| 164 | int fd; | ||
| 165 | ssize_t numwrite; | ||
| 166 | |||
| 167 | snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", | ||
| 168 | cpu, idlestate, fname); | ||
| 169 | |||
| 170 | fd = open(path, O_WRONLY); | ||
| 171 | if (fd == -1) | ||
| 172 | return 0; | ||
| 173 | |||
| 174 | numwrite = write(fd, value, len); | ||
| 175 | if (numwrite < 1) { | ||
| 176 | close(fd); | ||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | close(fd); | ||
| 181 | |||
| 182 | return (unsigned int) numwrite; | ||
| 183 | } | ||
| 184 | |||
| 124 | /* read access to files which contain one numeric value */ | 185 | /* read access to files which contain one numeric value */ |
| 125 | 186 | ||
| 126 | enum idlestate_value { | 187 | enum idlestate_value { |
| @@ -128,6 +189,7 @@ enum idlestate_value { | |||
| 128 | IDLESTATE_POWER, | 189 | IDLESTATE_POWER, |
| 129 | IDLESTATE_LATENCY, | 190 | IDLESTATE_LATENCY, |
| 130 | IDLESTATE_TIME, | 191 | IDLESTATE_TIME, |
| 192 | IDLESTATE_DISABLE, | ||
| 131 | MAX_IDLESTATE_VALUE_FILES | 193 | MAX_IDLESTATE_VALUE_FILES |
| 132 | }; | 194 | }; |
| 133 | 195 | ||
| @@ -136,6 +198,7 @@ static const char *idlestate_value_files[MAX_IDLESTATE_VALUE_FILES] = { | |||
| 136 | [IDLESTATE_POWER] = "power", | 198 | [IDLESTATE_POWER] = "power", |
| 137 | [IDLESTATE_LATENCY] = "latency", | 199 | [IDLESTATE_LATENCY] = "latency", |
| 138 | [IDLESTATE_TIME] = "time", | 200 | [IDLESTATE_TIME] = "time", |
| 201 | [IDLESTATE_DISABLE] = "disable", | ||
| 139 | }; | 202 | }; |
| 140 | 203 | ||
| 141 | static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu, | 204 | static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu, |
| @@ -205,8 +268,59 @@ static char *sysfs_idlestate_get_one_string(unsigned int cpu, | |||
| 205 | return result; | 268 | return result; |
| 206 | } | 269 | } |
| 207 | 270 | ||
| 271 | /* | ||
| 272 | * Returns: | ||
| 273 | * 1 if disabled | ||
| 274 | * 0 if enabled | ||
| 275 | * -1 if idlestate is not available | ||
| 276 | * -2 if disabling is not supported by the kernel | ||
| 277 | */ | ||
| 278 | int sysfs_is_idlestate_disabled(unsigned int cpu, | ||
| 279 | unsigned int idlestate) | ||
| 280 | { | ||
| 281 | if (sysfs_get_idlestate_count(cpu) < idlestate) | ||
| 282 | return -1; | ||
| 283 | |||
| 284 | if (!sysfs_idlestate_file_exists(cpu, idlestate, | ||
| 285 | idlestate_value_files[IDLESTATE_DISABLE])) | ||
| 286 | return -2; | ||
| 287 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_DISABLE); | ||
| 288 | } | ||
| 289 | |||
| 290 | /* | ||
| 291 | * Pass 1 as last argument to disable or 0 to enable the state | ||
| 292 | * Returns: | ||
| 293 | * 0 on success | ||
| 294 | * negative values on error, for example: | ||
| 295 | * -1 if idlestate is not available | ||
| 296 | * -2 if disabling is not supported by the kernel | ||
| 297 | * -3 No write access to disable/enable C-states | ||
| 298 | */ | ||
| 299 | int sysfs_idlestate_disable(unsigned int cpu, | ||
| 300 | unsigned int idlestate, | ||
| 301 | unsigned int disable) | ||
| 302 | { | ||
| 303 | char value[SYSFS_PATH_MAX]; | ||
| 304 | int bytes_written; | ||
| 305 | |||
| 306 | if (sysfs_get_idlestate_count(cpu) < idlestate) | ||
| 307 | return -1; | ||
| 308 | |||
| 309 | if (!sysfs_idlestate_file_exists(cpu, idlestate, | ||
| 310 | idlestate_value_files[IDLESTATE_DISABLE])) | ||
| 311 | return -2; | ||
| 312 | |||
| 313 | snprintf(value, SYSFS_PATH_MAX, "%u", disable); | ||
| 314 | |||
| 315 | bytes_written = sysfs_idlestate_write_file(cpu, idlestate, "disable", | ||
| 316 | value, sizeof(disable)); | ||
| 317 | if (bytes_written) | ||
| 318 | return 0; | ||
| 319 | return -3; | ||
| 320 | } | ||
| 321 | |||
| 208 | unsigned long sysfs_get_idlestate_latency(unsigned int cpu, | 322 | unsigned long sysfs_get_idlestate_latency(unsigned int cpu, |
| 209 | unsigned int idlestate) | 323 | unsigned int idlestate) |
| 210 | { | 324 | { |
| 211 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); | 325 | return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); |
| 212 | } | 326 | } |
| @@ -238,7 +352,7 @@ char *sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate) | |||
| 238 | * Negativ in error case | 352 | * Negativ in error case |
| 239 | * Zero if cpuidle does not export any C-states | 353 | * Zero if cpuidle does not export any C-states |
| 240 | */ | 354 | */ |
| 241 | int sysfs_get_idlestate_count(unsigned int cpu) | 355 | unsigned int sysfs_get_idlestate_count(unsigned int cpu) |
| 242 | { | 356 | { |
| 243 | char file[SYSFS_PATH_MAX]; | 357 | char file[SYSFS_PATH_MAX]; |
| 244 | struct stat statbuf; | 358 | struct stat statbuf; |
diff --git a/tools/power/cpupower/utils/helpers/sysfs.h b/tools/power/cpupower/utils/helpers/sysfs.h index 8cb797bbceb0..d28f11fedbda 100644 --- a/tools/power/cpupower/utils/helpers/sysfs.h +++ b/tools/power/cpupower/utils/helpers/sysfs.h | |||
| @@ -7,8 +7,16 @@ | |||
| 7 | 7 | ||
| 8 | extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen); | 8 | extern unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen); |
| 9 | 9 | ||
| 10 | extern unsigned int sysfs_idlestate_file_exists(unsigned int cpu, | ||
| 11 | unsigned int idlestate, | ||
| 12 | const char *fname); | ||
| 13 | |||
| 10 | extern int sysfs_is_cpu_online(unsigned int cpu); | 14 | extern int sysfs_is_cpu_online(unsigned int cpu); |
| 11 | 15 | ||
| 16 | extern int sysfs_is_idlestate_disabled(unsigned int cpu, | ||
| 17 | unsigned int idlestate); | ||
| 18 | extern int sysfs_idlestate_disable(unsigned int cpu, unsigned int idlestate, | ||
| 19 | unsigned int disable); | ||
| 12 | extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, | 20 | extern unsigned long sysfs_get_idlestate_latency(unsigned int cpu, |
| 13 | unsigned int idlestate); | 21 | unsigned int idlestate); |
| 14 | extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, | 22 | extern unsigned long sysfs_get_idlestate_usage(unsigned int cpu, |
| @@ -19,7 +27,7 @@ extern char *sysfs_get_idlestate_name(unsigned int cpu, | |||
| 19 | unsigned int idlestate); | 27 | unsigned int idlestate); |
| 20 | extern char *sysfs_get_idlestate_desc(unsigned int cpu, | 28 | extern char *sysfs_get_idlestate_desc(unsigned int cpu, |
| 21 | unsigned int idlestate); | 29 | unsigned int idlestate); |
| 22 | extern int sysfs_get_idlestate_count(unsigned int cpu); | 30 | extern unsigned int sysfs_get_idlestate_count(unsigned int cpu); |
| 23 | 31 | ||
| 24 | extern char *sysfs_get_cpuidle_governor(void); | 32 | extern char *sysfs_get_cpuidle_governor(void); |
| 25 | extern char *sysfs_get_cpuidle_driver(void); | 33 | extern char *sysfs_get_cpuidle_driver(void); |
diff --git a/tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c b/tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c new file mode 100644 index 000000000000..ebeaba6571a3 --- /dev/null +++ b/tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c | |||
| @@ -0,0 +1,196 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc. | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * Based on SandyBridge monitor. Implements the new package C-states | ||
| 7 | * (PC8, PC9, PC10) coming with a specific Haswell (family 0x45) CPU. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #if defined(__i386__) || defined(__x86_64__) | ||
| 11 | |||
| 12 | #include <stdio.h> | ||
| 13 | #include <stdint.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <string.h> | ||
| 16 | |||
| 17 | #include "helpers/helpers.h" | ||
| 18 | #include "idle_monitor/cpupower-monitor.h" | ||
| 19 | |||
| 20 | #define MSR_PKG_C8_RESIDENCY 0x00000630 | ||
| 21 | #define MSR_PKG_C9_RESIDENCY 0x00000631 | ||
| 22 | #define MSR_PKG_C10_RESIDENCY 0x00000632 | ||
| 23 | |||
| 24 | #define MSR_TSC 0x10 | ||
| 25 | |||
| 26 | enum intel_hsw_ext_id { PC8 = 0, PC9, PC10, HSW_EXT_CSTATE_COUNT, | ||
| 27 | TSC = 0xFFFF }; | ||
| 28 | |||
| 29 | static int hsw_ext_get_count_percent(unsigned int self_id, double *percent, | ||
| 30 | unsigned int cpu); | ||
| 31 | |||
| 32 | static cstate_t hsw_ext_cstates[HSW_EXT_CSTATE_COUNT] = { | ||
| 33 | { | ||
| 34 | .name = "PC8", | ||
| 35 | .desc = N_("Processor Package C8"), | ||
| 36 | .id = PC8, | ||
| 37 | .range = RANGE_PACKAGE, | ||
| 38 | .get_count_percent = hsw_ext_get_count_percent, | ||
| 39 | }, | ||
| 40 | { | ||
| 41 | .name = "PC9", | ||
| 42 | .desc = N_("Processor Package C9"), | ||
| 43 | .desc = N_("Processor Package C2"), | ||
| 44 | .id = PC9, | ||
| 45 | .range = RANGE_PACKAGE, | ||
| 46 | .get_count_percent = hsw_ext_get_count_percent, | ||
| 47 | }, | ||
| 48 | { | ||
| 49 | .name = "PC10", | ||
| 50 | .desc = N_("Processor Package C10"), | ||
| 51 | .id = PC10, | ||
| 52 | .range = RANGE_PACKAGE, | ||
| 53 | .get_count_percent = hsw_ext_get_count_percent, | ||
| 54 | }, | ||
| 55 | }; | ||
| 56 | |||
| 57 | static unsigned long long tsc_at_measure_start; | ||
| 58 | static unsigned long long tsc_at_measure_end; | ||
| 59 | static unsigned long long *previous_count[HSW_EXT_CSTATE_COUNT]; | ||
| 60 | static unsigned long long *current_count[HSW_EXT_CSTATE_COUNT]; | ||
| 61 | /* valid flag for all CPUs. If a MSR read failed it will be zero */ | ||
| 62 | static int *is_valid; | ||
| 63 | |||
| 64 | static int hsw_ext_get_count(enum intel_hsw_ext_id id, unsigned long long *val, | ||
| 65 | unsigned int cpu) | ||
| 66 | { | ||
| 67 | int msr; | ||
| 68 | |||
| 69 | switch (id) { | ||
| 70 | case PC8: | ||
| 71 | msr = MSR_PKG_C8_RESIDENCY; | ||
| 72 | break; | ||
| 73 | case PC9: | ||
| 74 | msr = MSR_PKG_C9_RESIDENCY; | ||
| 75 | break; | ||
| 76 | case PC10: | ||
| 77 | msr = MSR_PKG_C10_RESIDENCY; | ||
| 78 | break; | ||
| 79 | case TSC: | ||
| 80 | msr = MSR_TSC; | ||
| 81 | break; | ||
| 82 | default: | ||
| 83 | return -1; | ||
| 84 | }; | ||
| 85 | if (read_msr(cpu, msr, val)) | ||
| 86 | return -1; | ||
| 87 | return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | static int hsw_ext_get_count_percent(unsigned int id, double *percent, | ||
| 91 | unsigned int cpu) | ||
| 92 | { | ||
| 93 | *percent = 0.0; | ||
| 94 | |||
| 95 | if (!is_valid[cpu]) | ||
| 96 | return -1; | ||
| 97 | |||
| 98 | *percent = (100.0 * | ||
| 99 | (current_count[id][cpu] - previous_count[id][cpu])) / | ||
| 100 | (tsc_at_measure_end - tsc_at_measure_start); | ||
| 101 | |||
| 102 | dprint("%s: previous: %llu - current: %llu - (%u)\n", | ||
| 103 | hsw_ext_cstates[id].name, previous_count[id][cpu], | ||
| 104 | current_count[id][cpu], cpu); | ||
| 105 | |||
| 106 | dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n", | ||
| 107 | hsw_ext_cstates[id].name, | ||
| 108 | (unsigned long long) tsc_at_measure_end - tsc_at_measure_start, | ||
| 109 | current_count[id][cpu] - previous_count[id][cpu], | ||
| 110 | *percent, cpu); | ||
| 111 | |||
| 112 | return 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | static int hsw_ext_start(void) | ||
| 116 | { | ||
| 117 | int num, cpu; | ||
| 118 | unsigned long long val; | ||
| 119 | |||
| 120 | for (num = 0; num < HSW_EXT_CSTATE_COUNT; num++) { | ||
| 121 | for (cpu = 0; cpu < cpu_count; cpu++) { | ||
| 122 | hsw_ext_get_count(num, &val, cpu); | ||
| 123 | previous_count[num][cpu] = val; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | hsw_ext_get_count(TSC, &tsc_at_measure_start, 0); | ||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | |||
| 130 | static int hsw_ext_stop(void) | ||
| 131 | { | ||
| 132 | unsigned long long val; | ||
| 133 | int num, cpu; | ||
| 134 | |||
| 135 | hsw_ext_get_count(TSC, &tsc_at_measure_end, 0); | ||
| 136 | |||
| 137 | for (num = 0; num < HSW_EXT_CSTATE_COUNT; num++) { | ||
| 138 | for (cpu = 0; cpu < cpu_count; cpu++) { | ||
| 139 | is_valid[cpu] = !hsw_ext_get_count(num, &val, cpu); | ||
| 140 | current_count[num][cpu] = val; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | return 0; | ||
| 144 | } | ||
| 145 | |||
| 146 | struct cpuidle_monitor intel_hsw_ext_monitor; | ||
| 147 | |||
| 148 | static struct cpuidle_monitor *hsw_ext_register(void) | ||
| 149 | { | ||
| 150 | int num; | ||
| 151 | |||
| 152 | if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL | ||
| 153 | || cpupower_cpu_info.family != 6) | ||
| 154 | return NULL; | ||
| 155 | |||
| 156 | switch (cpupower_cpu_info.model) { | ||
| 157 | case 0x45: /* HSW */ | ||
| 158 | break; | ||
| 159 | default: | ||
| 160 | return NULL; | ||
| 161 | } | ||
| 162 | |||
| 163 | is_valid = calloc(cpu_count, sizeof(int)); | ||
| 164 | for (num = 0; num < HSW_EXT_CSTATE_COUNT; num++) { | ||
| 165 | previous_count[num] = calloc(cpu_count, | ||
| 166 | sizeof(unsigned long long)); | ||
| 167 | current_count[num] = calloc(cpu_count, | ||
| 168 | sizeof(unsigned long long)); | ||
| 169 | } | ||
| 170 | intel_hsw_ext_monitor.name_len = strlen(intel_hsw_ext_monitor.name); | ||
| 171 | return &intel_hsw_ext_monitor; | ||
| 172 | } | ||
| 173 | |||
| 174 | void hsw_ext_unregister(void) | ||
| 175 | { | ||
| 176 | int num; | ||
| 177 | free(is_valid); | ||
| 178 | for (num = 0; num < HSW_EXT_CSTATE_COUNT; num++) { | ||
| 179 | free(previous_count[num]); | ||
| 180 | free(current_count[num]); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | struct cpuidle_monitor intel_hsw_ext_monitor = { | ||
| 185 | .name = "HaswellExtended", | ||
| 186 | .hw_states = hsw_ext_cstates, | ||
| 187 | .hw_states_num = HSW_EXT_CSTATE_COUNT, | ||
| 188 | .start = hsw_ext_start, | ||
| 189 | .stop = hsw_ext_stop, | ||
| 190 | .do_register = hsw_ext_register, | ||
| 191 | .unregister = hsw_ext_unregister, | ||
| 192 | .needs_root = 1, | ||
| 193 | .overflow_s = 922000000 /* 922337203 seconds TSC overflow | ||
| 194 | at 20GHz */ | ||
| 195 | }; | ||
| 196 | #endif /* defined(__i386__) || defined(__x86_64__) */ | ||
diff --git a/tools/power/cpupower/utils/idle_monitor/idle_monitors.def b/tools/power/cpupower/utils/idle_monitor/idle_monitors.def index e3f8d9b2b18f..0d6ba4dbb9c7 100644 --- a/tools/power/cpupower/utils/idle_monitor/idle_monitors.def +++ b/tools/power/cpupower/utils/idle_monitor/idle_monitors.def | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | DEF(amd_fam14h) | 2 | DEF(amd_fam14h) |
| 3 | DEF(intel_nhm) | 3 | DEF(intel_nhm) |
| 4 | DEF(intel_snb) | 4 | DEF(intel_snb) |
| 5 | DEF(intel_hsw_ext) | ||
| 5 | DEF(mperf) | 6 | DEF(mperf) |
| 6 | #endif | 7 | #endif |
| 7 | DEF(cpuidle_sysfs) | 8 | DEF(cpuidle_sysfs) |
diff --git a/tools/power/cpupower/utils/idle_monitor/snb_idle.c b/tools/power/cpupower/utils/idle_monitor/snb_idle.c index a99b43b97d6d..efc8a69c9aba 100644 --- a/tools/power/cpupower/utils/idle_monitor/snb_idle.c +++ b/tools/power/cpupower/utils/idle_monitor/snb_idle.c | |||
| @@ -155,6 +155,10 @@ static struct cpuidle_monitor *snb_register(void) | |||
| 155 | case 0x2D: /* SNB Xeon */ | 155 | case 0x2D: /* SNB Xeon */ |
| 156 | case 0x3A: /* IVB */ | 156 | case 0x3A: /* IVB */ |
| 157 | case 0x3E: /* IVB Xeon */ | 157 | case 0x3E: /* IVB Xeon */ |
| 158 | case 0x3C: /* HSW */ | ||
| 159 | case 0x3F: /* HSW */ | ||
| 160 | case 0x45: /* HSW */ | ||
| 161 | case 0x46: /* HSW */ | ||
| 158 | break; | 162 | break; |
| 159 | default: | 163 | default: |
| 160 | return NULL; | 164 | return NULL; |
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 0d7fd8b51544..999eab1bc64f 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
| @@ -1796,7 +1796,7 @@ sub monitor { | |||
| 1796 | # We already booted into the kernel we are testing, | 1796 | # We already booted into the kernel we are testing, |
| 1797 | # but now we booted into another kernel? | 1797 | # but now we booted into another kernel? |
| 1798 | # Consider this a triple fault. | 1798 | # Consider this a triple fault. |
| 1799 | doprint "Aleady booted in Linux kernel $version, but now\n"; | 1799 | doprint "Already booted in Linux kernel $version, but now\n"; |
| 1800 | doprint "we booted into Linux kernel $1.\n"; | 1800 | doprint "we booted into Linux kernel $1.\n"; |
| 1801 | doprint "Assuming that this is a triple fault.\n"; | 1801 | doprint "Assuming that this is a triple fault.\n"; |
| 1802 | doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n"; | 1802 | doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n"; |
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 0a63658065f0..4cb14cae3791 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
| @@ -6,6 +6,7 @@ TARGETS += memory-hotplug | |||
| 6 | TARGETS += mqueue | 6 | TARGETS += mqueue |
| 7 | TARGETS += net | 7 | TARGETS += net |
| 8 | TARGETS += ptrace | 8 | TARGETS += ptrace |
| 9 | TARGETS += timers | ||
| 9 | TARGETS += vm | 10 | TARGETS += vm |
| 10 | 11 | ||
| 11 | all: | 12 | all: |
diff --git a/tools/testing/selftests/cpu-hotplug/Makefile b/tools/testing/selftests/cpu-hotplug/Makefile index 12657a5e4bf9..ae5faf9aade2 100644 --- a/tools/testing/selftests/cpu-hotplug/Makefile +++ b/tools/testing/selftests/cpu-hotplug/Makefile | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | all: | 1 | all: |
| 2 | 2 | ||
| 3 | run_tests: | 3 | run_tests: |
| 4 | @./on-off-test.sh || echo "cpu-hotplug selftests: [FAIL]" | 4 | @/bin/sh ./on-off-test.sh || echo "cpu-hotplug selftests: [FAIL]" |
| 5 | 5 | ||
| 6 | clean: | 6 | clean: |
diff --git a/tools/testing/selftests/kcmp/.gitignore b/tools/testing/selftests/kcmp/.gitignore new file mode 100644 index 000000000000..5a9b3732b2de --- /dev/null +++ b/tools/testing/selftests/kcmp/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | kcmp_test | ||
| 2 | kcmp-test-file | ||
diff --git a/tools/testing/selftests/kcmp/Makefile b/tools/testing/selftests/kcmp/Makefile index 56eb5523dbb8..d7d6bbeeff2f 100644 --- a/tools/testing/selftests/kcmp/Makefile +++ b/tools/testing/selftests/kcmp/Makefile | |||
| @@ -25,5 +25,4 @@ run_tests: all | |||
| 25 | @./kcmp_test || echo "kcmp_test: [FAIL]" | 25 | @./kcmp_test || echo "kcmp_test: [FAIL]" |
| 26 | 26 | ||
| 27 | clean: | 27 | clean: |
| 28 | rm -fr ./run_test | 28 | $(RM) kcmp_test kcmp-test-file |
| 29 | rm -fr ./test-file | ||
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile index 0f49c3f5f58d..350bfeda3aa8 100644 --- a/tools/testing/selftests/memory-hotplug/Makefile +++ b/tools/testing/selftests/memory-hotplug/Makefile | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | all: | 1 | all: |
| 2 | 2 | ||
| 3 | run_tests: | 3 | run_tests: |
| 4 | @./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]" | 4 | @/bin/sh ./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]" |
| 5 | 5 | ||
| 6 | clean: | 6 | clean: |
diff --git a/tools/testing/selftests/net/psock_tpacket.c b/tools/testing/selftests/net/psock_tpacket.c index c41b58640a05..24adf709bd9d 100644 --- a/tools/testing/selftests/net/psock_tpacket.c +++ b/tools/testing/selftests/net/psock_tpacket.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright 2013 Red Hat, Inc. | 2 | * Copyright 2013 Red Hat, Inc. |
| 3 | * Author: Daniel Borkmann <dborkman@redhat.com> | 3 | * Author: Daniel Borkmann <dborkman@redhat.com> |
| 4 | * Chetan Loke <loke.chetan@gmail.com> (TPACKET_V3 usage example) | ||
| 4 | * | 5 | * |
| 5 | * A basic test of packet socket's TPACKET_V1/TPACKET_V2/TPACKET_V3 behavior. | 6 | * A basic test of packet socket's TPACKET_V1/TPACKET_V2/TPACKET_V3 behavior. |
| 6 | * | 7 | * |
| @@ -71,18 +72,8 @@ | |||
| 71 | # define __align_tpacket(x) __attribute__((aligned(TPACKET_ALIGN(x)))) | 72 | # define __align_tpacket(x) __attribute__((aligned(TPACKET_ALIGN(x)))) |
| 72 | #endif | 73 | #endif |
| 73 | 74 | ||
| 74 | #define BLOCK_STATUS(x) ((x)->h1.block_status) | ||
| 75 | #define BLOCK_NUM_PKTS(x) ((x)->h1.num_pkts) | ||
| 76 | #define BLOCK_O2FP(x) ((x)->h1.offset_to_first_pkt) | ||
| 77 | #define BLOCK_LEN(x) ((x)->h1.blk_len) | ||
| 78 | #define BLOCK_SNUM(x) ((x)->h1.seq_num) | ||
| 79 | #define BLOCK_O2PRIV(x) ((x)->offset_to_priv) | ||
| 80 | #define BLOCK_PRIV(x) ((void *) ((uint8_t *) (x) + BLOCK_O2PRIV(x))) | ||
| 81 | #define BLOCK_HDR_LEN (ALIGN_8(sizeof(struct block_desc))) | ||
| 82 | #define ALIGN_8(x) (((x) + 8 - 1) & ~(8 - 1)) | ||
| 83 | #define BLOCK_PLUS_PRIV(sz_pri) (BLOCK_HDR_LEN + ALIGN_8((sz_pri))) | ||
| 84 | |||
| 85 | #define NUM_PACKETS 100 | 75 | #define NUM_PACKETS 100 |
| 76 | #define ALIGN_8(x) (((x) + 8 - 1) & ~(8 - 1)) | ||
| 86 | 77 | ||
| 87 | struct ring { | 78 | struct ring { |
| 88 | struct iovec *rd; | 79 | struct iovec *rd; |
| @@ -476,41 +467,30 @@ static uint64_t __v3_prev_block_seq_num = 0; | |||
| 476 | 467 | ||
| 477 | void __v3_test_block_seq_num(struct block_desc *pbd) | 468 | void __v3_test_block_seq_num(struct block_desc *pbd) |
| 478 | { | 469 | { |
| 479 | if (__v3_prev_block_seq_num + 1 != BLOCK_SNUM(pbd)) { | 470 | if (__v3_prev_block_seq_num + 1 != pbd->h1.seq_num) { |
| 480 | fprintf(stderr, "\nprev_block_seq_num:%"PRIu64", expected " | 471 | fprintf(stderr, "\nprev_block_seq_num:%"PRIu64", expected " |
| 481 | "seq:%"PRIu64" != actual seq:%"PRIu64"\n", | 472 | "seq:%"PRIu64" != actual seq:%"PRIu64"\n", |
| 482 | __v3_prev_block_seq_num, __v3_prev_block_seq_num + 1, | 473 | __v3_prev_block_seq_num, __v3_prev_block_seq_num + 1, |
| 483 | (uint64_t) BLOCK_SNUM(pbd)); | 474 | (uint64_t) pbd->h1.seq_num); |
| 484 | exit(1); | 475 | exit(1); |
| 485 | } | 476 | } |
| 486 | 477 | ||
| 487 | __v3_prev_block_seq_num = BLOCK_SNUM(pbd); | 478 | __v3_prev_block_seq_num = pbd->h1.seq_num; |
| 488 | } | 479 | } |
| 489 | 480 | ||
| 490 | static void __v3_test_block_len(struct block_desc *pbd, uint32_t bytes, int block_num) | 481 | static void __v3_test_block_len(struct block_desc *pbd, uint32_t bytes, int block_num) |
| 491 | { | 482 | { |
| 492 | if (BLOCK_NUM_PKTS(pbd)) { | 483 | if (pbd->h1.num_pkts && bytes != pbd->h1.blk_len) { |
| 493 | if (bytes != BLOCK_LEN(pbd)) { | 484 | fprintf(stderr, "\nblock:%u with %upackets, expected " |
| 494 | fprintf(stderr, "\nblock:%u with %upackets, expected " | 485 | "len:%u != actual len:%u\n", block_num, |
| 495 | "len:%u != actual len:%u\n", block_num, | 486 | pbd->h1.num_pkts, bytes, pbd->h1.blk_len); |
| 496 | BLOCK_NUM_PKTS(pbd), bytes, BLOCK_LEN(pbd)); | 487 | exit(1); |
| 497 | exit(1); | ||
| 498 | } | ||
| 499 | } else { | ||
| 500 | if (BLOCK_LEN(pbd) != BLOCK_PLUS_PRIV(13)) { | ||
| 501 | fprintf(stderr, "\nblock:%u, expected len:%lu != " | ||
| 502 | "actual len:%u\n", block_num, BLOCK_HDR_LEN, | ||
| 503 | BLOCK_LEN(pbd)); | ||
| 504 | exit(1); | ||
| 505 | } | ||
| 506 | } | 488 | } |
| 507 | } | 489 | } |
| 508 | 490 | ||
| 509 | static void __v3_test_block_header(struct block_desc *pbd, const int block_num) | 491 | static void __v3_test_block_header(struct block_desc *pbd, const int block_num) |
| 510 | { | 492 | { |
| 511 | uint32_t block_status = BLOCK_STATUS(pbd); | 493 | if ((pbd->h1.block_status & TP_STATUS_USER) == 0) { |
| 512 | |||
| 513 | if ((block_status & TP_STATUS_USER) == 0) { | ||
| 514 | fprintf(stderr, "\nblock %u: not in TP_STATUS_USER\n", block_num); | 494 | fprintf(stderr, "\nblock %u: not in TP_STATUS_USER\n", block_num); |
| 515 | exit(1); | 495 | exit(1); |
| 516 | } | 496 | } |
| @@ -520,14 +500,15 @@ static void __v3_test_block_header(struct block_desc *pbd, const int block_num) | |||
| 520 | 500 | ||
| 521 | static void __v3_walk_block(struct block_desc *pbd, const int block_num) | 501 | static void __v3_walk_block(struct block_desc *pbd, const int block_num) |
| 522 | { | 502 | { |
| 523 | int num_pkts = BLOCK_NUM_PKTS(pbd), i; | 503 | int num_pkts = pbd->h1.num_pkts, i; |
| 524 | unsigned long bytes = 0; | 504 | unsigned long bytes = 0, bytes_with_padding = ALIGN_8(sizeof(*pbd)); |
| 525 | unsigned long bytes_with_padding = BLOCK_PLUS_PRIV(13); | ||
| 526 | struct tpacket3_hdr *ppd; | 505 | struct tpacket3_hdr *ppd; |
| 527 | 506 | ||
| 528 | __v3_test_block_header(pbd, block_num); | 507 | __v3_test_block_header(pbd, block_num); |
| 529 | 508 | ||
| 530 | ppd = (struct tpacket3_hdr *) ((uint8_t *) pbd + BLOCK_O2FP(pbd)); | 509 | ppd = (struct tpacket3_hdr *) ((uint8_t *) pbd + |
| 510 | pbd->h1.offset_to_first_pkt); | ||
| 511 | |||
| 531 | for (i = 0; i < num_pkts; ++i) { | 512 | for (i = 0; i < num_pkts; ++i) { |
| 532 | bytes += ppd->tp_snaplen; | 513 | bytes += ppd->tp_snaplen; |
| 533 | 514 | ||
| @@ -551,7 +532,7 @@ static void __v3_walk_block(struct block_desc *pbd, const int block_num) | |||
| 551 | 532 | ||
| 552 | void __v3_flush_block(struct block_desc *pbd) | 533 | void __v3_flush_block(struct block_desc *pbd) |
| 553 | { | 534 | { |
| 554 | BLOCK_STATUS(pbd) = TP_STATUS_KERNEL; | 535 | pbd->h1.block_status = TP_STATUS_KERNEL; |
| 555 | __sync_synchronize(); | 536 | __sync_synchronize(); |
| 556 | } | 537 | } |
| 557 | 538 | ||
| @@ -577,7 +558,7 @@ static void walk_v3_rx(int sock, struct ring *ring) | |||
| 577 | while (total_packets < NUM_PACKETS * 2) { | 558 | while (total_packets < NUM_PACKETS * 2) { |
| 578 | pbd = (struct block_desc *) ring->rd[block_num].iov_base; | 559 | pbd = (struct block_desc *) ring->rd[block_num].iov_base; |
| 579 | 560 | ||
| 580 | while ((BLOCK_STATUS(pbd) & TP_STATUS_USER) == 0) | 561 | while ((pbd->h1.block_status & TP_STATUS_USER) == 0) |
| 581 | poll(&pfd, 1, 1); | 562 | poll(&pfd, 1, 1); |
| 582 | 563 | ||
| 583 | __v3_walk_block(pbd, block_num); | 564 | __v3_walk_block(pbd, block_num); |
| @@ -624,8 +605,8 @@ static void __v1_v2_fill(struct ring *ring, unsigned int blocks) | |||
| 624 | static void __v3_fill(struct ring *ring, unsigned int blocks) | 605 | static void __v3_fill(struct ring *ring, unsigned int blocks) |
| 625 | { | 606 | { |
| 626 | ring->req3.tp_retire_blk_tov = 64; | 607 | ring->req3.tp_retire_blk_tov = 64; |
| 627 | ring->req3.tp_sizeof_priv = 13; | 608 | ring->req3.tp_sizeof_priv = 0; |
| 628 | ring->req3.tp_feature_req_word |= TP_FT_REQ_FILL_RXHASH; | 609 | ring->req3.tp_feature_req_word = TP_FT_REQ_FILL_RXHASH; |
| 629 | 610 | ||
| 630 | ring->req3.tp_block_size = getpagesize() << 2; | 611 | ring->req3.tp_block_size = getpagesize() << 2; |
| 631 | ring->req3.tp_frame_size = TPACKET_ALIGNMENT << 7; | 612 | ring->req3.tp_frame_size = TPACKET_ALIGNMENT << 7; |
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile new file mode 100644 index 000000000000..eb2859f4ad21 --- /dev/null +++ b/tools/testing/selftests/timers/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | all: | ||
| 2 | gcc posix_timers.c -o posix_timers -lrt | ||
| 3 | |||
| 4 | run_tests: all | ||
| 5 | ./posix_timers | ||
| 6 | |||
| 7 | clean: | ||
| 8 | rm -f ./posix_timers | ||
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c new file mode 100644 index 000000000000..4fa655d68a81 --- /dev/null +++ b/tools/testing/selftests/timers/posix_timers.c | |||
| @@ -0,0 +1,221 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2013 Red Hat, Inc., Frederic Weisbecker <fweisbec@redhat.com> | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2 | ||
| 5 | * | ||
| 6 | * Selftests for a few posix timers interface. | ||
| 7 | * | ||
| 8 | * Kernel loop code stolen from Steven Rostedt <srostedt@redhat.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <sys/time.h> | ||
| 12 | #include <stdio.h> | ||
| 13 | #include <signal.h> | ||
| 14 | #include <unistd.h> | ||
| 15 | #include <time.h> | ||
| 16 | #include <pthread.h> | ||
| 17 | |||
| 18 | #define DELAY 2 | ||
| 19 | #define USECS_PER_SEC 1000000 | ||
| 20 | |||
| 21 | static volatile int done; | ||
| 22 | |||
| 23 | /* Busy loop in userspace to elapse ITIMER_VIRTUAL */ | ||
| 24 | static void user_loop(void) | ||
| 25 | { | ||
| 26 | while (!done); | ||
| 27 | } | ||
| 28 | |||
| 29 | /* | ||
| 30 | * Try to spend as much time as possible in kernelspace | ||
| 31 | * to elapse ITIMER_PROF. | ||
| 32 | */ | ||
| 33 | static void kernel_loop(void) | ||
| 34 | { | ||
| 35 | void *addr = sbrk(0); | ||
| 36 | |||
| 37 | while (!done) { | ||
| 38 | brk(addr + 4096); | ||
| 39 | brk(addr); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | /* | ||
| 44 | * Sleep until ITIMER_REAL expiration. | ||
| 45 | */ | ||
| 46 | static void idle_loop(void) | ||
| 47 | { | ||
| 48 | pause(); | ||
| 49 | } | ||
| 50 | |||
| 51 | static void sig_handler(int nr) | ||
| 52 | { | ||
| 53 | done = 1; | ||
| 54 | } | ||
| 55 | |||
| 56 | /* | ||
| 57 | * Check the expected timer expiration matches the GTOD elapsed delta since | ||
| 58 | * we armed the timer. Keep a 0.5 sec error margin due to various jitter. | ||
| 59 | */ | ||
| 60 | static int check_diff(struct timeval start, struct timeval end) | ||
| 61 | { | ||
| 62 | long long diff; | ||
| 63 | |||
| 64 | diff = end.tv_usec - start.tv_usec; | ||
| 65 | diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; | ||
| 66 | |||
| 67 | if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { | ||
| 68 | printf("Diff too high: %lld..", diff); | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | |||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | static int check_itimer(int which) | ||
| 76 | { | ||
| 77 | int err; | ||
| 78 | struct timeval start, end; | ||
| 79 | struct itimerval val = { | ||
| 80 | .it_value.tv_sec = DELAY, | ||
| 81 | }; | ||
| 82 | |||
| 83 | printf("Check itimer "); | ||
| 84 | |||
| 85 | if (which == ITIMER_VIRTUAL) | ||
| 86 | printf("virtual... "); | ||
| 87 | else if (which == ITIMER_PROF) | ||
| 88 | printf("prof... "); | ||
| 89 | else if (which == ITIMER_REAL) | ||
| 90 | printf("real... "); | ||
| 91 | |||
| 92 | fflush(stdout); | ||
| 93 | |||
| 94 | done = 0; | ||
| 95 | |||
| 96 | if (which == ITIMER_VIRTUAL) | ||
| 97 | signal(SIGVTALRM, sig_handler); | ||
| 98 | else if (which == ITIMER_PROF) | ||
| 99 | signal(SIGPROF, sig_handler); | ||
| 100 | else if (which == ITIMER_REAL) | ||
| 101 | signal(SIGALRM, sig_handler); | ||
| 102 | |||
| 103 | err = gettimeofday(&start, NULL); | ||
| 104 | if (err < 0) { | ||
| 105 | perror("Can't call gettimeofday()\n"); | ||
| 106 | return -1; | ||
| 107 | } | ||
| 108 | |||
| 109 | err = setitimer(which, &val, NULL); | ||
| 110 | if (err < 0) { | ||
| 111 | perror("Can't set timer\n"); | ||
| 112 | return -1; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (which == ITIMER_VIRTUAL) | ||
| 116 | user_loop(); | ||
| 117 | else if (which == ITIMER_PROF) | ||
| 118 | kernel_loop(); | ||
| 119 | else if (which == ITIMER_REAL) | ||
| 120 | idle_loop(); | ||
| 121 | |||
| 122 | gettimeofday(&end, NULL); | ||
| 123 | if (err < 0) { | ||
| 124 | perror("Can't call gettimeofday()\n"); | ||
| 125 | return -1; | ||
| 126 | } | ||
| 127 | |||
| 128 | if (!check_diff(start, end)) | ||
| 129 | printf("[OK]\n"); | ||
| 130 | else | ||
| 131 | printf("[FAIL]\n"); | ||
| 132 | |||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | static int check_timer_create(int which) | ||
| 137 | { | ||
| 138 | int err; | ||
| 139 | timer_t id; | ||
| 140 | struct timeval start, end; | ||
| 141 | struct itimerspec val = { | ||
| 142 | .it_value.tv_sec = DELAY, | ||
| 143 | }; | ||
| 144 | |||
| 145 | printf("Check timer_create() "); | ||
| 146 | if (which == CLOCK_THREAD_CPUTIME_ID) { | ||
| 147 | printf("per thread... "); | ||
| 148 | } else if (which == CLOCK_PROCESS_CPUTIME_ID) { | ||
| 149 | printf("per process... "); | ||
| 150 | } | ||
| 151 | fflush(stdout); | ||
| 152 | |||
| 153 | done = 0; | ||
| 154 | timer_create(which, NULL, &id); | ||
| 155 | if (err < 0) { | ||
| 156 | perror("Can't create timer\n"); | ||
| 157 | return -1; | ||
| 158 | } | ||
| 159 | signal(SIGALRM, sig_handler); | ||
| 160 | |||
| 161 | err = gettimeofday(&start, NULL); | ||
| 162 | if (err < 0) { | ||
| 163 | perror("Can't call gettimeofday()\n"); | ||
| 164 | return -1; | ||
| 165 | } | ||
| 166 | |||
| 167 | err = timer_settime(id, 0, &val, NULL); | ||
| 168 | if (err < 0) { | ||
| 169 | perror("Can't set timer\n"); | ||
| 170 | return -1; | ||
| 171 | } | ||
| 172 | |||
| 173 | user_loop(); | ||
| 174 | |||
| 175 | gettimeofday(&end, NULL); | ||
| 176 | if (err < 0) { | ||
| 177 | perror("Can't call gettimeofday()\n"); | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | |||
| 181 | if (!check_diff(start, end)) | ||
| 182 | printf("[OK]\n"); | ||
| 183 | else | ||
| 184 | printf("[FAIL]\n"); | ||
| 185 | |||
| 186 | return 0; | ||
| 187 | } | ||
| 188 | |||
| 189 | int main(int argc, char **argv) | ||
| 190 | { | ||
| 191 | int err; | ||
| 192 | |||
| 193 | printf("Testing posix timers. False negative may happen on CPU execution \n"); | ||
| 194 | printf("based timers if other threads run on the CPU...\n"); | ||
| 195 | |||
| 196 | if (check_itimer(ITIMER_VIRTUAL) < 0) | ||
| 197 | return -1; | ||
| 198 | |||
| 199 | if (check_itimer(ITIMER_PROF) < 0) | ||
| 200 | return -1; | ||
| 201 | |||
| 202 | if (check_itimer(ITIMER_REAL) < 0) | ||
| 203 | return -1; | ||
| 204 | |||
| 205 | if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) | ||
| 206 | return -1; | ||
| 207 | |||
| 208 | /* | ||
| 209 | * It's unfortunately hard to reliably test a timer expiration | ||
| 210 | * on parallel multithread cputime. We could arm it to expire | ||
| 211 | * on DELAY * nr_threads, with nr_threads busy looping, then wait | ||
| 212 | * the normal DELAY since the time is elapsing nr_threads faster. | ||
| 213 | * But for that we need to ensure we have real physical free CPUs | ||
| 214 | * to ensure true parallelism. So test only one thread until we | ||
| 215 | * find a better solution. | ||
| 216 | */ | ||
| 217 | if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) | ||
| 218 | return -1; | ||
| 219 | |||
| 220 | return 0; | ||
| 221 | } | ||
diff --git a/tools/testing/selftests/vm/.gitignore b/tools/testing/selftests/vm/.gitignore new file mode 100644 index 000000000000..ff1bb16cec4f --- /dev/null +++ b/tools/testing/selftests/vm/.gitignore | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | hugepage-mmap | ||
| 2 | hugepage-shm | ||
| 3 | map_hugetlb | ||
| 4 | thuge-gen | ||
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index 436d2e81868b..3f94e1afd6cf 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile | |||
| @@ -2,13 +2,14 @@ | |||
| 2 | 2 | ||
| 3 | CC = $(CROSS_COMPILE)gcc | 3 | CC = $(CROSS_COMPILE)gcc |
| 4 | CFLAGS = -Wall | 4 | CFLAGS = -Wall |
| 5 | BINARIES = hugepage-mmap hugepage-shm map_hugetlb thuge-gen hugetlbfstest | ||
| 5 | 6 | ||
| 6 | all: hugepage-mmap hugepage-shm map_hugetlb thuge-gen | 7 | all: $(BINARIES) |
| 7 | %: %.c | 8 | %: %.c |
| 8 | $(CC) $(CFLAGS) -o $@ $^ | 9 | $(CC) $(CFLAGS) -o $@ $^ |
| 9 | 10 | ||
| 10 | run_tests: all | 11 | run_tests: all |
| 11 | @/bin/sh ./run_vmtests || echo "vmtests: [FAIL]" | 12 | @/bin/sh ./run_vmtests || (echo "vmtests: [FAIL]"; exit 1) |
| 12 | 13 | ||
| 13 | clean: | 14 | clean: |
| 14 | $(RM) hugepage-mmap hugepage-shm map_hugetlb | 15 | $(RM) $(BINARIES) |
diff --git a/tools/testing/selftests/vm/hugetlbfstest.c b/tools/testing/selftests/vm/hugetlbfstest.c new file mode 100644 index 000000000000..ea40ff8c2391 --- /dev/null +++ b/tools/testing/selftests/vm/hugetlbfstest.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <assert.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <sys/mman.h> | ||
| 8 | #include <sys/stat.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | typedef unsigned long long u64; | ||
| 13 | |||
| 14 | static size_t length = 1 << 24; | ||
| 15 | |||
| 16 | static u64 read_rss(void) | ||
| 17 | { | ||
| 18 | char buf[4096], *s = buf; | ||
| 19 | int i, fd; | ||
| 20 | u64 rss; | ||
| 21 | |||
| 22 | fd = open("/proc/self/statm", O_RDONLY); | ||
| 23 | assert(fd > 2); | ||
| 24 | memset(buf, 0, sizeof(buf)); | ||
| 25 | read(fd, buf, sizeof(buf) - 1); | ||
| 26 | for (i = 0; i < 1; i++) | ||
| 27 | s = strchr(s, ' ') + 1; | ||
| 28 | rss = strtoull(s, NULL, 10); | ||
| 29 | return rss << 12; /* assumes 4k pagesize */ | ||
| 30 | } | ||
| 31 | |||
| 32 | static void do_mmap(int fd, int extra_flags, int unmap) | ||
| 33 | { | ||
| 34 | int *p; | ||
| 35 | int flags = MAP_PRIVATE | MAP_POPULATE | extra_flags; | ||
| 36 | u64 before, after; | ||
| 37 | |||
| 38 | before = read_rss(); | ||
| 39 | p = mmap(NULL, length, PROT_READ | PROT_WRITE, flags, fd, 0); | ||
| 40 | assert(p != MAP_FAILED || | ||
| 41 | !"mmap returned an unexpected error"); | ||
| 42 | after = read_rss(); | ||
| 43 | assert(llabs(after - before - length) < 0x40000 || | ||
| 44 | !"rss didn't grow as expected"); | ||
| 45 | if (!unmap) | ||
| 46 | return; | ||
| 47 | munmap(p, length); | ||
| 48 | after = read_rss(); | ||
| 49 | assert(llabs(after - before) < 0x40000 || | ||
| 50 | !"rss didn't shrink as expected"); | ||
| 51 | } | ||
| 52 | |||
| 53 | static int open_file(const char *path) | ||
| 54 | { | ||
| 55 | int fd, err; | ||
| 56 | |||
| 57 | unlink(path); | ||
| 58 | fd = open(path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL | ||
| 59 | | O_LARGEFILE | O_CLOEXEC, 0600); | ||
| 60 | assert(fd > 2); | ||
| 61 | unlink(path); | ||
| 62 | err = ftruncate(fd, length); | ||
| 63 | assert(!err); | ||
| 64 | return fd; | ||
| 65 | } | ||
| 66 | |||
| 67 | int main(void) | ||
| 68 | { | ||
| 69 | int hugefd, fd; | ||
| 70 | |||
| 71 | fd = open_file("/dev/shm/hugetlbhog"); | ||
| 72 | hugefd = open_file("/hugepages/hugetlbhog"); | ||
| 73 | |||
| 74 | system("echo 100 > /proc/sys/vm/nr_hugepages"); | ||
| 75 | do_mmap(-1, MAP_ANONYMOUS, 1); | ||
| 76 | do_mmap(fd, 0, 1); | ||
| 77 | do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 1); | ||
| 78 | do_mmap(hugefd, 0, 1); | ||
| 79 | do_mmap(hugefd, MAP_HUGETLB, 1); | ||
| 80 | /* Leak the last one to test do_exit() */ | ||
| 81 | do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 0); | ||
| 82 | printf("oll korrekt.\n"); | ||
| 83 | return 0; | ||
| 84 | } | ||
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests index 4c53cae6c273..c87b6812300d 100644 --- a/tools/testing/selftests/vm/run_vmtests +++ b/tools/testing/selftests/vm/run_vmtests | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #we need 256M, below is the size in kB | 4 | #we need 256M, below is the size in kB |
| 5 | needmem=262144 | 5 | needmem=262144 |
| 6 | mnt=./huge | 6 | mnt=./huge |
| 7 | exitcode=0 | ||
| 7 | 8 | ||
| 8 | #get pagesize and freepages from /proc/meminfo | 9 | #get pagesize and freepages from /proc/meminfo |
| 9 | while read name size unit; do | 10 | while read name size unit; do |
| @@ -41,6 +42,7 @@ echo "--------------------" | |||
| 41 | ./hugepage-mmap | 42 | ./hugepage-mmap |
| 42 | if [ $? -ne 0 ]; then | 43 | if [ $? -ne 0 ]; then |
| 43 | echo "[FAIL]" | 44 | echo "[FAIL]" |
| 45 | exitcode=1 | ||
| 44 | else | 46 | else |
| 45 | echo "[PASS]" | 47 | echo "[PASS]" |
| 46 | fi | 48 | fi |
| @@ -55,6 +57,7 @@ echo "--------------------" | |||
| 55 | ./hugepage-shm | 57 | ./hugepage-shm |
| 56 | if [ $? -ne 0 ]; then | 58 | if [ $? -ne 0 ]; then |
| 57 | echo "[FAIL]" | 59 | echo "[FAIL]" |
| 60 | exitcode=1 | ||
| 58 | else | 61 | else |
| 59 | echo "[PASS]" | 62 | echo "[PASS]" |
| 60 | fi | 63 | fi |
| @@ -67,6 +70,18 @@ echo "--------------------" | |||
| 67 | ./map_hugetlb | 70 | ./map_hugetlb |
| 68 | if [ $? -ne 0 ]; then | 71 | if [ $? -ne 0 ]; then |
| 69 | echo "[FAIL]" | 72 | echo "[FAIL]" |
| 73 | exitcode=1 | ||
| 74 | else | ||
| 75 | echo "[PASS]" | ||
| 76 | fi | ||
| 77 | |||
| 78 | echo "--------------------" | ||
| 79 | echo "running hugetlbfstest" | ||
| 80 | echo "--------------------" | ||
| 81 | ./hugetlbfstest | ||
| 82 | if [ $? -ne 0 ]; then | ||
| 83 | echo "[FAIL]" | ||
| 84 | exitcode=1 | ||
| 70 | else | 85 | else |
| 71 | echo "[PASS]" | 86 | echo "[PASS]" |
| 72 | fi | 87 | fi |
| @@ -75,3 +90,4 @@ fi | |||
| 75 | umount $mnt | 90 | umount $mnt |
| 76 | rm -rf $mnt | 91 | rm -rf $mnt |
| 77 | echo $nr_hugepgs > /proc/sys/vm/nr_hugepages | 92 | echo $nr_hugepgs > /proc/sys/vm/nr_hugepages |
| 93 | exit $exitcode | ||
diff --git a/tools/virtio/linux/module.h b/tools/virtio/linux/module.h index 3039a7e972b6..28ce95a05997 100644 --- a/tools/virtio/linux/module.h +++ b/tools/virtio/linux/module.h | |||
| @@ -1 +1,6 @@ | |||
| 1 | #include <linux/export.h> | 1 | #include <linux/export.h> |
| 2 | |||
| 3 | #define MODULE_LICENSE(__MODULE_LICENSE_value) \ | ||
| 4 | static __attribute__((unused)) const char *__MODULE_LICENSE_name = \ | ||
| 5 | __MODULE_LICENSE_value | ||
| 6 | |||
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h index cd801838156f..844783040703 100644 --- a/tools/virtio/linux/virtio.h +++ b/tools/virtio/linux/virtio.h | |||
| @@ -45,9 +45,6 @@ struct virtqueue { | |||
| 45 | void *priv; | 45 | void *priv; |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | #define MODULE_LICENSE(__MODULE_LICENSE_value) \ | ||
| 49 | const char *__MODULE_LICENSE_name = __MODULE_LICENSE_value | ||
| 50 | |||
| 51 | /* Interfaces exported by virtio_ring. */ | 48 | /* Interfaces exported by virtio_ring. */ |
| 52 | int virtqueue_add_sgs(struct virtqueue *vq, | 49 | int virtqueue_add_sgs(struct virtqueue *vq, |
| 53 | struct scatterlist *sgs[], | 50 | struct scatterlist *sgs[], |
