Skip to contentSkip to conversation

cpu delay collection via schedstats

PATCH In review Balbir Singh 2 participants 4 messages May 2, 2006 – May 10, 2006 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 3/8 cpu delay collection via schedstats

Changelog

Fixes comments by akpm
- comments about locking used in rq_sched_info_arrive/depart

No fix needed/possible
- redundant extern declaration of delayacct_on in sched.h suggested location (delayacct.h) cannot be used as it includes sched.h extern declaration moved to where its needed
- move unlikely declaration inside sched_info_on
Function only returns constants. Cannot be done.
- removal of #if defined in sched_fork (Dave Hansen) Refactoring suggested does not work if only SCHEDSTATS is configured

delayacct-shedstats.patch

Make the task-related schedstats functions
callable by delay accounting even if schedstats
collection isn't turned on. This removes the
dependency of delay accounting on schedstats.

---

 include/linux/sched.h |   20 ++++++++++++++---
 kernel/sched.c        |   58 +++++++++++++++++++++++++++++++++++---------------
 2 files changed, 58 insertions(+), 20 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~delayacct-schedstats +17 -3
diff -puN include/linux/sched.h~delayacct-schedstats include/linux/sched.h
@@ -521,7 +521,7 @@ typedef struct prio_array prio_array_t;
 struct backing_dev_info;
 struct reclaim_state;
 
-#ifdef CONFIG_SCHEDSTATS
+#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
 struct sched_info {
 	/* cumulative counters */
 	unsigned long	cpu_time,	/* time spent on the cpu */
@@ -532,9 +532,11 @@ struct sched_info {
 	unsigned long	last_arrival,	/* when we last ran on a cpu */
 			last_queued;	/* when we were last queued to run */
 };
+#endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
 
+#ifdef CONFIG_SCHEDSTATS
 extern struct file_operations proc_schedstat_operations;
-#endif
+#endif /* CONFIG_SCHEDSTATS */
 
 #ifdef CONFIG_TASK_DELAY_ACCT
 struct task_delay_info {
@@ -557,7 +559,19 @@ struct task_delay_info {
 	u32 blkio_count;
 	u32 swapin_count;
 };
+#endif	/* CONFIG_TASK_DELAY_ACCT */
+
+static inline int sched_info_on(void)
+{
+#ifdef CONFIG_SCHEDSTATS
+	return 1;
+#elif defined(CONFIG_TASK_DELAY_ACCT)
+	extern int delayacct_on;
+	return delayacct_on;
+#else
+	return 0;
 #endif
+}
 
 enum idle_type
 {
@@ -744,7 +758,7 @@ struct task_struct {
 	cpumask_t cpus_allowed;
 	unsigned int time_slice, first_time_slice;
 
-#ifdef CONFIG_SCHEDSTATS
+#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
 	struct sched_info sched_info;
 #endif
 
kernel/sched.c renamed from kernel/sched.c~delayacct-schedstats +41 -17

121 lines not on this page · raw message

_

#1 lore raw
Quoted 12 lines · Balbir Singh
kernel/sched.c renamed from kernel/sched.c~delayacct-schedstats +11 -0
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_arrive(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq) {
+		rq->rq_sched_info.run_delay += diff;
+		rq->rq_sched_info.pcnt++;
+	}
+}

kernel/sched.c struct file_operations proc_schedstat_op · line 492

Quoted 10 lines
kernel/sched.c renamed from kernel/sched.c~delayacct-schedstats +10 -0
+
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_depart(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq)
+		rq->rq_sched_info.cpu_time += diff;
+}

The kernel has many different units of time - jiffies, cpu ticks, ns, us, ms, etc. So the reader of these functions doesn't have a clue what "diff" is.

A good way to remove all doubt in all cases is to include the units in the variable's name. Something like delta_jiffies, perhaps.

#2 lore raw
Quoted 28 lines · Andrew Morton
Quoted 12 lines · Balbir Singh
kernel/sched.c renamed from kernel/sched.c~delayacct-schedstats +11 -0
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_arrive(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq) {
+		rq->rq_sched_info.run_delay += diff;
+		rq->rq_sched_info.pcnt++;
+	}
+}

kernel/sched.c struct file_operations proc_schedstat_op · line 492

Quoted 10 lines
kernel/sched.c renamed from kernel/sched.c~delayacct-schedstats +10 -0
+
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_depart(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq)
+		rq->rq_sched_info.cpu_time += diff;
+}

The kernel has many different units of time - jiffies, cpu ticks, ns, us, ms, etc. So the reader of these functions doesn't have a clue what "diff" is.

Quoted 2 lines

A good way to remove all doubt in all cases is to include the units in the variable's name. Something like delta_jiffies, perhaps.

