[PATCH v2 09/14] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy

Reinette Chatre posted 14 patches 2 weeks ago
[PATCH v2 09/14] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy
Posted by Reinette Chatre 2 weeks ago
info/last_cmd_status is intended to contain more information if a write to
any resctrl file fails. Writes to max_threshold_occupancy did not receive
last_cmd_status support during initial last_cmd_status enabling. Add it now.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v1:
- Add Ben's RB tag.
---
 fs/resctrl/rdtgroup.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 111bff8e33fd..6fa5c8f14e3a 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1238,16 +1238,27 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
 	unsigned int bytes;
 	int ret;
 
+	mutex_lock(&rdtgroup_mutex);
+	rdt_last_cmd_clear();
+
 	ret = kstrtouint(buf, 0, &bytes);
-	if (ret)
-		return ret;
+	if (ret) {
+		rdt_last_cmd_puts("Invalid input\n");
+		goto out_unlock;
+	}
 
-	if (bytes > resctrl_rmid_realloc_limit)
-		return -EINVAL;
+	if (bytes > resctrl_rmid_realloc_limit) {
+		rdt_last_cmd_printf("Exceeds limit (before adjustment) of %u bytes\n",
+				    resctrl_rmid_realloc_limit);
+		ret = -EINVAL;
+		goto out_unlock;
+	}
 
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
 
-	return nbytes;
+out_unlock:
+	mutex_unlock(&rdtgroup_mutex);
+	return ret ?: nbytes;
 }
 
 /*
-- 
2.50.1
Re: [PATCH v2 09/14] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy
Posted by Chen, Yu C 1 week, 4 days ago
On 3/21/2026 6:03 AM, Reinette Chatre wrote:
> info/last_cmd_status is intended to contain more information if a write to
> any resctrl file fails. Writes to max_threshold_occupancy did not receive
> last_cmd_status support during initial last_cmd_status enabling. Add it now.
> 
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> Reviewed-by: Ben Horgan <ben.horgan@arm.com>
> ---
> Changes since v1:
> - Add Ben's RB tag.
> ---
>   fs/resctrl/rdtgroup.c | 21 ++++++++++++++++-----
>   1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 111bff8e33fd..6fa5c8f14e3a 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -1238,16 +1238,27 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
>   	unsigned int bytes;
>   	int ret;
>   
> +	mutex_lock(&rdtgroup_mutex);

Maybe guard(mutex)(&rdtgroup_mutex) and return ret when failed
so we can get rid of goto out_unlock

thanks,
Chenyu
Re: [PATCH v2 09/14] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy
Posted by Reinette Chatre 1 week, 4 days ago
Hi Chenyu,

On 3/23/26 2:14 AM, Chen, Yu C wrote:
> On 3/21/2026 6:03 AM, Reinette Chatre wrote:
>> info/last_cmd_status is intended to contain more information if a write to
>> any resctrl file fails. Writes to max_threshold_occupancy did not receive
>> last_cmd_status support during initial last_cmd_status enabling. Add it now.
>>
>> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
>> Reviewed-by: Ben Horgan <ben.horgan@arm.com>
>> ---
>> Changes since v1:
>> - Add Ben's RB tag.
>> ---
>>   fs/resctrl/rdtgroup.c | 21 ++++++++++++++++-----
>>   1 file changed, 16 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
>> index 111bff8e33fd..6fa5c8f14e3a 100644
>> --- a/fs/resctrl/rdtgroup.c
>> +++ b/fs/resctrl/rdtgroup.c
>> @@ -1238,16 +1238,27 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
>>       unsigned int bytes;
>>       int ret;
>>   +    mutex_lock(&rdtgroup_mutex);
> 
> Maybe guard(mutex)(&rdtgroup_mutex) and return ret when failed
> so we can get rid of goto out_unlock

Will do. There is no plan to switch existing patterns to use guard(), but using it in
cases like this where it is a new introduction to a function that does not already
use goto should be fine.

Reinette