Blame view
drivers/base/topology.c
4.42 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 |
#include <linux/mm.h> #include <linux/cpu.h> #include <linux/module.h> |
b13d3720e topology: Fix spa... |
29 |
#include <linux/hardirq.h> |
69dcc9919 [PATCH] Export cp... |
30 |
#include <linux/topology.h> |
69dcc9919 [PATCH] Export cp... |
31 |
#define define_id_show_func(name) \ |
d6ea8d01d topology: replace... |
32 |
static ssize_t name##_show(struct device *dev, \ |
8a25a2fd1 cpu: convert 'cpu... |
33 |
struct device_attribute *attr, char *buf) \ |
69dcc9919 [PATCH] Export cp... |
34 |
{ \ |
53974e066 topology: Fix com... |
35 36 |
return sprintf(buf, "%d ", topology_##name(dev->id)); \ |
69dcc9919 [PATCH] Export cp... |
37 |
} |
d6ea8d01d topology: replace... |
38 39 |
#define define_siblings_show_map(name, mask) \ static ssize_t name##_show(struct device *dev, \ |
8a25a2fd1 cpu: convert 'cpu... |
40 |
struct device_attribute *attr, char *buf) \ |
23ca4bba3 x86: cleanup earl... |
41 |
{ \ |
d6ea8d01d topology: replace... |
42 |
return cpumap_print_to_pagebuf(false, buf, topology_##mask(dev->id));\ |
23ca4bba3 x86: cleanup earl... |
43 |
} |
d6ea8d01d topology: replace... |
44 45 46 47 |
#define define_siblings_show_list(name, mask) \ static ssize_t name##_list_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ |
23ca4bba3 x86: cleanup earl... |
48 |
{ \ |
d6ea8d01d topology: replace... |
49 |
return cpumap_print_to_pagebuf(true, buf, topology_##mask(dev->id));\ |
23ca4bba3 x86: cleanup earl... |
50 |
} |
23ca4bba3 x86: cleanup earl... |
51 |
|
d6ea8d01d topology: replace... |
52 53 54 |
#define define_siblings_show_func(name, mask) \ define_siblings_show_map(name, mask); \ define_siblings_show_list(name, mask) |
39106dcf8 cpumask: use new ... |
55 |
|
69dcc9919 [PATCH] Export cp... |
56 |
define_id_show_func(physical_package_id); |
d6ea8d01d topology: replace... |
57 |
static DEVICE_ATTR_RO(physical_package_id); |
69dcc9919 [PATCH] Export cp... |
58 |
|
69dcc9919 [PATCH] Export cp... |
59 |
define_id_show_func(core_id); |
d6ea8d01d topology: replace... |
60 |
static DEVICE_ATTR_RO(core_id); |
69dcc9919 [PATCH] Export cp... |
61 |
|
06931e622 sched/topology: R... |
62 |
define_siblings_show_func(thread_siblings, sibling_cpumask); |
d6ea8d01d topology: replace... |
63 64 |
static DEVICE_ATTR_RO(thread_siblings); static DEVICE_ATTR_RO(thread_siblings_list); |
69dcc9919 [PATCH] Export cp... |
65 |
|
d6ea8d01d topology: replace... |
66 67 68 |
define_siblings_show_func(core_siblings, core_cpumask); static DEVICE_ATTR_RO(core_siblings); static DEVICE_ATTR_RO(core_siblings_list); |
69dcc9919 [PATCH] Export cp... |
69 |
|
b40d8ed4e topology/sysfs: P... |
70 71 |
#ifdef CONFIG_SCHED_BOOK define_id_show_func(book_id); |
d6ea8d01d topology: replace... |
72 73 74 75 |
static DEVICE_ATTR_RO(book_id); define_siblings_show_func(book_siblings, book_cpumask); static DEVICE_ATTR_RO(book_siblings); static DEVICE_ATTR_RO(book_siblings_list); |
b40d8ed4e topology/sysfs: P... |
76 |
#endif |
a62247e1f topology/sysfs: p... |
77 78 79 80 81 82 83 |
#ifdef CONFIG_SCHED_DRAWER define_id_show_func(drawer_id); static DEVICE_ATTR_RO(drawer_id); define_siblings_show_func(drawer_siblings, drawer_cpumask); static DEVICE_ATTR_RO(drawer_siblings); static DEVICE_ATTR_RO(drawer_siblings_list); #endif |
69dcc9919 [PATCH] Export cp... |
84 |
static struct attribute *default_attrs[] = { |
8a25a2fd1 cpu: convert 'cpu... |
85 86 87 88 89 90 |
&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... |
91 |
#ifdef CONFIG_SCHED_BOOK |
8a25a2fd1 cpu: convert 'cpu... |
92 93 94 |
&dev_attr_book_id.attr, &dev_attr_book_siblings.attr, &dev_attr_book_siblings_list.attr, |
b40d8ed4e topology/sysfs: P... |
95 |
#endif |
a62247e1f topology/sysfs: p... |
96 97 98 99 100 |
#ifdef CONFIG_SCHED_DRAWER &dev_attr_drawer_id.attr, &dev_attr_drawer_siblings.attr, &dev_attr_drawer_siblings_list.attr, #endif |
69dcc9919 [PATCH] Export cp... |
101 102 103 104 105 106 107 108 109 |
NULL }; static struct attribute_group topology_attr_group = { .attrs = default_attrs, .name = "topology" }; /* Add/Remove cpu_topology interface for CPU device */ |
a83048ebd drivers: delete _... |
110 |
static int topology_add_dev(unsigned int cpu) |
69dcc9919 [PATCH] Export cp... |
111 |
{ |
8a25a2fd1 cpu: convert 'cpu... |
112 |
struct device *dev = get_cpu_device(cpu); |
06a4bcae1 cpu topology: con... |
113 |
|
8a25a2fd1 cpu: convert 'cpu... |
114 |
return sysfs_create_group(&dev->kobj, &topology_attr_group); |
69dcc9919 [PATCH] Export cp... |
115 |
} |
a83048ebd drivers: delete _... |
116 |
static void topology_remove_dev(unsigned int cpu) |
69dcc9919 [PATCH] Export cp... |
117 |
{ |
8a25a2fd1 cpu: convert 'cpu... |
118 |
struct device *dev = get_cpu_device(cpu); |
06a4bcae1 cpu topology: con... |
119 |
|
8a25a2fd1 cpu: convert 'cpu... |
120 |
sysfs_remove_group(&dev->kobj, &topology_attr_group); |
69dcc9919 [PATCH] Export cp... |
121 |
} |
a83048ebd drivers: delete _... |
122 123 |
static int topology_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) |
69dcc9919 [PATCH] Export cp... |
124 125 |
{ unsigned int cpu = (unsigned long)hcpu; |
06a4bcae1 cpu topology: con... |
126 |
int rc = 0; |
69dcc9919 [PATCH] Export cp... |
127 |
|
69dcc9919 [PATCH] Export cp... |
128 |
switch (action) { |
06a4bcae1 cpu topology: con... |
129 |
case CPU_UP_PREPARE: |
8bb784428 Add suspend-relat... |
130 |
case CPU_UP_PREPARE_FROZEN: |
06a4bcae1 cpu topology: con... |
131 |
rc = topology_add_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
132 |
break; |
06a4bcae1 cpu topology: con... |
133 |
case CPU_UP_CANCELED: |
8bb784428 Add suspend-relat... |
134 |
case CPU_UP_CANCELED_FROZEN: |
69dcc9919 [PATCH] Export cp... |
135 |
case CPU_DEAD: |
8bb784428 Add suspend-relat... |
136 |
case CPU_DEAD_FROZEN: |
06a4bcae1 cpu topology: con... |
137 |
topology_remove_dev(cpu); |
69dcc9919 [PATCH] Export cp... |
138 139 |
break; } |
ad84bb5b9 topology: convert... |
140 |
return notifier_from_errno(rc); |
69dcc9919 [PATCH] Export cp... |
141 |
} |
69dcc9919 [PATCH] Export cp... |
142 |
|
a83048ebd drivers: delete _... |
143 |
static int topology_sysfs_init(void) |
69dcc9919 [PATCH] Export cp... |
144 |
{ |
06a4bcae1 cpu topology: con... |
145 |
int cpu; |
e12b71119 drivers/base/topo... |
146 147 148 |
int rc = 0; cpu_notifier_register_begin(); |
69dcc9919 [PATCH] Export cp... |
149 |
|
06a4bcae1 cpu topology: con... |
150 151 152 |
for_each_online_cpu(cpu) { rc = topology_add_dev(cpu); if (rc) |
e12b71119 drivers/base/topo... |
153 |
goto out; |
69dcc9919 [PATCH] Export cp... |
154 |
} |
e12b71119 drivers/base/topo... |
155 |
__hotcpu_notifier(topology_cpu_callback, 0); |
69dcc9919 [PATCH] Export cp... |
156 |
|
e12b71119 drivers/base/topo... |
157 158 159 |
out: cpu_notifier_register_done(); return rc; |
69dcc9919 [PATCH] Export cp... |
160 161 162 |
} device_initcall(topology_sysfs_init); |