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))
34 struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu) in get_cpu_cacheinfo() argument
36 return ci_cacheinfo(cpu); in get_cpu_cacheinfo()
57 bool last_level_cache_is_valid(unsigned int cpu) in last_level_cache_is_valid() argument
61 if (!cache_leaves(cpu)) in last_level_cache_is_valid()
64 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in last_level_cache_is_valid()
203 static int cache_setup_of_node(unsigned int cpu) in cache_setup_of_node() argument
209 np = of_cpu_device_node_get(cpu); in cache_setup_of_node()
211 pr_err("Failed to find cpu%d device node\n", cpu); in cache_setup_of_node()
222 while (index < cache_leaves(cpu)) { in cache_setup_of_node()
223 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_setup_of_node()
238 if (index != cache_leaves(cpu)) /* not all OF nodes populated */ in cache_setup_of_node()
287 int init_of_cache_level(unsigned int cpu) in init_of_cache_level() argument
289 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in init_of_cache_level()
290 struct device_node *np = of_cpu_device_node_get(cpu); in init_of_cache_level()
330 static inline int cache_setup_of_node(unsigned int cpu) { return 0; } in cache_setup_of_node() argument
331 int init_of_cache_level(unsigned int cpu) { return 0; } in init_of_cache_level() argument
334 int __weak cache_setup_acpi(unsigned int cpu) in cache_setup_acpi() argument
341 static int cache_setup_properties(unsigned int cpu) in cache_setup_properties() argument
346 ret = cache_setup_of_node(cpu); in cache_setup_properties()
348 ret = cache_setup_acpi(cpu); in cache_setup_properties()
357 static int cache_shared_cpu_map_setup(unsigned int cpu) in cache_shared_cpu_map_setup() argument
359 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in cache_shared_cpu_map_setup()
372 if (!last_level_cache_is_valid(cpu) && !use_arch_info) { in cache_shared_cpu_map_setup()
373 ret = cache_setup_properties(cpu); in cache_shared_cpu_map_setup()
378 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_setup()
381 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_setup()
383 cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
387 if (i == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_setup()
402 cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
418 static void cache_shared_cpu_map_remove(unsigned int cpu) in cache_shared_cpu_map_remove() argument
420 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in cache_shared_cpu_map_remove()
424 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_remove()
425 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_remove()
430 if (sibling == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_remove()
446 cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_remove()
458 static void free_cache_attributes(unsigned int cpu) in free_cache_attributes() argument
460 if (!per_cpu_cacheinfo(cpu)) in free_cache_attributes()
463 cache_shared_cpu_map_remove(cpu); in free_cache_attributes()
466 int __weak early_cache_level(unsigned int cpu) in early_cache_level() argument
471 int __weak init_cache_level(unsigned int cpu) in init_cache_level() argument
476 int __weak populate_cache_leaves(unsigned int cpu) in populate_cache_leaves() argument
482 int allocate_cache_info(int cpu) in allocate_cache_info() argument
484 per_cpu_cacheinfo(cpu) = kcalloc(cache_leaves(cpu), in allocate_cache_info()
486 if (!per_cpu_cacheinfo(cpu)) { in allocate_cache_info()
487 cache_leaves(cpu) = 0; in allocate_cache_info()
494 int fetch_cache_info(unsigned int cpu) in fetch_cache_info() argument
496 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in fetch_cache_info()
501 ret = init_of_cache_level(cpu); in fetch_cache_info()
503 ret = acpi_get_cache_info(cpu, &levels, &split_levels); in fetch_cache_info()
516 if (ret || !cache_leaves(cpu)) { in fetch_cache_info()
517 ret = early_cache_level(cpu); in fetch_cache_info()
521 if (!cache_leaves(cpu)) in fetch_cache_info()
527 return allocate_cache_info(cpu); in fetch_cache_info()
530 static inline int init_level_allocate_ci(unsigned int cpu) in init_level_allocate_ci() argument
532 unsigned int early_leaves = cache_leaves(cpu); in init_level_allocate_ci()
544 if (per_cpu_cacheinfo(cpu) && !ci_cacheinfo(cpu)->early_ci_levels) in init_level_allocate_ci()
547 if (init_cache_level(cpu) || !cache_leaves(cpu)) in init_level_allocate_ci()
555 ci_cacheinfo(cpu)->early_ci_levels = false; in init_level_allocate_ci()
557 if (cache_leaves(cpu) <= early_leaves) in init_level_allocate_ci()
560 kfree(per_cpu_cacheinfo(cpu)); in init_level_allocate_ci()
561 return allocate_cache_info(cpu); in init_level_allocate_ci()
564 int detect_cache_attributes(unsigned int cpu) in detect_cache_attributes() argument
568 ret = init_level_allocate_ci(cpu); in detect_cache_attributes()
576 if (!last_level_cache_is_valid(cpu)) { in detect_cache_attributes()
581 ret = populate_cache_leaves(cpu); in detect_cache_attributes()
591 ret = cache_shared_cpu_map_setup(cpu); in detect_cache_attributes()
593 pr_warn("Unable to detect cache hierarchy for CPU %d\n", cpu); in detect_cache_attributes()
600 free_cache_attributes(cpu); in detect_cache_attributes()
606 #define per_cpu_cache_dev(cpu) (per_cpu(ci_cache_dev, cpu)) argument
612 #define per_cpu_index_dev(cpu) (per_cpu(ci_index_dev, cpu)) argument
613 #define per_cache_index_dev(cpu, idx) ((per_cpu_index_dev(cpu))[idx]) argument
822 static void cpu_cache_sysfs_exit(unsigned int cpu) in cpu_cache_sysfs_exit() argument
827 if (per_cpu_index_dev(cpu)) { in cpu_cache_sysfs_exit()
828 for (i = 0; i < cache_leaves(cpu); i++) { in cpu_cache_sysfs_exit()
829 ci_dev = per_cache_index_dev(cpu, i); in cpu_cache_sysfs_exit()
834 kfree(per_cpu_index_dev(cpu)); in cpu_cache_sysfs_exit()
835 per_cpu_index_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
837 device_unregister(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_exit()
838 per_cpu_cache_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
841 static int cpu_cache_sysfs_init(unsigned int cpu) in cpu_cache_sysfs_init() argument
843 struct device *dev = get_cpu_device(cpu); in cpu_cache_sysfs_init()
845 if (per_cpu_cacheinfo(cpu) == NULL) in cpu_cache_sysfs_init()
848 per_cpu_cache_dev(cpu) = cpu_device_create(dev, NULL, NULL, "cache"); in cpu_cache_sysfs_init()
849 if (IS_ERR(per_cpu_cache_dev(cpu))) in cpu_cache_sysfs_init()
850 return PTR_ERR(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_init()
853 per_cpu_index_dev(cpu) = kcalloc(cache_leaves(cpu), in cpu_cache_sysfs_init()
855 if (unlikely(per_cpu_index_dev(cpu) == NULL)) in cpu_cache_sysfs_init()
861 cpu_cache_sysfs_exit(cpu); in cpu_cache_sysfs_init()
865 static int cache_add_dev(unsigned int cpu) in cache_add_dev() argument
873 rc = cpu_cache_sysfs_init(cpu); in cache_add_dev()
877 parent = per_cpu_cache_dev(cpu); in cache_add_dev()
878 for (i = 0; i < cache_leaves(cpu); i++) { in cache_add_dev()
879 this_leaf = per_cpu_cacheinfo_idx(cpu, i); in cache_add_dev()
891 per_cache_index_dev(cpu, i) = ci_dev; in cache_add_dev()
893 cpumask_set_cpu(cpu, &cache_dev_map); in cache_add_dev()
897 cpu_cache_sysfs_exit(cpu); in cache_add_dev()
901 static int cacheinfo_cpu_online(unsigned int cpu) in cacheinfo_cpu_online() argument
903 int rc = detect_cache_attributes(cpu); in cacheinfo_cpu_online()
907 rc = cache_add_dev(cpu); in cacheinfo_cpu_online()
909 free_cache_attributes(cpu); in cacheinfo_cpu_online()
913 static int cacheinfo_cpu_pre_down(unsigned int cpu) in cacheinfo_cpu_pre_down() argument
915 if (cpumask_test_and_clear_cpu(cpu, &cache_dev_map)) in cacheinfo_cpu_pre_down()
916 cpu_cache_sysfs_exit(cpu); in cacheinfo_cpu_pre_down()
918 free_cache_attributes(cpu); in cacheinfo_cpu_pre_down()