Skip to content

Commit ae2328b

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Rename and change the units of resctrl_cqm_threshold
resctrl_cqm_threshold is stored in a hardware specific chunk size, but exposed to user-space as bytes. This means the filesystem parts of resctrl need to know how the hardware counts, to convert the user provided byte value to chunks. The interface between the architecture's resctrl code and the filesystem ought to treat everything as bytes. Change the unit of resctrl_cqm_threshold to bytes. resctrl_arch_rmid_read() still returns its value in chunks, so this needs converting to bytes. As all the users have been touched, rename the variable to resctrl_rmid_realloc_threshold, which describes what the value is for. Neither r->num_rmid nor hw_res->mon_scale are guaranteed to be a power of 2, so the existing code introduces a rounding error from resctrl's theoretical fraction of the cache usage. This behaviour is kept as it ensures the user visible value matches the value read from hardware when the rmid will be reallocated. 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 38f72f5 commit ae2328b

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

arch/x86/include/asm/resctrl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ static void __resctrl_sched_in(void)
8181
}
8282
}
8383

84+
static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
85+
{
86+
unsigned int scale = boot_cpu_data.x86_cache_occ_scale;
87+
88+
/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
89+
val /= scale;
90+
return val * scale;
91+
}
92+
8493
static inline void resctrl_sched_in(void)
8594
{
8695
if (static_branch_likely(&rdt_enable_key))

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ struct rmid_read {
9898
u64 val;
9999
};
100100

101-
extern unsigned int resctrl_cqm_threshold;
102101
extern bool rdt_alloc_capable;
103102
extern bool rdt_mon_capable;
104103
extern unsigned int rdt_mon_features;

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
#include <linux/module.h>
1919
#include <linux/slab.h>
20+
2021
#include <asm/cpu_device_id.h>
22+
#include <asm/resctrl.h>
23+
2124
#include "internal.h"
2225

2326
struct rmid_entry {
@@ -37,8 +40,8 @@ static LIST_HEAD(rmid_free_lru);
3740
* @rmid_limbo_count count of currently unused but (potentially)
3841
* dirty RMIDs.
3942
* This counts RMIDs that no one is currently using but that
40-
* may have a occupancy value > intel_cqm_threshold. User can change
41-
* the threshold occupancy value.
43+
* may have a occupancy value > resctrl_rmid_realloc_threshold. User can
44+
* change the threshold occupancy value.
4245
*/
4346
static unsigned int rmid_limbo_count;
4447

@@ -59,10 +62,10 @@ bool rdt_mon_capable;
5962
unsigned int rdt_mon_features;
6063

6164
/*
62-
* This is the threshold cache occupancy at which we will consider an
65+
* This is the threshold cache occupancy in bytes at which we will consider an
6366
* RMID available for re-allocation.
6467
*/
65-
unsigned int resctrl_cqm_threshold;
68+
unsigned int resctrl_rmid_realloc_threshold;
6669

6770
#define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5))
6871

@@ -223,14 +226,13 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
223226
*/
224227
void __check_limbo(struct rdt_domain *d, bool force_free)
225228
{
229+
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
230+
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
226231
struct rmid_entry *entry;
227-
struct rdt_resource *r;
228232
u32 crmid = 1, nrmid;
229233
bool rmid_dirty;
230234
u64 val = 0;
231235

232-
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
233-
234236
/*
235237
* Skip RMID 0 and start from RMID 1 and check all the RMIDs that
236238
* are marked as busy for occupancy < threshold. If the occupancy
@@ -245,10 +247,12 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
245247
entry = __rmid_entry(nrmid);
246248

247249
if (resctrl_arch_rmid_read(r, d, entry->rmid,
248-
QOS_L3_OCCUP_EVENT_ID, &val))
250+
QOS_L3_OCCUP_EVENT_ID, &val)) {
249251
rmid_dirty = true;
250-
else
251-
rmid_dirty = (val >= resctrl_cqm_threshold);
252+
} else {
253+
val *= hw_res->mon_scale;
254+
rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
255+
}
252256

253257
if (force_free || !rmid_dirty) {
254258
clear_bit(entry->rmid, d->rmid_busy_llc);
@@ -289,21 +293,21 @@ int alloc_rmid(void)
289293

290294
static void add_rmid_to_limbo(struct rmid_entry *entry)
291295
{
292-
struct rdt_resource *r;
296+
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
297+
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
293298
struct rdt_domain *d;
294299
int cpu, err;
295300
u64 val = 0;
296301

297-
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
298-
299302
entry->busy = 0;
300303
cpu = get_cpu();
301304
list_for_each_entry(d, &r->domains, list) {
302305
if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
303306
err = resctrl_arch_rmid_read(r, d, entry->rmid,
304307
QOS_L3_OCCUP_EVENT_ID,
305308
&val);
306-
if (err || val <= resctrl_cqm_threshold)
309+
val *= hw_res->mon_scale;
310+
if (err || val <= resctrl_rmid_realloc_threshold)
307311
continue;
308312
}
309313

@@ -744,6 +748,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
744748
unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
745749
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
746750
unsigned int cl_size = boot_cpu_data.x86_cache_size;
751+
unsigned int threshold;
747752
int ret;
748753

749754
hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
@@ -762,10 +767,14 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
762767
*
763768
* For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
764769
*/
765-
resctrl_cqm_threshold = cl_size * 1024 / r->num_rmid;
770+
threshold = cl_size * 1024 / r->num_rmid;
766771

767-
/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
768-
resctrl_cqm_threshold /= hw_res->mon_scale;
772+
/*
773+
* Because num_rmid may not be a power of two, round the value
774+
* to the nearest multiple of hw_res->mon_scale so it matches a
775+
* value the hardware will measure. mon_scale may not be a power of 2.
776+
*/
777+
resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
769778

770779
ret = dom_data_init(r);
771780
if (ret)

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,7 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
10301030
static int max_threshold_occ_show(struct kernfs_open_file *of,
10311031
struct seq_file *seq, void *v)
10321032
{
1033-
struct rdt_resource *r = of->kn->parent->priv;
1034-
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
1035-
1036-
seq_printf(seq, "%u\n", resctrl_cqm_threshold * hw_res->mon_scale);
1033+
seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
10371034

10381035
return 0;
10391036
}
@@ -1055,7 +1052,6 @@ static int rdt_thread_throttle_mode_show(struct kernfs_open_file *of,
10551052
static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
10561053
char *buf, size_t nbytes, loff_t off)
10571054
{
1058-
struct rdt_hw_resource *hw_res;
10591055
unsigned int bytes;
10601056
int ret;
10611057

@@ -1066,8 +1062,7 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
10661062
if (bytes > (boot_cpu_data.x86_cache_size * 1024))
10671063
return -EINVAL;
10681064

1069-
hw_res = resctrl_to_arch_res(of->kn->parent->priv);
1070-
resctrl_cqm_threshold = bytes / hw_res->mon_scale;
1065+
resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
10711066

10721067
return nbytes;
10731068
}

include/linux/resctrl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
250250
void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
251251
u32 rmid, enum resctrl_event_id eventid);
252252

253+
extern unsigned int resctrl_rmid_realloc_threshold;
254+
253255
#endif /* _RESCTRL_H */

0 commit comments

Comments
 (0)