aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/cacheinfo.h
diff options
context:
space:
mode:
authorSudeep Holla <sudeep.holla@arm.com>2014-09-30 09:48:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-07 14:45:00 -0500
commit246246cbde5e840012f853e27630ebb59f409486 (patch)
treec88cd0c8b3bd87ead3e110b37afdb1fa0c8fad28 /include/linux/cacheinfo.h
parent3d52943b3a51497a777e6d7d840a38596a92cee9 (diff)
drivers: base: support cpu cache information interface to userspace via sysfs
This patch adds initial support for providing processor cache information to userspace through sysfs interface. This is based on already existing implementations(x86, ia64, s390 and powerpc) and hence the interface is intended to be fully compatible. The main purpose of this generic support is to avoid further code duplication to support new architectures and also to unify all the existing different implementations. This implementation maintains the hierarchy of cache objects which reflects the system's cache topology. Cache devices are instantiated as needed as CPUs come online. The cache information is replicated per-cpu even if they are shared. A per-cpu array of cache information maintained is used mainly for sysfs-related book keeping. It also implements the shared_cpu_map attribute, which is essential for enabling both kernel and user-space to discover the system's overall cache topology. This patch also add the missing ABI documentation for the cacheinfo sysfs interface already, which is well defined and widely used. Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> Reviewed-by: Stephen Boyd <sboyd@codeaurora.org> Tested-by: Stephen Boyd <sboyd@codeaurora.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: linux-api@vger.kernel.org Cc: linux390@de.ibm.com Cc: linux-arm-kernel@lists.infradead.org Cc: linux-ia64@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-s390@vger.kernel.org Cc: x86@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/cacheinfo.h')
-rw-r--r--include/linux/cacheinfo.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
new file mode 100644
index 000000000000..3daf5ed392c9
--- /dev/null
+++ b/include/linux/cacheinfo.h
@@ -0,0 +1,100 @@
1#ifndef _LINUX_CACHEINFO_H
2#define _LINUX_CACHEINFO_H
3
4#include <linux/bitops.h>
5#include <linux/cpumask.h>
6#include <linux/smp.h>
7
8struct device_node;
9struct attribute;
10
11enum cache_type {
12 CACHE_TYPE_NOCACHE = 0,
13 CACHE_TYPE_INST = BIT(0),
14 CACHE_TYPE_DATA = BIT(1),
15 CACHE_TYPE_SEPARATE = CACHE_TYPE_INST | CACHE_TYPE_DATA,
16 CACHE_TYPE_UNIFIED = BIT(2),
17};
18
19/**
20 * struct cacheinfo - represent a cache leaf node
21 * @type: type of the cache - data, inst or unified
22 * @level: represents the hierarcy in the multi-level cache
23 * @coherency_line_size: size of each cache line usually representing
24 * the minimum amount of data that gets transferred from memory
25 * @number_of_sets: total number of sets, a set is a collection of cache
26 * lines sharing the same index
27 * @ways_of_associativity: number of ways in which a particular memory
28 * block can be placed in the cache
29 * @physical_line_partition: number of physical cache lines sharing the
30 * same cachetag
31 * @size: Total size of the cache
32 * @shared_cpu_map: logical cpumask representing all the cpus sharing
33 * this cache node
34 * @attributes: bitfield representing various cache attributes
35 * @of_node: if devicetree is used, this represents either the cpu node in
36 * case there's no explicit cache node or the cache node itself in the
37 * device tree
38 * @disable_sysfs: indicates whether this node is visible to the user via
39 * sysfs or not
40 * @priv: pointer to any private data structure specific to particular
41 * cache design
42 *
43 * While @of_node, @disable_sysfs and @priv are used for internal book
44 * keeping, the remaining members form the core properties of the cache
45 */
46struct cacheinfo {
47 enum cache_type type;
48 unsigned int level;
49 unsigned int coherency_line_size;
50 unsigned int number_of_sets;
51 unsigned int ways_of_associativity;
52 unsigned int physical_line_partition;
53 unsigned int size;
54 cpumask_t shared_cpu_map;
55 unsigned int attributes;
56#define CACHE_WRITE_THROUGH BIT(0)
57#define CACHE_WRITE_BACK BIT(1)
58#define CACHE_WRITE_POLICY_MASK \
59 (CACHE_WRITE_THROUGH | CACHE_WRITE_BACK)
60#define CACHE_READ_ALLOCATE BIT(2)
61#define CACHE_WRITE_ALLOCATE BIT(3)
62#define CACHE_ALLOCATE_POLICY_MASK \
63 (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE)
64
65 struct device_node *of_node;
66 bool disable_sysfs;
67 void *priv;
68};
69
70struct cpu_cacheinfo {
71 struct cacheinfo *info_list;
72 unsigned int num_levels;
73 unsigned int num_leaves;
74};
75
76/*
77 * Helpers to make sure "func" is executed on the cpu whose cache
78 * attributes are being detected
79 */
80#define DEFINE_SMP_CALL_CACHE_FUNCTION(func) \
81static inline void _##func(void *ret) \
82{ \
83 int cpu = smp_processor_id(); \
84 *(int *)ret = __##func(cpu); \
85} \
86 \
87int func(unsigned int cpu) \
88{ \
89 int ret; \
90 smp_call_function_single(cpu, _##func, &ret, true); \
91 return ret; \
92}
93
94struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu);
95int init_cache_level(unsigned int cpu);
96int populate_cache_leaves(unsigned int cpu);
97
98const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
99
100#endif /* _LINUX_CACHEINFO_H */