Skip to content

Commit fe2a20e

Browse files
babumogerbp3tk0v
authored andcommitted
x86/resctrl: Add multiple tasks to the resctrl group at once
The resctrl task assignment for monitor or control group needs to be done one at a time. For example: $mount -t resctrl resctrl /sys/fs/resctrl/ $mkdir /sys/fs/resctrl/ctrl_grp1 $echo 123 > /sys/fs/resctrl/ctrl_grp1/tasks $echo 456 > /sys/fs/resctrl/ctrl_grp1/tasks $echo 789 > /sys/fs/resctrl/ctrl_grp1/tasks This is not user-friendly when dealing with hundreds of tasks. Support multiple task assignment in one command with tasks ids separated by commas. For example: $echo 123,456,789 > /sys/fs/resctrl/ctrl_grp1/tasks Signed-off-by: Babu Moger <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Peter Newman <[email protected]> Reviewed-by: Tan Shaopeng <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Tan Shaopeng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aaa5fa3 commit fe2a20e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Documentation/arch/x86/resctrl.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,14 @@ All groups contain the following files:
306306
"tasks":
307307
Reading this file shows the list of all tasks that belong to
308308
this group. Writing a task id to the file will add a task to the
309-
group. If the group is a CTRL_MON group the task is removed from
309+
group. Multiple tasks can be added by separating the task ids
310+
with commas. Tasks will be assigned sequentially. Multiple
311+
failures are not supported. A single failure encountered while
312+
attempting to assign a task will cause the operation to abort and
313+
already added tasks before the failure will remain in the group.
314+
Failures will be logged to /sys/fs/resctrl/info/last_cmd_status.
315+
316+
If the group is a CTRL_MON group the task is removed from
310317
whichever previous CTRL_MON group owned the task and also from
311318
any MON group that owned the task. If the group is a MON group,
312319
then the task must already belong to the CTRL_MON parent of this

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,10 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
696696
char *buf, size_t nbytes, loff_t off)
697697
{
698698
struct rdtgroup *rdtgrp;
699+
char *pid_str;
699700
int ret = 0;
700701
pid_t pid;
701702

702-
if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0)
703-
return -EINVAL;
704703
rdtgrp = rdtgroup_kn_lock_live(of->kn);
705704
if (!rdtgrp) {
706705
rdtgroup_kn_unlock(of->kn);
@@ -715,7 +714,27 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
715714
goto unlock;
716715
}
717716

718-
ret = rdtgroup_move_task(pid, rdtgrp, of);
717+
while (buf && buf[0] != '\0' && buf[0] != '\n') {
718+
pid_str = strim(strsep(&buf, ","));
719+
720+
if (kstrtoint(pid_str, 0, &pid)) {
721+
rdt_last_cmd_printf("Task list parsing error pid %s\n", pid_str);
722+
ret = -EINVAL;
723+
break;
724+
}
725+
726+
if (pid < 0) {
727+
rdt_last_cmd_printf("Invalid pid %d\n", pid);
728+
ret = -EINVAL;
729+
break;
730+
}
731+
732+
ret = rdtgroup_move_task(pid, rdtgrp, of);
733+
if (ret) {
734+
rdt_last_cmd_printf("Error while processing task %d\n", pid);
735+
break;
736+
}
737+
}
719738

720739
unlock:
721740
rdtgroup_kn_unlock(of->kn);

0 commit comments

Comments
 (0)