Lines Matching refs:cache

3  * Processor cache information made available to userspace via sysfs;
27 * - a "cache" kobject for the top-level directory
28 * - a list of "index" objects representing the cpu's local cache hierarchy
31 struct kobject *kobj; /* bare (not embedded) kobject for cache
36 /* "index" object: each cpu's cache directory has an index
37 * subdirectory corresponding to a cache object associated with the
43 struct cache *cache;
47 * cache type */
52 /* Allow for both [di]-cache-line-size and
53 * [di]-cache-block-size properties. According to the PowerPC
55 * differs from the cache block size (that which is operated
56 * on by cache instructions), so we look for -line-size first.
64 #define CACHE_TYPE_UNIFIED 0 /* cache-size, cache-block-size, etc. */
65 #define CACHE_TYPE_UNIFIED_D 1 /* d-cache-size, d-cache-block-size, etc */
71 /* Embedded systems that use cache-size, cache-block-size,
72 * etc. for the Unified (typically L2) cache. */
74 .size_prop = "cache-size",
75 .line_size_props = { "cache-line-size",
76 "cache-block-size", },
77 .nr_sets_prop = "cache-sets",
80 /* PowerPC Processor binding says the [di]-cache-*
82 * d-cache properties. */
84 .size_prop = "d-cache-size",
85 .line_size_props = { "d-cache-line-size",
86 "d-cache-block-size", },
87 .nr_sets_prop = "d-cache-sets",
91 .size_prop = "i-cache-size",
92 .line_size_props = { "i-cache-line-size",
93 "i-cache-block-size", },
94 .nr_sets_prop = "i-cache-sets",
98 .size_prop = "d-cache-size",
99 .line_size_props = { "d-cache-line-size",
100 "d-cache-block-size", },
101 .nr_sets_prop = "d-cache-sets",
105 /* Cache object: each instance of this corresponds to a distinct cache
109 * cache object. A cache object is released when its shared_cpu_map
112 * A cache object is on two lists: an unsorted global list
113 * (cache_list) of cache objects; and a singly-linked list
114 * representing the local cache hierarchy, which is ordered by level
117 struct cache {
118 struct device_node *ofnode; /* OF node for this cache, may be cpu */
119 struct cpumask shared_cpu_map; /* online CPUs using this cache */
120 int type; /* split cache disambiguation */
122 int group_id; /* id of the group of threads that share this cache */
123 struct list_head list; /* global list of cache objects */
124 struct cache *next_local; /* next cache of >= level */
139 static const char *cache_type_string(const struct cache *cache)
141 return cache_type_info[cache->type].name;
144 static void cache_init(struct cache *cache, int type, int level,
147 cache->type = type;
148 cache->level = level;
149 cache->ofnode = of_node_get(ofnode);
150 cache->group_id = group_id;
151 INIT_LIST_HEAD(&cache->list);
152 list_add(&cache->list, &cache_list);
155 static struct cache *new_cache(int type, int level,
158 struct cache *cache;
160 cache = kzalloc(sizeof(*cache), GFP_KERNEL);
161 if (cache)
162 cache_init(cache, type, level, ofnode, group_id);
164 return cache;
167 static void release_cache_debugcheck(struct cache *cache)
169 struct cache *iter;
172 WARN_ONCE(iter->next_local == cache,
173 "cache for %pOFP(%s) refers to cache for %pOFP(%s)\n",
176 cache->ofnode,
177 cache_type_string(cache));
180 static void release_cache(struct cache *cache)
182 if (!cache)
185 pr_debug("freeing L%d %s cache for %pOFP\n", cache->level,
186 cache_type_string(cache), cache->ofnode);
188 release_cache_debugcheck(cache);
189 list_del(&cache->list);
190 of_node_put(cache->ofnode);
191 kfree(cache);
194 static void cache_cpu_set(struct cache *cache, int cpu)
196 struct cache *next = cache;
208 static int cache_size(const struct cache *cache, unsigned int *ret)
213 propname = cache_type_info[cache->type].size_prop;
215 cache_size = of_get_property(cache->ofnode, propname, NULL);
223 static int cache_size_kb(const struct cache *cache, unsigned int *ret)
227 if (cache_size(cache, &size))
234 /* not cache_line_size() because that's a macro in include/linux/cache.h */
235 static int cache_get_line_size(const struct cache *cache, unsigned int *ret)
240 lim = ARRAY_SIZE(cache_type_info[cache->type].line_size_props);
245 propname = cache_type_info[cache->type].line_size_props[i];
246 line_size = of_get_property(cache->ofnode, propname, NULL);
258 static int cache_nr_sets(const struct cache *cache, unsigned int *ret)
263 propname = cache_type_info[cache->type].nr_sets_prop;
265 nr_sets = of_get_property(cache->ofnode, propname, NULL);
273 static int cache_associativity(const struct cache *cache, unsigned int *ret)
279 if (cache_nr_sets(cache, &nr_sets))
282 /* If the cache is fully associative, there is no need to
290 if (cache_get_line_size(cache, &line_size))
292 if (cache_size(cache, &size))
305 static struct cache *cache_find_first_sibling(struct cache *cache)
307 struct cache *iter;
309 if (cache->type == CACHE_TYPE_UNIFIED ||
310 cache->type == CACHE_TYPE_UNIFIED_D)
311 return cache;
314 if (iter->ofnode == cache->ofnode &&
315 iter->group_id == cache->group_id &&
316 iter->next_local == cache)
319 return cache;
322 /* return the first cache on a local list matching node and thread-group id */
323 static struct cache *cache_lookup_by_node_group(const struct device_node *node,
326 struct cache *cache = NULL;
327 struct cache *iter;
333 cache = cache_find_first_sibling(iter);
337 return cache;
342 return of_get_property(np, "cache-unified", NULL);
347 * use cache-size, etc. for the unified cache size, but open firmware systems
348 * use d-cache-size, etc. Check on initialization for which type we have, and
351 * in /sys/devices/system/cpu/cpu0/cache/index2/, and this code will need
361 static struct cache *cache_do_one_devnode_unified(struct device_node *node, int group_id,
369 static struct cache *cache_do_one_devnode_split(struct device_node *node, int group_id,
372 struct cache *dcache, *icache;
392 static struct cache *cache_do_one_devnode(struct device_node *node, int group_id, int level)
394 struct cache *cache;
397 cache = cache_do_one_devnode_unified(node, group_id, level);
399 cache = cache_do_one_devnode_split(node, group_id, level);
401 return cache;
404 static struct cache *cache_lookup_or_instantiate(struct device_node *node,
408 struct cache *cache;
410 cache = cache_lookup_by_node_group(node, group_id);
412 WARN_ONCE(cache && cache->level != level,
413 "cache level mismatch on lookup (got %d, expected %d)\n",
414 cache->level, level);
416 if (!cache)
417 cache = cache_do_one_devnode(node, group_id, level);
419 return cache;
422 static void link_cache_lists(struct cache *smaller, struct cache *bigger)
433 * The cache->next_local list sorts by level ascending:
438 "linking L%i cache %pOFP to L%i cache %pOFP; skipped a level?\n",
442 static void do_subsidiary_caches_debugcheck(struct cache *cache)
444 WARN_ONCE(cache->level != 1,
445 "instantiating cache chain from L%d %s cache for "
446 "%pOFP instead of an L1\n", cache->level,
447 cache_type_string(cache), cache->ofnode);
448 WARN_ONCE(!of_node_is_type(cache->ofnode, "cpu"),
449 "instantiating cache chain from node %pOFP of type '%s' "
450 "instead of a cpu node\n", cache->ofnode,
451 of_node_get_device_type(cache->ofnode));
456 * L@level-cache (information obtained via "ibm,thread-groups"
460 * In the absence of any thread-group information for L@level-cache,
477 static void do_subsidiary_caches(struct cache *cache, unsigned int cpu_id)
480 int level = cache->level;
482 do_subsidiary_caches_debugcheck(cache);
484 while ((subcache_node = of_find_next_cache_node(cache->ofnode))) {
485 struct cache *subcache;
495 link_cache_lists(cache, subcache);
496 cache = subcache;
500 static struct cache *cache_chain_instantiate(unsigned int cpu_id)
503 struct cache *cpu_cache = NULL;
506 pr_debug("creating cache object(s) for CPU %i\n", cpu_id);
539 kobj = kobject_create_and_add("cache", &dev->kobj);
565 pr_debug("freeing index directory for L%d %s cache\n",
566 index->cache->level, cache_type_string(index->cache));
580 static struct cache *index_kobj_to_cache(struct kobject *k)
586 return index->cache;
592 struct cache *cache;
594 cache = index_kobj_to_cache(k);
596 if (cache_size_kb(cache, &size_kb))
609 struct cache *cache;
611 cache = index_kobj_to_cache(k);
613 if (cache_get_line_size(cache, &line_size))
625 struct cache *cache;
627 cache = index_kobj_to_cache(k);
629 if (cache_nr_sets(cache, &nr_sets))
641 struct cache *cache;
643 cache = index_kobj_to_cache(k);
645 if (cache_associativity(cache, &associativity))
656 struct cache *cache;
658 cache = index_kobj_to_cache(k);
660 return sprintf(buf, "%s\n", cache_type_string(cache));
669 struct cache *cache;
672 cache = index->cache;
674 return sprintf(buf, "%d\n", cache->level);
684 struct cache *cache;
688 cache = index->cache;
690 mask = &cache->shared_cpu_map;
713 * minimum data required to uniquely identify a cache.
724 /* Attributes which should be created if the cache device node has the
747 struct cache *cache;
755 cache = dir->cache;
756 cache_type = cache_type_string(cache);
773 attr->attr.name, cache->ofnode,
779 attr->attr.name, cache->ofnode, cache_type);
785 static void cacheinfo_create_index_dir(struct cache *cache, int index,
795 index_dir->cache = cache;
811 struct cache *cache_list)
814 struct cache *cache;
821 cache = cache_list;
822 while (cache) {
823 cacheinfo_create_index_dir(cache, index, cache_dir);
825 cache = cache->next_local;
831 struct cache *cache;
833 cache = cache_chain_instantiate(cpu_id);
834 if (!cache)
837 cacheinfo_sysfs_populate(cpu_id, cache);
840 /* functions needed to remove cache entry for cpu offline or suspend/resume */
845 static struct cache *cache_lookup_by_cpu(unsigned int cpu_id)
848 struct cache *cache;
857 cache = cache_lookup_by_node_group(cpu_node, group_id);
860 return cache;
882 /* Remove cache dir from sysfs */
890 static void cache_cpu_clear(struct cache *cache, int cpu)
892 while (cache) {
893 struct cache *next = cache->next_local;
895 WARN_ONCE(!cpumask_test_cpu(cpu, &cache->shared_cpu_map),
897 cpu, cache->ofnode,
898 cache_type_string(cache));
900 cpumask_clear_cpu(cpu, &cache->shared_cpu_map);
902 /* Release the cache object if all the cpus using it
904 if (cpumask_empty(&cache->shared_cpu_map))
905 release_cache(cache);
907 cache = next;
914 struct cache *cache;
926 /* clear the CPU's bit in its cache chain, possibly freeing
927 * cache objects */
928 cache = cache_lookup_by_cpu(cpu_id);
929 if (cache)
930 cache_cpu_clear(cache, cpu_id);