Commit c054efea authored by James Morse's avatar James Morse Committed by Zeng Heng
Browse files

x86/resctrl: Claim get_domain_from_cpu() for resctrl

maillist inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8T2RT

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/log/?h=mpam/snapshot/v6.7-rc2



---------------------------

get_domain_from_cpu() is a handy helper that both the arch code and
resctrl need to use. Rename it resctrl_get_domain_from_cpu() so it
gets moved out to /fs, and exported back to the arch code.

Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Signed-off-by: default avatarZeng Heng <zengheng4@huawei.com>
parent 8c19cd6d
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
@@ -357,28 +357,6 @@ cat_wrmsr(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
		wrmsrl(hw_res->msr_base + i, hw_dom->ctrl_val[i]);
}

struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r)
{
	struct rdt_domain *d;

	/*
	 * Walking r->domains, ensure it can't race with cpuhp.
	 * Because this is called via IPI by rdt_ctrl_update(), assertions
	 * about locks this thread holds will lead to false positives. Check
	 * someone is holding the CPUs lock.
	 */
	if (IS_ENABLED(CONFIG_LOCKDEP))
		lockdep_is_cpus_held();

	list_for_each_entry(d, &r->domains, list) {
		/* Find the domain that contains this CPU */
		if (cpumask_test_cpu(cpu, &d->cpu_mask))
			return d;
	}

	return NULL;
}

u32 resctrl_arch_get_num_closid(struct rdt_resource *r)
{
	return resctrl_to_arch_res(r)->num_closid;
@@ -392,7 +370,7 @@ void rdt_ctrl_update(void *arg)
	int cpu = smp_processor_id();
	struct rdt_domain *d;

	d = get_domain_from_cpu(cpu, r);
	d = resctrl_get_domain_from_cpu(cpu, r);
	if (d) {
		hw_res->msr_update(d, m, r);
		return;
+0 −1
Original line number Diff line number Diff line
@@ -476,7 +476,6 @@ int rdt_pseudo_lock_init(void);
void rdt_pseudo_lock_release(void);
int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp);
void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp);
struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r);
int closids_supported(void);
void closid_free(int closid);
int alloc_rmid(u32 closid);
+1 −1
Original line number Diff line number Diff line
@@ -679,7 +679,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
	idx = resctrl_arch_rmid_idx_encode(closid, rmid);
	pmbm_data = &dom_mbm->mbm_local[idx];

	dom_mba = get_domain_from_cpu(smp_processor_id(), r_mba);
	dom_mba = resctrl_get_domain_from_cpu(smp_processor_id(), r_mba);
	if (!dom_mba) {
		pr_warn_once("Failure to get domain for MBA update\n");
		return;
+1 −1
Original line number Diff line number Diff line
@@ -4166,7 +4166,7 @@ void resctrl_offline_cpu(unsigned int cpu)
	if (!l3->mon_capable)
		goto out_unlock;

	d = get_domain_from_cpu(cpu, l3);
	d = resctrl_get_domain_from_cpu(cpu, l3);
	if (d) {
		if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
			cancel_delayed_work(&d->mbm_over);
+28 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#ifndef _RESCTRL_H
#define _RESCTRL_H

#include <linux/cpu.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/pid.h>
@@ -271,6 +272,33 @@ static inline u32 resctrl_get_config_index(u32 closid,
	}
}

/*
 * Caller must be in a RCU read-side critical section, or hold the
 * cpuhp read lock to prevent the struct rdt_domain being freed.
 */
static inline struct rdt_domain *
resctrl_get_domain_from_cpu(int cpu, struct rdt_resource *r)
{
	struct rdt_domain *d;

	/*
	 * Walking r->domains, ensure it can't race with cpuhp.
	 * Because this is called via IPI by rdt_ctrl_update(), assertions
	 * about locks this thread holds will lead to false positives. Check
	 * someone is holding the CPUs lock.
	 */
	if (IS_ENABLED(CONFIG_LOCKDEP))
		lockdep_is_cpus_held();

	list_for_each_entry_rcu(d, &r->domains, list) {
		/* Find the domain that contains this CPU */
		if (cpumask_test_cpu(cpu, &d->cpu_mask))
			return d;
	}

	return NULL;
}

/*
 * Update the ctrl_val and apply this config right now.
 * Must be called on one of the domain's CPUs.