Blame view
drivers/base/topology.c
5.24 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 |
/* * 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. * */ |
69dcc9919 [PATCH] Export cp... |
26 27 28 29 |
#include <linux/init.h> #include <linux/mm.h> #include <linux/cpu.h> #include <linux/module.h> |
b13d3720e topology: Fix spa... |
30 |
#include <linux/hardirq.h> |
69dcc9919 [PATCH] Export cp... |
31 |
#include <linux/topology.h> |
fbd59a8d1 cpumask: Use topo... |
32 |
#define define_one_ro_named(_name, _func) \ |
8a25a2fd1 cpu: convert 'cpu... |
33 |
static DEVICE_ATTR(_name, 0444, _func, NULL) |
fbd59a8d1 cpumask: Use topo... |
34 35 |
#define define_one_ro(_name) \ |
8a25a2fd1 cpu: convert 'cpu... |
36 |
static DEVICE_ATTR(_name, 0444, show_##_name, NULL) |
69dcc9919 [PATCH] Export cp... |
37 38 |
#define define_id_show_func(name) \ |
8a25a2fd1 cpu: convert 'cpu... |
39 40 |
static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, char *buf) \ |
69dcc9919 [PATCH] Export cp... |
41 42 43 44 45 |
{ \ unsigned int cpu = dev->id; \ return sprintf(buf, "%d ", topology_##name(cpu)); \ } |
b40d8ed4e topology/sysfs: P... |
46 47 |
#if defined(topology_thread_cpumask) || defined(topology_core_cpumask) || \ defined(topology_book_cpumask) |
fbd59a8d1 cpumask: Use topo... |
48 |
static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf) |
39106dcf8 cpumask: use new ... |
49 50 51 52 53 54 |
{ ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; int n = 0; if (len > 1) { n = type? |
29c0177e6 cpumask: change c... |
55 56 |
cpulist_scnprintf(buf, len-2, mask) : cpumask_scnprintf(buf, len-2, mask); |
39106dcf8 cpumask: use new ... |
57 58 59 60 61 62 |
buf[n++] = ' '; buf[n] = '\0'; } return n; } |
23ca4bba3 x86: cleanup earl... |
63 |
#endif |
39106dcf8 cpumask: use new ... |
64 |
|
23ca4bba3 x86: cleanup earl... |
65 |
#ifdef arch_provides_topology_pointers |
39106dcf8 cpumask: use new ... |
66 |
#define define_siblings_show_map(name) \ |
8a25a2fd1 cpu: convert 'cpu... |
67 68 |
static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, char *buf) \ |
39106dcf8 cpumask: use new ... |
69 70 |
{ \ unsigned int cpu = dev->id; \ |
fbd59a8d1 cpumask: Use topo... |
71 |
return show_cpumap(0, topology_##name(cpu), buf); \ |
39106dcf8 cpumask: use new ... |
72 73 74 |
} #define define_siblings_show_list(name) \ |
8a25a2fd1 cpu: convert 'cpu... |
75 76 |
static ssize_t show_##name##_list(struct device *dev, \ struct device_attribute *attr, \ |
4a0b2b4db sysdev: Pass the ... |
77 |
char *buf) \ |
69dcc9919 [PATCH] Export cp... |
78 |
{ \ |
69dcc9919 [PATCH] Export cp... |
79 |
unsigned int cpu = dev->id; \ |
fbd59a8d1 cpumask: Use topo... |
80 |
return show_cpumap(1, topology_##name(cpu), buf); \ |
69dcc9919 [PATCH] Export cp... |
81 |
} |
23ca4bba3 x86: cleanup earl... |
82 83 |
#else #define define_siblings_show_map(name) \ |
8a25a2fd1 cpu: convert 'cpu... |
84 85 |
static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, char *buf) \ |
23ca4bba3 x86: cleanup earl... |
86 |
{ \ |
fbd59a8d1 cpumask: Use topo... |
87 |
return show_cpumap(0, topology_##name(dev->id), buf); \ |
23ca4bba3 x86: cleanup earl... |
88 89 90 |
} #define define_siblings_show_list(name) \ |
8a25a2fd1 cpu: convert 'cpu... |
91 92 |
static ssize_t show_##name##_list(struct device *dev, \ struct device_attribute *attr, \ |
4a0b2b4db sysdev: Pass the ... |
93 |
char *buf) \ |
23ca4bba3 x86: cleanup earl... |
94 |
{ \ |
fbd59a8d1 cpumask: Use topo... |
95 |
return show_cpumap(1, topology_##name(dev->id), buf); \ |
23ca4bba3 x86: cleanup earl... |
96 97 |
} #endif |
39106dcf8 cpumask: use new ... |
98 99 |
#define define_siblings_show_func(name) \ define_siblings_show_map(name); define_siblings_show_list(name) |
69dcc9919 [PATCH] Export cp... |
100 101 |
define_id_show_func(physical_package_id); define_one_ro(physical_package_id); |
69dcc9919 [PATCH] Export cp... |
102 |
|
69dcc9919 [PATCH] Export cp... |
103 104 |
define_id_show_func(core_id); define_one_ro(core_id); |
69dcc9919 [PATCH] Export cp... |
105 |
|
fbd59a8d1 cpumask: Use topo... |
106 107 108 |
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... |
109 |
|
fbd59a8d1 cpumask: Use topo... |
110 111 112 |
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... |
113 |
|
b40d8ed4e topology/sysfs: P... |
114 115 116 117 118 119 120 |
#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... |
121 |
static struct attribute *default_attrs[] = { |
8a25a2fd1 cpu: convert 'cpu... |
122 123 124 125 126 127 |
&dev_attr_physical_package_id.attr, &dev_attr_core_id.attr, &dev_attr_thread_siblings.attr, &dev_attr_thread_siblings_list.attr, &dev_attr_core_siblings.attr, &dev_attr_core_siblings_list.attr, |
b40d8ed4e topology/sysfs: P... |
128 |
#ifdef CONFIG_SCHED_BOOK |
8a25a2fd1 cpu: convert 'cpu... |
129 130 131 |
&dev_attr_book_id.attr, &dev_attr_book_siblings.attr, &dev_attr_book_siblings_list.attr, |
b40d8ed4e topology/sysfs: P... |
132 |
#endif |
69dcc9919 [PATCH] Export cp... |
133 134 135 136 137 138 139 140 141 |
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... |
142 |
static int __cpuinit topology_add_dev(unsigned int cpu) |
69dcc9919 [PATCH] Export cp... |
143 |
{ |
8a25a2fd1 cpu: convert 'cpu... |
144 |
struct device *dev = get_cpu_device(cpu); |
06a4bcae1 cpu topology: con... |
145 |
|
8a25a2fd1 cpu: convert 'cpu... |
146 |
return sysfs_create_group(&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 |
{ |
8a25a2fd1 cpu: convert 'cpu... |
150 |
struct device *dev = get_cpu_device(cpu); |
06a4bcae1 cpu topology: con... |
151 |
|
8a25a2fd1 cpu: convert 'cpu... |
152 |
sysfs_remove_group(&dev->kobj, &topology_attr_group); |
69dcc9919 [PATCH] Export cp... |
153 |
} |
9c7b216d2 [PATCH] cpu hotpl... |
154 |
static int __cpuinit topology_cpu_callback(struct notifier_block *nfb, |
06a4bcae1 cpu topology: con... |
155 |
unsigned long action, void *hcpu) |
69dcc9919 [PATCH] Export cp... |
156 157 |
{ unsigned int cpu = (unsigned long)hcpu; |
06a4bcae1 cpu topology: con... |
158 |
int rc = 0; |
69dcc9919 [PATCH] Export cp... |
159 |
|
69dcc9919 [PATCH] Export cp... |
160 |
switch (action) { |
06a4bcae1 cpu topology: con... |
161 |
case CPU_UP_PREPARE: |
8bb784428 Add suspend-relat... |
162 |
case CPU_UP_PREPARE_FROZEN: |
06a4bcae1 cpu topology: con... |
163 |
rc = topology_add_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
164 |
break; |
06a4bcae1 cpu topology: con... |
165 |
case CPU_UP_CANCELED: |
8bb784428 Add suspend-relat... |
166 |
case CPU_UP_CANCELED_FROZEN: |
69dcc9919 [PATCH] Export cp... |
167 |
case CPU_DEAD: |
8bb784428 Add suspend-relat... |
168 |
case CPU_DEAD_FROZEN: |
06a4bcae1 cpu topology: con... |
169 |
topology_remove_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
170 171 |
break; } |
ad84bb5b9 topology: convert... |
172 |
return notifier_from_errno(rc); |
69dcc9919 [PATCH] Export cp... |
173 |
} |
69dcc9919 [PATCH] Export cp... |
174 175 176 |
static int __cpuinit topology_sysfs_init(void) { |
06a4bcae1 cpu topology: con... |
177 178 |
int cpu; int rc; |
69dcc9919 [PATCH] Export cp... |
179 |
|
06a4bcae1 cpu topology: con... |
180 181 182 183 |
for_each_online_cpu(cpu) { rc = topology_add_dev(cpu); if (rc) return rc; |
69dcc9919 [PATCH] Export cp... |
184 |
} |
06a4bcae1 cpu topology: con... |
185 |
hotcpu_notifier(topology_cpu_callback, 0); |
69dcc9919 [PATCH] Export cp... |
186 187 188 189 190 |
return 0; } device_initcall(topology_sysfs_init); |