Blame view
drivers/base/topology.c
5.26 KB
69dcc9919 [PATCH] Export cp... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* * driver/base/topology.c - Populate sysfs with cpu topology information * * Written by: Zhang Yanmin, Intel Corporation * * Copyright (C) 2006, Intel Corp. * * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include <linux/sysdev.h> #include <linux/init.h> #include <linux/mm.h> #include <linux/cpu.h> #include <linux/module.h> |
b13d3720e topology: Fix spa... |
31 |
#include <linux/hardirq.h> |
69dcc9919 [PATCH] Export cp... |
32 |
#include <linux/topology.h> |
fbd59a8d1 cpumask: Use topo... |
33 34 35 36 |
#define define_one_ro_named(_name, _func) \ static SYSDEV_ATTR(_name, 0444, _func, NULL) #define define_one_ro(_name) \ |
69dcc9919 [PATCH] Export cp... |
37 38 39 |
static SYSDEV_ATTR(_name, 0444, show_##_name, NULL) #define define_id_show_func(name) \ |
4a0b2b4db sysdev: Pass the ... |
40 41 |
static ssize_t show_##name(struct sys_device *dev, \ struct sysdev_attribute *attr, char *buf) \ |
69dcc9919 [PATCH] Export cp... |
42 43 44 45 46 |
{ \ unsigned int cpu = dev->id; \ return sprintf(buf, "%d ", topology_##name(cpu)); \ } |
b40d8ed4e topology/sysfs: P... |
47 48 |
#if defined(topology_thread_cpumask) || defined(topology_core_cpumask) || \ defined(topology_book_cpumask) |
fbd59a8d1 cpumask: Use topo... |
49 |
static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf) |
39106dcf8 cpumask: use new ... |
50 51 52 53 54 55 |
{ ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; int n = 0; if (len > 1) { n = type? |
29c0177e6 cpumask: change c... |
56 57 |
cpulist_scnprintf(buf, len-2, mask) : cpumask_scnprintf(buf, len-2, mask); |
39106dcf8 cpumask: use new ... |
58 59 60 61 62 63 |
buf[n++] = ' '; buf[n] = '\0'; } return n; } |
23ca4bba3 x86: cleanup earl... |
64 |
#endif |
39106dcf8 cpumask: use new ... |
65 |
|
23ca4bba3 x86: cleanup earl... |
66 |
#ifdef arch_provides_topology_pointers |
39106dcf8 cpumask: use new ... |
67 |
#define define_siblings_show_map(name) \ |
4a0b2b4db sysdev: Pass the ... |
68 69 |
static ssize_t show_##name(struct sys_device *dev, \ struct sysdev_attribute *attr, char *buf) \ |
39106dcf8 cpumask: use new ... |
70 71 |
{ \ unsigned int cpu = dev->id; \ |
fbd59a8d1 cpumask: Use topo... |
72 |
return show_cpumap(0, topology_##name(cpu), buf); \ |
39106dcf8 cpumask: use new ... |
73 74 75 |
} #define define_siblings_show_list(name) \ |
4a0b2b4db sysdev: Pass the ... |
76 77 78 |
static ssize_t show_##name##_list(struct sys_device *dev, \ struct sysdev_attribute *attr, \ char *buf) \ |
69dcc9919 [PATCH] Export cp... |
79 |
{ \ |
69dcc9919 [PATCH] Export cp... |
80 |
unsigned int cpu = dev->id; \ |
fbd59a8d1 cpumask: Use topo... |
81 |
return show_cpumap(1, topology_##name(cpu), buf); \ |
69dcc9919 [PATCH] Export cp... |
82 |
} |
23ca4bba3 x86: cleanup earl... |
83 84 |
#else #define define_siblings_show_map(name) \ |
4a0b2b4db sysdev: Pass the ... |
85 86 |
static ssize_t show_##name(struct sys_device *dev, \ struct sysdev_attribute *attr, char *buf) \ |
23ca4bba3 x86: cleanup earl... |
87 |
{ \ |
fbd59a8d1 cpumask: Use topo... |
88 |
return show_cpumap(0, topology_##name(dev->id), buf); \ |
23ca4bba3 x86: cleanup earl... |
89 90 91 |
} #define define_siblings_show_list(name) \ |
4a0b2b4db sysdev: Pass the ... |
92 93 94 |
static ssize_t show_##name##_list(struct sys_device *dev, \ struct sysdev_attribute *attr, \ char *buf) \ |
23ca4bba3 x86: cleanup earl... |
95 |
{ \ |
fbd59a8d1 cpumask: Use topo... |
96 |
return show_cpumap(1, topology_##name(dev->id), buf); \ |
23ca4bba3 x86: cleanup earl... |
97 98 |
} #endif |
39106dcf8 cpumask: use new ... |
99 100 |
#define define_siblings_show_func(name) \ define_siblings_show_map(name); define_siblings_show_list(name) |
69dcc9919 [PATCH] Export cp... |
101 102 |
define_id_show_func(physical_package_id); define_one_ro(physical_package_id); |
69dcc9919 [PATCH] Export cp... |
103 |
|
69dcc9919 [PATCH] Export cp... |
104 105 |
define_id_show_func(core_id); define_one_ro(core_id); |
69dcc9919 [PATCH] Export cp... |
106 |
|
fbd59a8d1 cpumask: Use topo... |
107 108 109 |
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); |
69dcc9919 [PATCH] Export cp... |
110 |
|
fbd59a8d1 cpumask: Use topo... |
111 112 113 |
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); |
69dcc9919 [PATCH] Export cp... |
114 |
|
b40d8ed4e topology/sysfs: P... |
115 116 117 118 119 120 121 |
#ifdef CONFIG_SCHED_BOOK define_id_show_func(book_id); define_one_ro(book_id); define_siblings_show_func(book_cpumask); define_one_ro_named(book_siblings, show_book_cpumask); define_one_ro_named(book_siblings_list, show_book_cpumask_list); #endif |
69dcc9919 [PATCH] Export cp... |
122 |
static struct attribute *default_attrs[] = { |
c50cbb05a cpu topology: alw... |
123 124 125 126 127 128 |
&attr_physical_package_id.attr, &attr_core_id.attr, &attr_thread_siblings.attr, &attr_thread_siblings_list.attr, &attr_core_siblings.attr, &attr_core_siblings_list.attr, |
b40d8ed4e topology/sysfs: P... |
129 130 131 132 133 |
#ifdef CONFIG_SCHED_BOOK &attr_book_id.attr, &attr_book_siblings.attr, &attr_book_siblings_list.attr, #endif |
69dcc9919 [PATCH] Export cp... |
134 135 136 137 138 139 140 141 142 |
NULL }; static struct attribute_group topology_attr_group = { .attrs = default_attrs, .name = "topology" }; /* Add/Remove cpu_topology interface for CPU device */ |
06a4bcae1 cpu topology: con... |
143 |
static int __cpuinit topology_add_dev(unsigned int cpu) |
69dcc9919 [PATCH] Export cp... |
144 |
{ |
06a4bcae1 cpu topology: con... |
145 |
struct sys_device *sys_dev = get_cpu_sysdev(cpu); |
9780e3e96 cpu hotplug: topo... |
146 |
return sysfs_create_group(&sys_dev->kobj, &topology_attr_group); |
69dcc9919 [PATCH] Export cp... |
147 |
} |
06a4bcae1 cpu topology: con... |
148 |
static void __cpuinit topology_remove_dev(unsigned int cpu) |
69dcc9919 [PATCH] Export cp... |
149 |
{ |
06a4bcae1 cpu topology: con... |
150 |
struct sys_device *sys_dev = get_cpu_sysdev(cpu); |
69dcc9919 [PATCH] Export cp... |
151 |
sysfs_remove_group(&sys_dev->kobj, &topology_attr_group); |
69dcc9919 [PATCH] Export cp... |
152 |
} |
9c7b216d2 [PATCH] cpu hotpl... |
153 |
static int __cpuinit topology_cpu_callback(struct notifier_block *nfb, |
06a4bcae1 cpu topology: con... |
154 |
unsigned long action, void *hcpu) |
69dcc9919 [PATCH] Export cp... |
155 156 |
{ unsigned int cpu = (unsigned long)hcpu; |
06a4bcae1 cpu topology: con... |
157 |
int rc = 0; |
69dcc9919 [PATCH] Export cp... |
158 |
|
69dcc9919 [PATCH] Export cp... |
159 |
switch (action) { |
06a4bcae1 cpu topology: con... |
160 |
case CPU_UP_PREPARE: |
8bb784428 Add suspend-relat... |
161 |
case CPU_UP_PREPARE_FROZEN: |
06a4bcae1 cpu topology: con... |
162 |
rc = topology_add_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
163 |
break; |
06a4bcae1 cpu topology: con... |
164 |
case CPU_UP_CANCELED: |
8bb784428 Add suspend-relat... |
165 |
case CPU_UP_CANCELED_FROZEN: |
69dcc9919 [PATCH] Export cp... |
166 |
case CPU_DEAD: |
8bb784428 Add suspend-relat... |
167 |
case CPU_DEAD_FROZEN: |
06a4bcae1 cpu topology: con... |
168 |
topology_remove_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
169 170 |
break; } |
ad84bb5b9 topology: convert... |
171 |
return notifier_from_errno(rc); |
69dcc9919 [PATCH] Export cp... |
172 |
} |
69dcc9919 [PATCH] Export cp... |
173 174 175 |
static int __cpuinit topology_sysfs_init(void) { |
06a4bcae1 cpu topology: con... |
176 177 |
int cpu; int rc; |
69dcc9919 [PATCH] Export cp... |
178 |
|
06a4bcae1 cpu topology: con... |
179 180 181 182 |
for_each_online_cpu(cpu) { rc = topology_add_dev(cpu); if (rc) return rc; |
69dcc9919 [PATCH] Export cp... |
183 |
} |
06a4bcae1 cpu topology: con... |
184 |
hotcpu_notifier(topology_cpu_callback, 0); |
69dcc9919 [PATCH] Export cp... |
185 186 187 188 189 |
return 0; } device_initcall(topology_sysfs_init); |