Skip to content

Commit 8286618

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read()
resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a hardware register. Currently the function returns the MBM values in chunks directly from hardware. To convert this to bytes, some correction and overflow calculations are needed. These depend on the resource and domain structures. Overflow detection requires the old chunks value. None of this is available to resctrl_arch_rmid_read(). MPAM requires the resource and domain structures to find the MMIO device that holds the registers. Pass the resource and domain to resctrl_arch_rmid_read(). This makes rmid_dirty() too big. Instead merge it with its only caller, and the name is kept as a local variable. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jamie Iles <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Xin Hao <[email protected]> Tested-by: Shaopeng Tan <[email protected]> Tested-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4d044c5 commit 8286618

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,14 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
167167
memset(am, 0, sizeof(*am));
168168
}
169169

170-
int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
170+
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
171+
u32 rmid, enum resctrl_event_id eventid, u64 *val)
171172
{
172173
u64 msr_val;
173174

175+
if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
176+
return -EINVAL;
177+
174178
/*
175179
* As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
176180
* with a valid event code for supported resource type and the bits
@@ -192,16 +196,6 @@ int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
192196
return 0;
193197
}
194198

195-
static bool rmid_dirty(struct rmid_entry *entry)
196-
{
197-
u64 val = 0;
198-
199-
if (resctrl_arch_rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID, &val))
200-
return true;
201-
202-
return val >= resctrl_cqm_threshold;
203-
}
204-
205199
/*
206200
* Check the RMIDs that are marked as busy for this domain. If the
207201
* reported LLC occupancy is below the threshold clear the busy bit and
@@ -213,6 +207,8 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
213207
struct rmid_entry *entry;
214208
struct rdt_resource *r;
215209
u32 crmid = 1, nrmid;
210+
bool rmid_dirty;
211+
u64 val = 0;
216212

217213
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
218214

@@ -228,7 +224,14 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
228224
break;
229225

230226
entry = __rmid_entry(nrmid);
231-
if (force_free || !rmid_dirty(entry)) {
227+
228+
if (resctrl_arch_rmid_read(r, d, entry->rmid,
229+
QOS_L3_OCCUP_EVENT_ID, &val))
230+
rmid_dirty = true;
231+
else
232+
rmid_dirty = (val >= resctrl_cqm_threshold);
233+
234+
if (force_free || !rmid_dirty) {
232235
clear_bit(entry->rmid, d->rmid_busy_llc);
233236
if (!--entry->busy) {
234237
rmid_limbo_count--;
@@ -278,7 +281,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
278281
cpu = get_cpu();
279282
list_for_each_entry(d, &r->domains, list) {
280283
if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
281-
err = resctrl_arch_rmid_read(entry->rmid,
284+
err = resctrl_arch_rmid_read(r, d, entry->rmid,
282285
QOS_L3_OCCUP_EVENT_ID,
283286
&val);
284287
if (err || val <= resctrl_cqm_threshold)
@@ -336,7 +339,7 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr)
336339
if (rr->first)
337340
resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
338341

339-
rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
342+
rr->err = resctrl_arch_rmid_read(rr->r, rr->d, rmid, rr->evtid, &tval);
340343
if (rr->err)
341344
return rr->err;
342345

include/linux/resctrl.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,23 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
219219
u32 closid, enum resctrl_conf_type type);
220220
int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
221221
void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
222-
int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *res);
222+
223+
/**
224+
* resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
225+
* for this resource and domain.
226+
* @r: resource that the counter should be read from.
227+
* @d: domain that the counter should be read from.
228+
* @rmid: rmid of the counter to read.
229+
* @eventid: eventid to read, e.g. L3 occupancy.
230+
* @val: result of the counter read in chunks.
231+
*
232+
* Call from process context on a CPU that belongs to domain @d.
233+
*
234+
* Return:
235+
* 0 on success, or -EIO, -EINVAL etc on error.
236+
*/
237+
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
238+
u32 rmid, enum resctrl_event_id eventid, u64 *val);
223239

224240
/**
225241
* resctrl_arch_reset_rmid() - Reset any private state associated with rmid

0 commit comments

Comments
 (0)