From: Prarit Bhargava <prarit@redhat.com> Date: Fri, 5 Mar 2010 19:41:20 -0500 Subject: [misc] add {thread,core}_siblings_list to /sys Message-id: <20100305194120.30279.85323.sendpatchset@prarit.bos.redhat.com> Patchwork-id: 23505 O-Subject: [RHEL5.6 PATCH]: add thread_siblings_list and core_siblings_list to /sys Bugzilla: 570610 RH-Acked-by: Christopher Lalancette <clalance@redhat.com> RH-Acked-by: Jarod Wilson <jarod@redhat.com> >From clalance: "libvirt depends on the kernel to get socket/core/thread topology information. Currently this information is parsed out of /proc/cpuinfo, but I'm re-working the code to use /sys/devices/system/cpu (see BZ 570527 for more details). As part of that, it would be easier to parse a formatted list of thread and core siblings instead of the raw bitmask. RHEL-5 currently provides the raw bitmask in /sys/devices/system/cpu/cpu[0-9]*/topology/thread_sibilings, but it would be easier to parse" So I (Prarit) backported the upstream topology stuff to make clalance's libvirt modification easier. Brew built across all arches here: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=2303344 Successfully tested by me. Resolves BZ 570610. Signed-off-by: Jarod Wilson <jarod@redhat.com> diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 3ef9d51..d1e9766 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -30,7 +30,10 @@ #include <linux/module.h> #include <linux/topology.h> -#define define_one_ro(_name) \ +#define define_one_ro_named(_name, _func) \ +static SYSDEV_ATTR(_name, 0444, _func, NULL) + +#define define_one_ro(_name) \ static SYSDEV_ATTR(_name, 0444, show_##_name, NULL) #define define_id_show_func(name) \ @@ -40,16 +43,54 @@ static ssize_t show_##name(struct sys_device *dev, char *buf) \ return sprintf(buf, "%d\n", topology_##name(cpu)); \ } -#define define_siblings_show_func(name) \ +static ssize_t show_cpumap(int type, const cpumask_t mask, char *buf) +{ + ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; + int n = 0; + + if (len > 1) { + n = type? + cpulist_scnprintf(buf, len-2, mask) : + cpumask_scnprintf(buf, len-2, mask); + buf[n++] = '\n'; + buf[n] = '\0'; + } + return n; +} + +#ifdef arch_provides_topology_pointers +#define define_siblings_show_map(name) \ static ssize_t show_##name(struct sys_device *dev, char *buf) \ { \ - ssize_t len = -1; \ unsigned int cpu = dev->id; \ - len = cpumask_scnprintf(buf, NR_CPUS+1, topology_##name(cpu)); \ - return (len + sprintf(buf + len, "\n")); \ + return show_cpumap(0, topology_##name(cpu), buf); \ } -#ifdef topology_physical_package_id +#define define_siblings_show_list(name) \ +static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ +{ \ + unsigned int cpu = dev->id; \ + return show_cpumap(1, topology_##name(cpu), buf); \ +} + +#else +#define define_siblings_show_map(name) \ +static ssize_t show_##name(struct sys_device *dev, char *buf) \ +{ \ + return show_cpumap(0, topology_##name(dev->id), buf); \ +} + +#define define_siblings_show_list(name) \ +static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ +{ \ + return show_cpumap(1, topology_##name(dev->id), buf); \ +} +#endif + +#define define_siblings_show_func(name) \ + define_siblings_show_map(name); define_siblings_show_list(name) + +#ifdef topology_physical_package_id define_id_show_func(physical_package_id); define_one_ro(physical_package_id); #define ref_physical_package_id_attr &attr_physical_package_id.attr, @@ -65,27 +106,35 @@ define_one_ro(core_id); #define ref_core_id_attr #endif -#ifdef topology_thread_siblings -define_siblings_show_func(thread_siblings); -define_one_ro(thread_siblings); +#ifdef topology_thread_cpumask +define_siblings_show_func(thread_cpumask); +define_one_ro_named(thread_siblings, show_thread_cpumask); +define_one_ro_named(thread_siblings_list, show_thread_cpumask_list); #define ref_thread_siblings_attr &attr_thread_siblings.attr, +#define ref_thread_siblings_list_attr &attr_thread_siblings_list.attr, #else #define ref_thread_siblings_attr +#define ref_thread_siblings_list_attr #endif -#ifdef topology_core_siblings -define_siblings_show_func(core_siblings); -define_one_ro(core_siblings); +#ifdef topology_core_cpumask +define_siblings_show_func(core_cpumask); +define_one_ro_named(core_siblings, show_core_cpumask); +define_one_ro_named(core_siblings_list, show_core_cpumask_list); #define ref_core_siblings_attr &attr_core_siblings.attr, +#define ref_core_siblings_list_attr &attr_core_siblings_list.attr, #else #define ref_core_siblings_attr +#define ref_core_siblings_list_attr #endif static struct attribute *default_attrs[] = { ref_physical_package_id_attr ref_core_id_attr ref_thread_siblings_attr + ref_thread_siblings_list_attr ref_core_siblings_attr + ref_core_siblings_list_attr NULL }; diff --git a/include/asm-i386/topology.h b/include/asm-i386/topology.h index 9234497..0dbc5be 100644 --- a/include/asm-i386/topology.h +++ b/include/asm-i386/topology.h @@ -30,8 +30,8 @@ #ifdef CONFIG_X86_HT #define topology_physical_package_id(cpu) (cpu_data[cpu].phys_proc_id) #define topology_core_id(cpu) (cpu_data[cpu].cpu_core_id) -#define topology_core_siblings(cpu) (cpu_core_map[cpu]) -#define topology_thread_siblings(cpu) (cpu_sibling_map[cpu]) +#define topology_core_cpumask(cpu) (cpu_core_map[cpu]) +#define topology_thread_cpumask(cpu) (cpu_sibling_map[cpu]) #endif #ifdef CONFIG_NUMA diff --git a/include/asm-ia64/topology.h b/include/asm-ia64/topology.h index 7d12dc6..2be14b2 100644 --- a/include/asm-ia64/topology.h +++ b/include/asm-ia64/topology.h @@ -110,8 +110,8 @@ void build_cpu_to_node_map(void); #ifdef CONFIG_SMP #define topology_physical_package_id(cpu) (cpu_data(cpu)->socket_id) #define topology_core_id(cpu) (cpu_data(cpu)->core_id) -#define topology_core_siblings(cpu) (cpu_core_map[cpu]) -#define topology_thread_siblings(cpu) (cpu_sibling_map[cpu]) +#define topology_core_cpumask(cpu) (cpu_core_map[cpu]) +#define topology_thread_cpumask(cpu) (cpu_sibling_map[cpu]) #define smt_capable() (smp_num_siblings > 1) #endif diff --git a/include/asm-x86_64/topology.h b/include/asm-x86_64/topology.h index c38717c..2d0def8 100644 --- a/include/asm-x86_64/topology.h +++ b/include/asm-x86_64/topology.h @@ -57,8 +57,8 @@ extern int __node_distance(int, int); #ifdef CONFIG_SMP #define topology_physical_package_id(cpu) (cpu_data[cpu].phys_proc_id) #define topology_core_id(cpu) (cpu_data[cpu].cpu_core_id) -#define topology_core_siblings(cpu) (cpu_core_map[cpu]) -#define topology_thread_siblings(cpu) (cpu_sibling_map[cpu]) +#define topology_core_cpumask(cpu) (cpu_core_map[cpu]) +#define topology_thread_cpumask(cpu) (cpu_sibling_map[cpu]) #define mc_capable() (boot_cpu_data.x86_max_cores > 1) #define smt_capable() (smp_num_siblings > 1) #endif