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
208 struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu); in cache_setup_of_node()
210 pr_err("Failed to find cpu%d device node\n", cpu); in cache_setup_of_node()
218 while (index < cache_leaves(cpu)) { in cache_setup_of_node()
219 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_setup_of_node()
231 if (index != cache_leaves(cpu)) /* not all OF nodes populated */ in cache_setup_of_node()
277 int init_of_cache_level(unsigned int cpu) in init_of_cache_level() argument
279 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in init_of_cache_level()
280 struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu); in init_of_cache_level()
315 static inline int cache_setup_of_node(unsigned int cpu) { return 0; } in cache_setup_of_node() argument
316 int init_of_cache_level(unsigned int cpu) { return 0; } in init_of_cache_level() argument
319 int __weak cache_setup_acpi(unsigned int cpu) in cache_setup_acpi() argument
326 static int cache_setup_properties(unsigned int cpu) in cache_setup_properties() argument
331 ret = cache_setup_of_node(cpu); in cache_setup_properties()
333 ret = cache_setup_acpi(cpu); in cache_setup_properties()
342 static int cache_shared_cpu_map_setup(unsigned int cpu) in cache_shared_cpu_map_setup() argument
344 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in cache_shared_cpu_map_setup()
357 if (!last_level_cache_is_valid(cpu) && !use_arch_info) { in cache_shared_cpu_map_setup()
358 ret = cache_setup_properties(cpu); in cache_shared_cpu_map_setup()
363 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_setup()
366 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_setup()
368 cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
372 if (i == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_setup()
387 cpumask_set_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_setup()
403 static void cache_shared_cpu_map_remove(unsigned int cpu) in cache_shared_cpu_map_remove() argument
405 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in cache_shared_cpu_map_remove()
409 for (index = 0; index < cache_leaves(cpu); index++) { in cache_shared_cpu_map_remove()
410 this_leaf = per_cpu_cacheinfo_idx(cpu, index); in cache_shared_cpu_map_remove()
415 if (sibling == cpu || !sib_cpu_ci->info_list) in cache_shared_cpu_map_remove()
431 cpumask_clear_cpu(cpu, &sib_leaf->shared_cpu_map); in cache_shared_cpu_map_remove()
443 static void free_cache_attributes(unsigned int cpu) in free_cache_attributes() argument
445 if (!per_cpu_cacheinfo(cpu)) in free_cache_attributes()
448 cache_shared_cpu_map_remove(cpu); in free_cache_attributes()
451 int __weak early_cache_level(unsigned int cpu) in early_cache_level() argument
456 int __weak init_cache_level(unsigned int cpu) in init_cache_level() argument
461 int __weak populate_cache_leaves(unsigned int cpu) in populate_cache_leaves() argument
467 int allocate_cache_info(int cpu) in allocate_cache_info() argument
469 per_cpu_cacheinfo(cpu) = kcalloc(cache_leaves(cpu), in allocate_cache_info()
471 if (!per_cpu_cacheinfo(cpu)) { in allocate_cache_info()
472 cache_leaves(cpu) = 0; in allocate_cache_info()
479 int fetch_cache_info(unsigned int cpu) in fetch_cache_info() argument
481 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); in fetch_cache_info()
486 ret = init_of_cache_level(cpu); in fetch_cache_info()
488 ret = acpi_get_cache_info(cpu, &levels, &split_levels); in fetch_cache_info()
501 if (ret || !cache_leaves(cpu)) { in fetch_cache_info()
502 ret = early_cache_level(cpu); in fetch_cache_info()
506 if (!cache_leaves(cpu)) in fetch_cache_info()
512 return allocate_cache_info(cpu); in fetch_cache_info()
515 static inline int init_level_allocate_ci(unsigned int cpu) in init_level_allocate_ci() argument
517 unsigned int early_leaves = cache_leaves(cpu); in init_level_allocate_ci()
529 if (per_cpu_cacheinfo(cpu) && !ci_cacheinfo(cpu)->early_ci_levels) in init_level_allocate_ci()
532 if (init_cache_level(cpu) || !cache_leaves(cpu)) in init_level_allocate_ci()
540 ci_cacheinfo(cpu)->early_ci_levels = false; in init_level_allocate_ci()
542 if (cache_leaves(cpu) <= early_leaves) in init_level_allocate_ci()
545 kfree(per_cpu_cacheinfo(cpu)); in init_level_allocate_ci()
546 return allocate_cache_info(cpu); in init_level_allocate_ci()
549 int detect_cache_attributes(unsigned int cpu) in detect_cache_attributes() argument
553 ret = init_level_allocate_ci(cpu); in detect_cache_attributes()
561 if (!last_level_cache_is_valid(cpu)) { in detect_cache_attributes()
566 ret = populate_cache_leaves(cpu); in detect_cache_attributes()
576 ret = cache_shared_cpu_map_setup(cpu); in detect_cache_attributes()
578 pr_warn("Unable to detect cache hierarchy for CPU %d\n", cpu); in detect_cache_attributes()
585 free_cache_attributes(cpu); in detect_cache_attributes()
591 #define per_cpu_cache_dev(cpu) (per_cpu(ci_cache_dev, cpu)) argument
597 #define per_cpu_index_dev(cpu) (per_cpu(ci_index_dev, cpu)) argument
598 #define per_cache_index_dev(cpu, idx) ((per_cpu_index_dev(cpu))[idx]) argument
807 static void cpu_cache_sysfs_exit(unsigned int cpu) in cpu_cache_sysfs_exit() argument
812 if (per_cpu_index_dev(cpu)) { in cpu_cache_sysfs_exit()
813 for (i = 0; i < cache_leaves(cpu); i++) { in cpu_cache_sysfs_exit()
814 ci_dev = per_cache_index_dev(cpu, i); in cpu_cache_sysfs_exit()
819 kfree(per_cpu_index_dev(cpu)); in cpu_cache_sysfs_exit()
820 per_cpu_index_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
822 device_unregister(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_exit()
823 per_cpu_cache_dev(cpu) = NULL; in cpu_cache_sysfs_exit()
826 static int cpu_cache_sysfs_init(unsigned int cpu) in cpu_cache_sysfs_init() argument
828 struct device *dev = get_cpu_device(cpu); in cpu_cache_sysfs_init()
830 if (per_cpu_cacheinfo(cpu) == NULL) in cpu_cache_sysfs_init()
833 per_cpu_cache_dev(cpu) = cpu_device_create(dev, NULL, NULL, "cache"); in cpu_cache_sysfs_init()
834 if (IS_ERR(per_cpu_cache_dev(cpu))) in cpu_cache_sysfs_init()
835 return PTR_ERR(per_cpu_cache_dev(cpu)); in cpu_cache_sysfs_init()
838 per_cpu_index_dev(cpu) = kcalloc(cache_leaves(cpu), in cpu_cache_sysfs_init()
840 if (unlikely(per_cpu_index_dev(cpu) == NULL)) in cpu_cache_sysfs_init()
846 cpu_cache_sysfs_exit(cpu); in cpu_cache_sysfs_init()
850 static int cache_add_dev(unsigned int cpu) in cache_add_dev() argument
858 rc = cpu_cache_sysfs_init(cpu); in cache_add_dev()
862 parent = per_cpu_cache_dev(cpu); in cache_add_dev()
863 for (i = 0; i < cache_leaves(cpu); i++) { in cache_add_dev()
864 this_leaf = per_cpu_cacheinfo_idx(cpu, i); in cache_add_dev()
876 per_cache_index_dev(cpu, i) = ci_dev; in cache_add_dev()
878 cpumask_set_cpu(cpu, &cache_dev_map); in cache_add_dev()
882 cpu_cache_sysfs_exit(cpu); in cache_add_dev()
886 static unsigned int cpu_map_shared_cache(bool online, unsigned int cpu, in cpu_map_shared_cache() argument
892 if (!last_level_cache_is_valid(cpu)) in cpu_map_shared_cache()
895 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in cpu_map_shared_cache()
907 if (sibling == cpu || !last_level_cache_is_valid(sibling)) in cpu_map_shared_cache()
928 static void update_per_cpu_data_slice_size_cpu(unsigned int cpu) in update_per_cpu_data_slice_size_cpu() argument
934 if (!last_level_cache_is_valid(cpu)) in update_per_cpu_data_slice_size_cpu()
937 ci = ci_cacheinfo(cpu); in update_per_cpu_data_slice_size_cpu()
938 llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); in update_per_cpu_data_slice_size_cpu()
948 static void update_per_cpu_data_slice_size(bool cpu_online, unsigned int cpu, in update_per_cpu_data_slice_size() argument
954 if (!cpu_online && icpu == cpu) in update_per_cpu_data_slice_size()
961 static int cacheinfo_cpu_online(unsigned int cpu) in cacheinfo_cpu_online() argument
963 int rc = detect_cache_attributes(cpu); in cacheinfo_cpu_online()
968 rc = cache_add_dev(cpu); in cacheinfo_cpu_online()
971 if (cpu_map_shared_cache(true, cpu, &cpu_map)) in cacheinfo_cpu_online()
972 update_per_cpu_data_slice_size(true, cpu, cpu_map); in cacheinfo_cpu_online()
975 free_cache_attributes(cpu); in cacheinfo_cpu_online()
979 static int cacheinfo_cpu_pre_down(unsigned int cpu) in cacheinfo_cpu_pre_down() argument
984 nr_shared = cpu_map_shared_cache(false, cpu, &cpu_map); in cacheinfo_cpu_pre_down()
985 if (cpumask_test_and_clear_cpu(cpu, &cache_dev_map)) in cacheinfo_cpu_pre_down()
986 cpu_cache_sysfs_exit(cpu); in cacheinfo_cpu_pre_down()
988 free_cache_attributes(cpu); in cacheinfo_cpu_pre_down()
990 update_per_cpu_data_slice_size(false, cpu, cpu_map); in cacheinfo_cpu_pre_down()