Skip to content

Commit f385f02

Browse files
aeglbp3tk0v
authored andcommitted
x86/resctrl: Replace open coded cacheinfo searches
pseudo_lock_region_init() and rdtgroup_cbm_to_size() open code a search for details of a particular cache level. Replace with get_cpu_cacheinfo_level(). Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 685cb16 commit f385f02

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
292292
*/
293293
static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
294294
{
295-
struct cpu_cacheinfo *ci;
295+
struct cacheinfo *ci;
296296
int ret;
297-
int i;
298297

299298
/* Pick the first cpu we find that is associated with the cache. */
300299
plr->cpu = cpumask_first(&plr->d->cpu_mask);
@@ -306,15 +305,11 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
306305
goto out_region;
307306
}
308307

309-
ci = get_cpu_cacheinfo(plr->cpu);
310-
311-
plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
312-
313-
for (i = 0; i < ci->num_leaves; i++) {
314-
if (ci->info_list[i].level == plr->s->res->cache_level) {
315-
plr->line_size = ci->info_list[i].coherency_line_size;
316-
return 0;
317-
}
308+
ci = get_cpu_cacheinfo_level(plr->cpu, plr->s->res->cache_level);
309+
if (ci) {
310+
plr->line_size = ci->coherency_line_size;
311+
plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
312+
return 0;
318313
}
319314

320315
ret = -1;

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,18 +1450,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
14501450
unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
14511451
struct rdt_domain *d, unsigned long cbm)
14521452
{
1453-
struct cpu_cacheinfo *ci;
14541453
unsigned int size = 0;
1455-
int num_b, i;
1454+
struct cacheinfo *ci;
1455+
int num_b;
14561456

14571457
num_b = bitmap_weight(&cbm, r->cache.cbm_len);
1458-
ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
1459-
for (i = 0; i < ci->num_leaves; i++) {
1460-
if (ci->info_list[i].level == r->cache_level) {
1461-
size = ci->info_list[i].size / r->cache.cbm_len * num_b;
1462-
break;
1463-
}
1464-
}
1458+
ci = get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->cache_level);
1459+
if (ci)
1460+
size = ci->size / r->cache.cbm_len * num_b;
14651461

14661462
return size;
14671463
}

0 commit comments

Comments
 (0)