Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d41bf8c9 authored by Tejun Heo's avatar Tejun Heo
Browse files

cgroup, sched: Move basic cpu stats from cgroup.stat to cpu.stat



The basic cpu stat is currently shown with "cpu." prefix in
cgroup.stat, and the same information is duplicated in cpu.stat when
cpu controller is enabled.  This is ugly and not very scalable as we
want to expand the coverage of stat information which is always
available.

This patch makes cgroup core always create "cpu.stat" file and show
the basic cpu stat there and calls the cpu controller to show the
extra stats when enabled.  This ensures that the same information
isn't presented in multiple places and makes future expansion of basic
stats easier.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
parent 0d593634
Loading
Loading
Loading
Loading
+5 −10
Original line number Original line Diff line number Diff line
@@ -886,15 +886,6 @@ All cgroup core files are prefixed with "cgroup."
		A dying cgroup can consume system resources not exceeding
		A dying cgroup can consume system resources not exceeding
		limits, which were active at the moment of cgroup deletion.
		limits, which were active at the moment of cgroup deletion.


	  cpu.usage_usec
		CPU time consumed in the subtree.

	  cpu.user_usec
		User CPU time consumed in the subtree.

	  cpu.system_usec
		System CPU time consumed in the subtree.



Controllers
Controllers
===========
===========
@@ -915,12 +906,16 @@ All time durations are in microseconds.


  cpu.stat
  cpu.stat
	A read-only flat-keyed file which exists on non-root cgroups.
	A read-only flat-keyed file which exists on non-root cgroups.
	This file exists whether the controller is enabled or not.


	It reports the following six stats:
	It always reports the following three stats:


	- usage_usec
	- usage_usec
	- user_usec
	- user_usec
	- system_usec
	- system_usec

	and the following three when the controller is enabled:

	- nr_periods
	- nr_periods
	- nr_throttled
	- nr_throttled
	- throttled_usec
	- throttled_usec
+2 −0
Original line number Original line Diff line number Diff line
@@ -569,6 +569,8 @@ struct cgroup_subsys {
	void (*css_released)(struct cgroup_subsys_state *css);
	void (*css_released)(struct cgroup_subsys_state *css);
	void (*css_free)(struct cgroup_subsys_state *css);
	void (*css_free)(struct cgroup_subsys_state *css);
	void (*css_reset)(struct cgroup_subsys_state *css);
	void (*css_reset)(struct cgroup_subsys_state *css);
	int (*css_extra_stat_show)(struct seq_file *seq,
				   struct cgroup_subsys_state *css);


	int (*can_attach)(struct cgroup_taskset *tset);
	int (*can_attach)(struct cgroup_taskset *tset);
	void (*cancel_attach)(struct cgroup_taskset *tset);
	void (*cancel_attach)(struct cgroup_taskset *tset);
+0 −2
Original line number Original line Diff line number Diff line
@@ -703,8 +703,6 @@ static inline void cpuacct_account_field(struct task_struct *tsk, int index,
					 u64 val) {}
					 u64 val) {}
#endif
#endif


void cgroup_stat_show_cputime(struct seq_file *seq, const char *prefix);

void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec);
void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec);
void __cgroup_account_cputime_field(struct cgroup *cgrp,
void __cgroup_account_cputime_field(struct cgroup *cgrp,
				    enum cpu_usage_stat index, u64 delta_exec);
				    enum cpu_usage_stat index, u64 delta_exec);
+1 −0
Original line number Original line Diff line number Diff line
@@ -205,6 +205,7 @@ int cgroup_task_count(const struct cgroup *cgrp);
void cgroup_stat_flush(struct cgroup *cgrp);
void cgroup_stat_flush(struct cgroup *cgrp);
int cgroup_stat_init(struct cgroup *cgrp);
int cgroup_stat_init(struct cgroup *cgrp);
void cgroup_stat_exit(struct cgroup *cgrp);
void cgroup_stat_exit(struct cgroup *cgrp);
void cgroup_stat_show_cputime(struct seq_file *seq);
void cgroup_stat_boot(void);
void cgroup_stat_boot(void);


/*
/*
+58 −2
Original line number Original line Diff line number Diff line
@@ -463,6 +463,28 @@ static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp,
		return &cgrp->self;
		return &cgrp->self;
}
}


/**
 * cgroup_tryget_css - try to get a cgroup's css for the specified subsystem
 * @cgrp: the cgroup of interest
 * @ss: the subsystem of interest
 *
 * Find and get @cgrp's css assocaited with @ss.  If the css doesn't exist
 * or is offline, %NULL is returned.
 */
static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp,
						     struct cgroup_subsys *ss)
{
	struct cgroup_subsys_state *css;

	rcu_read_lock();
	css = cgroup_css(cgrp, ss);
	if (!css || !css_tryget_online(css))
		css = NULL;
	rcu_read_unlock();

	return css;
}

/**
/**
 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem
 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem
 * @cgrp: the cgroup of interest
 * @cgrp: the cgroup of interest
@@ -3311,9 +3333,38 @@ static int cgroup_stat_show(struct seq_file *seq, void *v)
	seq_printf(seq, "nr_dying_descendants %d\n",
	seq_printf(seq, "nr_dying_descendants %d\n",
		   cgroup->nr_dying_descendants);
		   cgroup->nr_dying_descendants);


	cgroup_stat_show_cputime(seq, "cpu.");
	return 0;
}

static int __maybe_unused cgroup_extra_stat_show(struct seq_file *seq,
						 struct cgroup *cgrp, int ssid)
{
	struct cgroup_subsys *ss = cgroup_subsys[ssid];
	struct cgroup_subsys_state *css;
	int ret;

	if (!ss->css_extra_stat_show)
		return 0;


	css = cgroup_tryget_css(cgrp, ss);
	if (!css)
		return 0;
		return 0;

	ret = ss->css_extra_stat_show(seq, css);
	css_put(css);
	return ret;
}

static int cpu_stat_show(struct seq_file *seq, void *v)
{
	struct cgroup *cgrp = seq_css(seq)->cgroup;
	int ret = 0;

	cgroup_stat_show_cputime(seq);
#ifdef CONFIG_CGROUP_SCHED
	ret = cgroup_extra_stat_show(seq, cgrp, cpu_cgrp_id);
#endif
	return ret;
}
}


static int cgroup_file_open(struct kernfs_open_file *of)
static int cgroup_file_open(struct kernfs_open_file *of)
@@ -4423,6 +4474,11 @@ static struct cftype cgroup_base_files[] = {
		.name = "cgroup.stat",
		.name = "cgroup.stat",
		.seq_show = cgroup_stat_show,
		.seq_show = cgroup_stat_show,
	},
	},
	{
		.name = "cpu.stat",
		.flags = CFTYPE_NOT_ON_ROOT,
		.seq_show = cpu_stat_show,
	},
	{ }	/* terminate */
	{ }	/* terminate */
};
};


Loading