Skip to content

Commit 4244057

Browse files
committed
Merge branch 'x86-cache-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 resource control updates from Ingo Molnar: "The main change in this tree is the extension of the resctrl procfs ABI with a new file that helps tooling to navigate from tasks back to resctrl groups: /proc/{pid}/cpu_resctrl_groups. Also fix static key usage for certain feature combinations and simplify the task exit resctrl case" * 'x86-cache-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/resctrl: Add task resctrl information display x86/resctrl: Check monitoring static key in the MBM overflow handler x86/resctrl: Do not reconfigure exiting tasks
2 parents 6b90e71 + e79f15a commit 4244057

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

arch/x86/Kconfig

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

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
5757
}
5858

5959
DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
60+
DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
6061

6162
/**
6263
* struct mon_evt - Entry in the event list of a resource

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void mbm_handle_overflow(struct work_struct *work)
514514

515515
mutex_lock(&rdtgroup_mutex);
516516

517-
if (!static_branch_likely(&rdt_enable_key))
517+
if (!static_branch_likely(&rdt_mon_enable_key))
518518
goto out_unlock;
519519

520520
d = get_domain_from_cpu(cpu, &rdt_resources_all[RDT_RESOURCE_L3]);
@@ -543,7 +543,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)
543543
unsigned long delay = msecs_to_jiffies(delay_ms);
544544
int cpu;
545545

546-
if (!static_branch_likely(&rdt_enable_key))
546+
if (!static_branch_likely(&rdt_mon_enable_key))
547547
return;
548548
cpu = cpumask_any(&dom->cpu_mask);
549549
dom->mbm_work_cpu = cpu;

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,15 @@ static void move_myself(struct callback_head *head)
532532
kfree(rdtgrp);
533533
}
534534

535+
if (unlikely(current->flags & PF_EXITING))
536+
goto out;
537+
535538
preempt_disable();
536539
/* update PQR_ASSOC MSR to make resource group go into effect */
537540
resctrl_sched_in();
538541
preempt_enable();
539542

543+
out:
540544
kfree(callback);
541545
}
542546

@@ -725,6 +729,92 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of,
725729
return ret;
726730
}
727731

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+
728818
static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
729819
struct seq_file *seq, void *v)
730820
{

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
@@ -95,6 +95,7 @@
9595
#include <linux/sched/stat.h>
9696
#include <linux/posix-timers.h>
9797
#include <linux/time_namespace.h>
98+
#include <linux/resctrl.h>
9899
#include <trace/events/oom.h>
99100
#include "internal.h"
100101
#include "fd.h"
@@ -3154,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
31543155
#endif
31553156
#ifdef CONFIG_CGROUPS
31563157
ONE("cgroup", S_IRUGO, proc_cgroup_show),
3158+
#endif
3159+
#ifdef CONFIG_PROC_CPU_RESCTRL
3160+
ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
31573161
#endif
31583162
ONE("oom_score", S_IRUGO, proc_oom_score),
31593163
REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
@@ -3554,6 +3558,9 @@ static const struct pid_entry tid_base_stuff[] = {
35543558
#endif
35553559
#ifdef CONFIG_CGROUPS
35563560
ONE("cgroup", S_IRUGO, proc_cgroup_show),
3561+
#endif
3562+
#ifdef CONFIG_PROC_CPU_RESCTRL
3563+
ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
35573564
#endif
35583565
ONE("oom_score", S_IRUGO, proc_oom_score),
35593566
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)