2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* This file contains NUMA specific variables and functions which can
|
|
|
|
* be split away from DISCONTIGMEM and are used on NUMA machines with
|
|
|
|
* contiguous memory.
|
|
|
|
* 2002/08/07 Erich Focht <efocht@ess.nec.de>
|
|
|
|
* Populate cpu entries in sysfs for non-numa systems as well
|
|
|
|
* Intel Corporation - Ashok Raj
|
2006-02-26 20:37:45 -07:00
|
|
|
* 02/27/2006 Zhang, Yanmin
|
|
|
|
* Populate cpu cache entries in sysfs for cpu cache info
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/node.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/nodemask.h>
|
2006-02-26 20:37:45 -07:00
|
|
|
#include <linux/notifier.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/mmzone.h>
|
|
|
|
#include <asm/numa.h>
|
|
|
|
#include <asm/cpu.h>
|
|
|
|
|
|
|
|
static struct ia64_cpu *sysfs_cpus;
|
|
|
|
|
2008-04-29 16:05:29 -06:00
|
|
|
void arch_fix_phys_package_id(int num, u32 slot)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (cpu_data(num)->socket_id == -1)
|
|
|
|
cpu_data(num)->socket_id = slot;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(arch_fix_phys_package_id);
|
|
|
|
|
2008-04-30 01:50:55 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
int __ref arch_register_cpu(int num)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-30 01:50:55 -06:00
|
|
|
#ifdef CONFIG_ACPI
|
2005-03-31 20:51:10 -07:00
|
|
|
/*
|
2006-12-06 18:14:10 -07:00
|
|
|
* If CPEI can be re-targetted or if this is not
|
|
|
|
* CPEI target, then it is hotpluggable
|
2005-03-31 20:51:10 -07:00
|
|
|
*/
|
2006-12-06 18:14:10 -07:00
|
|
|
if (can_cpei_retarget() || !is_cpu_cpei_target(num))
|
|
|
|
sysfs_cpus[num].cpu.hotpluggable = 1;
|
2006-09-25 17:25:31 -06:00
|
|
|
map_cpu_to_node(num, node_cpuid[num].nid);
|
2005-07-13 22:09:00 -06:00
|
|
|
#endif
|
[PATCH] node hotplug: register cpu: remove node struct
With Goto-san's patch, we can add new pgdat/node at runtime. I'm now
considering node-hot-add with cpu + memory on ACPI.
I found acpi container, which describes node, could evaluate cpu before
memory. This means cpu-hot-add occurs before memory hot add.
In most part, cpu-hot-add doesn't depend on node hot add. But register_cpu(),
which creates symbolic link from node to cpu, requires that node should be
onlined before register_cpu(). When a node is onlined, its pgdat should be
there.
This patch-set holds off creating symbolic link from node to cpu
until node is onlined.
This removes node arguments from register_cpu().
Now, register_cpu() requires 'struct node' as its argument. But the array of
struct node is now unified in driver/base/node.c now (By Goto's node hotplug
patch). We can get struct node in generic way. So, this argument is not
necessary now.
This patch also guarantees add cpu under node only when node is onlined. It
is necessary for node-hot-add vs. cpu-hot-add patch following this.
Moreover, register_cpu calculates cpu->node_id by cpu_to_node() without regard
to its 'struct node *root' argument. This patch removes it.
Also modify callers of register_cpu()/unregister_cpu, whose args are changed
by register-cpu-remove-node-struct patch.
[Brice.Goglin@ens-lyon.org: fix it]
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Brice Goglin <Brice.Goglin@ens-lyon.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-27 03:53:41 -06:00
|
|
|
return register_cpu(&sysfs_cpus[num].cpu, num);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2008-04-30 01:50:55 -06:00
|
|
|
EXPORT_SYMBOL(arch_register_cpu);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-12-08 07:43:46 -07:00
|
|
|
void __ref arch_unregister_cpu(int num)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-25 17:25:31 -06:00
|
|
|
unregister_cpu(&sysfs_cpus[num].cpu);
|
2008-12-08 07:43:46 -07:00
|
|
|
#ifdef CONFIG_ACPI
|
2006-09-25 17:25:31 -06:00
|
|
|
unmap_cpu_from_node(num, cpu_to_node(num));
|
2008-12-08 07:43:46 -07:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(arch_unregister_cpu);
|
2008-04-30 01:50:55 -06:00
|
|
|
#else
|
|
|
|
static int __init arch_register_cpu(int num)
|
|
|
|
{
|
|
|
|
return register_cpu(&sysfs_cpus[num].cpu, num);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /*CONFIG_HOTPLUG_CPU*/
|
|
|
|
|
|
|
|
|
|
|
|
static int __init topology_init(void)
|
|
|
|
{
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_NUMA
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
/*
|
|
|
|
* MCD - Do we want to register all ONLINE nodes, or all POSSIBLE nodes?
|
|
|
|
*/
|
|
|
|
for_each_online_node(i) {
|
2006-06-27 03:53:38 -06:00
|
|
|
if ((err = register_one_node(i)))
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
sysfs_cpus = kzalloc(sizeof(struct ia64_cpu) * NR_CPUS, GFP_KERNEL);
|
2006-08-14 23:45:49 -06:00
|
|
|
if (!sysfs_cpus)
|
|
|
|
panic("kzalloc in topology_init failed - NR_CPUS too big?");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
for_each_present_cpu(i) {
|
2005-04-16 16:20:36 -06:00
|
|
|
if((err = arch_register_cpu(i)))
|
|
|
|
goto out;
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
[PATCH] Export cpu topology in sysfs
The patch implements cpu topology exportation by sysfs.
Items (attributes) are similar to /proc/cpuinfo.
1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
represent the physical package id of cpu X;
2) /sys/devices/system/cpu/cpuX/topology/core_id:
represent the cpu core id to cpu X;
3) /sys/devices/system/cpu/cpuX/topology/thread_siblings:
represent the thread siblings to cpu X in the same core;
4) /sys/devices/system/cpu/cpuX/topology/core_siblings:
represent the thread siblings to cpu X in the same physical package;
To implement it in an architecture-neutral way, a new source file,
driver/base/topology.c, is to export the 5 attributes.
If one architecture wants to support this feature, it just needs to
implement 4 defines, typically in file include/asm-XXX/topology.h.
The 4 defines are:
#define topology_physical_package_id(cpu)
#define topology_core_id(cpu)
#define topology_thread_siblings(cpu)
#define topology_core_siblings(cpu)
The type of **_id is int.
The type of siblings is cpumask_t.
To be consistent on all architectures, the 4 attributes should have
deafult values if their values are unavailable. Below is the rule.
1) physical_package_id: If cpu has no physical package id, -1 is the
default value.
2) core_id: If cpu doesn't support multi-core, its core id is 0.
3) thread_siblings: Just include itself, if the cpu doesn't support
HT/multi-thread.
4) core_siblings: Just include itself, if the cpu doesn't support
multi-core and HT/Multi-thread.
So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
If an attribute isn't defined on an architecture, it won't be exported.
Thank Nathan, Greg, Andi, Paul and Venki.
The patch provides defines for i386/x86_64/ia64.
Signed-off-by: Zhang, Yanmin <yanmin.zhang@intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 04:04:36 -07:00
|
|
|
subsys_initcall(topology_init);
|
2006-02-26 20:37:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Export cpu cache information through sysfs
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A bunch of string array to get pretty printing
|
|
|
|
*/
|
|
|
|
static const char *cache_types[] = {
|
|
|
|
"", /* not used */
|
|
|
|
"Instruction",
|
|
|
|
"Data",
|
|
|
|
"Unified" /* unified */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *cache_mattrib[]={
|
|
|
|
"WriteThrough",
|
|
|
|
"WriteBack",
|
|
|
|
"", /* reserved */
|
|
|
|
"" /* reserved */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cache_info {
|
|
|
|
pal_cache_config_info_t cci;
|
|
|
|
cpumask_t shared_cpu_map;
|
|
|
|
int level;
|
|
|
|
int type;
|
|
|
|
struct kobject kobj;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cpu_cache_info {
|
|
|
|
struct cache_info *cache_leaves;
|
|
|
|
int num_cache_leaves;
|
|
|
|
struct kobject kobj;
|
|
|
|
};
|
|
|
|
|
2007-10-02 14:39:45 -06:00
|
|
|
static struct cpu_cache_info all_cpu_cache_info[NR_CPUS] __cpuinitdata;
|
2006-02-26 20:37:45 -07:00
|
|
|
#define LEAF_KOBJECT_PTR(x,y) (&all_cpu_cache_info[x].cache_leaves[y])
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2007-10-02 14:39:45 -06:00
|
|
|
static void __cpuinit cache_shared_cpu_map_setup( unsigned int cpu,
|
2006-02-26 20:37:45 -07:00
|
|
|
struct cache_info * this_leaf)
|
|
|
|
{
|
|
|
|
pal_cache_shared_info_t csi;
|
|
|
|
int num_shared, i = 0;
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
if (cpu_data(cpu)->threads_per_core <= 1 &&
|
|
|
|
cpu_data(cpu)->cores_per_socket <= 1) {
|
|
|
|
cpu_set(cpu, this_leaf->shared_cpu_map);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ia64_pal_cache_shared_info(this_leaf->level,
|
|
|
|
this_leaf->type,
|
|
|
|
0,
|
|
|
|
&csi) != PAL_STATUS_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
num_shared = (int) csi.num_shared;
|
|
|
|
do {
|
2006-06-25 06:46:43 -06:00
|
|
|
for_each_possible_cpu(j)
|
2006-02-26 20:37:45 -07:00
|
|
|
if (cpu_data(cpu)->socket_id == cpu_data(j)->socket_id
|
|
|
|
&& cpu_data(j)->core_id == csi.log1_cid
|
|
|
|
&& cpu_data(j)->thread_id == csi.log1_tid)
|
|
|
|
cpu_set(j, this_leaf->shared_cpu_map);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} while (i < num_shared &&
|
|
|
|
ia64_pal_cache_shared_info(this_leaf->level,
|
|
|
|
this_leaf->type,
|
|
|
|
i,
|
|
|
|
&csi) == PAL_STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
#else
|
2007-10-02 14:39:45 -06:00
|
|
|
static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu,
|
2006-02-26 20:37:45 -07:00
|
|
|
struct cache_info * this_leaf)
|
|
|
|
{
|
|
|
|
cpu_set(cpu, this_leaf->shared_cpu_map);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static ssize_t show_coherency_line_size(struct cache_info *this_leaf,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", 1 << this_leaf->cci.pcci_line_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_ways_of_associativity(struct cache_info *this_leaf,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", this_leaf->cci.pcci_assoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_attributes(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf,
|
|
|
|
"%s\n",
|
|
|
|
cache_mattrib[this_leaf->cci.pcci_cache_attr]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_size(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%uK\n", this_leaf->cci.pcci_cache_size / 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_number_of_sets(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
unsigned number_of_sets = this_leaf->cci.pcci_cache_size;
|
|
|
|
number_of_sets /= this_leaf->cci.pcci_assoc;
|
|
|
|
number_of_sets /= 1 << this_leaf->cci.pcci_line_size;
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", number_of_sets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_shared_cpu_map(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
ssize_t len;
|
|
|
|
cpumask_t shared_cpu_map;
|
|
|
|
|
|
|
|
cpus_and(shared_cpu_map, this_leaf->shared_cpu_map, cpu_online_map);
|
2008-12-13 03:50:25 -07:00
|
|
|
len = cpumask_scnprintf(buf, NR_CPUS+1, &shared_cpu_map);
|
2006-02-26 20:37:45 -07:00
|
|
|
len += sprintf(buf+len, "\n");
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_type(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
int type = this_leaf->type + this_leaf->cci.pcci_unified;
|
|
|
|
return sprintf(buf, "%s\n", cache_types[type]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_level(struct cache_info *this_leaf, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", this_leaf->level);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cache_attr {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct cache_info *, char *);
|
|
|
|
ssize_t (*store)(struct cache_info *, const char *, size_t count);
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef define_one_ro
|
|
|
|
#undef define_one_ro
|
|
|
|
#endif
|
|
|
|
#define define_one_ro(_name) \
|
|
|
|
static struct cache_attr _name = \
|
|
|
|
__ATTR(_name, 0444, show_##_name, NULL)
|
|
|
|
|
|
|
|
define_one_ro(level);
|
|
|
|
define_one_ro(type);
|
|
|
|
define_one_ro(coherency_line_size);
|
|
|
|
define_one_ro(ways_of_associativity);
|
|
|
|
define_one_ro(size);
|
|
|
|
define_one_ro(number_of_sets);
|
|
|
|
define_one_ro(shared_cpu_map);
|
|
|
|
define_one_ro(attributes);
|
|
|
|
|
|
|
|
static struct attribute * cache_default_attrs[] = {
|
|
|
|
&type.attr,
|
|
|
|
&level.attr,
|
|
|
|
&coherency_line_size.attr,
|
|
|
|
&ways_of_associativity.attr,
|
|
|
|
&attributes.attr,
|
|
|
|
&size.attr,
|
|
|
|
&number_of_sets.attr,
|
|
|
|
&shared_cpu_map.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_object(k) container_of(k, struct cache_info, kobj)
|
|
|
|
#define to_attr(a) container_of(a, struct cache_attr, attr)
|
|
|
|
|
|
|
|
static ssize_t cache_show(struct kobject * kobj, struct attribute * attr, char * buf)
|
|
|
|
{
|
|
|
|
struct cache_attr *fattr = to_attr(attr);
|
|
|
|
struct cache_info *this_leaf = to_object(kobj);
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = fattr->show ? fattr->show(this_leaf, buf) : 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-18 18:58:23 -07:00
|
|
|
static const struct sysfs_ops cache_sysfs_ops = {
|
2006-02-26 20:37:45 -07:00
|
|
|
.show = cache_show
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type cache_ktype = {
|
|
|
|
.sysfs_ops = &cache_sysfs_ops,
|
|
|
|
.default_attrs = cache_default_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type cache_ktype_percpu_entry = {
|
|
|
|
.sysfs_ops = &cache_sysfs_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __cpuinit cpu_cache_sysfs_exit(unsigned int cpu)
|
|
|
|
{
|
2006-04-20 11:11:09 -06:00
|
|
|
kfree(all_cpu_cache_info[cpu].cache_leaves);
|
|
|
|
all_cpu_cache_info[cpu].cache_leaves = NULL;
|
2006-02-26 20:37:45 -07:00
|
|
|
all_cpu_cache_info[cpu].num_cache_leaves = 0;
|
|
|
|
memset(&all_cpu_cache_info[cpu].kobj, 0, sizeof(struct kobject));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __cpuinit cpu_cache_sysfs_init(unsigned int cpu)
|
|
|
|
{
|
2009-05-22 14:49:49 -06:00
|
|
|
unsigned long i, levels, unique_caches;
|
2006-02-26 20:37:45 -07:00
|
|
|
pal_cache_config_info_t cci;
|
|
|
|
int j;
|
2009-05-22 14:49:49 -06:00
|
|
|
long status;
|
2006-02-26 20:37:45 -07:00
|
|
|
struct cache_info *this_cache;
|
|
|
|
int num_cache_leaves = 0;
|
|
|
|
|
|
|
|
if ((status = ia64_pal_cache_summary(&levels, &unique_caches)) != 0) {
|
|
|
|
printk(KERN_ERR "ia64_pal_cache_summary=%ld\n", status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this_cache=kzalloc(sizeof(struct cache_info)*unique_caches,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (this_cache == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i=0; i < levels; i++) {
|
|
|
|
for (j=2; j >0 ; j--) {
|
|
|
|
if ((status=ia64_pal_cache_config_info(i,j, &cci)) !=
|
|
|
|
PAL_STATUS_SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
this_cache[num_cache_leaves].cci = cci;
|
|
|
|
this_cache[num_cache_leaves].level = i + 1;
|
|
|
|
this_cache[num_cache_leaves].type = j;
|
|
|
|
|
|
|
|
cache_shared_cpu_map_setup(cpu,
|
|
|
|
&this_cache[num_cache_leaves]);
|
|
|
|
num_cache_leaves ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
all_cpu_cache_info[cpu].cache_leaves = this_cache;
|
|
|
|
all_cpu_cache_info[cpu].num_cache_leaves = num_cache_leaves;
|
|
|
|
|
|
|
|
memset(&all_cpu_cache_info[cpu].kobj, 0, sizeof(struct kobject));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add cache interface for CPU device */
|
|
|
|
static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
|
|
|
|
{
|
|
|
|
unsigned int cpu = sys_dev->id;
|
|
|
|
unsigned long i, j;
|
|
|
|
struct cache_info *this_object;
|
|
|
|
int retval = 0;
|
|
|
|
cpumask_t oldmask;
|
|
|
|
|
|
|
|
if (all_cpu_cache_info[cpu].kobj.parent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
oldmask = current->cpus_allowed;
|
2010-03-26 16:02:23 -06:00
|
|
|
retval = set_cpus_allowed_ptr(current, cpumask_of(cpu));
|
2006-02-26 20:37:45 -07:00
|
|
|
if (unlikely(retval))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = cpu_cache_sysfs_init(cpu);
|
2010-03-26 16:02:23 -06:00
|
|
|
set_cpus_allowed_ptr(current, &oldmask);
|
2006-02-26 20:37:45 -07:00
|
|
|
if (unlikely(retval < 0))
|
|
|
|
return retval;
|
|
|
|
|
2007-12-17 12:54:39 -07:00
|
|
|
retval = kobject_init_and_add(&all_cpu_cache_info[cpu].kobj,
|
|
|
|
&cache_ktype_percpu_entry, &sys_dev->kobj,
|
|
|
|
"%s", "cache");
|
2009-08-11 15:52:11 -06:00
|
|
|
if (unlikely(retval < 0)) {
|
|
|
|
cpu_cache_sysfs_exit(cpu);
|
|
|
|
return retval;
|
|
|
|
}
|
2006-02-26 20:37:45 -07:00
|
|
|
|
|
|
|
for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) {
|
|
|
|
this_object = LEAF_KOBJECT_PTR(cpu,i);
|
2007-12-17 12:54:39 -07:00
|
|
|
retval = kobject_init_and_add(&(this_object->kobj),
|
|
|
|
&cache_ktype,
|
|
|
|
&all_cpu_cache_info[cpu].kobj,
|
|
|
|
"index%1lu", i);
|
2006-02-26 20:37:45 -07:00
|
|
|
if (unlikely(retval)) {
|
|
|
|
for (j = 0; j < i; j++) {
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&(LEAF_KOBJECT_PTR(cpu,j)->kobj));
|
2006-02-26 20:37:45 -07:00
|
|
|
}
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&all_cpu_cache_info[cpu].kobj);
|
2006-02-26 20:37:45 -07:00
|
|
|
cpu_cache_sysfs_exit(cpu);
|
2009-08-11 15:52:11 -06:00
|
|
|
return retval;
|
2006-02-26 20:37:45 -07:00
|
|
|
}
|
2007-12-17 12:54:39 -07:00
|
|
|
kobject_uevent(&(this_object->kobj), KOBJ_ADD);
|
2006-02-26 20:37:45 -07:00
|
|
|
}
|
2007-12-17 12:54:39 -07:00
|
|
|
kobject_uevent(&all_cpu_cache_info[cpu].kobj, KOBJ_ADD);
|
2006-02-26 20:37:45 -07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove cache interface for CPU device */
|
|
|
|
static int __cpuinit cache_remove_dev(struct sys_device * sys_dev)
|
|
|
|
{
|
|
|
|
unsigned int cpu = sys_dev->id;
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++)
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&(LEAF_KOBJECT_PTR(cpu,i)->kobj));
|
2006-02-26 20:37:45 -07:00
|
|
|
|
|
|
|
if (all_cpu_cache_info[cpu].kobj.parent) {
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&all_cpu_cache_info[cpu].kobj);
|
2006-02-26 20:37:45 -07:00
|
|
|
memset(&all_cpu_cache_info[cpu].kobj,
|
|
|
|
0,
|
|
|
|
sizeof(struct kobject));
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_cache_sysfs_exit(cpu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a cpu is hot-plugged, do a check and initiate
|
|
|
|
* cache kobject if necessary
|
|
|
|
*/
|
2006-06-27 03:54:07 -06:00
|
|
|
static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
|
2006-02-26 20:37:45 -07:00
|
|
|
unsigned long action, void *hcpu)
|
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned long)hcpu;
|
|
|
|
struct sys_device *sys_dev;
|
|
|
|
|
|
|
|
sys_dev = get_cpu_sysdev(cpu);
|
|
|
|
switch (action) {
|
|
|
|
case CPU_ONLINE:
|
2007-05-09 03:35:10 -06:00
|
|
|
case CPU_ONLINE_FROZEN:
|
2006-02-26 20:37:45 -07:00
|
|
|
cache_add_dev(sys_dev);
|
|
|
|
break;
|
|
|
|
case CPU_DEAD:
|
2007-05-09 03:35:10 -06:00
|
|
|
case CPU_DEAD_FROZEN:
|
2006-02-26 20:37:45 -07:00
|
|
|
cache_remove_dev(sys_dev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-27 03:54:09 -06:00
|
|
|
static struct notifier_block __cpuinitdata cache_cpu_notifier =
|
2006-02-26 20:37:45 -07:00
|
|
|
{
|
|
|
|
.notifier_call = cache_cpu_callback
|
|
|
|
};
|
|
|
|
|
2007-10-02 14:39:45 -06:00
|
|
|
static int __init cache_sysfs_init(void)
|
2006-02-26 20:37:45 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_online_cpu(i) {
|
2007-10-02 14:39:45 -06:00
|
|
|
struct sys_device *sys_dev = get_cpu_sysdev((unsigned int)i);
|
|
|
|
cache_add_dev(sys_dev);
|
2006-02-26 20:37:45 -07:00
|
|
|
}
|
|
|
|
|
2006-07-30 04:03:37 -06:00
|
|
|
register_hotcpu_notifier(&cache_cpu_notifier);
|
2006-02-26 20:37:45 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(cache_sysfs_init);
|
|
|
|
|