From: Thomas Renninger <trenn@suse.de> To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Felix Schnizlein <fschnizlein@suse.de>, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk, will.deacon@arm.com, x86@kernel.org, trenn@suse.de, fschnitzlein@suse.de, Felix Schnizlein <fschnizlein@suse.com>, Thomas Renninger <trenn@suse.com> Subject: [PATCH 2/3] x86 cpuinfo: implement sysfs nodes for x86 Date: Fri, 6 Dec 2019 17:24:20 +0100 [thread overview] Message-ID: <20191206162421.15050-3-trenn@suse.de> (raw) In-Reply-To: <20191206162421.15050-1-trenn@suse.de> From: Felix Schnizlein <fschnizlein@suse.de> Enable sysfs cpuinfo for x86 based cpus. Export often used cpu information to sysfs: stepping, flags, bugs, bogomips, family, vendor_id, model, and model_name are exported. Sysfs documentation is updated to reflect changes. Example (on a kvm instance running no an intel cpu): /sys/devices/system/cpu/cpu1/info/:[0]# head * ==> bogomips <== 5187.72 ==> bugs <== cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit ==> cpu_family <== 6 ==> flags <== fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip ==> model <== 60 ==> model_name <== Intel Core Processor (Haswell, no TSX, IBRS) ==> stepping <== 1 ==> vendor_id <== GenuineIntel Signed-off-by: Felix Schnizlein <fschnizlein@suse.com> Signed-off-by: Thomas Renninger <trenn@suse.com> --- Documentation/ABI/testing/sysfs-devices-system-cpu | 23 +++++ arch/x86/Kconfig | 1 + arch/x86/kernel/Makefile | 2 + arch/x86/kernel/cpuinfo.c | 99 ++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 arch/x86/kernel/cpuinfo.c diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index 84c324773b36..791390ab66d5 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -581,3 +581,26 @@ Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> Description: Various information about the online cpu. Which attributes are available depends on the architecture, kernel configuration and cpu model. + +What: /sys/devices/system/cpu/cpu#/info/ + /sys/devices/system/cpu/cpu#/info/vendor_id + /sys/devices/system/cpu/cpu#/info/cpu_family + /sys/devices/system/cpu/cpu#/info/model + /sys/devices/system/cpu/cpu#/info/model_name + /sys/devices/system/cpu/cpu#/info/stepping + /sys/devices/system/cpu/cpu#/info/flags + /sys/devices/system/cpu/cpu#/info/bugs + /sys/devices/system/cpu/cpu#/info/bogomips +Date: June 2017 +Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> +Description: Expose information about x86 cpu information. + + vendor_id, + cpu_family, + model, + model_name, + stepping: Cpu identification depending on each vendor + + flags: Extended capabilities supported by the cpu + bugs: Known bugs by cpu + bogomips: calculated bogomips diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8529a9dbd5ca..29fadd69d541 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -154,6 +154,7 @@ config X86 select HAVE_CMPXCHG_LOCAL select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_COPY_THREAD_TLS + select HAVE_CPUINFO_SYSFS if SYSFS select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index ccb13271895d..ccf1a338bc37 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -146,6 +146,8 @@ obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o obj-$(CONFIG_UNWINDER_FRAME_POINTER) += unwind_frame.o obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o +obj-$(CONFIG_CPUINFO_SYSFS) += cpuinfo.o + ### # 64 bit specific files ifeq ($(CONFIG_X86_64),y) diff --git a/arch/x86/kernel/cpuinfo.c b/arch/x86/kernel/cpuinfo.c new file mode 100644 index 000000000000..3b772faf9f5f --- /dev/null +++ b/arch/x86/kernel/cpuinfo.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2017 SUSE Linux GmbH + * Written by: Felix Schnizlein <fschnizlein@suse.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include <linux/cpu.h> +#include <linux/cpuinfo.h> +#include <linux/cpufreq.h> +#include <linux/smp.h> + +static ssize_t cpuinfo_stepping(unsigned int c, char *buf) +{ + if (cpu_data(c).x86_stepping || cpu_data(c).cpuid_level >= 0) + return sprintf(buf, "%d\n", cpu_data(c).x86_stepping); + return sprintf(buf, "unknown\n"); +} + +static ssize_t cpuinfo_flags(unsigned int c, char *buf) +{ + struct cpuinfo_x86 *cpu = &cpu_data(c); + unsigned int i; + ssize_t len = 0; + + for (i = 0; i < (32 * NCAPINTS); i++) { + if (cpu_has(cpu, i) && x86_cap_flags[i] != NULL) + len += sprintf(buf+len, len == 0 ? "%s" : " %s", + x86_cap_flags[i]); + } + if (!len) + return 0; + return len + sprintf(buf+len, "\n"); +} + +static ssize_t cpuinfo_bugs(unsigned int c, char *buf) +{ + struct cpuinfo_x86 *cpu = &cpu_data(c); + unsigned int i; + ssize_t len = 0; + + for (i = 0; i < 32*NBUGINTS; i++) { + unsigned int bug_bit = 32*NCAPINTS + i; + + if (cpu_has_bug(cpu, bug_bit) && x86_bug_flags[i]) + len += sprintf(buf+len, len == 0 ? "%s" : " %s", + x86_bug_flags[i]); + } + if (!len) + return 0; + return len + sprintf(buf+len, "\n"); +} + +static ssize_t cpuinfo_bogomips(unsigned int c, char *buf) +{ + struct cpuinfo_x86 cpu = cpu_data(c); + + return sprintf(buf, "%lu.%02lu\n", cpu.loops_per_jiffy / (500000 / HZ), + (cpu.loops_per_jiffy / (5000 / HZ)) % 100); +} + +#define cpuinfo_cpu_family(cpu) cpu_data(cpu).x86 +#define cpuinfo_model(cpu) cpu_data(cpu).x86_model + +#define cpuinfo_vendor_id(cpu) cpu_data(cpu).x86_vendor_id[0] ?\ + cpu_data(cpu).x86_vendor_id : "unknown" + +#define cpuinfo_model_name(cpu) cpu_data(cpu).x86_model_id[0] ? \ + cpu_data(cpu).x86_model_id : "unknown" + +CPUINFO_DEFINE_ATTR(cpu_family, "%d"); +CPUINFO_DEFINE_ATTR(model, "%u"); +CPUINFO_DEFINE_ATTR(vendor_id, "%s"); +CPUINFO_DEFINE_ATTR(model_name, "%s"); + +CPUINFO_DEFINE_ATTR_FUNC(stepping); +CPUINFO_DEFINE_ATTR_FUNC(flags); +CPUINFO_DEFINE_ATTR_FUNC(bugs); +CPUINFO_DEFINE_ATTR_FUNC(bogomips); + +struct attribute *cpuinfo_attrs[] = { + CPUINFO_ATTR(vendor_id), + CPUINFO_ATTR(cpu_family), + CPUINFO_ATTR(model), + CPUINFO_ATTR(model_name), + CPUINFO_ATTR(stepping), + CPUINFO_ATTR(flags), + CPUINFO_ATTR(bugs), + CPUINFO_ATTR(bogomips), + NULL +}; -- 2.16.4
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Renninger <trenn@suse.de> To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, Felix Schnizlein <fschnizlein@suse.de>, Felix Schnizlein <fschnizlein@suse.com>, gregkh@linuxfoundation.org, x86@kernel.org, will.deacon@arm.com, linux@armlinux.org.uk, Thomas Renninger <trenn@suse.com>, fschnitzlein@suse.de, trenn@suse.de, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] x86 cpuinfo: implement sysfs nodes for x86 Date: Fri, 6 Dec 2019 17:24:20 +0100 [thread overview] Message-ID: <20191206162421.15050-3-trenn@suse.de> (raw) In-Reply-To: <20191206162421.15050-1-trenn@suse.de> From: Felix Schnizlein <fschnizlein@suse.de> Enable sysfs cpuinfo for x86 based cpus. Export often used cpu information to sysfs: stepping, flags, bugs, bogomips, family, vendor_id, model, and model_name are exported. Sysfs documentation is updated to reflect changes. Example (on a kvm instance running no an intel cpu): /sys/devices/system/cpu/cpu1/info/:[0]# head * ==> bogomips <== 5187.72 ==> bugs <== cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit ==> cpu_family <== 6 ==> flags <== fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip ==> model <== 60 ==> model_name <== Intel Core Processor (Haswell, no TSX, IBRS) ==> stepping <== 1 ==> vendor_id <== GenuineIntel Signed-off-by: Felix Schnizlein <fschnizlein@suse.com> Signed-off-by: Thomas Renninger <trenn@suse.com> --- Documentation/ABI/testing/sysfs-devices-system-cpu | 23 +++++ arch/x86/Kconfig | 1 + arch/x86/kernel/Makefile | 2 + arch/x86/kernel/cpuinfo.c | 99 ++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 arch/x86/kernel/cpuinfo.c diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index 84c324773b36..791390ab66d5 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -581,3 +581,26 @@ Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> Description: Various information about the online cpu. Which attributes are available depends on the architecture, kernel configuration and cpu model. + +What: /sys/devices/system/cpu/cpu#/info/ + /sys/devices/system/cpu/cpu#/info/vendor_id + /sys/devices/system/cpu/cpu#/info/cpu_family + /sys/devices/system/cpu/cpu#/info/model + /sys/devices/system/cpu/cpu#/info/model_name + /sys/devices/system/cpu/cpu#/info/stepping + /sys/devices/system/cpu/cpu#/info/flags + /sys/devices/system/cpu/cpu#/info/bugs + /sys/devices/system/cpu/cpu#/info/bogomips +Date: June 2017 +Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> +Description: Expose information about x86 cpu information. + + vendor_id, + cpu_family, + model, + model_name, + stepping: Cpu identification depending on each vendor + + flags: Extended capabilities supported by the cpu + bugs: Known bugs by cpu + bogomips: calculated bogomips diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8529a9dbd5ca..29fadd69d541 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -154,6 +154,7 @@ config X86 select HAVE_CMPXCHG_LOCAL select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_COPY_THREAD_TLS + select HAVE_CPUINFO_SYSFS if SYSFS select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index ccb13271895d..ccf1a338bc37 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -146,6 +146,8 @@ obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o obj-$(CONFIG_UNWINDER_FRAME_POINTER) += unwind_frame.o obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o +obj-$(CONFIG_CPUINFO_SYSFS) += cpuinfo.o + ### # 64 bit specific files ifeq ($(CONFIG_X86_64),y) diff --git a/arch/x86/kernel/cpuinfo.c b/arch/x86/kernel/cpuinfo.c new file mode 100644 index 000000000000..3b772faf9f5f --- /dev/null +++ b/arch/x86/kernel/cpuinfo.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2017 SUSE Linux GmbH + * Written by: Felix Schnizlein <fschnizlein@suse.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include <linux/cpu.h> +#include <linux/cpuinfo.h> +#include <linux/cpufreq.h> +#include <linux/smp.h> + +static ssize_t cpuinfo_stepping(unsigned int c, char *buf) +{ + if (cpu_data(c).x86_stepping || cpu_data(c).cpuid_level >= 0) + return sprintf(buf, "%d\n", cpu_data(c).x86_stepping); + return sprintf(buf, "unknown\n"); +} + +static ssize_t cpuinfo_flags(unsigned int c, char *buf) +{ + struct cpuinfo_x86 *cpu = &cpu_data(c); + unsigned int i; + ssize_t len = 0; + + for (i = 0; i < (32 * NCAPINTS); i++) { + if (cpu_has(cpu, i) && x86_cap_flags[i] != NULL) + len += sprintf(buf+len, len == 0 ? "%s" : " %s", + x86_cap_flags[i]); + } + if (!len) + return 0; + return len + sprintf(buf+len, "\n"); +} + +static ssize_t cpuinfo_bugs(unsigned int c, char *buf) +{ + struct cpuinfo_x86 *cpu = &cpu_data(c); + unsigned int i; + ssize_t len = 0; + + for (i = 0; i < 32*NBUGINTS; i++) { + unsigned int bug_bit = 32*NCAPINTS + i; + + if (cpu_has_bug(cpu, bug_bit) && x86_bug_flags[i]) + len += sprintf(buf+len, len == 0 ? "%s" : " %s", + x86_bug_flags[i]); + } + if (!len) + return 0; + return len + sprintf(buf+len, "\n"); +} + +static ssize_t cpuinfo_bogomips(unsigned int c, char *buf) +{ + struct cpuinfo_x86 cpu = cpu_data(c); + + return sprintf(buf, "%lu.%02lu\n", cpu.loops_per_jiffy / (500000 / HZ), + (cpu.loops_per_jiffy / (5000 / HZ)) % 100); +} + +#define cpuinfo_cpu_family(cpu) cpu_data(cpu).x86 +#define cpuinfo_model(cpu) cpu_data(cpu).x86_model + +#define cpuinfo_vendor_id(cpu) cpu_data(cpu).x86_vendor_id[0] ?\ + cpu_data(cpu).x86_vendor_id : "unknown" + +#define cpuinfo_model_name(cpu) cpu_data(cpu).x86_model_id[0] ? \ + cpu_data(cpu).x86_model_id : "unknown" + +CPUINFO_DEFINE_ATTR(cpu_family, "%d"); +CPUINFO_DEFINE_ATTR(model, "%u"); +CPUINFO_DEFINE_ATTR(vendor_id, "%s"); +CPUINFO_DEFINE_ATTR(model_name, "%s"); + +CPUINFO_DEFINE_ATTR_FUNC(stepping); +CPUINFO_DEFINE_ATTR_FUNC(flags); +CPUINFO_DEFINE_ATTR_FUNC(bugs); +CPUINFO_DEFINE_ATTR_FUNC(bogomips); + +struct attribute *cpuinfo_attrs[] = { + CPUINFO_ATTR(vendor_id), + CPUINFO_ATTR(cpu_family), + CPUINFO_ATTR(model), + CPUINFO_ATTR(model_name), + CPUINFO_ATTR(stepping), + CPUINFO_ATTR(flags), + CPUINFO_ATTR(bugs), + CPUINFO_ATTR(bogomips), + NULL +}; -- 2.16.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-12-06 16:24 UTC|newest] Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-06 16:24 [PATCH v5 0/3] sysfs: add sysfs based cpuinfo Thomas Renninger 2019-12-06 16:24 ` Thomas Renninger 2019-12-06 16:24 ` [PATCH 1/3] cpuinfo: add sysfs based arch independent cpuinfo framework Thomas Renninger 2019-12-06 16:24 ` Thomas Renninger 2019-12-06 16:33 ` Greg KH 2019-12-06 16:33 ` Greg KH 2019-12-06 16:33 ` Greg KH 2019-12-06 16:56 ` Randy Dunlap 2019-12-06 16:56 ` Randy Dunlap 2019-12-06 16:56 ` Randy Dunlap 2019-12-06 16:24 ` Thomas Renninger [this message] 2019-12-06 16:24 ` [PATCH 2/3] x86 cpuinfo: implement sysfs nodes for x86 Thomas Renninger 2019-12-06 16:36 ` Greg KH 2019-12-06 16:36 ` Greg KH 2019-12-10 20:48 ` Thomas Gleixner 2019-12-10 20:48 ` Thomas Gleixner 2019-12-10 20:53 ` Greg KH 2019-12-10 20:53 ` Greg KH 2019-12-11 10:42 ` Thomas Renninger 2019-12-11 10:42 ` Thomas Renninger 2019-12-11 13:56 ` Greg KH 2019-12-11 13:56 ` Greg KH 2019-12-11 14:12 ` Thomas Renninger 2019-12-11 14:12 ` Thomas Renninger 2019-12-11 14:26 ` Greg KH 2019-12-11 14:26 ` Greg KH 2019-12-11 14:52 ` Thomas Renninger 2019-12-11 14:52 ` Thomas Renninger 2019-12-11 14:57 ` Greg KH 2019-12-11 14:57 ` Greg KH 2019-12-06 16:24 ` [PATCH 3/3] arm64 cpuinfo: implement sysfs nodes for arm64 Thomas Renninger 2019-12-06 16:24 ` Thomas Renninger 2019-12-06 16:37 ` Greg KH 2019-12-06 16:37 ` Greg KH 2019-12-09 10:31 ` Will Deacon 2019-12-09 10:31 ` Will Deacon 2019-12-09 11:28 ` Thomas Renninger 2019-12-09 11:28 ` Thomas Renninger 2019-12-09 17:38 ` Will Deacon 2019-12-09 17:38 ` Will Deacon 2019-12-10 13:33 ` Thomas Renninger 2019-12-10 13:33 ` Thomas Renninger 2019-12-10 14:47 ` Greg KH 2019-12-10 14:47 ` Greg KH 2019-12-10 16:24 ` Thomas Renninger 2019-12-10 16:24 ` Thomas Renninger 2019-12-06 16:58 ` [PATCH v5 0/3] sysfs: add sysfs based cpuinfo Mark Rutland 2019-12-06 16:58 ` Mark Rutland 2019-12-06 17:29 ` Thomas Renninger 2019-12-06 17:29 ` Thomas Renninger 2019-12-06 18:16 ` Mark Rutland 2019-12-06 18:16 ` Mark Rutland
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191206162421.15050-3-trenn@suse.de \ --to=trenn@suse.de \ --cc=fschnitzlein@suse.de \ --cc=fschnizlein@suse.com \ --cc=fschnizlein@suse.de \ --cc=gregkh@linuxfoundation.org \ --cc=linux-arch@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@armlinux.org.uk \ --cc=trenn@suse.com \ --cc=will.deacon@arm.com \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.