Commit 2dfc29e7 authored by Lu Jialin's avatar Lu Jialin Committed by yanhaitao
Browse files

sched/psi: Export cgroup psi from cgroupv2 to cgroupv1

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8QUNW

----------------------------------------------

Export cgroup psi(cpu/memory/io/irq) from cgroup v2 to cgroupv1.
We attach cgroupv1 psi with cpuacct subsystem, referring to
(0c58735850e5: "ck: psi: Support PSI under cgroup v1")[1].

To make cgroupv1 psi more meaningful and accurate, processes should
have the same management in cpu/io/memory/cpuacct subsystem, which
is similar with the process management in cgroup v2.

[1] https://github.com/alibaba/cloud-kernel/commit/0c58735850e5ae4d98680a815eec8ef0ff0d5bae



Signed-off-by: default avatarLu Jialin <lujialin4@huawei.com>
parent c4069ab3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@ struct css_set;
#ifdef CONFIG_PSI

extern struct static_key_false psi_disabled;
#ifdef CONFIG_PSI_CGROUP_V1
extern struct static_key_true psi_v1_disabled;
#endif
extern struct psi_group psi_system;

void psi_init(void);
+10 −0
Original line number Diff line number Diff line
@@ -667,6 +667,16 @@ config PSI_DEFAULT_DISABLED

	  Say N if unsure.

config PSI_CGROUP_V1
       bool "Support PSI under cgroup v1"
       default n
       depends on PSI
       help
         If set, pressure stall information tracking will be used
         for cgroup v1 other than v2.

         Say N if unsure.

endmenu # "CPU/Task time and stats accounting"

config CPU_ISOLATION
+39 −0
Original line number Diff line number Diff line
@@ -3919,6 +3919,45 @@ bool cgroup_psi_enabled(void)
	return (cgroup_feature_disable_mask & (1 << OPT_FEATURE_PRESSURE)) == 0;
}

#ifdef CONFIG_PSI_CGROUP_V1
struct cftype cgroup_v1_psi_files[] = {
	{
		.name = "io.pressure",
		.flags = CFTYPE_NO_PREFIX,
		.seq_show = cgroup_io_pressure_show,
		.write = cgroup_io_pressure_write,
		.poll = cgroup_pressure_poll,
		.release = cgroup_pressure_release,
	},
	{
		.name = "memory.pressure",
		.flags = CFTYPE_NO_PREFIX,
		.seq_show = cgroup_memory_pressure_show,
		.write = cgroup_memory_pressure_write,
		.poll = cgroup_pressure_poll,
		.release = cgroup_pressure_release,
	},
	{
		.name = "cpu.pressure",
		.flags = CFTYPE_NO_PREFIX,
		.seq_show = cgroup_cpu_pressure_show,
		.write = cgroup_cpu_pressure_write,
		.poll = cgroup_pressure_poll,
		.release = cgroup_pressure_release,
	},
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
	{
		.name = "irq.pressure",
		.flags = CFTYPE_NO_PREFIX,
		.seq_show = cgroup_irq_pressure_show,
		.write = cgroup_irq_pressure_write,
		.poll = cgroup_pressure_poll,
		.release = cgroup_pressure_release,
	},
#endif
	{ }	/* terminate */
};
#endif
#else /* CONFIG_PSI */
bool cgroup_psi_enabled(void)
{
+25 −0
Original line number Diff line number Diff line
@@ -361,3 +361,28 @@ struct cgroup_subsys cpuacct_cgrp_subsys = {
	.legacy_cftypes	= files,
	.early_init	= true,
};

#ifdef CONFIG_PSI_CGROUP_V1
extern struct cftype cgroup_v1_psi_files[];

static int __init setup_psi_v1(char *str)
{
	if (!strcmp(str, "1"))
		static_branch_disable(&psi_v1_disabled);

	return 1;
}
__setup("psi_v1=", setup_psi_v1);

static int __init cgroup_v1_psi_init(void)
{
	if (static_branch_likely(&psi_v1_disabled))
		return 0;

	cgroup_add_legacy_cftypes(&cpuacct_cgrp_subsys, cgroup_v1_psi_files);

	return 0;
}

late_initcall_sync(cgroup_v1_psi_init);
#endif
+26 −1
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@
static int psi_bug __read_mostly;

DEFINE_STATIC_KEY_FALSE(psi_disabled);
DEFINE_STATIC_KEY_TRUE(psi_v1_disabled);
static DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);

#ifdef CONFIG_PSI_DEFAULT_DISABLED
@@ -881,11 +882,35 @@ static void psi_group_change(struct psi_group *group, int cpu,
		schedule_delayed_work(&group->avgs_work, PSI_FREQ);
}

#if defined(CONFIG_CGROUP_CPUACCT) && defined(CONFIG_PSI_CGROUP_V1)
static bool task_is_in_psi_v1(void)
{
	if (static_branch_likely(&psi_v1_disabled))
		return false;

	return !cgroup_subsys_on_dfl(cpuacct_cgrp_subsys);
}
#else
static bool task_is_in_psi_v1(void)
{
	return false;
}
#endif

static inline struct psi_group *task_psi_group(struct task_struct *task)
{
#ifdef CONFIG_CGROUPS
	if (static_branch_likely(&psi_cgroups_enabled))
	if (static_branch_likely(&psi_cgroups_enabled)) {
		if (task_is_in_psi_v1()) {
			struct cgroup *cgroup;

			rcu_read_lock();
			cgroup = task_cgroup(task, cpuacct_cgrp_id);
			rcu_read_unlock();
			return cgroup_psi(cgroup);
		}
		return cgroup_psi(task_dfl_cgroup(task));
	}
#endif
	return &psi_system;
}