Commit faf9a4c3 authored by Wang ShaoBo's avatar Wang ShaoBo Committed by Zheng Zengkai
Browse files

arm64/mpam: Pick MPAM resources and events for resctrl_res exported



hulk inclusion
category: feature
feature: ARM MPAM support
bugzilla: 48265
CVE: NA

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

Pick available classes and exported as well-known caches and MBA():

1) System with MPAM support may have a variety of control types at any
   point of their system layout. We can only expose certain types of
   control, and only if they exist at particular locations.

   Start with the well-know caches. These have to be depth 2 or 3
   and support MPAM's cache portion bitmap controls, with a number
   of portions fewer that resctrl's limit.

2) Picking which MPAM component we can expose via resctrl as MBA
   (Memory Bandwidth Allocation) is tricky. The ABI is a percentage of
   available bandwidth.

   We can either do this with the memory bandwidth portion bitmaps, or
   the memory bandwidth maximum control. If both are implemented we
   prefer the bitmap.

   We require and candidate for this resource type to support bandwidth
   monitoring too.

   For 'MBA's position in the toplogy, we want it to be at, or after,
   the last level cache that is being exposed via resctrl. If there
   are multiple candidates, we prefer the one closer to the outermost
   exposed cache.

Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Link: http://www.linux-arm.org/git?p=linux-jm.git;a=patch;h=b6870246e25f8f6f9c7b275f0aaa50fc772094a6
Link: http://www.linux-arm.org/git?p=linux-jm.git;a=patch;h=676d9aee8c2b27a17dd9cbebe5c9ecdd63c6281f


Signed-off-by: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
Reviewed-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: default avatarCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 8a6445f7
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -8,6 +8,25 @@
#define resctrl_alloc_capable rdt_alloc_capable
#define resctrl_mon_capable rdt_mon_capable

enum resctrl_resource_level {
	RDT_RESOURCE_SMMU,
	RDT_RESOURCE_L3,
	RDT_RESOURCE_L2,
	RDT_RESOURCE_MC,

	/* Must be the last */
	RDT_NUM_RESOURCES,
};

enum rdt_event_id {
	QOS_L3_OCCUP_EVENT_ID           = 0x01,
	QOS_L3_MBM_TOTAL_EVENT_ID       = 0x02,
	QOS_L3_MBM_LOCAL_EVENT_ID       = 0x03,

	/* Must be the last */
	RESCTRL_NUM_EVENT_IDS,
};

static inline int alloc_mon_id(void)
{

+1 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_MPAM)  += mpam_resctrl.o mpam_mon.o \
					mpam_ctrlmon.o mpam_device.o
					mpam_ctrlmon.o mpam_device.o mpam_setup.o
+25 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/cacheinfo.h>
#include <asm/mpam.h>
#include <asm/mpam_resource.h>
#include <asm/mpam.h>

#include "mpam_device.h"

@@ -71,6 +72,11 @@ static struct work_struct mpam_enable_work;
static int mpam_broken;
static struct work_struct mpam_failed_work;

void mpam_class_list_lock_held(void)
{
	lockdep_assert_held(&mpam_devices_lock);
}

static inline u32 mpam_read_reg(struct mpam_device *dev, u16 reg)
{
	WARN_ON_ONCE(reg > SZ_MPAM_DEVICE);
@@ -411,6 +417,25 @@ static void __init mpam_enable(struct work_struct *work)
	if (err)
		return;
	mutex_unlock(&mpam_devices_lock);

	/*
	 * mpam_enable() runs in parallel with cpuhp callbacks bringing other
	 * CPUs online, as we eagerly schedule the work. To give resctrl a
	 * clean start, we make all cpus look offline, set resctrl_registered,
	 * and then bring them back.
	 */
	mutex_lock(&mpam_cpuhp_lock);
	if (!mpam_cpuhp_state) {
		/* We raced with mpam_failed(). */
		mutex_unlock(&mpam_cpuhp_lock);
		return;
	}
	cpuhp_remove_state(mpam_cpuhp_state);
	mutex_unlock(&mpam_cpuhp_lock);

	mutex_lock(&mpam_devices_lock);
	err = mpam_resctrl_setup();
	mutex_unlock(&mpam_devices_lock);
}

static void mpam_failed(struct work_struct *work)
+38 −0
Original line number Diff line number Diff line
@@ -2,8 +2,42 @@
#ifndef _ASM_ARM64_MPAM_INTERNAL_H
#define _ASM_ARM64_MPAM_INTERNAL_H

#include <linux/resctrlfs.h>

typedef u32 mpam_features_t;

struct mpam_component;
struct rdt_domain;
struct mpam_class;

extern bool rdt_alloc_capable;
extern bool rdt_mon_capable;

extern struct list_head mpam_classes;

struct mpam_resctrl_dom {
	struct mpam_component   *comp;

	struct rdt_domain   resctrl_dom;
};

struct mpam_resctrl_res {
	struct mpam_class   *class;

	bool resctrl_mba_uses_mbw_part;

	struct resctrl_resource resctrl_res;
};

#define for_each_resctrl_exports(r) \
		for (r = &mpam_resctrl_exports[0]; \
			r < &mpam_resctrl_exports[0] + \
			ARRAY_SIZE(mpam_resctrl_exports); r++)

#define for_each_supported_resctrl_exports(r) \
		for_each_resctrl_exports(r) \
			if (r->class)

/*
 * MPAM component config Structure
 */
@@ -82,4 +116,8 @@ static inline void mpam_clear_feature(enum mpam_device_features feat,
u16 mpam_sysprops_num_partid(void);
u16 mpam_sysprops_num_pmg(void);

void mpam_class_list_lock_held(void);

int mpam_resctrl_setup(void);

#endif
+2 −1
Original line number Diff line number Diff line
@@ -26,9 +26,10 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/resctrlfs.h>

#include <asm/resctrl.h>

#include "mpam_internal.h"

/*
 * Global boolean for rdt_monitor which is true if any
 * resource monitoring is enabled.
Loading