Yes, that makes sense and enhances readability. We will fix the naming convention. "diff" is indeed "delta_jiffies"

Thanks,
Balbir Singh,
Linux Technology Center,
IBM Software Labs

#3 lore raw

PATCH 1/1 Use better names in schedstats (was Re: [Patch 3/8] cpu delay collection via schedstats)

In reply to Andrew Morton
Quoted 28 lines · Andrew Morton
Quoted 12 lines · Balbir Singh
(quoted diff) +11 -0
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_arrive(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq) {
+		rq->rq_sched_info.run_delay += diff;
+		rq->rq_sched_info.pcnt++;
+	}
+}

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+/*
+ * Expects runqueue lock to be held for atomicity of update
+ */
+static inline void rq_sched_info_depart(struct runqueue *rq,
+						unsigned long diff)
+{
+	if (rq)
+		rq->rq_sched_info.cpu_time += diff;
+}

The kernel has many different units of time - jiffies, cpu ticks, ns, us, ms, etc. So the reader of these functions doesn't have a clue what "diff" is.

Quoted 2 lines

A good way to remove all doubt in all cases is to include the units in the variable's name. Something like delta_jiffies, perhaps.

Hi, Andrew

I have renamed all the "diff" to "delta_jiffies" to make it easier to read the code as suggested in the review comments.

Balbir Singh,
Linux Technology Center,
IBM Software Labs

Changelog
1. Clean up the usage of the names. Use names with units to make the code easier to read

---

 kernel/sched.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)
kernel/sched.c renamed from kernel/sched.c~schedstats-use-better-names +15 -13
diff -puN kernel/sched.c~schedstats-use-better-names kernel/sched.c
@@ -473,10 +473,10 @@ struct file_operations proc_schedstat_op
  * Expects runqueue lock to be held for atomicity of update
  */
 static inline void rq_sched_info_arrive(struct runqueue *rq,
-						unsigned long diff)
+						unsigned long delta_jiffies)
 {
 	if (rq) {
-		rq->rq_sched_info.run_delay += diff;
+		rq->rq_sched_info.run_delay += delta_jiffies;
 		rq->rq_sched_info.pcnt++;
 	}
 }
@@ -485,17 +485,19 @@ static inline void rq_sched_info_arrive(
  * Expects runqueue lock to be held for atomicity of update
  */
 static inline void rq_sched_info_depart(struct runqueue *rq,
-						unsigned long diff)
+						unsigned long delta_jiffies)
 {
 	if (rq)
-		rq->rq_sched_info.cpu_time += diff;
+		rq->rq_sched_info.cpu_time += delta_jiffies;
 }
 # define schedstat_inc(rq, field)	do { (rq)->field++; } while (0)
 # define schedstat_add(rq, field, amt)	do { (rq)->field += (amt); } while (0)
 #else /* !CONFIG_SCHEDSTATS */
-static inline void rq_sched_info_arrive(struct runqueue *rq, unsigned long diff)
+static inline void rq_sched_info_arrive(struct runqueue *rq,
+						unsigned long delta_jiffies)
 {}
-static inline void rq_sched_info_depart(struct runqueue *rq, unsigned long diff)
+static inline void rq_sched_info_depart(struct runqueue *rq,
+						unsigned long delta_jiffies)
 {}
 # define schedstat_inc(rq, field)	do { } while (0)
 # define schedstat_add(rq, field, amt)	do { } while (0)
@@ -544,16 +546,16 @@ static inline void sched_info_dequeued(t
  */
 static void sched_info_arrive(task_t *t)
 {
-	unsigned long now = jiffies, diff = 0;
+	unsigned long now = jiffies, delta_jiffies = 0;
 
 	if (t->sched_info.last_queued)
-		diff = now - t->sched_info.last_queued;
+		delta_jiffies = now - t->sched_info.last_queued;
 	sched_info_dequeued(t);
-	t->sched_info.run_delay += diff;
+	t->sched_info.run_delay += delta_jiffies;
 	t->sched_info.last_arrival = now;
 	t->sched_info.pcnt++;
 
-	rq_sched_info_arrive(task_rq(t), diff);
+	rq_sched_info_arrive(task_rq(t), delta_jiffies);
 }
 
 /*
@@ -584,10 +586,10 @@ static inline void sched_info_queued(tas
  */
 static inline void sched_info_depart(task_t *t)
 {
-	unsigned long diff = jiffies - t->sched_info.last_arrival;
+	unsigned long delta_jiffies = jiffies - t->sched_info.last_arrival;
 
-	t->sched_info.cpu_time += diff;
-	rq_sched_info_depart(task_rq(t), diff);
+	t->sched_info.cpu_time += delta_jiffies;
+	rq_sched_info_depart(task_rq(t), delta_jiffies);
 }
 
 /*

_