Skip to content

Commit 475228d

Browse files
James Morsectmarinas
authored andcommitted
arm_mpam: Add a helper to touch an MSC from any CPU
Resetting RIS entries from the cpuhp callback is easy as the callback occurs on the correct CPU. This won't be true for any other caller that wants to reset or configure an MSC. Add a helper that schedules the provided function if necessary. Callers should take the cpuhp lock to prevent the cpuhp callbacks from changing the MSC state. Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Ben Horgan <ben.horgan@arm.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent f188a36 commit 475228d

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

drivers/resctrl/mpam_devices.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,28 +806,59 @@ static void mpam_reset_ris_partid(struct mpam_msc_ris *ris, u16 partid)
806806
mutex_unlock(&msc->part_sel_lock);
807807
}
808808

809-
static void mpam_reset_ris(struct mpam_msc_ris *ris)
809+
/*
810+
* Called via smp_call_on_cpu() to prevent migration, while still being
811+
* pre-emptible.
812+
*/
813+
static int mpam_reset_ris(void *arg)
810814
{
811815
u16 partid, partid_max;
816+
struct mpam_msc_ris *ris = arg;
812817

813818
WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
814819

815820
if (ris->in_reset_state)
816-
return;
821+
return 0;
817822

818823
spin_lock(&partid_max_lock);
819824
partid_max = mpam_partid_max;
820825
spin_unlock(&partid_max_lock);
821826
for (partid = 0; partid <= partid_max; partid++)
822827
mpam_reset_ris_partid(ris, partid);
828+
829+
return 0;
830+
}
831+
832+
/*
833+
* Get the preferred CPU for this MSC. If it is accessible from this CPU,
834+
* this CPU is preferred. This can be preempted/migrated, it will only result
835+
* in more work.
836+
*/
837+
static int mpam_get_msc_preferred_cpu(struct mpam_msc *msc)
838+
{
839+
int cpu = raw_smp_processor_id();
840+
841+
if (cpumask_test_cpu(cpu, &msc->accessibility))
842+
return cpu;
843+
844+
return cpumask_first_and(&msc->accessibility, cpu_online_mask);
845+
}
846+
847+
static int mpam_touch_msc(struct mpam_msc *msc, int (*fn)(void *a), void *arg)
848+
{
849+
lockdep_assert_irqs_enabled();
850+
lockdep_assert_cpus_held();
851+
WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
852+
853+
return smp_call_on_cpu(mpam_get_msc_preferred_cpu(msc), fn, arg, true);
823854
}
824855

825856
static void mpam_reset_msc(struct mpam_msc *msc, bool online)
826857
{
827858
struct mpam_msc_ris *ris;
828859

829860
list_for_each_entry_srcu(ris, &msc->ris, msc_list, srcu_read_lock_held(&mpam_srcu)) {
830-
mpam_reset_ris(ris);
861+
mpam_touch_msc(msc, &mpam_reset_ris, ris);
831862

832863
/*
833864
* Set in_reset_state when coming online. The reset state

0 commit comments

Comments
 (0)