Commit 4a69b565 authored by Lu Jialin's avatar Lu Jialin Committed by yanhaitao
Browse files

sched/psi: Introduce pressure.stat in psi

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



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

Introduce pressure.stat in psi for cgroupv1 and system, which will show
the fine grained time tracking for cgroup memory reclaim.

for example:

/test # cat /tmp/cpuacct/test/pressure.stat
cgroup_memory_reclaim
some avg10=45.78 avg60=10.40 avg300=2.26 total=13491160
full avg10=0.00 avg60=0.00 avg300=0.00 total=0

Signed-off-by: default avatarLu Jialin <lujialin4@huawei.com>
parent 0df60cce
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ void psi_trigger_destroy(struct psi_trigger *t);
__poll_t psi_trigger_poll(void **trigger_ptr, struct file *file,
			poll_table *wait);

#ifdef CONFIG_PSI_FINE_GRAINED
int psi_stat_show(struct seq_file *s, struct psi_group *group);
#endif

#ifdef CONFIG_CGROUPS
static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
{
+12 −0
Original line number Diff line number Diff line
@@ -3920,6 +3920,13 @@ bool cgroup_psi_enabled(void)
}

#ifdef CONFIG_PSI_CGROUP_V1
#ifdef CONFIG_PSI_FINE_GRAINED
static int cgroup_psi_stat_show(struct seq_file *seq, void *v)
{
	return psi_stat_show(seq, cgroup_psi(seq_css(seq)->cgroup));
}
#endif

struct cftype cgroup_v1_psi_files[] = {
	{
		.name = "io.pressure",
@@ -3955,6 +3962,11 @@ struct cftype cgroup_v1_psi_files[] = {
		.release = cgroup_pressure_release,
	},
#endif
	{
		.name = "pressure.stat",
		.flags = CFTYPE_NO_PREFIX,
		.seq_show = cgroup_psi_stat_show,
	},
	{ }	/* terminate */
};
#endif
+61 −0
Original line number Diff line number Diff line
@@ -1814,6 +1814,64 @@ static const struct proc_ops psi_cpu_proc_ops = {
	.proc_release	= psi_fop_release,
};

#ifdef CONFIG_PSI_FINE_GRAINED
static const char *const psi_stat_names[] = {
	"cgroup_memory_reclaim",
};

int psi_stat_show(struct seq_file *m, struct psi_group *group)
{
	int i;
	u64 now;

	if (static_branch_likely(&psi_disabled))
		return -EOPNOTSUPP;

	mutex_lock(&group->avgs_lock);
	now = sched_clock();
	collect_percpu_times(group, PSI_AVGS, NULL);
	if (now >= group->avg_next_update)
		group->avg_next_update = update_averages(group, now);
	mutex_unlock(&group->avgs_lock);

	for (i = 0; i < NR_PSI_STAT_STATES; i++) {
		unsigned long avg[3] = {0, };
		int w;
		u64 total;
		bool is_full = i % 2;

		for (w = 0; w < 3; w++)
			avg[w] = group->fine_grained_avg[i][w];
		total = div_u64(group->fine_grained_total[PSI_AVGS][i], NSEC_PER_USEC);
		if (!is_full)
			seq_printf(m, "%s\n", psi_stat_names[i / 2]);
		seq_printf(m, "%s avg10=%lu.%02lu avg60=%lu.%02lu avg300=%lu.%02lu total=%llu\n",
			   is_full ? "full" : "some",
			   LOAD_INT(avg[0]), LOAD_FRAC(avg[0]),
			   LOAD_INT(avg[1]), LOAD_FRAC(avg[1]),
			   LOAD_INT(avg[2]), LOAD_FRAC(avg[2]),
			   total);
	}
	return 0;
}
static int system_psi_stat_show(struct seq_file *m, void *v)
{
	return psi_stat_show(m, &psi_system);
}

static int psi_stat_open(struct inode *inode, struct file *file)
{
	return single_open(file, system_psi_stat_show, NULL);
}

static const struct proc_ops psi_stat_proc_ops = {
	.proc_open	= psi_stat_open,
	.proc_read	= seq_read,
	.proc_lseek	= seq_lseek,
	.proc_release	= psi_fop_release,
};
#endif

#ifdef CONFIG_IRQ_TIME_ACCOUNTING
static int psi_irq_show(struct seq_file *m, void *v)
{
@@ -1850,6 +1908,9 @@ static int __init psi_proc_init(void)
		proc_create("pressure/cpu", 0666, NULL, &psi_cpu_proc_ops);
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
		proc_create("pressure/irq", 0666, NULL, &psi_irq_proc_ops);
#endif
#ifdef CONFIG_PSI_FINE_GRAINED
		proc_create("pressure/stat", 0666, NULL, &psi_stat_proc_ops);
#endif
	}
	return 0;