Skip to contentSkip to conversation

CPU controller statistics (v5)

-mm Balbir Singh 3 participants 6 messages Jun 3, 2008 – Jun 11, 2008 cgroup

lore
Share & tools
lore
#0 lore raw

From: Balaji Rao <[email protected]>

This is a repost of Balaji's patches at
http://kerneltrap.org/mailarchive/linux-kernel/2008/5/11/1791504
I've made changes to the format exported to user space. I've used clock_t, since /proc/<pid>/stat uses the same format to export data.

I've run some basic tests to verify that the patches work.

Andrew could you please consider them for inclusion if there are no objections to this patch. This patch helps fill a void in the controllers we have w.r.t. statistics

The patch is against the latest git.

---
 include/linux/cgroup.h |    1 
 kernel/cgroup.c        |    6 ++
 kernel/sched.c         |  100
 3 files changed, 106 insertions(+), 1 deletion(-)
include/linux/cgroup.h +1 -0
index e155aa7..60a25cb 100644
@@ -293,6 +293,7 @@ int cgroup_is_descendant(const struct cgroup *cgrp);
 struct cgroup_subsys {
 	struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
 						  struct cgroup *cgrp);
+	void (*initialize)(int early);
 	void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	int (*can_attach)(struct cgroup_subsys *ss,
kernel/cgroup.c +6 -0
index 15ac0e1..77569d7 100644
@@ -2553,6 +2553,9 @@ int __init cgroup_init_early(void)
 
 		if (ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(1);
 	}
 	return 0;
 }
@@ -2577,6 +2580,9 @@ int __init cgroup_init(void)
 		struct cgroup_subsys *ss = subsys[i];
 		if (!ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(0);
 	}
 
 	/* Add init_css_set to the hash table */
kernel/sched.c +99 -1

158 lines not on this page · raw message

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
#1 lore raw
Quoted 7 lines · On Wed, 4 Jun 2008 01:35:15 +0530 Balbir Singh <[email protected]>…

From: Balaji Rao <[email protected]>

This is a repost of Balaji's patches at
http://kerneltrap.org/mailarchive/linux-kernel/2008/5/11/1791504
I've made changes to the format exported to user space. I've used clock_t, since /proc/<pid>/stat uses the same format to export data.

Quoted 8 lines

I've run some basic tests to verify that the patches work.

Andrew could you please consider them for inclusion if there are no objections to this patch. This patch helps fill a void in the controllers we have w.r.t. statistics

The patch is against the latest git.

That is not a changelog. Please always include a (good) changelog with each iteration of a patch.

Were all my previous comments addressed? Most, it seems.

Quoted 28 lines
include/linux/cgroup.h +1 -0
index e155aa7..60a25cb 100644
@@ -293,6 +293,7 @@ int cgroup_is_descendant(const struct cgroup *cgrp);
 struct cgroup_subsys {
 	struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
 						  struct cgroup *cgrp);
+	void (*initialize)(int early);
 	void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	int (*can_attach)(struct cgroup_subsys *ss,
kernel/cgroup.c +3 -0
index 15ac0e1..77569d7 100644
@@ -2553,6 +2553,9 @@ int __init cgroup_init_early(void)
 
 		if (ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(1);
 	}
 	return 0;
 }

kernel/cgroup.c int __init cgroup_init(void) · line 2585

Quoted 6 lines
kernel/cgroup.c +3 -0
@@ -2577,6 +2580,9 @@ int __init cgroup_init(void)
 		struct cgroup_subsys *ss = subsys[i];
 		if (!ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(0);

Can we avoid these tests? By requiring that cgroup_subsys.initialize() always be non-zero? It might make sense, and it might not...

Quoted 62 lines
kernel/cgroup.c +0 -0
 	}
 
 	/* Add init_css_set to the hash table */
kernel/sched.c +31 -1
index bfb8ad8..d6df3d3 100644
@@ -245,11 +245,32 @@ static DEFINE_MUTEX(sched_domains_mutex);
 struct cfs_rq;
 
 static LIST_HEAD(task_groups);
