Skip to content

Commit 709c436

Browse files
James Morsesuryasaimadhu
authored andcommitted
cacheinfo: Move resctrl's get_cache_id() to the cacheinfo header file
resctrl/core.c defines get_cache_id() for use in its cpu-hotplug callbacks. This gets the id attribute of the cache at the corresponding level of a CPU. Later rework means this private function needs to be shared. Move it to the header file. The name conflicts with a different definition in intel_cacheinfo.c, name it get_cpu_cacheinfo_id() to show its relation with get_cpu_cacheinfo(). Now this is visible on other architectures, check the id attribute has actually been set. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Babu Moger <babu.moger@amd.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lkml.kernel.org/r/20200708163929.2783-11-james.morse@arm.com
1 parent 316e7f9 commit 709c436

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,6 @@ static void rdt_get_cdp_l2_config(void)
350350
rdt_get_cdp_config(RDT_RESOURCE_L2, RDT_RESOURCE_L2CODE);
351351
}
352352

353-
static int get_cache_id(int cpu, int level)
354-
{
355-
struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
356-
int i;
357-
358-
for (i = 0; i < ci->num_leaves; i++) {
359-
if (ci->info_list[i].level == level)
360-
return ci->info_list[i].id;
361-
}
362-
363-
return -1;
364-
}
365-
366353
static void
367354
mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
368355
{
@@ -560,7 +547,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
560547
*/
561548
static void domain_add_cpu(int cpu, struct rdt_resource *r)
562549
{
563-
int id = get_cache_id(cpu, r->cache_level);
550+
int id = get_cpu_cacheinfo_id(cpu, r->cache_level);
564551
struct list_head *add_pos = NULL;
565552
struct rdt_domain *d;
566553

@@ -606,7 +593,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
606593

607594
static void domain_remove_cpu(int cpu, struct rdt_resource *r)
608595
{
609-
int id = get_cache_id(cpu, r->cache_level);
596+
int id = get_cpu_cacheinfo_id(cpu, r->cache_level);
610597
struct rdt_domain *d;
611598

612599
d = rdt_find_domain(r, id, NULL);

include/linux/cacheinfo.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _LINUX_CACHEINFO_H
44

55
#include <linux/bitops.h>
6+
#include <linux/cpu.h>
67
#include <linux/cpumask.h>
78
#include <linux/smp.h>
89

@@ -119,4 +120,24 @@ int acpi_find_last_cache_level(unsigned int cpu);
119120

120121
const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
121122

123+
/*
124+
* Get the id of the cache associated with @cpu at level @level.
125+
* cpuhp lock must be held.
126+
*/
127+
static inline int get_cpu_cacheinfo_id(int cpu, int level)
128+
{
129+
struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
130+
int i;
131+
132+
for (i = 0; i < ci->num_leaves; i++) {
133+
if (ci->info_list[i].level == level) {
134+
if (ci->info_list[i].attributes & CACHE_ID)
135+
return ci->info_list[i].id;
136+
return -1;
137+
}
138+
}
139+
140+
return -1;
141+
}
142+
122143
#endif /* _LINUX_CACHEINFO_H */

0 commit comments

Comments
 (0)