本文共 2270 字,大约阅读时间需要 7 分钟。
在driver/base/cacheinfo.c 中cache_shared_cpu_map_setup 函数会通过pptt table来parse bios 通过ACPI 表传给os的cache信息cache_shared_cpu_map_setup->cache_setup_acpi其源码在driver/acpi/pptt.c 中int cache_setup_acpi(unsigned int cpu){ struct acpi_table_header *table; acpi_status status; pr_debug("Cache Setup ACPI cpu %d\n", cpu);#得到pptt table status = acpi_get_table(ACPI_SIG_PPTT, 0, &table); if (ACPI_FAILURE(status)) { pr_warn_once("No PPTT table found, cache topology may be inaccurate\n"); return -ENOENT; }#开始parse Cache信息 cache_setup_acpi_cpu(table, cpu); acpi_put_table(table); return status;}static void cache_setup_acpi_cpu(struct acpi_table_header *table, unsigned int cpu){ struct acpi_pptt_cache *found_cache; struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); struct cacheinfo *this_leaf; unsigned int index = 0; struct acpi_pptt_processor *cpu_node = NULL; while (index < get_cpu_cacheinfo(cpu)->num_leaves) { this_leaf = this_cpu_ci->info_list + index; found_cache = acpi_find_cache_node(table, acpi_cpu_id, this_leaf->type, this_leaf->level, &cpu_node); pr_debug("found = %p %p\n", found_cache, cpu_node); if (found_cache) #找到cache node,则根据flag更新cache信息 update_cache_properties(this_leaf, found_cache, cpu_node); index++; }}static void update_cache_properties(struct cacheinfo *this_leaf, struct acpi_pptt_cache *found_cache, struct acpi_pptt_processor *cpu_node){ this_leaf->fw_token = cpu_node; #根据flag更新cache的size等信息 if (found_cache->flags & ACPI_PPTT_SIZE_PROPERTY_VALID) this_leaf->size = found_cache->size; if (found_cache->flags & ACPI_PPTT_LINE_SIZE_VALID) this_leaf->coherency_line_size = found_cache->line_size; if (found_cache->flags & ACPI_PPTT_NUMBER_OF_SETS_VALID) this_leaf->number_of_sets = found_cache->number_of_sets; if (found_cache->flags & ACPI_PPTT_ASSOCIATIVITY_VALID) this_leaf->ways_of_associativity = found_cache->associativity; if (found_cache->flags & ACPI_PPTT_WRITE_POLICY_VALID) { switch (found_cache->attributes & ACPI_PPTT_MASK_WRITE_POLICY) { case ACPI_PPTT_CACHE_POLICY_WT: this_leaf->attributes = CACHE_WRITE_THROUGH; break; case ACPI_PPTT_CACHE_POLICY_WB: this_leaf->attributes = CACHE_WRITE_BACK; break; } } }
转载地址:http://nvnmi.baihongyu.com/