+#ifdef CONFIG_CGROUP_SCHED
+#define CPU_CGROUP_STAT_THRESHOLD (1 << 30)
+enum cpu_cgroup_stat_index {
+	CPU_CGROUP_STAT_UTIME, /* Usertime of the task group */
+	CPU_CGROUP_STAT_STIME, /* Kerneltime of the task group */
+
+	CPU_CGROUP_STAT_NSTATS,
+};
+
+struct cpu_cgroup_stat {
+	struct percpu_counter cpustat[CPU_CGROUP_STAT_NSTATS];
+};
+
+static void __cpu_cgroup_stat_add(struct cpu_cgroup_stat *stat,
+		enum cpu_cgroup_stat_index idx, s64 val)
+{
+	if (stat)
+		percpu_counter_add(&stat->cpustat[idx], val);
+}
+#endif
 
 /* task group related information */
 struct task_group {
 #ifdef CONFIG_CGROUP_SCHED
 	struct cgroup_subsys_state css;
+	struct cpu_cgroup_stat *stat;
 #endif
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
@@ -3885,6 +3906,16 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
 		cpustat->nice = cputime64_add(cpustat->nice, tmp);
 	else
 		cpustat->user = cputime64_add(cpustat->user, tmp);
+
+       /* Charge the task's group */
+#ifdef CONFIG_CGROUP_SCHED
+	{
+		struct task_group *tg;
+		tg = task_group(p);
+		__cpu_cgroup_stat_add(tg->stat, CPU_CGROUP_STAT_UTIME,
+				cputime_to_msecs(cputime) * NSEC_PER_MSEC);
+	}
+#endif
 }
 
 /*
@@ -3942,8 +3973,17 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
 		cpustat->irq = cputime64_add(cpustat->irq, tmp);
 	else if (softirq_count())
 		cpustat->softirq = cputime64_add(cpustat->softirq, tmp);
-	else if (p != rq->idle)

kernel/sched.c void account_system_time(struct task_struct *p, int hardirq_offset, · line 3985

Quoted 10 lines
kernel/sched.c +9 -0
+	else if (p != rq->idle) {
 		cpustat->system = cputime64_add(cpustat->system, tmp);
+#ifdef CONFIG_CGROUP_SCHED
+		{
+			struct task_group *tg;
+			tg = task_group(p);
+			__cpu_cgroup_stat_add(tg->stat, CPU_CGROUP_STAT_STIME,
+				cputime_to_msecs(cputime) * NSEC_PER_MSEC);
+		}
+#endif

The above two almost-identical code sequences should, I suggest, be broken out into a standalone helper function, which has two implementations, the CONFIG_CGROUP_SCHED=n version of which is a do-nothing stub, in the usual fashion.

I suggested this last time.

Quoted 7 lines
kernel/sched.c +1 -0
+	}
 	else if (atomic_read(&rq->nr_iowait) > 0)
 		cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
 	else
@@ -8325,6 +8365,24 @@ unsigned long sched_group_shares(struct task_group *tg)
 }
 #endif

kernel/sched.c unsigned long sched_group_shares(struct task_group *tg) · line 8376

Quoted 10 lines
kernel/sched.c +9 -0
 
+static s64 cpu_cgroup_read_stat(struct cpu_cgroup_stat *stat,
+		enum cpu_cgroup_stat_index idx)
+{
+	if (stat)
+		return nsec_to_clock_t(
+				percpu_counter_read(&stat->cpustat[idx]));
+
+	return 0;
+}

ick at the code layout. How about this:

	if (!stat)
		return 0;
	return nsec_to_clock_t(percpu_counter_read(&stat->cpustat[idx]));

?

Quoted 12 lines
kernel/sched.c +8 -0
+static const struct cpu_cgroup_stat_desc {
+	const char *msg;
+	u64 unit;
+} cpu_cgroup_stat_desc[] = {
+	[CPU_CGROUP_STAT_UTIME] = { "utime", 1, },
+	[CPU_CGROUP_STAT_STIME] = { "stime", 1, },
+};
+
 #ifdef CONFIG_RT_GROUP_SCHED
 /*
  * Ensure that the real time constraints are schedulable.

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8618

Quoted 10 lines
kernel/sched.c +7 -0
@@ -8551,10 +8609,41 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp)
 			    struct task_group, css);
 }
 
+static int cpu_cgroup_stats_show(struct cgroup *cgrp, struct cftype *cft,
+		struct cgroup_map_cb *cb)
+{
+	struct task_group *tg = cgroup_tg(cgrp);
+	struct cpu_cgroup_stat *stat = tg->stat;
+	int i;
+	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++) {

Please prefer to put a blank line between end-of-locals and start-of-code. It does make the code somewhat easier to read.

Quoted 4 lines
kernel/sched.c +4 -0
+		s64 val;
+		val = cpu_cgroup_read_stat(stat, i);
+		val *= cpu_cgroup_stat_desc[i].unit;
+		cb->fill(cb, cpu_cgroup_stat_desc[i].msg, val);

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8632

Quoted 10 lines
kernel/sched.c +10 -0
+	}
+	return 0;
+}
+
+static void cpu_cgroup_initialize(int early)
+{
+	int i;
+	struct cpu_cgroup_stat *stat;
+
+	if (!early) {

like that.

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8637

Quoted 5 lines
kernel/sched.c +5 -0
+		stat = kmalloc(sizeof(struct cpu_cgroup_stat)
+				, GFP_KERNEL);
+		for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
+			percpu_counter_init(
+					&stat->cpustat[i], 0);

Suppose the kmalloc failed?

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8640

Quoted 3 lines
kernel/sched.c +3 -0
+		init_task_group.stat = stat;
+	}
+}

more icky layout, and what's that comma doing there?

Again, please use a bit of thought rather than blindly whacking in newlines everywhere.

static void cpu_cgroup_initialize(int early)

{
	int i;
	struct cpu_cgroup_stat *stat;

	if (early)
		return;

	stat = kmalloc(sizeof(struct cpu_cgroup_stat), GFP_KERNEL);
	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
		percpu_counter_init(&stat->cpustat[i], 0);
	init_task_group.stat = stat;
}

is better, yes?

Also, if this code is likely to be executed with any frequency then the test of `early' could be inlined:

static inline void cpu_cgroup_initialize(int early)

{
	if (unlikely(!early))
		__cpu_cgroup_initialize();
}

yes?

Quoted 9 lines
kernel/sched.c +1 -0
 static struct cgroup_subsys_state *
 cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp)
 {
 	struct task_group *tg, *parent;
+	int i;
 
 	if (!cgrp->parent) {
 		/* This is early initialization for the top cgroup */

