Lines Matching +full:slice +full:- +full:per +full:- +full:line
1 // SPDX-License-Identifier: GPL-2.0
3 * cacheinfo support - processor cache information via sysfs
23 /* pointer to per cpu cacheinfo */
26 #define cache_leaves(cpu) (ci_cacheinfo(cpu)->num_leaves)
27 #define per_cpu_cacheinfo(cpu) (ci_cacheinfo(cpu)->info_list)
44 * system-wide shared caches for all other levels. in cache_leaves_are_shared()
48 return (this_leaf->level != 1) && (sib_leaf->level != 1); in cache_leaves_are_shared()
50 if ((sib_leaf->attributes & CACHE_ID) && in cache_leaves_are_shared()
51 (this_leaf->attributes & CACHE_ID)) in cache_leaves_are_shared()
52 return sib_leaf->id == this_leaf->id; in cache_leaves_are_shared()
54 return sib_leaf->fw_token == this_leaf->fw_token; in cache_leaves_are_shared()
64 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in last_level_cache_is_valid()
66 return (llc->attributes & CACHE_ID) || !!llc->fw_token; in last_level_cache_is_valid()
78 llc_x = per_cpu_cacheinfo_idx(cpu_x, cache_leaves(cpu_x) - 1); in last_level_cache_is_shared()
79 llc_y = per_cpu_cacheinfo_idx(cpu_y, cache_leaves(cpu_y) - 1); in last_level_cache_is_shared()
97 .size_prop = "cache-size",
98 .line_size_props = { "cache-line-size",
99 "cache-block-size", },
100 .nr_sets_prop = "cache-sets",
102 .size_prop = "i-cache-size",
103 .line_size_props = { "i-cache-line-size",
104 "i-cache-block-size", },
105 .nr_sets_prop = "i-cache-sets",
107 .size_prop = "d-cache-size",
108 .line_size_props = { "d-cache-line-size",
109 "d-cache-block-size", },
110 .nr_sets_prop = "d-cache-sets",
126 ct_idx = get_cacheinfo_idx(this_leaf->type); in cache_size()
129 of_property_read_u32(np, propname, &this_leaf->size); in cache_size()
138 ct_idx = get_cacheinfo_idx(this_leaf->type); in cache_get_line_size()
149 this_leaf->coherency_line_size = line_size; in cache_get_line_size()
160 ct_idx = get_cacheinfo_idx(this_leaf->type); in cache_nr_sets()
163 of_property_read_u32(np, propname, &this_leaf->number_of_sets); in cache_nr_sets()
168 unsigned int line_size = this_leaf->coherency_line_size; in cache_associativity()
169 unsigned int nr_sets = this_leaf->number_of_sets; in cache_associativity()
170 unsigned int size = this_leaf->size; in cache_associativity()
177 this_leaf->ways_of_associativity = (size / nr_sets) / line_size; in cache_associativity()
183 return of_property_read_bool(np, "cache-unified"); in cache_node_is_unified()
194 if (this_leaf->type == CACHE_TYPE_NOCACHE && in cache_of_set_props()
196 this_leaf->type = CACHE_TYPE_UNIFIED; in cache_of_set_props()
211 return -ENOENT; in cache_setup_of_node()
215 return -ENOENT; in cache_setup_of_node()
220 if (this_leaf->level != 1) { in cache_setup_of_node()
227 this_leaf->fw_token = np; in cache_setup_of_node()
232 return -ENOENT; in cache_setup_of_node()
239 if (of_property_present(np, "cache-size") || in of_check_cache_nodes()
240 of_property_present(np, "i-cache-size") || in of_check_cache_nodes()
241 of_property_present(np, "d-cache-size") || in of_check_cache_nodes()
242 of_property_present(np, "cache-unified")) in of_check_cache_nodes()
257 if (of_property_present(np, "cache-size")) in of_count_cache_leaves()
259 if (of_property_present(np, "i-cache-size")) in of_count_cache_leaves()
261 if (of_property_present(np, "d-cache-size")) in of_count_cache_leaves()
265 /* The '[i-|d-|]cache-size' property is required, but in of_count_cache_leaves()
266 * if absent, fallback on the 'cache-unified' property. in of_count_cache_leaves()
268 if (of_property_read_bool(np, "cache-unified")) in of_count_cache_leaves()
284 return -ENOENT; in init_of_cache_level()
298 return -EINVAL; in init_of_cache_level()
299 if (of_property_read_u32(np, "cache-level", &level)) in init_of_cache_level()
300 return -EINVAL; in init_of_cache_level()
302 return -EINVAL; in init_of_cache_level()
308 this_cpu_ci->num_levels = levels; in init_of_cache_level()
309 this_cpu_ci->num_leaves = leaves; in init_of_cache_level()
321 return -ENOTSUPP; in cache_setup_acpi()
349 if (this_cpu_ci->cpu_map_populated) in cache_shared_cpu_map_setup()
368 cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
380 if (sib_leaf->level != this_leaf->level || in cache_shared_cpu_map_setup()
381 sib_leaf->type != this_leaf->type) in cache_shared_cpu_map_setup()
385 cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
386 cpumask_set_cpu(i, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
391 /* record the maximum cache line size */ in cache_shared_cpu_map_setup()
392 if (this_leaf->coherency_line_size > coherency_max_size) in cache_shared_cpu_map_setup()
393 coherency_max_size = this_leaf->coherency_line_size; in cache_shared_cpu_map_setup()
397 this_cpu_ci->cpu_map_populated = true; in cache_shared_cpu_map_setup()
409 for_each_cpu(sibling, &this_leaf->shared_cpu_map) { in cache_shared_cpu_map_remove()
421 if (sib_leaf->level != this_leaf->level || in cache_shared_cpu_map_remove()
422 sib_leaf->type != this_leaf->type) in cache_shared_cpu_map_remove()
426 cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_remove()
427 cpumask_clear_cpu(sibling, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_remove()
435 this_cpu_ci->cpu_map_populated = false; in cache_shared_cpu_map_remove()
448 return -ENOENT; in early_cache_level()
453 return -ENOENT; in init_cache_level()
458 return -ENOENT; in populate_cache_leaves()
466 return -ENOMEM; in allocate_cache_info()
483 this_cpu_ci->num_levels = levels; in fetch_cache_info()
486 * - there cannot be any split caches (data/instruction) in fetch_cache_info()
488 * - data/instruction caches come by pair in fetch_cache_info()
490 this_cpu_ci->num_leaves = levels + split_levels; in fetch_cache_info()
500 return -ENOENT; in fetch_cache_info()
502 this_cpu_ci->early_ci_levels = true; in fetch_cache_info()
517 * allocated early through the arch-specific early_cache_level() call, in init_level_allocate_ci()
519 * that case, call init_cache_level() anyway to give the arch-specific in init_level_allocate_ci()
522 if (per_cpu_cacheinfo(cpu) && !ci_cacheinfo(cpu)->early_ci_levels) in init_level_allocate_ci()
526 return -ENOENT; in init_level_allocate_ci()
533 ci_cacheinfo(cpu)->early_ci_levels = false; in init_level_allocate_ci()
602 return sysfs_emit(buf, "%u\n", this_leaf->object); \
617 return sysfs_emit(buf, "%uK\n", this_leaf->size >> 10); in size_show()
624 const struct cpumask *mask = &this_leaf->shared_cpu_map; in shared_cpu_map_show()
633 const struct cpumask *mask = &this_leaf->shared_cpu_map; in shared_cpu_list_show()
644 switch (this_leaf->type) { in type_show()
655 return -EINVAL; in type_show()
665 unsigned int ci_attr = this_leaf->attributes; in allocation_policy_show()
684 unsigned int ci_attr = this_leaf->attributes; in write_policy_show()
729 const struct cpumask *mask = &this_leaf->shared_cpu_map; in cache_default_attrs_is_visible()
730 umode_t mode = attr->mode; in cache_default_attrs_is_visible()
732 if ((attr == &dev_attr_id.attr) && (this_leaf->attributes & CACHE_ID)) in cache_default_attrs_is_visible()
734 if ((attr == &dev_attr_type.attr) && this_leaf->type) in cache_default_attrs_is_visible()
736 if ((attr == &dev_attr_level.attr) && this_leaf->level) in cache_default_attrs_is_visible()
743 this_leaf->coherency_line_size) in cache_default_attrs_is_visible()
746 this_leaf->size) /* allow 0 = full associativity */ in cache_default_attrs_is_visible()
749 this_leaf->number_of_sets) in cache_default_attrs_is_visible()
751 if ((attr == &dev_attr_size.attr) && this_leaf->size) in cache_default_attrs_is_visible()
754 (this_leaf->attributes & CACHE_WRITE_POLICY_MASK)) in cache_default_attrs_is_visible()
757 (this_leaf->attributes & CACHE_ALLOCATE_POLICY_MASK)) in cache_default_attrs_is_visible()
760 this_leaf->physical_line_partition) in cache_default_attrs_is_visible()
828 return -ENOENT; in cpu_cache_sysfs_init()
844 return -ENOMEM; in cpu_cache_sysfs_init()
862 if (this_leaf->disable_sysfs) in cache_add_dev()
864 if (this_leaf->type == CACHE_TYPE_NOCACHE) in cache_add_dev()
892 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in cpu_map_shared_cache()
894 if (llc->type != CACHE_TYPE_DATA && llc->type != CACHE_TYPE_UNIFIED) in cpu_map_shared_cache()
898 *map = &llc->shared_cpu_map; in cpu_map_shared_cache()
903 for_each_cpu(sibling, &llc->shared_cpu_map) { in cpu_map_shared_cache()
906 sib_llc = per_cpu_cacheinfo_idx(sibling, cache_leaves(sibling) - 1); in cpu_map_shared_cache()
907 *map = &sib_llc->shared_cpu_map; in cpu_map_shared_cache()
915 * Calculate the size of the per-CPU data cache slice. This can be
916 * used to estimate the size of the data cache slice that can be used
921 * Because the cache inclusive/non-inclusive information isn't
922 * available, we just use the size of the per-CPU slice of LLC to make
935 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in update_per_cpu_data_slice_size_cpu()
937 if (llc->type != CACHE_TYPE_DATA && llc->type != CACHE_TYPE_UNIFIED) in update_per_cpu_data_slice_size_cpu()
940 nr_shared = cpumask_weight(&llc->shared_cpu_map); in update_per_cpu_data_slice_size_cpu()
942 ci->per_cpu_data_slice_size = llc->size / nr_shared; in update_per_cpu_data_slice_size_cpu()