2019-05-29 07:18:02 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-07-25 14:14:27 -07:00
|
|
|
/*
|
|
|
|
* Resource Director Technology(RDT)
|
|
|
|
* - Monitoring code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Vikas Shivappa <vikas.shivappa@intel.com>
|
|
|
|
*
|
|
|
|
* This replaces the cqm.c based on perf but we reuse a lot of
|
|
|
|
* code and datastructures originally from Peter Zijlstra and Matt Fleming.
|
|
|
|
*
|
|
|
|
* More information about RDT be found in the Intel (R) x86 Architecture
|
|
|
|
* Software Developer Manual June 2016, volume 3, section 17.17.
|
|
|
|
*/
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
#include <linux/cpu.h>
|
2017-07-25 14:14:27 -07:00
|
|
|
#include <linux/module.h>
|
2022-09-02 15:48:29 +00:00
|
|
|
#include <linux/sizes.h>
|
2017-07-25 14:14:27 -07:00
|
|
|
#include <linux/slab.h>
|
2022-09-02 15:48:27 +00:00
|
|
|
|
2017-07-25 14:14:27 -07:00
|
|
|
#include <asm/cpu_device_id.h>
|
2022-09-02 15:48:27 +00:00
|
|
|
#include <asm/resctrl.h>
|
|
|
|
|
2018-11-21 20:28:25 +00:00
|
|
|
#include "internal.h"
|
2024-04-08 17:23:03 +08:00
|
|
|
#include "trace.h"
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
/**
|
|
|
|
* struct rmid_entry - dirty tracking for all RMID.
|
|
|
|
* @closid: The CLOSID for this entry.
|
|
|
|
* @rmid: The RMID for this entry.
|
|
|
|
* @busy: The number of domains with cached data using this RMID.
|
|
|
|
* @list: Member of the rmid_free_lru list when busy == 0.
|
|
|
|
*
|
|
|
|
* Depending on the architecture the correct monitor is accessed using
|
|
|
|
* both @closid and @rmid, or @rmid only.
|
|
|
|
*
|
|
|
|
* Take the rdtgroup_mutex when accessing.
|
|
|
|
*/
|
2017-07-25 14:14:27 -07:00
|
|
|
struct rmid_entry {
|
2024-02-13 18:44:19 +00:00
|
|
|
u32 closid;
|
2017-07-25 14:14:27 -07:00
|
|
|
u32 rmid;
|
2017-08-15 18:00:43 -07:00
|
|
|
int busy;
|
2017-07-25 14:14:27 -07:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2023-10-06 16:51:32 -07:00
|
|
|
/*
|
|
|
|
* @rmid_free_lru - A least recently used list of free RMIDs
|
2017-07-25 14:14:27 -07:00
|
|
|
* These RMIDs are guaranteed to have an occupancy less than the
|
|
|
|
* threshold occupancy
|
|
|
|
*/
|
|
|
|
static LIST_HEAD(rmid_free_lru);
|
|
|
|
|
2024-02-13 18:44:22 +00:00
|
|
|
/*
|
|
|
|
* @closid_num_dirty_rmid The number of dirty RMID each CLOSID has.
|
|
|
|
* Only allocated when CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is defined.
|
|
|
|
* Indexed by CLOSID. Protected by rdtgroup_mutex.
|
|
|
|
*/
|
|
|
|
static u32 *closid_num_dirty_rmid;
|
|
|
|
|
2023-10-06 16:51:32 -07:00
|
|
|
/*
|
|
|
|
* @rmid_limbo_count - count of currently unused but (potentially)
|
2017-07-25 14:14:27 -07:00
|
|
|
* dirty RMIDs.
|
2017-08-15 18:00:43 -07:00
|
|
|
* This counts RMIDs that no one is currently using but that
|
2022-09-02 15:48:27 +00:00
|
|
|
* may have a occupancy value > resctrl_rmid_realloc_threshold. User can
|
|
|
|
* change the threshold occupancy value.
|
2017-07-25 14:14:27 -07:00
|
|
|
*/
|
2017-10-02 15:59:31 +01:00
|
|
|
static unsigned int rmid_limbo_count;
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2023-10-06 16:51:32 -07:00
|
|
|
/*
|
2017-07-25 14:14:27 -07:00
|
|
|
* @rmid_entry - The entry in the limbo and free lists.
|
|
|
|
*/
|
|
|
|
static struct rmid_entry *rmid_ptrs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global boolean for rdt_monitor which is true if any
|
|
|
|
* resource monitoring is enabled.
|
|
|
|
*/
|
|
|
|
bool rdt_mon_capable;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global to indicate which monitoring events are enabled.
|
|
|
|
*/
|
|
|
|
unsigned int rdt_mon_features;
|
|
|
|
|
|
|
|
/*
|
2022-09-02 15:48:27 +00:00
|
|
|
* This is the threshold cache occupancy in bytes at which we will consider an
|
2017-07-25 14:14:27 -07:00
|
|
|
* RMID available for re-allocation.
|
|
|
|
*/
|
2022-09-02 15:48:27 +00:00
|
|
|
unsigned int resctrl_rmid_realloc_threshold;
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2022-09-02 15:48:28 +00:00
|
|
|
/*
|
|
|
|
* This is the maximum value for the reallocation threshold, in bytes.
|
|
|
|
*/
|
|
|
|
unsigned int resctrl_rmid_realloc_limit;
|
|
|
|
|
2020-10-14 00:49:27 +00:00
|
|
|
#define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5))
|
|
|
|
|
|
|
|
/*
|
2023-03-14 17:06:44 -06:00
|
|
|
* The correction factor table is documented in Documentation/arch/x86/resctrl.rst.
|
2020-10-14 00:49:27 +00:00
|
|
|
* If rmid > rmid threshold, MBM total and local values should be multiplied
|
|
|
|
* by the correction factor.
|
|
|
|
*
|
|
|
|
* The original table is modified for better code:
|
|
|
|
*
|
|
|
|
* 1. The threshold 0 is changed to rmid count - 1 so don't do correction
|
|
|
|
* for the case.
|
|
|
|
* 2. MBM total and local correction table indexed by core counter which is
|
|
|
|
* equal to (x86_cache_max_rmid + 1) / 8 - 1 and is from 0 up to 27.
|
|
|
|
* 3. The correction factor is normalized to 2^20 (1048576) so it's faster
|
|
|
|
* to calculate corrected value by shifting:
|
|
|
|
* corrected_value = (original_value * correction_factor) >> 20
|
|
|
|
*/
|
|
|
|
static const struct mbm_correction_factor_table {
|
|
|
|
u32 rmidthreshold;
|
|
|
|
u64 cf;
|
2021-04-25 14:12:29 -07:00
|
|
|
} mbm_cf_table[] __initconst = {
|
2020-10-14 00:49:27 +00:00
|
|
|
{7, CF(1.000000)},
|
|
|
|
{15, CF(1.000000)},
|
|
|
|
{15, CF(0.969650)},
|
|
|
|
{31, CF(1.000000)},
|
|
|
|
{31, CF(1.066667)},
|
|
|
|
{31, CF(0.969650)},
|
|
|
|
{47, CF(1.142857)},
|
|
|
|
{63, CF(1.000000)},
|
|
|
|
{63, CF(1.185115)},
|
|
|
|
{63, CF(1.066553)},
|
|
|
|
{79, CF(1.454545)},
|
|
|
|
{95, CF(1.000000)},
|
|
|
|
{95, CF(1.230769)},
|
|
|
|
{95, CF(1.142857)},
|
|
|
|
{95, CF(1.066667)},
|
|
|
|
{127, CF(1.000000)},
|
|
|
|
{127, CF(1.254863)},
|
|
|
|
{127, CF(1.185255)},
|
|
|
|
{151, CF(1.000000)},
|
|
|
|
{127, CF(1.066667)},
|
|
|
|
{167, CF(1.000000)},
|
|
|
|
{159, CF(1.454334)},
|
|
|
|
{183, CF(1.000000)},
|
|
|
|
{127, CF(0.969744)},
|
|
|
|
{191, CF(1.280246)},
|
|
|
|
{191, CF(1.230921)},
|
|
|
|
{215, CF(1.000000)},
|
|
|
|
{191, CF(1.143118)},
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 mbm_cf_rmidthreshold __read_mostly = UINT_MAX;
|
|
|
|
static u64 mbm_cf __read_mostly;
|
|
|
|
|
|
|
|
static inline u64 get_corrected_mbm_count(u32 rmid, unsigned long val)
|
|
|
|
{
|
|
|
|
/* Correct MBM value. */
|
|
|
|
if (rmid > mbm_cf_rmidthreshold)
|
|
|
|
val = (val * mbm_cf) >> 20;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
/*
|
|
|
|
* x86 and arm64 differ in their handling of monitoring.
|
|
|
|
* x86's RMID are independent numbers, there is only one source of traffic
|
|
|
|
* with an RMID value of '1'.
|
|
|
|
* arm64's PMG extends the PARTID/CLOSID space, there are multiple sources of
|
|
|
|
* traffic with a PMG value of '1', one for each CLOSID, meaning the RMID
|
|
|
|
* value is no longer unique.
|
|
|
|
* To account for this, resctrl uses an index. On x86 this is just the RMID,
|
|
|
|
* on arm64 it encodes the CLOSID and RMID. This gives a unique number.
|
|
|
|
*
|
|
|
|
* The domain's rmid_busy_llc and rmid_ptrs[] are sized by index. The arch code
|
|
|
|
* must accept an attempt to read every index.
|
|
|
|
*/
|
|
|
|
static inline struct rmid_entry *__rmid_entry(u32 idx)
|
2017-07-25 14:14:27 -07:00
|
|
|
{
|
|
|
|
struct rmid_entry *entry;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 closid, rmid;
|
|
|
|
|
|
|
|
entry = &rmid_ptrs[idx];
|
|
|
|
resctrl_arch_rmid_idx_decode(idx, &closid, &rmid);
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
WARN_ON_ONCE(entry->closid != closid);
|
|
|
|
WARN_ON_ONCE(entry->rmid != rmid);
|
2017-07-25 14:14:27 -07:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2022-12-20 17:41:31 +01:00
|
|
|
static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
|
|
|
|
{
|
|
|
|
u64 msr_val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
|
|
|
|
* with a valid event code for supported resource type and the bits
|
|
|
|
* IA32_QM_EVTSEL.RMID (bits 41:32) are configured with valid RMID,
|
|
|
|
* IA32_QM_CTR.data (bits 61:0) reports the monitored data.
|
|
|
|
* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62)
|
|
|
|
* are error bits.
|
|
|
|
*/
|
|
|
|
wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
|
|
|
|
rdmsrl(MSR_IA32_QM_CTR, msr_val);
|
|
|
|
|
|
|
|
if (msr_val & RMID_VAL_ERROR)
|
|
|
|
return -EIO;
|
|
|
|
if (msr_val & RMID_VAL_UNAVAIL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*val = msr_val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:22 +00:00
|
|
|
static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,
|
|
|
|
u32 rmid,
|
|
|
|
enum resctrl_event_id eventid)
|
|
|
|
{
|
|
|
|
switch (eventid) {
|
|
|
|
case QOS_L3_OCCUP_EVENT_ID:
|
|
|
|
return NULL;
|
|
|
|
case QOS_L3_MBM_TOTAL_EVENT_ID:
|
|
|
|
return &hw_dom->arch_mbm_total[rmid];
|
|
|
|
case QOS_L3_MBM_LOCAL_EVENT_ID:
|
|
|
|
return &hw_dom->arch_mbm_local[rmid];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Never expect to get here */
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
|
2024-02-13 18:44:19 +00:00
|
|
|
u32 unused, u32 rmid,
|
|
|
|
enum resctrl_event_id eventid)
|
2022-09-02 15:48:22 +00:00
|
|
|
{
|
|
|
|
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
|
|
|
|
struct arch_mbm_state *am;
|
|
|
|
|
|
|
|
am = get_arch_mbm_state(hw_dom, rmid, eventid);
|
2022-12-20 17:41:31 +01:00
|
|
|
if (am) {
|
2022-09-02 15:48:22 +00:00
|
|
|
memset(am, 0, sizeof(*am));
|
2022-12-20 17:41:31 +01:00
|
|
|
|
|
|
|
/* Record any initial, non-zero count value. */
|
|
|
|
__rmid_read(rmid, eventid, &am->prev_msr);
|
|
|
|
}
|
2022-09-02 15:48:22 +00:00
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:37 -06:00
|
|
|
/*
|
|
|
|
* Assumes that hardware counters are also reset and thus that there is
|
|
|
|
* no need to record initial non-zero counts.
|
|
|
|
*/
|
|
|
|
void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d)
|
|
|
|
{
|
|
|
|
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
|
|
|
|
|
|
|
|
if (is_mbm_total_enabled())
|
|
|
|
memset(hw_dom->arch_mbm_total, 0,
|
|
|
|
sizeof(*hw_dom->arch_mbm_total) * r->num_rmid);
|
|
|
|
|
|
|
|
if (is_mbm_local_enabled())
|
|
|
|
memset(hw_dom->arch_mbm_local, 0,
|
|
|
|
sizeof(*hw_dom->arch_mbm_local) * r->num_rmid);
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:25 +00:00
|
|
|
static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
|
|
|
|
{
|
|
|
|
u64 shift = 64 - width, chunks;
|
|
|
|
|
|
|
|
chunks = (cur_msr << shift) - (prev_msr << shift);
|
|
|
|
return chunks >> shift;
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:24 +00:00
|
|
|
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
|
2024-02-13 18:44:19 +00:00
|
|
|
u32 unused, u32 rmid, enum resctrl_event_id eventid,
|
2024-02-13 18:44:29 +00:00
|
|
|
u64 *val, void *ignored)
|
2017-07-25 14:14:28 -07:00
|
|
|
{
|
2022-09-02 15:48:25 +00:00
|
|
|
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
|
|
|
|
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
|
|
|
|
struct arch_mbm_state *am;
|
2022-09-02 15:48:29 +00:00
|
|
|
u64 msr_val, chunks;
|
2022-12-20 17:41:31 +01:00
|
|
|
int ret;
|
2017-07-25 14:14:28 -07:00
|
|
|
|
x86/resctrl: Allow resctrl_arch_rmid_read() to sleep
MPAM's cache occupancy counters can take a little while to settle once the
monitor has been configured. The maximum settling time is described to the
driver via a firmware table. The value could be large enough that it makes
sense to sleep. To avoid exposing this to resctrl, it should be hidden behind
MPAM's resctrl_arch_rmid_read().
resctrl_arch_rmid_read() may be called via IPI meaning it is unable to sleep.
In this case, it should return an error if it needs to sleep. This will only
affect MPAM platforms where the cache occupancy counter isn't available
immediately, nohz_full is in use, and there are no housekeeping CPUs in the
necessary domain.
There are three callers of resctrl_arch_rmid_read(): __mon_event_count() and
__check_limbo() are both called from a non-migrateable context.
mon_event_read() invokes __mon_event_count() using smp_call_on_cpu(), which
adds work to the target CPUs workqueue. rdtgroup_mutex() is held, meaning this
cannot race with the resctrl cpuhp callback. __check_limbo() is invoked via
schedule_delayed_work_on() also adds work to a per-cpu workqueue.
The remaining call is add_rmid_to_limbo() which is called in response to
a user-space syscall that frees an RMID. This opportunistically reads the LLC
occupancy counter on the current domain to see if the RMID is over the dirty
threshold. This has to disable preemption to avoid reading the wrong domain's
value. Disabling preemption here prevents resctrl_arch_rmid_read() from
sleeping.
add_rmid_to_limbo() walks each domain, but only reads the counter on one
domain. If the system has more than one domain, the RMID will always be added
to the limbo list. If the RMIDs usage was not over the threshold, it will be
removed from the list when __check_limbo() runs. Make this the default
behaviour. Free RMIDs are always added to the limbo list for each domain.
The user visible effect of this is that a clean RMID is not available for
re-allocation immediately after 'rmdir()' completes. This behaviour was never
portable as it never happened on a machine with multiple domains.
Removing this path allows resctrl_arch_rmid_read() to sleep if its called with
interrupts unmasked. Document this is the expected behaviour, and add
a might_sleep() annotation to catch changes that won't work on arm64.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-15-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:28 +00:00
|
|
|
resctrl_arch_rmid_read_context_check();
|
|
|
|
|
2022-09-02 15:48:24 +00:00
|
|
|
if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2022-12-20 17:41:31 +01:00
|
|
|
ret = __rmid_read(rmid, eventid, &msr_val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2022-09-02 15:48:23 +00:00
|
|
|
|
2022-09-02 15:48:25 +00:00
|
|
|
am = get_arch_mbm_state(hw_dom, rmid, eventid);
|
|
|
|
if (am) {
|
2022-09-02 15:48:26 +00:00
|
|
|
am->chunks += mbm_overflow_count(am->prev_msr, msr_val,
|
|
|
|
hw_res->mbm_width);
|
2022-09-02 15:48:29 +00:00
|
|
|
chunks = get_corrected_mbm_count(rmid, am->chunks);
|
2022-09-02 15:48:25 +00:00
|
|
|
am->prev_msr = msr_val;
|
|
|
|
} else {
|
2022-09-02 15:48:29 +00:00
|
|
|
chunks = msr_val;
|
2022-09-02 15:48:25 +00:00
|
|
|
}
|
2022-09-02 15:48:23 +00:00
|
|
|
|
2022-09-02 15:48:29 +00:00
|
|
|
*val = chunks * hw_res->mon_scale;
|
|
|
|
|
2022-09-02 15:48:23 +00:00
|
|
|
return 0;
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:22 +00:00
|
|
|
static void limbo_release_entry(struct rmid_entry *entry)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
rmid_limbo_count--;
|
|
|
|
list_add_tail(&entry->list, &rmid_free_lru);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID))
|
|
|
|
closid_num_dirty_rmid[entry->closid]--;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:28 -07:00
|
|
|
/*
|
2017-08-15 18:00:43 -07:00
|
|
|
* Check the RMIDs that are marked as busy for this domain. If the
|
|
|
|
* reported LLC occupancy is below the threshold clear the busy bit and
|
|
|
|
* decrement the count. If the busy count gets to zero on an RMID, we
|
|
|
|
* free the RMID
|
2017-07-25 14:14:28 -07:00
|
|
|
*/
|
2017-08-15 18:00:43 -07:00
|
|
|
void __check_limbo(struct rdt_domain *d, bool force_free)
|
2017-07-25 14:14:28 -07:00
|
|
|
{
|
2022-09-02 15:48:27 +00:00
|
|
|
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
|
2017-08-15 18:00:43 -07:00
|
|
|
struct rmid_entry *entry;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx, cur_idx = 1;
|
2024-02-13 18:44:29 +00:00
|
|
|
void *arch_mon_ctx;
|
2022-09-02 15:48:24 +00:00
|
|
|
bool rmid_dirty;
|
|
|
|
u64 val = 0;
|
2017-07-25 14:14:28 -07:00
|
|
|
|
2024-02-13 18:44:29 +00:00
|
|
|
arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_L3_OCCUP_EVENT_ID);
|
|
|
|
if (IS_ERR(arch_mon_ctx)) {
|
|
|
|
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
|
|
|
|
PTR_ERR(arch_mon_ctx));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:28 -07:00
|
|
|
/*
|
2017-08-15 18:00:43 -07:00
|
|
|
* Skip RMID 0 and start from RMID 1 and check all the RMIDs that
|
|
|
|
* are marked as busy for occupancy < threshold. If the occupancy
|
|
|
|
* is less than the threshold decrement the busy counter of the
|
|
|
|
* RMID and move it to the free list when the counter reaches 0.
|
2017-07-25 14:14:28 -07:00
|
|
|
*/
|
2017-08-15 18:00:43 -07:00
|
|
|
for (;;) {
|
2024-02-13 18:44:20 +00:00
|
|
|
idx = find_next_bit(d->rmid_busy_llc, idx_limit, cur_idx);
|
|
|
|
if (idx >= idx_limit)
|
2017-08-15 18:00:43 -07:00
|
|
|
break;
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
entry = __rmid_entry(idx);
|
2024-02-13 18:44:19 +00:00
|
|
|
if (resctrl_arch_rmid_read(r, d, entry->closid, entry->rmid,
|
2024-02-13 18:44:29 +00:00
|
|
|
QOS_L3_OCCUP_EVENT_ID, &val,
|
|
|
|
arch_mon_ctx)) {
|
2022-09-02 15:48:24 +00:00
|
|
|
rmid_dirty = true;
|
2022-09-02 15:48:27 +00:00
|
|
|
} else {
|
|
|
|
rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
|
2024-04-08 17:23:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* x86's CLOSID and RMID are independent numbers, so the entry's
|
|
|
|
* CLOSID is an empty CLOSID (X86_RESCTRL_EMPTY_CLOSID). On Arm the
|
|
|
|
* RMID (PMG) extends the CLOSID (PARTID) space with bits that aren't
|
|
|
|
* used to select the configuration. It is thus necessary to track both
|
|
|
|
* CLOSID and RMID because there may be dependencies between them
|
|
|
|
* on some architectures.
|
|
|
|
*/
|
|
|
|
trace_mon_llc_occupancy_limbo(entry->closid, entry->rmid, d->id, val);
|
2022-09-02 15:48:27 +00:00
|
|
|
}
|
2022-09-02 15:48:24 +00:00
|
|
|
|
|
|
|
if (force_free || !rmid_dirty) {
|
2024-02-13 18:44:20 +00:00
|
|
|
clear_bit(idx, d->rmid_busy_llc);
|
2024-02-13 18:44:22 +00:00
|
|
|
if (!--entry->busy)
|
|
|
|
limbo_release_entry(entry);
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
2024-02-13 18:44:20 +00:00
|
|
|
cur_idx = idx + 1;
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
2024-02-13 18:44:29 +00:00
|
|
|
|
|
|
|
resctrl_arch_mon_ctx_free(r, QOS_L3_OCCUP_EVENT_ID, arch_mon_ctx);
|
2017-08-15 18:00:43 -07:00
|
|
|
}
|
2017-07-25 14:14:28 -07:00
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
bool has_busy_rmid(struct rdt_domain *d)
|
2017-08-15 18:00:43 -07:00
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
|
|
|
|
|
|
|
|
return find_first_bit(d->rmid_busy_llc, idx_limit) != idx_limit;
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:21 +00:00
|
|
|
static struct rmid_entry *resctrl_find_free_rmid(u32 closid)
|
|
|
|
{
|
|
|
|
struct rmid_entry *itr;
|
|
|
|
u32 itr_idx, cmp_idx;
|
|
|
|
|
|
|
|
if (list_empty(&rmid_free_lru))
|
|
|
|
return rmid_limbo_count ? ERR_PTR(-EBUSY) : ERR_PTR(-ENOSPC);
|
|
|
|
|
|
|
|
list_for_each_entry(itr, &rmid_free_lru, list) {
|
|
|
|
/*
|
|
|
|
* Get the index of this free RMID, and the index it would need
|
|
|
|
* to be if it were used with this CLOSID.
|
|
|
|
* If the CLOSID is irrelevant on this architecture, the two
|
|
|
|
* index values are always the same on every entry and thus the
|
|
|
|
* very first entry will be returned.
|
|
|
|
*/
|
|
|
|
itr_idx = resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid);
|
|
|
|
cmp_idx = resctrl_arch_rmid_idx_encode(closid, itr->rmid);
|
|
|
|
|
|
|
|
if (itr_idx == cmp_idx)
|
|
|
|
return itr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PTR(-ENOSPC);
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:24 +00:00
|
|
|
/**
|
|
|
|
* resctrl_find_cleanest_closid() - Find a CLOSID where all the associated
|
|
|
|
* RMID are clean, or the CLOSID that has
|
|
|
|
* the most clean RMID.
|
|
|
|
*
|
|
|
|
* MPAM's equivalent of RMID are per-CLOSID, meaning a freshly allocated CLOSID
|
|
|
|
* may not be able to allocate clean RMID. To avoid this the allocator will
|
|
|
|
* choose the CLOSID with the most clean RMID.
|
|
|
|
*
|
|
|
|
* When the CLOSID and RMID are independent numbers, the first free CLOSID will
|
|
|
|
* be returned.
|
|
|
|
*/
|
|
|
|
int resctrl_find_cleanest_closid(void)
|
|
|
|
{
|
|
|
|
u32 cleanest_closid = ~0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
for (i = 0; i < closids_supported(); i++) {
|
|
|
|
int num_dirty;
|
|
|
|
|
|
|
|
if (closid_allocated(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
num_dirty = closid_num_dirty_rmid[i];
|
|
|
|
if (num_dirty == 0)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
if (cleanest_closid == ~0)
|
|
|
|
cleanest_closid = i;
|
|
|
|
|
|
|
|
if (num_dirty < closid_num_dirty_rmid[cleanest_closid])
|
|
|
|
cleanest_closid = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cleanest_closid == ~0)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
return cleanest_closid;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:28 -07:00
|
|
|
/*
|
2024-02-13 18:44:21 +00:00
|
|
|
* For MPAM the RMID value is not unique, and has to be considered with
|
|
|
|
* the CLOSID. The (CLOSID, RMID) pair is allocated on all domains, which
|
|
|
|
* allows all domains to be managed by a single free list.
|
|
|
|
* Each domain also has a rmid_busy_llc to reduce the work of the limbo handler.
|
2017-07-25 14:14:28 -07:00
|
|
|
*/
|
2024-02-13 18:44:21 +00:00
|
|
|
int alloc_rmid(u32 closid)
|
2017-07-25 14:14:28 -07:00
|
|
|
{
|
|
|
|
struct rmid_entry *entry;
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:21 +00:00
|
|
|
entry = resctrl_find_free_rmid(closid);
|
|
|
|
if (IS_ERR(entry))
|
|
|
|
return PTR_ERR(entry);
|
2017-07-25 14:14:28 -07:00
|
|
|
|
|
|
|
list_del(&entry->list);
|
|
|
|
return entry->rmid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_rmid_to_limbo(struct rmid_entry *entry)
|
|
|
|
{
|
2022-09-02 15:48:27 +00:00
|
|
|
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
|
2017-07-25 14:14:28 -07:00
|
|
|
struct rdt_domain *d;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx;
|
|
|
|
|
2024-02-13 18:44:22 +00:00
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
/* Walking r->domains, ensure it can't race with cpuhp */
|
|
|
|
lockdep_assert_cpus_held();
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
idx = resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid);
|
2017-07-25 14:14:28 -07:00
|
|
|
|
2017-08-15 18:00:43 -07:00
|
|
|
entry->busy = 0;
|
2017-07-25 14:14:28 -07:00
|
|
|
list_for_each_entry(d, &r->domains, list) {
|
2017-08-15 18:00:43 -07:00
|
|
|
/*
|
|
|
|
* For the first limbo RMID in the domain,
|
|
|
|
* setup up the limbo worker.
|
|
|
|
*/
|
2024-02-13 18:44:20 +00:00
|
|
|
if (!has_busy_rmid(d))
|
2024-02-13 18:44:35 +00:00
|
|
|
cqm_setup_limbo_handler(d, CQM_LIMBOCHECK_INTERVAL,
|
|
|
|
RESCTRL_PICK_ANY_CPU);
|
2024-02-13 18:44:20 +00:00
|
|
|
set_bit(idx, d->rmid_busy_llc);
|
2017-08-15 18:00:43 -07:00
|
|
|
entry->busy++;
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
|
|
|
|
x86/resctrl: Allow resctrl_arch_rmid_read() to sleep
MPAM's cache occupancy counters can take a little while to settle once the
monitor has been configured. The maximum settling time is described to the
driver via a firmware table. The value could be large enough that it makes
sense to sleep. To avoid exposing this to resctrl, it should be hidden behind
MPAM's resctrl_arch_rmid_read().
resctrl_arch_rmid_read() may be called via IPI meaning it is unable to sleep.
In this case, it should return an error if it needs to sleep. This will only
affect MPAM platforms where the cache occupancy counter isn't available
immediately, nohz_full is in use, and there are no housekeeping CPUs in the
necessary domain.
There are three callers of resctrl_arch_rmid_read(): __mon_event_count() and
__check_limbo() are both called from a non-migrateable context.
mon_event_read() invokes __mon_event_count() using smp_call_on_cpu(), which
adds work to the target CPUs workqueue. rdtgroup_mutex() is held, meaning this
cannot race with the resctrl cpuhp callback. __check_limbo() is invoked via
schedule_delayed_work_on() also adds work to a per-cpu workqueue.
The remaining call is add_rmid_to_limbo() which is called in response to
a user-space syscall that frees an RMID. This opportunistically reads the LLC
occupancy counter on the current domain to see if the RMID is over the dirty
threshold. This has to disable preemption to avoid reading the wrong domain's
value. Disabling preemption here prevents resctrl_arch_rmid_read() from
sleeping.
add_rmid_to_limbo() walks each domain, but only reads the counter on one
domain. If the system has more than one domain, the RMID will always be added
to the limbo list. If the RMIDs usage was not over the threshold, it will be
removed from the list when __check_limbo() runs. Make this the default
behaviour. Free RMIDs are always added to the limbo list for each domain.
The user visible effect of this is that a clean RMID is not available for
re-allocation immediately after 'rmdir()' completes. This behaviour was never
portable as it never happened on a machine with multiple domains.
Removing this path allows resctrl_arch_rmid_read() to sleep if its called with
interrupts unmasked. Document this is the expected behaviour, and add
a might_sleep() annotation to catch changes that won't work on arm64.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-15-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:28 +00:00
|
|
|
rmid_limbo_count++;
|
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID))
|
|
|
|
closid_num_dirty_rmid[entry->closid]++;
|
2017-07-25 14:14:28 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
void free_rmid(u32 closid, u32 rmid)
|
2017-07-25 14:14:28 -07:00
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
|
2017-07-25 14:14:28 -07:00
|
|
|
struct rmid_entry *entry;
|
|
|
|
|
|
|
|
lockdep_assert_held(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
/*
|
|
|
|
* Do not allow the default rmid to be free'd. Comparing by index
|
|
|
|
* allows architectures that ignore the closid parameter to avoid an
|
|
|
|
* unnecessary check.
|
|
|
|
*/
|
|
|
|
if (idx == resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID,
|
|
|
|
RESCTRL_RESERVED_RMID))
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry = __rmid_entry(idx);
|
2017-07-25 14:14:28 -07:00
|
|
|
|
|
|
|
if (is_llc_occupancy_enabled())
|
|
|
|
add_rmid_to_limbo(entry);
|
|
|
|
else
|
|
|
|
list_add_tail(&entry->list, &rmid_free_lru);
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
static struct mbm_state *get_mbm_state(struct rdt_domain *d, u32 closid,
|
|
|
|
u32 rmid, enum resctrl_event_id evtid)
|
2022-12-20 17:41:32 +01:00
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
|
|
|
|
|
2022-12-20 17:41:32 +01:00
|
|
|
switch (evtid) {
|
|
|
|
case QOS_L3_MBM_TOTAL_EVENT_ID:
|
2024-02-13 18:44:20 +00:00
|
|
|
return &d->mbm_total[idx];
|
2022-12-20 17:41:32 +01:00
|
|
|
case QOS_L3_MBM_LOCAL_EVENT_ID:
|
2024-02-13 18:44:20 +00:00
|
|
|
return &d->mbm_local[idx];
|
2022-12-20 17:41:32 +01:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
|
2017-07-25 14:14:38 -07:00
|
|
|
{
|
2017-07-25 14:14:45 -07:00
|
|
|
struct mbm_state *m;
|
2022-09-02 15:48:25 +00:00
|
|
|
u64 tval = 0;
|
2017-07-25 14:14:38 -07:00
|
|
|
|
2022-12-20 17:41:32 +01:00
|
|
|
if (rr->first) {
|
2024-02-13 18:44:19 +00:00
|
|
|
resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
|
|
|
|
m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
|
2022-12-20 17:41:32 +01:00
|
|
|
if (m)
|
|
|
|
memset(m, 0, sizeof(struct mbm_state));
|
|
|
|
return 0;
|
|
|
|
}
|
2022-09-02 15:48:22 +00:00
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, rr->evtid,
|
2024-02-13 18:44:29 +00:00
|
|
|
&tval, rr->arch_mon_ctx);
|
2022-09-02 15:48:23 +00:00
|
|
|
if (rr->err)
|
|
|
|
return rr->err;
|
|
|
|
|
2022-09-02 15:48:26 +00:00
|
|
|
rr->val += tval;
|
2020-10-14 00:49:27 +00:00
|
|
|
|
2017-07-25 14:14:45 -07:00
|
|
|
return 0;
|
2017-07-25 14:14:38 -07:00
|
|
|
}
|
|
|
|
|
2018-04-20 15:36:20 -07:00
|
|
|
/*
|
2022-09-02 15:48:20 +00:00
|
|
|
* mbm_bw_count() - Update bw count from values previously read by
|
|
|
|
* __mon_event_count().
|
2024-02-13 18:44:19 +00:00
|
|
|
* @closid: The closid used to identify the cached mbm_state.
|
2022-09-02 15:48:20 +00:00
|
|
|
* @rmid: The rmid used to identify the cached mbm_state.
|
|
|
|
* @rr: The struct rmid_read populated by __mon_event_count().
|
|
|
|
*
|
2018-04-20 15:36:20 -07:00
|
|
|
* Supporting function to calculate the memory bandwidth
|
2022-09-02 15:48:20 +00:00
|
|
|
* and delta bandwidth in MBps. The chunks value previously read by
|
|
|
|
* __mon_event_count() is compared with the chunks value from the previous
|
|
|
|
* invocation. This must be called once per second to maintain values in MBps.
|
2018-04-20 15:36:20 -07:00
|
|
|
*/
|
2024-02-13 18:44:19 +00:00
|
|
|
static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
|
2018-04-20 15:36:20 -07:00
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
|
|
|
|
struct mbm_state *m = &rr->d->mbm_local[idx];
|
2022-09-02 15:48:29 +00:00
|
|
|
u64 cur_bw, bytes, cur_bytes;
|
2018-04-20 15:36:20 -07:00
|
|
|
|
2022-09-02 15:48:29 +00:00
|
|
|
cur_bytes = rr->val;
|
|
|
|
bytes = cur_bytes - m->prev_bw_bytes;
|
|
|
|
m->prev_bw_bytes = cur_bytes;
|
2018-04-20 15:36:20 -07:00
|
|
|
|
2022-09-02 15:48:29 +00:00
|
|
|
cur_bw = bytes / SZ_1M;
|
2018-04-20 15:36:20 -07:00
|
|
|
|
|
|
|
m->prev_bw = cur_bw;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:38 -07:00
|
|
|
/*
|
x86/resctrl: Queue mon_event_read() instead of sending an IPI
Intel is blessed with an abundance of monitors, one per RMID, that can be
read from any CPU in the domain. MPAMs monitors reside in the MMIO MSC,
the number implemented is up to the manufacturer. This means when there are
fewer monitors than needed, they need to be allocated and freed.
MPAM's CSU monitors are used to back the 'llc_occupancy' monitor file. The
CSU counter is allowed to return 'not ready' for a small number of
micro-seconds after programming. To allow one CSU hardware monitor to be
used for multiple control or monitor groups, the CPU accessing the
monitor needs to be able to block when configuring and reading the
counter.
Worse, the domain may be broken up into slices, and the MMIO accesses
for each slice may need performing from different CPUs.
These two details mean MPAMs monitor code needs to be able to sleep, and
IPI another CPU in the domain to read from a resource that has been sliced.
mon_event_read() already invokes mon_event_count() via IPI, which means
this isn't possible. On systems using nohz-full, some CPUs need to be
interrupted to run kernel work as they otherwise stay in user-space
running realtime workloads. Interrupting these CPUs should be avoided,
and scheduling work on them may never complete.
Change mon_event_read() to pick a housekeeping CPU, (one that is not using
nohz_full) and schedule mon_event_count() and wait. If all the CPUs
in a domain are using nohz-full, then an IPI is used as the fallback.
This function is only used in response to a user-space filesystem request
(not the timing sensitive overflow code).
This allows MPAM to hide the slice behaviour from resctrl, and to keep
the monitor-allocation in monitor.c. When the IPI fallback is used on
machines where MPAM needs to make an access on multiple CPUs, the counter
read will always fail.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-14-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:27 +00:00
|
|
|
* This is scheduled by mon_event_read() to read the CQM/MBM counters
|
2017-07-25 14:14:38 -07:00
|
|
|
* on a domain.
|
|
|
|
*/
|
|
|
|
void mon_event_count(void *info)
|
|
|
|
{
|
|
|
|
struct rdtgroup *rdtgrp, *entry;
|
|
|
|
struct rmid_read *rr = info;
|
|
|
|
struct list_head *head;
|
2022-09-02 15:48:23 +00:00
|
|
|
int ret;
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
rdtgrp = rr->rgrp;
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
ret = __mon_event_count(rdtgrp->closid, rdtgrp->mon.rmid, rr);
|
2017-07-25 14:14:38 -07:00
|
|
|
|
|
|
|
/*
|
2021-08-02 14:38:58 -05:00
|
|
|
* For Ctrl groups read data from child monitor groups and
|
|
|
|
* add them together. Count events which are read successfully.
|
|
|
|
* Discard the rmid_read's reporting errors.
|
2017-07-25 14:14:38 -07:00
|
|
|
*/
|
|
|
|
head = &rdtgrp->mon.crdtgrp_list;
|
|
|
|
|
|
|
|
if (rdtgrp->type == RDTCTRL_GROUP) {
|
|
|
|
list_for_each_entry(entry, head, mon.crdtgrp_list) {
|
2024-02-13 18:44:19 +00:00
|
|
|
if (__mon_event_count(entry->closid, entry->mon.rmid,
|
|
|
|
rr) == 0)
|
2022-09-02 15:48:23 +00:00
|
|
|
ret = 0;
|
2017-07-25 14:14:38 -07:00
|
|
|
}
|
|
|
|
}
|
2021-08-02 14:38:58 -05:00
|
|
|
|
2022-09-02 15:48:23 +00:00
|
|
|
/*
|
|
|
|
* __mon_event_count() calls for newly created monitor groups may
|
|
|
|
* report -EINVAL/Unavailable if the monitor hasn't seen any traffic.
|
|
|
|
* Discard error if any of the monitor event reads succeeded.
|
|
|
|
*/
|
|
|
|
if (ret == 0)
|
|
|
|
rr->err = 0;
|
2017-07-25 14:14:38 -07:00
|
|
|
}
|
2017-07-25 14:14:41 -07:00
|
|
|
|
2018-04-20 15:36:21 -07:00
|
|
|
/*
|
|
|
|
* Feedback loop for MBA software controller (mba_sc)
|
|
|
|
*
|
|
|
|
* mba_sc is a feedback loop where we periodically read MBM counters and
|
|
|
|
* adjust the bandwidth percentage values via the IA32_MBA_THRTL_MSRs so
|
|
|
|
* that:
|
|
|
|
*
|
2021-03-18 15:28:01 +01:00
|
|
|
* current bandwidth(cur_bw) < user specified bandwidth(user_bw)
|
2018-04-20 15:36:21 -07:00
|
|
|
*
|
|
|
|
* This uses the MBM counters to measure the bandwidth and MBA throttle
|
|
|
|
* MSRs to control the bandwidth for a particular rdtgrp. It builds on the
|
|
|
|
* fact that resctrl rdtgroups have both monitoring and control.
|
|
|
|
*
|
|
|
|
* The frequency of the checks is 1s and we just tag along the MBM overflow
|
|
|
|
* timer. Having 1s interval makes the calculation of bandwidth simpler.
|
|
|
|
*
|
|
|
|
* Although MBA's goal is to restrict the bandwidth to a maximum, there may
|
2021-03-21 22:28:53 +01:00
|
|
|
* be a need to increase the bandwidth to avoid unnecessarily restricting
|
2018-04-20 15:36:21 -07:00
|
|
|
* the L2 <-> L3 traffic.
|
|
|
|
*
|
|
|
|
* Since MBA controls the L2 external bandwidth where as MBM measures the
|
|
|
|
* L3 external bandwidth the following sequence could lead to such a
|
|
|
|
* situation.
|
|
|
|
*
|
|
|
|
* Consider an rdtgroup which had high L3 <-> memory traffic in initial
|
|
|
|
* phases -> mba_sc kicks in and reduced bandwidth percentage values -> but
|
|
|
|
* after some time rdtgroup has mostly L2 <-> L3 traffic.
|
|
|
|
*
|
|
|
|
* In this case we may restrict the rdtgroup's L2 <-> L3 traffic as its
|
|
|
|
* throttle MSRs already have low percentage values. To avoid
|
|
|
|
* unnecessarily restricting such rdtgroups, we also increase the bandwidth.
|
|
|
|
*/
|
|
|
|
static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
|
|
|
|
{
|
2022-09-02 15:48:19 +00:00
|
|
|
u32 closid, rmid, cur_msr_val, new_msr_val;
|
2018-04-20 15:36:21 -07:00
|
|
|
struct mbm_state *pmbm_data, *cmbm_data;
|
|
|
|
struct rdt_resource *r_mba;
|
|
|
|
struct rdt_domain *dom_mba;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 cur_bw, user_bw, idx;
|
2018-04-20 15:36:21 -07:00
|
|
|
struct list_head *head;
|
|
|
|
struct rdtgroup *entry;
|
|
|
|
|
2019-06-10 13:15:44 -04:00
|
|
|
if (!is_mbm_local_enabled())
|
|
|
|
return;
|
|
|
|
|
2022-09-02 15:48:19 +00:00
|
|
|
r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
|
|
|
|
|
2018-04-20 15:36:21 -07:00
|
|
|
closid = rgrp->closid;
|
|
|
|
rmid = rgrp->mon.rmid;
|
2024-02-13 18:44:20 +00:00
|
|
|
idx = resctrl_arch_rmid_idx_encode(closid, rmid);
|
|
|
|
pmbm_data = &dom_mbm->mbm_local[idx];
|
2018-04-20 15:36:21 -07:00
|
|
|
|
|
|
|
dom_mba = get_domain_from_cpu(smp_processor_id(), r_mba);
|
|
|
|
if (!dom_mba) {
|
|
|
|
pr_warn_once("Failure to get domain for MBA update\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_bw = pmbm_data->prev_bw;
|
2022-09-02 15:48:17 +00:00
|
|
|
user_bw = dom_mba->mbps_val[closid];
|
|
|
|
|
|
|
|
/* MBA resource doesn't support CDP */
|
|
|
|
cur_msr_val = resctrl_arch_get_config(r_mba, dom_mba, closid, CDP_NONE);
|
2018-04-20 15:36:21 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For Ctrl groups read data from child monitor groups.
|
|
|
|
*/
|
|
|
|
head = &rgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry(entry, head, mon.crdtgrp_list) {
|
|
|
|
cmbm_data = &dom_mbm->mbm_local[entry->mon.rmid];
|
|
|
|
cur_bw += cmbm_data->prev_bw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scale up/down the bandwidth linearly for the ctrl group. The
|
|
|
|
* bandwidth step is the bandwidth granularity specified by the
|
|
|
|
* hardware.
|
2024-01-22 10:08:07 -08:00
|
|
|
* Always increase throttling if current bandwidth is above the
|
|
|
|
* target set by user.
|
|
|
|
* But avoid thrashing up and down on every poll by checking
|
|
|
|
* whether a decrease in throttling is likely to push the group
|
|
|
|
* back over target. E.g. if currently throttling to 30% of bandwidth
|
|
|
|
* on a system with 10% granularity steps, check whether moving to
|
|
|
|
* 40% would go past the limit by multiplying current bandwidth by
|
|
|
|
* "(30 + 10) / 30".
|
2018-04-20 15:36:21 -07:00
|
|
|
*/
|
|
|
|
if (cur_msr_val > r_mba->membw.min_bw && user_bw < cur_bw) {
|
|
|
|
new_msr_val = cur_msr_val - r_mba->membw.bw_gran;
|
|
|
|
} else if (cur_msr_val < MAX_MBA_BW &&
|
2024-01-22 10:08:07 -08:00
|
|
|
(user_bw > (cur_bw * (cur_msr_val + r_mba->membw.min_bw) / cur_msr_val))) {
|
2018-04-20 15:36:21 -07:00
|
|
|
new_msr_val = cur_msr_val + r_mba->membw.bw_gran;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-02 15:48:19 +00:00
|
|
|
resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val);
|
2018-04-20 15:36:21 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
static void mbm_update(struct rdt_resource *r, struct rdt_domain *d,
|
|
|
|
u32 closid, u32 rmid)
|
2017-07-25 14:14:47 -07:00
|
|
|
{
|
|
|
|
struct rmid_read rr;
|
|
|
|
|
|
|
|
rr.first = false;
|
2020-05-05 15:36:16 -07:00
|
|
|
rr.r = r;
|
2017-07-25 14:14:47 -07:00
|
|
|
rr.d = d;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is protected from concurrent reads from user
|
|
|
|
* as both the user and we hold the global mutex.
|
|
|
|
*/
|
|
|
|
if (is_mbm_total_enabled()) {
|
|
|
|
rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
|
2022-09-02 15:48:20 +00:00
|
|
|
rr.val = 0;
|
2024-02-13 18:44:29 +00:00
|
|
|
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
|
|
|
|
if (IS_ERR(rr.arch_mon_ctx)) {
|
|
|
|
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
|
|
|
|
PTR_ERR(rr.arch_mon_ctx));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
__mon_event_count(closid, rmid, &rr);
|
2024-02-13 18:44:29 +00:00
|
|
|
|
|
|
|
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
if (is_mbm_local_enabled()) {
|
|
|
|
rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
|
2022-09-02 15:48:20 +00:00
|
|
|
rr.val = 0;
|
2024-02-13 18:44:29 +00:00
|
|
|
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
|
|
|
|
if (IS_ERR(rr.arch_mon_ctx)) {
|
|
|
|
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
|
|
|
|
PTR_ERR(rr.arch_mon_ctx));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:19 +00:00
|
|
|
__mon_event_count(closid, rmid, &rr);
|
2018-04-20 15:36:21 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the MBA software controller only for the
|
|
|
|
* control groups and when user has enabled
|
|
|
|
* the software controller explicitly.
|
|
|
|
*/
|
x86/resctrl: Fix incorrect local bandwidth when mba_sc is enabled
The MBA software controller (mba_sc) is a feedback loop which
periodically reads MBM counters and tries to restrict the bandwidth
below a user-specified value. It tags along the MBM counter overflow
handler to do the updates with 1s interval in mbm_update() and
update_mba_bw().
The purpose of mbm_update() is to periodically read the MBM counters to
make sure that the hardware counter doesn't wrap around more than once
between user samplings. mbm_update() calls __mon_event_count() for local
bandwidth updating when mba_sc is not enabled, but calls mbm_bw_count()
instead when mba_sc is enabled. __mon_event_count() will not be called
for local bandwidth updating in MBM counter overflow handler, but it is
still called when reading MBM local bandwidth counter file
'mbm_local_bytes', the call path is as below:
rdtgroup_mondata_show()
mon_event_read()
mon_event_count()
__mon_event_count()
In __mon_event_count(), m->chunks is updated by delta chunks which is
calculated from previous MSR value (m->prev_msr) and current MSR value.
When mba_sc is enabled, m->chunks is also updated in mbm_update() by
mistake by the delta chunks which is calculated from m->prev_bw_msr
instead of m->prev_msr. But m->chunks is not used in update_mba_bw() in
the mba_sc feedback loop.
When reading MBM local bandwidth counter file, m->chunks was changed
unexpectedly by mbm_bw_count(). As a result, the incorrect local
bandwidth counter which calculated from incorrect m->chunks is shown to
the user.
Fix this by removing incorrect m->chunks updating in mbm_bw_count() in
MBM counter overflow handler, and always calling __mon_event_count() in
mbm_update() to make sure that the hardware local bandwidth counter
doesn't wrap around.
Test steps:
# Run workload with aggressive memory bandwidth (e.g., 10 GB/s)
git clone https://github.com/intel/intel-cmt-cat && cd intel-cmt-cat
&& make
./tools/membw/membw -c 0 -b 10000 --read
# Enable MBA software controller
mount -t resctrl resctrl -o mba_MBps /sys/fs/resctrl
# Create control group c1
mkdir /sys/fs/resctrl/c1
# Set MB throttle to 6 GB/s
echo "MB:0=6000;1=6000" > /sys/fs/resctrl/c1/schemata
# Write PID of the workload to tasks file
echo `pidof membw` > /sys/fs/resctrl/c1/tasks
# Read local bytes counters twice with 1s interval, the calculated
# local bandwidth is not as expected (approaching to 6 GB/s):
local_1=`cat /sys/fs/resctrl/c1/mon_data/mon_L3_00/mbm_local_bytes`
sleep 1
local_2=`cat /sys/fs/resctrl/c1/mon_data/mon_L3_00/mbm_local_bytes`
echo "local b/w (bytes/s):" `expr $local_2 - $local_1`
Before fix:
local b/w (bytes/s): 11076796416
After fix:
local b/w (bytes/s): 5465014272
Fixes: ba0f26d8529c (x86/intel_rdt/mba_sc: Prepare for feedback loop)
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/1607063279-19437-1-git-send-email-xiaochen.shen@intel.com
2020-12-04 14:27:59 +08:00
|
|
|
if (is_mba_sc(NULL))
|
2024-02-13 18:44:19 +00:00
|
|
|
mbm_bw_count(closid, rmid, &rr);
|
2024-02-13 18:44:29 +00:00
|
|
|
|
|
|
|
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:00:43 -07:00
|
|
|
/*
|
|
|
|
* Handler to scan the limbo list and move the RMIDs
|
|
|
|
* to free list whose occupancy < threshold_occupancy.
|
|
|
|
*/
|
|
|
|
void cqm_handle_limbo(struct work_struct *work)
|
|
|
|
{
|
|
|
|
unsigned long delay = msecs_to_jiffies(CQM_LIMBOCHECK_INTERVAL);
|
|
|
|
struct rdt_domain *d;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2017-08-15 18:00:43 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
2020-07-08 16:39:23 +00:00
|
|
|
d = container_of(work, struct rdt_domain, cqm_limbo.work);
|
2017-08-15 18:00:43 -07:00
|
|
|
|
|
|
|
__check_limbo(d, false);
|
|
|
|
|
2024-02-13 18:44:26 +00:00
|
|
|
if (has_busy_rmid(d)) {
|
2024-02-13 18:44:35 +00:00
|
|
|
d->cqm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask,
|
|
|
|
RESCTRL_PICK_ANY_CPU);
|
2024-02-13 18:44:26 +00:00
|
|
|
schedule_delayed_work_on(d->cqm_work_cpu, &d->cqm_limbo,
|
|
|
|
delay);
|
|
|
|
}
|
2017-08-15 18:00:43 -07:00
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2017-08-15 18:00:43 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:35 +00:00
|
|
|
/**
|
|
|
|
* cqm_setup_limbo_handler() - Schedule the limbo handler to run for this
|
|
|
|
* domain.
|
|
|
|
* @dom: The domain the limbo handler should run for.
|
|
|
|
* @delay_ms: How far in the future the handler should run.
|
|
|
|
* @exclude_cpu: Which CPU the handler should not run on,
|
|
|
|
* RESCTRL_PICK_ANY_CPU to pick any CPU.
|
|
|
|
*/
|
|
|
|
void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms,
|
|
|
|
int exclude_cpu)
|
2017-08-15 18:00:43 -07:00
|
|
|
{
|
|
|
|
unsigned long delay = msecs_to_jiffies(delay_ms);
|
|
|
|
int cpu;
|
|
|
|
|
2024-02-13 18:44:35 +00:00
|
|
|
cpu = cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu);
|
2017-08-15 18:00:43 -07:00
|
|
|
dom->cqm_work_cpu = cpu;
|
|
|
|
|
2024-02-13 18:44:35 +00:00
|
|
|
if (cpu < nr_cpu_ids)
|
|
|
|
schedule_delayed_work_on(cpu, &dom->cqm_limbo, delay);
|
2017-08-15 18:00:43 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:47 -07:00
|
|
|
void mbm_handle_overflow(struct work_struct *work)
|
|
|
|
{
|
|
|
|
unsigned long delay = msecs_to_jiffies(MBM_OVERFLOW_INTERVAL);
|
|
|
|
struct rdtgroup *prgrp, *crgrp;
|
|
|
|
struct list_head *head;
|
2020-05-05 15:36:16 -07:00
|
|
|
struct rdt_resource *r;
|
2017-07-25 14:14:47 -07:00
|
|
|
struct rdt_domain *d;
|
|
|
|
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_lock();
|
2017-07-25 14:14:47 -07:00
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:30 +00:00
|
|
|
/*
|
|
|
|
* If the filesystem has been unmounted this work no longer needs to
|
|
|
|
* run.
|
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (!resctrl_mounted || !resctrl_arch_mon_capable())
|
2017-07-25 14:14:47 -07:00
|
|
|
goto out_unlock;
|
|
|
|
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
|
2020-07-08 16:39:23 +00:00
|
|
|
d = container_of(work, struct rdt_domain, mbm_over.work);
|
2017-07-25 14:14:47 -07:00
|
|
|
|
|
|
|
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
|
2024-02-13 18:44:19 +00:00
|
|
|
mbm_update(r, d, prgrp->closid, prgrp->mon.rmid);
|
2017-07-25 14:14:47 -07:00
|
|
|
|
|
|
|
head = &prgrp->mon.crdtgrp_list;
|
|
|
|
list_for_each_entry(crgrp, head, mon.crdtgrp_list)
|
2024-02-13 18:44:19 +00:00
|
|
|
mbm_update(r, d, crgrp->closid, crgrp->mon.rmid);
|
2018-04-20 15:36:21 -07:00
|
|
|
|
|
|
|
if (is_mba_sc(NULL))
|
|
|
|
update_mba_bw(prgrp, d);
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:26 +00:00
|
|
|
/*
|
|
|
|
* Re-check for housekeeping CPUs. This allows the overflow handler to
|
|
|
|
* move off a nohz_full CPU quickly.
|
|
|
|
*/
|
2024-02-13 18:44:35 +00:00
|
|
|
d->mbm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask,
|
|
|
|
RESCTRL_PICK_ANY_CPU);
|
2024-02-13 18:44:26 +00:00
|
|
|
schedule_delayed_work_on(d->mbm_work_cpu, &d->mbm_over, delay);
|
2017-08-15 18:00:43 -07:00
|
|
|
|
2017-07-25 14:14:47 -07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
x86/resctrl: Separate arch and fs resctrl locks
resctrl has one mutex that is taken by the architecture-specific code, and the
filesystem parts. The two interact via cpuhp, where the architecture code
updates the domain list. Filesystem handlers that walk the domains list should
not run concurrently with the cpuhp callback modifying the list.
Exposing a lock from the filesystem code means the interface is not cleanly
defined, and creates the possibility of cross-architecture lock ordering
headaches. The interaction only exists so that certain filesystem paths are
serialised against CPU hotplug. The CPU hotplug code already has a mechanism to
do this using cpus_read_lock().
MPAM's monitors have an overflow interrupt, so it needs to be possible to walk
the domains list in irq context. RCU is ideal for this, but some paths need to
be able to sleep to allocate memory.
Because resctrl_{on,off}line_cpu() take the rdtgroup_mutex as part of a cpuhp
callback, cpus_read_lock() must always be taken first.
rdtgroup_schemata_write() already does this.
Most of the filesystem code's domain list walkers are currently protected by
the rdtgroup_mutex taken in rdtgroup_kn_lock_live(). The exceptions are
rdt_bit_usage_show() and the mon_config helpers which take the lock directly.
Make the domain list protected by RCU. An architecture-specific lock prevents
concurrent writers. rdt_bit_usage_show() could walk the domain list using RCU,
but to keep all the filesystem operations the same, this is changed to call
cpus_read_lock(). The mon_config helpers send multiple IPIs, take the
cpus_read_lock() in these cases.
The other filesystem list walkers need to be able to sleep. Add
cpus_read_lock() to rdtgroup_kn_lock_live() so that the cpuhp callbacks can't
be invoked when file system operations are occurring.
Add lockdep_assert_cpus_held() in the cases where the rdtgroup_kn_lock_live()
call isn't obvious.
Resctrl's domain online/offline calls now need to take the rdtgroup_mutex
themselves.
[ bp: Fold in a build fix: https://lore.kernel.org/r/87zfvwieli.ffs@tglx ]
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-25-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
2024-02-13 18:44:38 +00:00
|
|
|
cpus_read_unlock();
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:35 +00:00
|
|
|
/**
|
|
|
|
* mbm_setup_overflow_handler() - Schedule the overflow handler to run for this
|
|
|
|
* domain.
|
|
|
|
* @dom: The domain the overflow handler should run for.
|
|
|
|
* @delay_ms: How far in the future the handler should run.
|
|
|
|
* @exclude_cpu: Which CPU the handler should not run on,
|
|
|
|
* RESCTRL_PICK_ANY_CPU to pick any CPU.
|
|
|
|
*/
|
|
|
|
void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms,
|
|
|
|
int exclude_cpu)
|
2017-07-25 14:14:47 -07:00
|
|
|
{
|
2017-08-15 18:00:42 -07:00
|
|
|
unsigned long delay = msecs_to_jiffies(delay_ms);
|
2017-07-25 14:14:47 -07:00
|
|
|
int cpu;
|
|
|
|
|
2024-02-13 18:44:30 +00:00
|
|
|
/*
|
|
|
|
* When a domain comes online there is no guarantee the filesystem is
|
|
|
|
* mounted. If not, there is no need to catch counter overflow.
|
|
|
|
*/
|
2024-02-13 18:44:33 +00:00
|
|
|
if (!resctrl_mounted || !resctrl_arch_mon_capable())
|
2017-07-25 14:14:47 -07:00
|
|
|
return;
|
2024-02-13 18:44:35 +00:00
|
|
|
cpu = cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu);
|
2017-07-25 14:14:47 -07:00
|
|
|
dom->mbm_work_cpu = cpu;
|
2024-02-13 18:44:35 +00:00
|
|
|
|
|
|
|
if (cpu < nr_cpu_ids)
|
|
|
|
schedule_delayed_work_on(cpu, &dom->mbm_over, delay);
|
2017-07-25 14:14:47 -07:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:27 -07:00
|
|
|
static int dom_data_init(struct rdt_resource *r)
|
|
|
|
{
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
|
2024-02-13 18:44:22 +00:00
|
|
|
u32 num_closid = resctrl_arch_get_num_closid(r);
|
2017-07-25 14:14:27 -07:00
|
|
|
struct rmid_entry *entry = NULL;
|
2024-02-13 18:44:22 +00:00
|
|
|
int err = 0, i;
|
2024-02-13 18:44:20 +00:00
|
|
|
u32 idx;
|
2024-02-13 18:44:22 +00:00
|
|
|
|
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
|
|
|
|
u32 *tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the architecture hasn't provided a sanitised value here,
|
|
|
|
* this may result in larger arrays than necessary. Resctrl will
|
|
|
|
* use a smaller system wide value based on the resources in
|
|
|
|
* use.
|
|
|
|
*/
|
|
|
|
tmp = kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL);
|
|
|
|
if (!tmp) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
closid_num_dirty_rmid = tmp;
|
|
|
|
}
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
rmid_ptrs = kcalloc(idx_limit, sizeof(struct rmid_entry), GFP_KERNEL);
|
2024-02-13 18:44:22 +00:00
|
|
|
if (!rmid_ptrs) {
|
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
|
|
|
|
kfree(closid_num_dirty_rmid);
|
|
|
|
closid_num_dirty_rmid = NULL;
|
|
|
|
}
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
for (i = 0; i < idx_limit; i++) {
|
2017-07-25 14:14:27 -07:00
|
|
|
entry = &rmid_ptrs[i];
|
|
|
|
INIT_LIST_HEAD(&entry->list);
|
|
|
|
|
2024-02-13 18:44:20 +00:00
|
|
|
resctrl_arch_rmid_idx_decode(i, &entry->closid, &entry->rmid);
|
2017-07-25 14:14:27 -07:00
|
|
|
list_add_tail(&entry->list, &rmid_free_lru);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-02-13 18:44:19 +00:00
|
|
|
* RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and
|
|
|
|
* are always allocated. These are used for the rdtgroup_default
|
|
|
|
* control group, which will be setup later in rdtgroup_init().
|
2017-07-25 14:14:27 -07:00
|
|
|
*/
|
2024-02-13 18:44:20 +00:00
|
|
|
idx = resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID,
|
|
|
|
RESCTRL_RESERVED_RMID);
|
|
|
|
entry = __rmid_entry(idx);
|
2017-07-25 14:14:27 -07:00
|
|
|
list_del(&entry->list);
|
|
|
|
|
2024-02-13 18:44:22 +00:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
|
|
|
|
return err;
|
2017-07-25 14:14:27 -07:00
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:16 +00:00
|
|
|
static void __exit dom_data_exit(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&rdtgroup_mutex);
|
|
|
|
|
2024-02-13 18:44:22 +00:00
|
|
|
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
|
|
|
|
kfree(closid_num_dirty_rmid);
|
|
|
|
closid_num_dirty_rmid = NULL;
|
|
|
|
}
|
|
|
|
|
2024-02-13 18:44:16 +00:00
|
|
|
kfree(rmid_ptrs);
|
|
|
|
rmid_ptrs = NULL;
|
|
|
|
|
|
|
|
mutex_unlock(&rdtgroup_mutex);
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:27 -07:00
|
|
|
static struct mon_evt llc_occupancy_event = {
|
|
|
|
.name = "llc_occupancy",
|
|
|
|
.evtid = QOS_L3_OCCUP_EVENT_ID,
|
|
|
|
};
|
|
|
|
|
2017-07-25 14:14:45 -07:00
|
|
|
static struct mon_evt mbm_total_event = {
|
|
|
|
.name = "mbm_total_bytes",
|
|
|
|
.evtid = QOS_L3_MBM_TOTAL_EVENT_ID,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mon_evt mbm_local_event = {
|
|
|
|
.name = "mbm_local_bytes",
|
|
|
|
.evtid = QOS_L3_MBM_LOCAL_EVENT_ID,
|
|
|
|
};
|
|
|
|
|
2017-07-25 14:14:27 -07:00
|
|
|
/*
|
|
|
|
* Initialize the event list for the resource.
|
|
|
|
*
|
|
|
|
* Note that MBM events are also part of RDT_RESOURCE_L3 resource
|
|
|
|
* because as per the SDM the total and local memory bandwidth
|
|
|
|
* are enumerated as part of L3 monitoring.
|
|
|
|
*/
|
|
|
|
static void l3_mon_evt_init(struct rdt_resource *r)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&r->evt_list);
|
|
|
|
|
|
|
|
if (is_llc_occupancy_enabled())
|
|
|
|
list_add_tail(&llc_occupancy_event.list, &r->evt_list);
|
2017-07-25 14:14:45 -07:00
|
|
|
if (is_mbm_total_enabled())
|
|
|
|
list_add_tail(&mbm_total_event.list, &r->evt_list);
|
|
|
|
if (is_mbm_local_enabled())
|
|
|
|
list_add_tail(&mbm_local_event.list, &r->evt_list);
|
2017-07-25 14:14:27 -07:00
|
|
|
}
|
|
|
|
|
2023-01-13 09:20:33 -06:00
|
|
|
int __init rdt_get_mon_l3_config(struct rdt_resource *r)
|
2017-07-25 14:14:27 -07:00
|
|
|
{
|
2020-05-05 15:36:18 -07:00
|
|
|
unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
|
2022-09-02 15:48:27 +00:00
|
|
|
unsigned int threshold;
|
2017-07-25 14:14:27 -07:00
|
|
|
int ret;
|
|
|
|
|
2022-09-02 15:48:28 +00:00
|
|
|
resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
|
2017-07-25 14:14:27 -07:00
|
|
|
r->num_rmid = boot_cpu_data.x86_cache_max_rmid + 1;
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
hw_res->mbm_width = MBM_CNTR_WIDTH_BASE;
|
2020-05-05 15:36:18 -07:00
|
|
|
|
|
|
|
if (mbm_offset > 0 && mbm_offset <= MBM_CNTR_WIDTH_OFFSET_MAX)
|
x86/resctrl: Split struct rdt_resource
resctrl is the defacto Linux ABI for SoC resource partitioning features.
To support it on another architecture, it needs to be abstracted from
the features provided by Intel RDT and AMD PQoS, and moved to /fs/.
struct rdt_resource contains a mix of architecture private details
and properties of the filesystem interface user-space uses.
Start by splitting struct rdt_resource, into an architecture private
'hw' struct, which contains the common resctrl structure that would be
used by any architecture. The foreach helpers are most commonly used by
the filesystem code, and should return the common resctrl structure.
for_each_rdt_resource() is changed to walk the common structure in its
parent arch private structure.
Move as much of the structure as possible into the common structure
in the core code's header file. The x86 hardware accessors remain
part of the architecture private code, as do num_closid, mon_scale
and mbm_width.
mon_scale and mbm_width are used to detect overflow of the hardware
counters, and convert them from their native size to bytes. Any
cross-architecture abstraction should be in terms of bytes, making
these properties private.
The hardware's num_closid is kept in the private structure to force the
filesystem code to use a helper to access it. MPAM would return a single
value for the system, regardless of the resource. Using the helper
prevents this field from being confused with the version of num_closid
that is being exposed to user-space (added in a later patch).
After this split, filesystem code touching a 'hw' struct indicates
where an abstraction is needed.
Splitting this structure only moves types around, and should not lead
to any change in behaviour.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jamie Iles <jamie@nuviainc.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lkml.kernel.org/r/20210728170637.25610-2-james.morse@arm.com
2021-07-28 17:06:14 +00:00
|
|
|
hw_res->mbm_width += mbm_offset;
|
2020-05-05 15:36:18 -07:00
|
|
|
else if (mbm_offset > MBM_CNTR_WIDTH_OFFSET_MAX)
|
|
|
|
pr_warn("Ignoring impossible MBM counter offset\n");
|
2017-07-25 14:14:27 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A reasonable upper limit on the max threshold is the number
|
|
|
|
* of lines tagged per RMID if all RMIDs have the same number of
|
|
|
|
* lines tagged in the LLC.
|
|
|
|
*
|
|
|
|
* For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
|
|
|
|
*/
|
2022-09-02 15:48:28 +00:00
|
|
|
threshold = resctrl_rmid_realloc_limit / r->num_rmid;
|
2017-07-25 14:14:27 -07:00
|
|
|
|
2022-09-02 15:48:27 +00:00
|
|
|
/*
|
|
|
|
* Because num_rmid may not be a power of two, round the value
|
|
|
|
* to the nearest multiple of hw_res->mon_scale so it matches a
|
|
|
|
* value the hardware will measure. mon_scale may not be a power of 2.
|
|
|
|
*/
|
|
|
|
resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
|
2017-07-25 14:14:27 -07:00
|
|
|
|
|
|
|
ret = dom_data_init(r);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2023-01-13 09:20:34 -06:00
|
|
|
if (rdt_cpu_has(X86_FEATURE_BMEC)) {
|
2024-01-15 16:52:28 -06:00
|
|
|
u32 eax, ebx, ecx, edx;
|
|
|
|
|
|
|
|
/* Detect list of bandwidth sources that can be tracked */
|
|
|
|
cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
|
|
|
|
hw_res->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
|
|
|
|
|
2023-01-13 09:20:35 -06:00
|
|
|
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
|
2023-01-13 09:20:34 -06:00
|
|
|
mbm_total_event.configurable = true;
|
2023-01-13 09:20:35 -06:00
|
|
|
mbm_config_rftype_init("mbm_total_bytes_config");
|
|
|
|
}
|
2023-01-13 09:20:36 -06:00
|
|
|
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
|
2023-01-13 09:20:34 -06:00
|
|
|
mbm_local_event.configurable = true;
|
2023-01-13 09:20:36 -06:00
|
|
|
mbm_config_rftype_init("mbm_local_bytes_config");
|
|
|
|
}
|
2023-01-13 09:20:34 -06:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:14:27 -07:00
|
|
|
l3_mon_evt_init(r);
|
|
|
|
|
|
|
|
r->mon_capable = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-14 00:49:27 +00:00
|
|
|
|
2024-02-13 18:44:16 +00:00
|
|
|
void __exit rdt_put_mon_l3_config(void)
|
|
|
|
{
|
|
|
|
dom_data_exit();
|
|
|
|
}
|
|
|
|
|
2020-10-14 00:49:27 +00:00
|
|
|
void __init intel_rdt_mbm_apply_quirk(void)
|
|
|
|
{
|
|
|
|
int cf_index;
|
|
|
|
|
|
|
|
cf_index = (boot_cpu_data.x86_cache_max_rmid + 1) / 8 - 1;
|
|
|
|
if (cf_index >= ARRAY_SIZE(mbm_cf_table)) {
|
|
|
|
pr_info("No MBM correction factor available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbm_cf_rmidthreshold = mbm_cf_table[cf_index].rmidthreshold;
|
|
|
|
mbm_cf = mbm_cf_table[cf_index].cf;
|
|
|
|
}
|