kernel/sched.c cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) · line 8661

Quoted 6 lines
kernel/sched.c +3 -0
@@ -8567,6 +8656,10 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp)
 	if (IS_ERR(tg))
 		return ERR_PTR(-ENOMEM);
 
+	tg->stat = kmalloc(sizeof(struct cpu_cgroup_stat), GFP_KERNEL);
+	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
+		percpu_counter_init(&tg->stat->cpustat[i], 0);

Which will crash the machine if the kmalloc failed.

c'mon guys, that wasn't a great effort.

#2 lore raw
Quoted 16 lines · Andrew Morton
Quoted 13 lines · On Wed, 4 Jun 2008 01:35:15 +0530 Balbir Singh <[email protected]>…

From: Balaji Rao <[email protected]>

This is a repost of Balaji's patches at
http://kerneltrap.org/mailarchive/linux-kernel/2008/5/11/1791504
I've made changes to the format exported to user space. I've used clock_t, since /proc/<pid>/stat uses the same format to export data.

I've run some basic tests to verify that the patches work.

Andrew could you please consider them for inclusion if there are no objections to this patch. This patch helps fill a void in the controllers we have w.r.t. statistics

Quoted 6 lines
Quoted 2 lines

The patch is against the latest git.

That is not a changelog. Please always include a (good) changelog with each iteration of a patch.

Sure, will do

Quoted 2 lines

Were all my previous comments addressed? Most, it seems.

Yes, Balaji did work on addressing them

Quoted 28 lines
Quoted 28 lines
include/linux/cgroup.h +1 -0
index e155aa7..60a25cb 100644
@@ -293,6 +293,7 @@ int cgroup_is_descendant(const struct cgroup *cgrp);
 struct cgroup_subsys {
 	struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
 						  struct cgroup *cgrp);
+	void (*initialize)(int early);
 	void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
 	int (*can_attach)(struct cgroup_subsys *ss,
kernel/cgroup.c +3 -0
index 15ac0e1..77569d7 100644
@@ -2553,6 +2553,9 @@ int __init cgroup_init_early(void)
 
 		if (ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(1);
 	}
 	return 0;
 }
@@ -2577,6 +2580,9 @@ int __init cgroup_init(void)
 		struct cgroup_subsys *ss = subsys[i];
Quoted 9 lines

kernel/cgroup.c int __init cgroup_init(void) · line 2585

Quoted 5 lines
kernel/cgroup.c +3 -0
 		if (!ss->early_init)
 			cgroup_init_subsys(ss);
+
+		if (ss->initialize)
+			ss->initialize(0);

