Skip to content

Commit e79f15a

Browse files
yu-chen-surfsuryasaimadhu
authored andcommitted
x86/resctrl: Add task resctrl information display
Monitoring tools that want to find out which resctrl control and monitor groups a task belongs to must currently read the "tasks" file in every group until they locate the process ID. Add an additional file /proc/{pid}/cpu_resctrl_groups to provide this information: 1) res: mon: resctrl is not available. 2) res:/ mon: Task is part of the root resctrl control group, and it is not associated to any monitor group. 3) res:/ mon:mon0 Task is part of the root resctrl control group and monitor group mon0. 4) res:group0 mon: Task is part of resctrl control group group0, and it is not associated to any monitor group. 5) res:group0 mon:mon1 Task is part of resctrl control group group0 and monitor group mon1. Signed-off-by: Chen Yu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Jinshi Chen <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 536a0d8 commit e79f15a

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ config X86_CPU_RESCTRL
456456
bool "x86 CPU resource control support"
457457
depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
458458
select KERNFS
459+
select PROC_CPU_RESCTRL if PROC_FS
459460
help
460461
Enable x86 CPU resource control support.
461462

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,92 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of,
729729
return ret;
730730
}
731731

732+
#ifdef CONFIG_PROC_CPU_RESCTRL
733+
734+
/*
735+
* A task can only be part of one resctrl control group and of one monitor
736+
* group which is associated to that control group.
737+
*
738+
* 1) res:
739+
* mon:
740+
*
741+
* resctrl is not available.
742+
*
743+
* 2) res:/
744+
* mon:
745+
*
746+
* Task is part of the root resctrl control group, and it is not associated
747+
* to any monitor group.
748+
*
749+
* 3) res:/
750+
* mon:mon0
751+
*
752+
* Task is part of the root resctrl control group and monitor group mon0.
753+
*
754+
* 4) res:group0
755+
* mon:
756+
*
757+
* Task is part of resctrl control group group0, and it is not associated
758+
* to any monitor group.
759+
*
760+
* 5) res:group0
761+
* mon:mon1
762+
*
763+
* Task is part of resctrl control group group0 and monitor group mon1.
764+
*/
765+
int proc_resctrl_show(struct seq_file *s, struct pid_namespace *ns,
766+
struct pid *pid, struct task_struct *tsk)
767+
{
768+
struct rdtgroup *rdtg;
769+
int ret = 0;
770+
771+
mutex_lock(&rdtgroup_mutex);
772+
773+
/* Return empty if resctrl has not been mounted. */
774+
if (!static_branch_unlikely(&rdt_enable_key)) {
775+
seq_puts(s, "res:\nmon:\n");
776+
goto unlock;
777+
}
778+
779+
list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) {
780+
struct rdtgroup *crg;
781+
782+
/*
783+
* Task information is only relevant for shareable
784+
* and exclusive groups.
785+
*/
786+
if (rdtg->mode != RDT_MODE_SHAREABLE &&
787+
rdtg->mode != RDT_MODE_EXCLUSIVE)
788+
continue;
789+
790+
if (rdtg->closid != tsk->closid)
791+
continue;
792+
793+
seq_printf(s, "res:%s%s\n", (rdtg == &rdtgroup_default) ? "/" : "",
794+
rdtg->kn->name);
795+
seq_puts(s, "mon:");
796+
list_for_each_entry(crg, &rdtg->mon.crdtgrp_list,
797+
mon.crdtgrp_list) {
798+
if (tsk->rmid != crg->mon.rmid)
799+
continue;
800+
seq_printf(s, "%s", crg->kn->name);
801+
break;
802+
}
803+
seq_putc(s, '\n');
804+
goto unlock;
805+
}
806+
/*
807+
* The above search should succeed. Otherwise return
808+
* with an error.
809+
*/
810+
ret = -ENOENT;
811+
unlock:
812+
mutex_unlock(&rdtgroup_mutex);
813+
814+
return ret;
815+
}
816+
#endif
817+
732818
static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
733819
struct seq_file *seq, void *v)
734820
{

fs/proc/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ config PROC_CHILDREN
103103
config PROC_PID_ARCH_STATUS
104104
def_bool n
105105
depends on PROC_FS
106+
107+
config PROC_CPU_RESCTRL
108+
def_bool n
109+
depends on PROC_FS

fs/proc/base.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include <linux/sched/debug.h>
9595
#include <linux/sched/stat.h>
9696
#include <linux/posix-timers.h>
97+
#include <linux/resctrl.h>
9798
#include <trace/events/oom.h>
9899
#include "internal.h"
99100
#include "fd.h"
@@ -3060,6 +3061,9 @@ static const struct pid_entry tgid_base_stuff[] = {
30603061
#endif
30613062
#ifdef CONFIG_CGROUPS
30623063
ONE("cgroup", S_IRUGO, proc_cgroup_show),
3064+
#endif
3065+
#ifdef CONFIG_PROC_CPU_RESCTRL
3066+
ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
30633067
#endif
30643068
ONE("oom_score", S_IRUGO, proc_oom_score),
30653069
REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
@@ -3460,6 +3464,9 @@ static const struct pid_entry tid_base_stuff[] = {
34603464
#endif
34613465
#ifdef CONFIG_CGROUPS
34623466
ONE("cgroup", S_IRUGO, proc_cgroup_show),
3467+
#endif
3468+
#ifdef CONFIG_PROC_CPU_RESCTRL
3469+
ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
34633470
#endif
34643471
ONE("oom_score", S_IRUGO, proc_oom_score),
34653472
REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),

include/linux/resctrl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _RESCTRL_H
3+
#define _RESCTRL_H
4+
5+
#ifdef CONFIG_PROC_CPU_RESCTRL
6+
7+
int proc_resctrl_show(struct seq_file *m,
8+
struct pid_namespace *ns,
9+
struct pid *pid,
10+
struct task_struct *tsk);
11+
12+
#endif
13+
14+
#endif /* _RESCTRL_H */

0 commit comments

Comments
 (0)