Lines Matching refs:cpu
25 #define ci_cacheinfo(cpu) (&per_cpu(ci_cpu_cacheinfo, cpu)) argument
26 #define cache_leaves(cpu) (ci_cacheinfo(cpu)->num_leaves) argument
27 #define per_cpu_cacheinfo(cpu) (ci_cacheinfo(cpu)->info_list) argument
28 #define per_cpu_cacheinfo_idx(cpu, idx) \ argument
29 (per_cpu_cacheinfo(cpu) + (idx))
31 struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu) in get_cpu_cacheinfo() argument
33 return ci_cacheinfo(cpu); in get_cpu_cacheinfo()
54 bool last_level_cache_is_valid(unsigned int cpu) in last_level_cache_is_valid() argument
58 if (!cache_leaves(cpu)) in last_level_cache_is_valid()
61 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in last_level_cache_is_valid()
197 static int cache_setup_of_node(unsigned int cpu) in cache_setup_of_node() argument
203 np = of_cpu_device_node_get(cpu); in cache_setup_of_node()
205 pr_err("Failed to find cpu%d device node\n", cpu); in cache_setup_of_node()
211 while (index < cache_leaves(cpu)) { in cache_setup_of_node()
212 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_setup_of_node()
227 if (index != cache_leaves(cpu)) /* not all OF nodes populated */ in cache_setup_of_node()
257 int init_of_cache_level(unsigned int cpu) in init_of_cache_level() argument
259 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in init_of_cache_level()
260 struct device_node *np = of_cpu_device_node_get(cpu); in init_of_cache_level()
295 static inline int cache_setup_of_node(unsigned int cpu) { return 0; } in cache_setup_of_node() argument
296 int init_of_cache_level(unsigned int cpu) { return 0; } in init_of_cache_level() argument
299 int __weak cache_setup_acpi(unsigned int cpu) in cache_setup_acpi() argument
306 static int cache_setup_properties(unsigned int cpu) in cache_setup_properties() argument
311 ret = cache_setup_of_node(cpu); in cache_setup_properties()
313 ret = cache_setup_acpi(cpu); in cache_setup_properties()
318 static int cache_shared_cpu_map_setup(unsigned int cpu) in cache_shared_cpu_map_setup() argument
320 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in cache_shared_cpu_map_setup()
333 if (!last_level_cache_is_valid(cpu)) { in cache_shared_cpu_map_setup()
334 ret = cache_setup_properties(cpu); in cache_shared_cpu_map_setup()
339 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_setup()
342 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_setup()
344 cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
348 if (i == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_setup()
353 cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
367 static void cache_shared_cpu_map_remove(unsigned int cpu) in cache_shared_cpu_map_remove() argument
372 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_remove()
373 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_remove()
378 if (sibling == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_remove()
384 cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_remove()
393 static void free_cache_attributes(unsigned int cpu) in free_cache_attributes() argument
395 if (!per_cpu_cacheinfo(cpu)) in free_cache_attributes()
398 cache_shared_cpu_map_remove(cpu); in free_cache_attributes()
401 int __weak init_cache_level(unsigned int cpu) in init_cache_level() argument
406 int __weak populate_cache_leaves(unsigned int cpu) in populate_cache_leaves() argument
412 int allocate_cache_info(int cpu) in allocate_cache_info() argument
414 per_cpu_cacheinfo(cpu) = kcalloc(cache_leaves(cpu), in allocate_cache_info()
416 if (!per_cpu_cacheinfo(cpu)) { in allocate_cache_info()
417 cache_leaves(cpu) = 0; in allocate_cache_info()
424 int fetch_cache_info(unsigned int cpu) in fetch_cache_info() argument
431 ret = init_of_cache_level(cpu); in fetch_cache_info()
435 ret = acpi_get_cache_info(cpu, &levels, &split_levels); in fetch_cache_info()
439 this_cpu_ci = get_cpu_cacheinfo(cpu); in fetch_cache_info()
449 if (!cache_leaves(cpu)) in fetch_cache_info()
452 return allocate_cache_info(cpu); in fetch_cache_info()
455 int detect_cache_attributes(unsigned int cpu) in detect_cache_attributes() argument
465 if (per_cpu_cacheinfo(cpu)) in detect_cache_attributes()
468 if (init_cache_level(cpu) || !cache_leaves(cpu)) in detect_cache_attributes()
471 ret = allocate_cache_info(cpu); in detect_cache_attributes()
480 ret = populate_cache_leaves(cpu); in detect_cache_attributes()
489 ret = cache_shared_cpu_map_setup(cpu); in detect_cache_attributes()
491 pr_warn("Unable to detect cache hierarchy for CPU %d\n", cpu); in detect_cache_attributes()
498 free_cache_attributes(cpu); in detect_cache_attributes()
504 #define per_cpu_cache_dev(cpu) (per_cpu(ci_cache_dev, cpu)) argument
510 #define per_cpu_index_dev(cpu) (per_cpu(ci_index_dev, cpu)) argument
511 #define per_cache_index_dev(cpu, idx) ((per_cpu_index_dev(cpu))[idx]) argument
720 static void cpu_cache_sysfs_exit(unsigned int cpu) in cpu_cache_sysfs_exit() argument
725 if (per_cpu_index_dev(cpu)) { in cpu_cache_sysfs_exit()
726 for (i = 0; i < cache_leaves(cpu); i++) { in cpu_cache_sysfs_exit()
727 ci_dev = per_cache_index_dev(cpu, i); in cpu_cache_sysfs_exit()
732 kfree(per_cpu_index_dev(cpu)); in cpu_cache_sysfs_exit()
733 per_cpu_index_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
735 device_unregister(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_exit()
736 per_cpu_cache_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
739 static int cpu_cache_sysfs_init(unsigned int cpu) in cpu_cache_sysfs_init() argument
741 struct device *dev = get_cpu_device(cpu); in cpu_cache_sysfs_init()
743 if (per_cpu_cacheinfo(cpu) == NULL) in cpu_cache_sysfs_init()
746 per_cpu_cache_dev(cpu) = cpu_device_create(dev, NULL, NULL, "cache"); in cpu_cache_sysfs_init()
747 if (IS_ERR(per_cpu_cache_dev(cpu))) in cpu_cache_sysfs_init()
748 return PTR_ERR(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_init()
751 per_cpu_index_dev(cpu) = kcalloc(cache_leaves(cpu), in cpu_cache_sysfs_init()
753 if (unlikely(per_cpu_index_dev(cpu) == NULL)) in cpu_cache_sysfs_init()
759 cpu_cache_sysfs_exit(cpu); in cpu_cache_sysfs_init()
763 static int cache_add_dev(unsigned int cpu) in cache_add_dev() argument
771 rc = cpu_cache_sysfs_init(cpu); in cache_add_dev()
775 parent = per_cpu_cache_dev(cpu); in cache_add_dev()
776 for (i = 0; i < cache_leaves(cpu); i++) { in cache_add_dev()
777 this_leaf = per_cpu_cacheinfo_idx(cpu, i); in cache_add_dev()
789 per_cache_index_dev(cpu, i) = ci_dev; in cache_add_dev()
791 cpumask_set_cpu(cpu, &cache_dev_map); in cache_add_dev()
795 cpu_cache_sysfs_exit(cpu); in cache_add_dev()
799 static int cacheinfo_cpu_online(unsigned int cpu) in cacheinfo_cpu_online() argument
801 int rc = detect_cache_attributes(cpu); in cacheinfo_cpu_online()
805 rc = cache_add_dev(cpu); in cacheinfo_cpu_online()
807 free_cache_attributes(cpu); in cacheinfo_cpu_online()
811 static int cacheinfo_cpu_pre_down(unsigned int cpu) in cacheinfo_cpu_pre_down() argument
813 if (cpumask_test_and_clear_cpu(cpu, &cache_dev_map)) in cacheinfo_cpu_pre_down()
814 cpu_cache_sysfs_exit(cpu); in cacheinfo_cpu_pre_down()
816 free_cache_attributes(cpu); in cacheinfo_cpu_pre_down()