Can we avoid these tests? By requiring that cgroup_subsys.initialize() always be non-zero? It might make sense, and it might not...

They are really hard to avoid, otherwise we might be taking away the flexibility we have.

Quoted 78 lines
Quoted 62 lines
kernel/cgroup.c +0 -0
 	}
 
 	/* Add init_css_set to the hash table */
kernel/sched.c +31 -1
index bfb8ad8..d6df3d3 100644
@@ -245,11 +245,32 @@ static DEFINE_MUTEX(sched_domains_mutex);
 struct cfs_rq;
 
 static LIST_HEAD(task_groups);
+#ifdef CONFIG_CGROUP_SCHED
+#define CPU_CGROUP_STAT_THRESHOLD (1 << 30)
+enum cpu_cgroup_stat_index {
+	CPU_CGROUP_STAT_UTIME, /* Usertime of the task group */
+	CPU_CGROUP_STAT_STIME, /* Kerneltime of the task group */
+
+	CPU_CGROUP_STAT_NSTATS,
+};
+
+struct cpu_cgroup_stat {
+	struct percpu_counter cpustat[CPU_CGROUP_STAT_NSTATS];
+};
+
+static void __cpu_cgroup_stat_add(struct cpu_cgroup_stat *stat,
+		enum cpu_cgroup_stat_index idx, s64 val)
+{
+	if (stat)
+		percpu_counter_add(&stat->cpustat[idx], val);
+}
+#endif
 
 /* task group related information */
 struct task_group {
 #ifdef CONFIG_CGROUP_SCHED
 	struct cgroup_subsys_state css;
+	struct cpu_cgroup_stat *stat;
 #endif
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
@@ -3885,6 +3906,16 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
 		cpustat->nice = cputime64_add(cpustat->nice, tmp);
 	else
 		cpustat->user = cputime64_add(cpustat->user, tmp);
+
+       /* Charge the task's group */
+#ifdef CONFIG_CGROUP_SCHED
+	{
+		struct task_group *tg;
+		tg = task_group(p);
+		__cpu_cgroup_stat_add(tg->stat, CPU_CGROUP_STAT_UTIME,
+				cputime_to_msecs(cputime) * NSEC_PER_MSEC);
+	}
+#endif
 }
 
 /*
@@ -3942,8 +3973,17 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
 		cpustat->irq = cputime64_add(cpustat->irq, tmp);
 	else if (softirq_count())
 		cpustat->softirq = cputime64_add(cpustat->softirq, tmp);
-	else if (p != rq->idle)

kernel/sched.c void account_system_time(struct task_struct *p, int hardirq_offset, · line 3985

Quoted 10 lines
kernel/sched.c +9 -0
+	else if (p != rq->idle) {
 		cpustat->system = cputime64_add(cpustat->system, tmp);
+#ifdef CONFIG_CGROUP_SCHED
+		{
+			struct task_group *tg;
+			tg = task_group(p);
+			__cpu_cgroup_stat_add(tg->stat, CPU_CGROUP_STAT_STIME,
+				cputime_to_msecs(cputime) * NSEC_PER_MSEC);
+		}
+#endif

The above two almost-identical code sequences should, I suggest, be broken out into a standalone helper function, which has two implementations, the CONFIG_CGROUP_SCHED=n version of which is a do-nothing stub, in the usual fashion.

Quoted 2 lines

I suggested this last time.

OK, will do. I thought that we had addressed this, but we let this one slip. Will fix.

Quoted 20 lines
Quoted 7 lines
kernel/sched.c +1 -0
+	}
 	else if (atomic_read(&rq->nr_iowait) > 0)
 		cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
 	else
@@ -8325,6 +8365,24 @@ unsigned long sched_group_shares(struct task_group *tg)
 }
 #endif

kernel/sched.c unsigned long sched_group_shares(struct task_group *tg) · line 8376

Quoted 10 lines
kernel/sched.c +9 -0
 
+static s64 cpu_cgroup_read_stat(struct cpu_cgroup_stat *stat,
+		enum cpu_cgroup_stat_index idx)
+{
+	if (stat)
+		return nsec_to_clock_t(
+				percpu_counter_read(&stat->cpustat[idx]));
+
+	return 0;
+}

ick at the code layout. How about this:

Quoted 5 lines
	if (!stat)
		return 0;
	return nsec_to_clock_t(percpu_counter_read(&stat->cpustat[idx]));

?

Definitely! My bad again - I should have reviewed the patch more closely.

Quoted 16 lines
Quoted 16 lines
kernel/sched.c +8 -0
+static const struct cpu_cgroup_stat_desc {
+	const char *msg;
+	u64 unit;
+} cpu_cgroup_stat_desc[] = {
+	[CPU_CGROUP_STAT_UTIME] = { "utime", 1, },
+	[CPU_CGROUP_STAT_STIME] = { "stime", 1, },
+};
+
 #ifdef CONFIG_RT_GROUP_SCHED
 /*
  * Ensure that the real time constraints are schedulable.
@@ -8551,10 +8609,41 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp)
 			    struct task_group, css);
 }
 
Quoted 11 lines

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8618

Quoted 7 lines
kernel/sched.c +7 -0
+static int cpu_cgroup_stats_show(struct cgroup *cgrp, struct cftype *cft,
+		struct cgroup_map_cb *cb)
+{
+	struct task_group *tg = cgroup_tg(cgrp);
+	struct cpu_cgroup_stat *stat = tg->stat;
+	int i;
+	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++) {

Please prefer to put a blank line between end-of-locals and start-of-code. It does make the code somewhat easier to read.

Sure, will fix.

Quoted 18 lines
Quoted 5 lines
kernel/sched.c +4 -0
+		s64 val;
+		val = cpu_cgroup_read_stat(stat, i);
+		val *= cpu_cgroup_stat_desc[i].unit;
+		cb->fill(cb, cpu_cgroup_stat_desc[i].msg, val);

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8632

Quoted 10 lines
kernel/sched.c +10 -0
+	}
+	return 0;
+}
+
+static void cpu_cgroup_initialize(int early)
+{
+	int i;
+	struct cpu_cgroup_stat *stat;
+
+	if (!early) {

like that.

Quoted 8 lines

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8637

Quoted 5 lines
kernel/sched.c +5 -0
+		stat = kmalloc(sizeof(struct cpu_cgroup_stat)
+				, GFP_KERNEL);
+		for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
+			percpu_counter_init(
+					&stat->cpustat[i], 0);

Suppose the kmalloc failed?

Good point. Just goes to show that picking up someone elses code and working off
it, requires more effort that I put in.

Quoted 9 lines

kernel/sched.c static inline struct task_group *cgroup_tg(struct cgroup *cgrp) · line 8640

Quoted 3 lines
kernel/sched.c +3 -0
+		init_task_group.stat = stat;
+	}
+}

more icky layout, and what's that comma doing there?

Again, please use a bit of thought rather than blindly whacking in newlines everywhere.

Sure, will do

Quoted 14 lines

static void cpu_cgroup_initialize(int early)

{
	int i;
	struct cpu_cgroup_stat *stat;

	if (early)
		return;

	stat = kmalloc(sizeof(struct cpu_cgroup_stat), GFP_KERNEL);
	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
		percpu_counter_init(&stat->cpustat[i], 0);
	init_task_group.stat = stat;
}
Quoted 3 lines

is better, yes?

Yep

Quoted 11 lines

Also, if this code is likely to be executed with any frequency then the test of `early' could be inlined:

static inline void cpu_cgroup_initialize(int early)

{
	if (unlikely(!early))
		__cpu_cgroup_initialize();
}

yes?

Definitely

Quoted 21 lines
Quoted 10 lines
kernel/sched.c +1 -0
 static struct cgroup_subsys_state *
 cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp)
 {
 	struct task_group *tg, *parent;
+	int i;
 
 	if (!cgrp->parent) {
 		/* This is early initialization for the top cgroup */

