[PATCH v4 17/19] x86/resctrl: Introduce the interface switch between ABMC and mbm_legacy

Babu Moger posted 19 patches 1 year, 8 months ago
There is a newer version of this series
[PATCH v4 17/19] x86/resctrl: Introduce the interface switch between ABMC and mbm_legacy
Posted by Babu Moger 1 year, 8 months ago
Introduce interface to switch between ABMC and legacy_mbm modes.

By default ABMC is enabled on resctrl mount if the feature is available.
However, user will have the option to go back to legacy_mbm if required.

$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign
[abmc]
mbm_legacy

To enable the legacy monitoring feature:
$ echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v4: Minor commit text changes. Keep the default to ABMC when supported.

v3: New patch to address the review comments from upstream.
---
 Documentation/arch/x86/resctrl.rst     | 10 +++++++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index ab3cde61a124..fd050d4d22cd 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -271,6 +271,16 @@ with the following files:
 	  [abmc]
 	  mbm_legacy
 
+	* To enable ABMC feature:
+	  ::
+
+	    # echo  "abmc" > /sys/fs/resctrl/info/L3_MON/mbm_assign
+
+	* To enable the legacy monitoring feature:
+	  ::
+
+	    # echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index f452b6d9bb99..d77ff059269a 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -908,6 +908,43 @@ static int rdtgroup_mbm_assign_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+/*
+ * rdtgroup_mode_write - Modify the resource group's mode
+ */
+static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
+					 char *buf, size_t nbytes,
+					 loff_t off)
+{
+	struct rdt_resource *r = of->kn->parent->priv;
+	int ret = 0;
+
+	if (!r->abmc_capable)
+		return -EINVAL;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+
+	buf[nbytes - 1] = '\0';
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "mbm_legacy"))
+		resctrl_abmc_disable(RDT_RESOURCE_L3);
+	else if (!strcmp(buf, "abmc"))
+		ret = resctrl_abmc_enable(RDT_RESOURCE_L3);
+	else
+		ret = -EINVAL;
+
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret ?: nbytes;
+}
+
 #ifdef CONFIG_PROC_CPU_RESCTRL
 
 /*
@@ -2087,9 +2124,10 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "mbm_assign",
-		.mode		= 0444,
+		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
 		.seq_show	= rdtgroup_mbm_assign_show,
+		.write		= rdtgroup_mbm_assign_write,
 	},
 	{
 		.name		= "cpus",
-- 
2.34.1
Re: [PATCH v4 17/19] x86/resctrl: Introduce the interface switch between ABMC and mbm_legacy
Posted by Markus Elfring 1 year, 7 months ago
…
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
…
> +static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
> +					 char *buf, size_t nbytes,
> +					 loff_t off)
> +{
…
> +	cpus_read_lock();
> +	mutex_lock(&rdtgroup_mutex);
> +
> +	rdt_last_cmd_clear();
…
> +	mutex_unlock(&rdtgroup_mutex);
> +	cpus_read_unlock();
> +
> +	return ret ?: nbytes;
> +}
…

Would you become interested to apply statements like the following?

* guard(cpus_read_lock)();
  https://elixir.bootlin.com/linux/v6.10-rc4/source/include/linux/cleanup.h#L133

* guard(mutex)(&rdtgroup_mutex);
  https://elixir.bootlin.com/linux/v6.10-rc4/source/include/linux/mutex.h#L196

Regards,
Markus
Re: [PATCH v4 17/19] x86/resctrl: Introduce the interface switch between ABMC and mbm_legacy
Posted by Reinette Chatre 1 year, 8 months ago
Hi Babu,

On 5/24/24 5:23 AM, Babu Moger wrote:
> Introduce interface to switch between ABMC and legacy_mbm modes.

shortlog and first sentence of changelog do not match: mbm_legacy vs legacy_mbm?

> 
> By default ABMC is enabled on resctrl mount if the feature is available.
> However, user will have the option to go back to legacy_mbm if required.
> 
> $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign
> [abmc]
> mbm_legacy
> 
> To enable the legacy monitoring feature:
> $ echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign

Missing information about user visible impact to counters/events
and any mitigations needed in implementation.

> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
> v4: Minor commit text changes. Keep the default to ABMC when supported.
> 
> v3: New patch to address the review comments from upstream.
> ---
>   Documentation/arch/x86/resctrl.rst     | 10 +++++++
>   arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++++++++++-
>   2 files changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
> index ab3cde61a124..fd050d4d22cd 100644
> --- a/Documentation/arch/x86/resctrl.rst
> +++ b/Documentation/arch/x86/resctrl.rst
> @@ -271,6 +271,16 @@ with the following files:
>   	  [abmc]
>   	  mbm_legacy
>   
> +	* To enable ABMC feature:
> +	  ::
> +
> +	    # echo  "abmc" > /sys/fs/resctrl/info/L3_MON/mbm_assign
> +
> +	* To enable the legacy monitoring feature:
> +	  ::
> +
> +	    # echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign
> +

No information about what the features are or what will happen on such a switch.

>   "max_threshold_occupancy":
>   		Read/write file provides the largest value (in
>   		bytes) at which a previously used LLC_occupancy
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index f452b6d9bb99..d77ff059269a 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -908,6 +908,43 @@ static int rdtgroup_mbm_assign_show(struct kernfs_open_file *of,
>   	return 0;
>   }
>   
> +/*
> + * rdtgroup_mode_write - Modify the resource group's mode

Comment does not match function name. Seems like "mode" is the generic term
to use instead of "assign".

> + */
> +static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
> +					 char *buf, size_t nbytes,
> +					 loff_t off)
> +{
> +	struct rdt_resource *r = of->kn->parent->priv;
> +	int ret = 0;
> +
> +	if (!r->abmc_capable)
> +		return -EINVAL;
> +
> +	/* Valid input requires a trailing newline */
> +	if (nbytes == 0 || buf[nbytes - 1] != '\n')
> +		return -EINVAL;
> +
> +	buf[nbytes - 1] = '\0';
> +
> +	cpus_read_lock();
> +	mutex_lock(&rdtgroup_mutex);
> +
> +	rdt_last_cmd_clear();
> +
> +	if (!strcmp(buf, "mbm_legacy"))
> +		resctrl_abmc_disable(RDT_RESOURCE_L3);
> +	else if (!strcmp(buf, "abmc"))
> +		ret = resctrl_abmc_enable(RDT_RESOURCE_L3);
> +	else
> +		ret = -EINVAL;
> +
> +	mutex_unlock(&rdtgroup_mutex);
> +	cpus_read_unlock();
> +
> +	return ret ?: nbytes;
> +}
> +
>   #ifdef CONFIG_PROC_CPU_RESCTRL
>   
>   /*
> @@ -2087,9 +2124,10 @@ static struct rftype res_common_files[] = {
>   	},
>   	{
>   		.name		= "mbm_assign",
> -		.mode		= 0444,
> +		.mode		= 0644,
>   		.kf_ops		= &rdtgroup_kf_single_ops,
>   		.seq_show	= rdtgroup_mbm_assign_show,
> +		.write		= rdtgroup_mbm_assign_write,
>   	},
>   	{
>   		.name		= "cpus",


Reinette
Re: [PATCH v4 17/19] x86/resctrl: Introduce the interface switch between ABMC and mbm_legacy
Posted by Moger, Babu 1 year, 7 months ago
Hi Reinette,

On 6/13/24 20:51, Reinette Chatre wrote:
> Hi Babu,
> 
> On 5/24/24 5:23 AM, Babu Moger wrote:
>> Introduce interface to switch between ABMC and legacy_mbm modes.
> 
> shortlog and first sentence of changelog do not match: mbm_legacy vs
> legacy_mbm?

Will correct it.

> 
>>
>> By default ABMC is enabled on resctrl mount if the feature is available.
>> However, user will have the option to go back to legacy_mbm if required.
>>
>> $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign
>> [abmc]
>> mbm_legacy
>>
>> To enable the legacy monitoring feature:
>> $ echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign
> 
> Missing information about user visible impact to counters/events
> and any mitigations needed in implementation.

Sure. Will add the details.

> 
>>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
>> v4: Minor commit text changes. Keep the default to ABMC when supported.
>>
>> v3: New patch to address the review comments from upstream.
>> ---
>>   Documentation/arch/x86/resctrl.rst     | 10 +++++++
>>   arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++++++++++-
>>   2 files changed, 49 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/arch/x86/resctrl.rst
>> b/Documentation/arch/x86/resctrl.rst
>> index ab3cde61a124..fd050d4d22cd 100644
>> --- a/Documentation/arch/x86/resctrl.rst
>> +++ b/Documentation/arch/x86/resctrl.rst
>> @@ -271,6 +271,16 @@ with the following files:
>>         [abmc]
>>         mbm_legacy
>>   +    * To enable ABMC feature:
>> +      ::
>> +
>> +        # echo  "abmc" > /sys/fs/resctrl/info/L3_MON/mbm_assign
>> +
>> +    * To enable the legacy monitoring feature:
>> +      ::
>> +
>> +        # echo  "mbm_legacy" > /sys/fs/resctrl/info/L3_MON/mbm_assign
>> +
> 
> No information about what the features are or what will happen on such a
> switch.

Ok. Sure.  Will add more documentation.

> 
>>   "max_threshold_occupancy":
>>           Read/write file provides the largest value (in
>>           bytes) at which a previously used LLC_occupancy
>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> index f452b6d9bb99..d77ff059269a 100644
>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> @@ -908,6 +908,43 @@ static int rdtgroup_mbm_assign_show(struct
>> kernfs_open_file *of,
>>       return 0;
>>   }
>>   +/*
>> + * rdtgroup_mode_write - Modify the resource group's mode
> 
> Comment does not match function name. Seems like "mode" is the generic term
> to use instead of "assign".

Sure. Will fix.

> 
>> + */
>> +static ssize_t rdtgroup_mbm_assign_write(struct kernfs_open_file *of,
>> +                     char *buf, size_t nbytes,
>> +                     loff_t off)
>> +{
>> +    struct rdt_resource *r = of->kn->parent->priv;
>> +    int ret = 0;
>> +
>> +    if (!r->abmc_capable)
>> +        return -EINVAL;
>> +
>> +    /* Valid input requires a trailing newline */
>> +    if (nbytes == 0 || buf[nbytes - 1] != '\n')
>> +        return -EINVAL;
>> +
>> +    buf[nbytes - 1] = '\0';
>> +
>> +    cpus_read_lock();
>> +    mutex_lock(&rdtgroup_mutex);
>> +
>> +    rdt_last_cmd_clear();
>> +
>> +    if (!strcmp(buf, "mbm_legacy"))
>> +        resctrl_abmc_disable(RDT_RESOURCE_L3);
>> +    else if (!strcmp(buf, "abmc"))
>> +        ret = resctrl_abmc_enable(RDT_RESOURCE_L3);
>> +    else
>> +        ret = -EINVAL;
>> +
>> +    mutex_unlock(&rdtgroup_mutex);
>> +    cpus_read_unlock();
>> +
>> +    return ret ?: nbytes;
>> +}
>> +
>>   #ifdef CONFIG_PROC_CPU_RESCTRL
>>     /*
>> @@ -2087,9 +2124,10 @@ static struct rftype res_common_files[] = {
>>       },
>>       {
>>           .name        = "mbm_assign",
>> -        .mode        = 0444,
>> +        .mode        = 0644,
>>           .kf_ops        = &rdtgroup_kf_single_ops,
>>           .seq_show    = rdtgroup_mbm_assign_show,
>> +        .write        = rdtgroup_mbm_assign_write,
>>       },
>>       {
>>           .name        = "cpus",
> 
> 
> Reinette
> 

-- 
Thanks
Babu Moger