kernel/sched.c cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) · line 8661

Quoted 6 lines
kernel/sched.c +3 -0
@@ -8567,6 +8656,10 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp)
 	if (IS_ERR(tg))
 		return ERR_PTR(-ENOMEM);
 
+	tg->stat = kmalloc(sizeof(struct cpu_cgroup_stat), GFP_KERNEL);
+	for (i = 0; i < CPU_CGROUP_STAT_NSTATS; i++)
+		percpu_counter_init(&tg->stat->cpustat[i], 0);

Which will crash the machine if the kmalloc failed.

Quoted 1 line

c'mon guys, that wasn't a great effort.

Yes, true. I might be better off, rewriting it. I'll see.

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
#3 lore raw
Quoted 7 lines · Balbir Singh
Quoted 4 lines

Can we avoid these tests? By requiring that cgroup_subsys.initialize() always be non-zero? It might make sense, and it might not...

They are really hard to avoid, otherwise we might be taking away the flexibility we have.

And this is something that only gets called at startup.

Quoted 10 lines
Quoted 10 lines

Also, if this code is likely to be executed with any frequency then the test of `early' could be inlined:

static inline void cpu_cgroup_initialize(int early)

{
      if (unlikely(!early))
              __cpu_cgroup_initialize();
}
Quoted 4 lines
Quoted 2 lines

yes?

Definitely

Er, no. It gets called twice at system boot (once with early=true and once with early=false) via a vtable. So there's nothing to optimize for, and making the function inline won't help since the compiler needs to take its address.

Paul

#4 lore raw
In reply to Balbir Singh
Quoted 27 lines · Balbir Singh
include/linux/cgroup.h +1 -0
index e155aa7..60a25cb 100644
@@ -293,6 +293,7 @@ int cgroup_is_descendant(const struct cgroup *cgrp);
 struct cgroup_subsys {
       struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
                                                 struct cgroup *cgrp);
+       void (*initialize)(int early);
       void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
       void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
       int (*can_attach)(struct cgroup_subsys *ss,
kernel/cgroup.c +3 -0
index 15ac0e1..77569d7 100644
@@ -2553,6 +2553,9 @@ int __init cgroup_init_early(void)
 
               if (ss->early_init)
                       cgroup_init_subsys(ss);
+
+               if (ss->initialize)
+                       ss->initialize(1);
       }
       return 0;
 }

kernel/cgroup.c int __init cgroup_init(void) · line 2586

Quoted 7 lines
kernel/cgroup.c +3 -0
@@ -2577,6 +2580,9 @@ int __init cgroup_init(void)
               struct cgroup_subsys *ss = subsys[i];
               if (!ss->early_init)
                       cgroup_init_subsys(ss);
+
+               if (ss->initialize)
+                       ss->initialize(0);
       }

This seems a little weird - even if the subsystem didn't want early initialization, we call its initialize() during early setup?

I assume the idea is to move away from the current model where the subsystem is expected to initialize itself during the first call to its create() method, when it gets passed a cgroup with a NULL parent? I agree that was a bit icky. How about we call ss->initialize() from cgroup_init_subsys()? Then we wouldn't need the "early" parameter, since it would be implicit based on whether the subsystem wanted early initialization or not.

Also, if you're adding a new subsystem method, you should document it in Documentation/cgroups.txt

Paul

#5 lore raw
Quoted 39 lines · Paul Menage
Quoted 27 lines · Balbir Singh
include/linux/cgroup.h +1 -0
index e155aa7..60a25cb 100644
@@ -293,6 +293,7 @@ int cgroup_is_descendant(const struct cgroup *cgrp);
 struct cgroup_subsys {
       struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
                                                 struct cgroup *cgrp);
+       void (*initialize)(int early);
       void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
       void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
       int (*can_attach)(struct cgroup_subsys *ss,
kernel/cgroup.c +3 -0
index 15ac0e1..77569d7 100644
@@ -2553,6 +2553,9 @@ int __init cgroup_init_early(void)
 
               if (ss->early_init)
                       cgroup_init_subsys(ss);
+
+               if (ss->initialize)
+                       ss->initialize(1);
       }
       return 0;
 }

kernel/cgroup.c int __init cgroup_init(void) · line 2586

Quoted 7 lines
kernel/cgroup.c +3 -0
@@ -2577,6 +2580,9 @@ int __init cgroup_init(void)
               struct cgroup_subsys *ss = subsys[i];
               if (!ss->early_init)
                       cgroup_init_subsys(ss);
+
+               if (ss->initialize)
+                       ss->initialize(0);
       }

This seems a little weird - even if the subsystem didn't want early initialization, we call its initialize() during early setup?

Quoted 8 lines

I assume the idea is to move away from the current model where the subsystem is expected to initialize itself during the first call to its create() method, when it gets passed a cgroup with a NULL parent? I agree that was a bit icky. How about we call ss->initialize() from cgroup_init_subsys()? Then we wouldn't need the "early" parameter, since it would be implicit based on whether the subsystem wanted early initialization or not.

The motivation was to ensure that kmalloc* calls are available at the time of ss_initialize

Quoted 2 lines

Also, if you're adding a new subsystem method, you should document it in Documentation/cgroups.txt

Thanks for the comments. There were some more things that are wrong with this patch and Andrew pointed them out. We'll work on a newer vesion.

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL