Skip to contentSkip to conversation

sched: move content out of core files for load calculations

PATCH In review Paul Gortmaker 3 participants 8 messages Apr 19, 2013 – May 7, 2013 Scheduler

lore
Share & tools
lore
#0 lore raw

v2 cover sched: move content out of core files for load calculations

Recent activity has had a focus on moving functionally related blocks of stuff out of sched/core.c into stand-alone files. The code relating to load calculations has grown significantly enough recently to warrant placing it in a separate file.

Here we do that, and in doing so, we shed ~20k of code from sched/core.c (~10%).

A couple small static functions in the core sched.h header were also localized to their singular user in sched/fair.c at the same time, with the goal to also reduce the amount of "broadcast" content in that sched.h file.

Paul.
---

v2 changes:

1) rebase from tip's sched/core (v3.9-rc1-38-gb329fd5) to today's

     tip master (v3.9-rc6-2031-g27f8b76).

2) rename file from load_avg.c to proc.c

---

The following changes since commit 27f8b769cba5a97ffcbaae92fd4c0ed84f00e214:

manual merge of tools/kvm (2013-04-19 13:05:17 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux.git for-ingo

for you to fetch changes up to dac25445169ff97142ae4f7174e3d94ce7036ad3:

sched: move update_load_[add/sub/set] from sched.h to fair.c (2013-04-19 14:38:11 -0400)

----------------------------------------------------------------
Paul Gortmaker (2):
sched: fork load calculation code from sched/core --> sched/proc
sched: move update_load_[add/sub/set] from sched.h to fair.c

 kernel/sched/Makefile |   2 +-
 kernel/sched/core.c   | 569 -------------------------------------------------
 kernel/sched/fair.c   |  18 ++
 kernel/sched/proc.c   | 578 ++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h  |  26 +--
 5 files changed, 605 insertions(+), 588 deletions(-)
 create mode 100644 kernel/sched/proc.c
#1 lore raw

PATCH v2 1/2 sched: fork load calculation code from sched/core --> sched/proc

This large chunk of load calculation code can be easily divorced from the main core.c scheduler file, with only a couple prototypes and externs added to a kernel/sched header.

Some recent commits expanded the code and the documentation of it, making it large enough to warrant separation. For example, see:

556061b, "sched/nohz: Fix rq->cpu_load[] calculations" 5aaa0b7, "sched/nohz: Fix rq->cpu_load calculations some more" 5167e8d, "sched/nohz: Rewrite and fix load-avg computation -- again"

More importantly, it helps reduce the size of the main sched/core.c by yet another significant amount (~600 lines).

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/sched/Makefile |   2 +-
 kernel/sched/core.c   | 569 -------------------------------------------------
 kernel/sched/proc.c   | 578 ++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h  |   8 +
 4 files changed, 587 insertions(+), 570 deletions(-)
 create mode 100644 kernel/sched/proc.c
kernel/sched/Makefile +1 -1
index deaf90e..54adcf3 100644
@@ -11,7 +11,7 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
 CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
 endif
 
-obj-y += core.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
+obj-y += core.o proc.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
 obj-$(CONFIG_SMP) += cpupri.o
 obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
 obj-$(CONFIG_SCHEDSTATS) += stats.o
kernel/sched/core.c +0 -569

575 lines not on this page · raw message

kernel/sched/proc.c new file +578 -0

578 lines not on this page · raw message

kernel/sched/sched.h +8 -0
index 47e27d7..49d4114 100644
@@ -9,8 +9,16 @@
 #include "cpupri.h"
 #include "cpuacct.h"
 
+struct rq;
+
 extern __read_mostly int scheduler_running;
 
+extern unsigned long calc_load_update;
+extern atomic_long_t calc_load_tasks;
+
+extern long calc_load_fold_active(struct rq *this_rq);
+extern void update_cpu_load_active(struct rq *this_rq);
+
 /*
  * Convert user-nice values [ -20 ... 0 ... 19 ]
  * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
Signature · 1 line
1.8.1.2
#2 lore raw

[tip:sched/urgent] sched: Factor out load calculation code from sched/core.c --> sched/proc.c

sched: Factor out load calculation code from sched/core.c --> sched/proc.c
Commit-ID:  45ceebf77653975815d82fcf7cec0a164215ae11
Gitweb:     http://git.kernel.org/tip/45ceebf77653975815d82fcf7cec0a164215ae11
Author:     Paul Gortmaker <[email protected]>
AuthorDate: Fri, 19 Apr 2013 15:10:49 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 7 May 2013 13:14:50 +0200

sched: Factor out load calculation code from sched/core.c --> sched/proc.c

This large chunk of load calculation code can be easily divorced from the main core.c scheduler file, with only a couple prototypes and externs added to a kernel/sched header.

Some recent commits expanded the code and the documentation of it, making it large enough to warrant separation. For example, see:

556061b, "sched/nohz: Fix rq->cpu_load[] calculations" 5aaa0b7, "sched/nohz: Fix rq->cpu_load calculations some more" 5167e8d, "sched/nohz: Rewrite and fix load-avg computation -- again"

More importantly, it helps reduce the size of the main sched/core.c by yet another significant amount (~600 lines).

---
 kernel/sched/Makefile |   2 +-
 kernel/sched/core.c   | 569 -------------------------------------------------
 kernel/sched/proc.c   | 578 ++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h  |   8 +
 4 files changed, 587 insertions(+), 570 deletions(-)
kernel/sched/Makefile +1 -1
index deaf90e..54adcf3 100644
@@ -11,7 +11,7 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
 CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
 endif
 
-obj-y += core.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
+obj-y += core.o proc.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
 obj-$(CONFIG_SMP) += cpupri.o
 obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
 obj-$(CONFIG_SCHEDSTATS) += stats.o
kernel/sched/core.c +0 -569

575 lines not on this page · raw message

kernel/sched/proc.c new file +578 -0

578 lines not on this page · raw message

kernel/sched/sched.h +8 -0
index ce39224..a38ee0a 100644
@@ -10,8 +10,16 @@
 #include "cpupri.h"
 #include "cpuacct.h"
 
+struct rq;
+
 extern __read_mostly int scheduler_running;
 
+extern unsigned long calc_load_update;
+extern atomic_long_t calc_load_tasks;
+
+extern long calc_load_fold_active(struct rq *this_rq);
+extern void update_cpu_load_active(struct rq *this_rq);
+
 /*
  * Convert user-nice values [ -20 ... 0 ... 19 ]
  * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
#3 lore raw

PATCH v2 2/2 sched: move update_load_[add/sub/set] from sched.h to fair.c

In reply to Paul Gortmaker

These inlines are only used by kernel/sched/fair.c so they do not need to be present in the main kernel/sched/sched.h file.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/sched/fair.c  | 18 ++++++++++++++++++
 kernel/sched/sched.h | 18 ------------------
 2 files changed, 18 insertions(+), 18 deletions(-)
kernel/sched/fair.c +18 -0
index 68324a9..82f160c 100644
@@ -113,6 +113,24 @@ unsigned int __read_mostly sysctl_sched_shares_window = 10000000UL;
 unsigned int sysctl_sched_cfs_bandwidth_slice = 5000UL;
 #endif
 
+static inline void update_load_add(struct load_weight *lw, unsigned long inc)
+{
+	lw->weight += inc;
+	lw->inv_weight = 0;
+}
+
+static inline void update_load_sub(struct load_weight *lw, unsigned long dec)
+{
+	lw->weight -= dec;
+	lw->inv_weight = 0;
+}
+
+static inline void update_load_set(struct load_weight *lw, unsigned long w)
+{
+	lw->weight = w;
+	lw->inv_weight = 0;
+}
+
 /*
  * Increase the granularity value when there are more CPUs,
  * because with more CPUs the 'effective latency' as visible
kernel/sched/sched.h +0 -18
index 49d4114..c9c1cdb 100644
@@ -888,24 +888,6 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
 #define WF_FORK		0x02		/* child wakeup after fork */
 #define WF_MIGRATED	0x4		/* internal use, task got migrated */
 
-static inline void update_load_add(struct load_weight *lw, unsigned long inc)
-{
-	lw->weight += inc;
-	lw->inv_weight = 0;
-}
-
-static inline void update_load_sub(struct load_weight *lw, unsigned long dec)
-{
-	lw->weight -= dec;
-	lw->inv_weight = 0;
-}
-
-static inline void update_load_set(struct load_weight *lw, unsigned long w)
-{
-	lw->weight = w;
-	lw->inv_weight = 0;
-}
-
 /*
  * To aid in avoiding the subversion of "niceness" due to uneven distribution
  * of tasks with abnormal "nice" values across CPUs the contribution that
Signature · 1 line
1.8.1.2
#4 lore raw

[tip:sched/urgent] sched: Move update_load_*() methods from sched.h to fair.c

sched: Move update_load_*() methods from sched.h to fair.c
Commit-ID:  8527632dc95472adb571701e852479531c0567a2
Gitweb:     http://git.kernel.org/tip/8527632dc95472adb571701e852479531c0567a2
Author:     Paul Gortmaker <[email protected]>
AuthorDate: Fri, 19 Apr 2013 15:10:50 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 7 May 2013 13:14:51 +0200

sched: Move update_load_*() methods from sched.h to fair.c

These inlines are only used by kernel/sched/fair.c so they do not need to be present in the main kernel/sched/sched.h file.

---
 kernel/sched/fair.c  | 18 ++++++++++++++++++
 kernel/sched/sched.h | 18 ------------------
 2 files changed, 18 insertions(+), 18 deletions(-)
kernel/sched/fair.c +18 -0
index c61a614..08a554d 100644
@@ -113,6 +113,24 @@ unsigned int __read_mostly sysctl_sched_shares_window = 10000000UL;
 unsigned int sysctl_sched_cfs_bandwidth_slice = 5000UL;
 #endif
 
+static inline void update_load_add(struct load_weight *lw, unsigned long inc)
+{
+	lw->weight += inc;
+	lw->inv_weight = 0;
+}
+
+static inline void update_load_sub(struct load_weight *lw, unsigned long dec)
+{
+	lw->weight -= dec;
+	lw->inv_weight = 0;
+}
+
+static inline void update_load_set(struct load_weight *lw, unsigned long w)
+{
+	lw->weight = w;
+	lw->inv_weight = 0;
+}
+
 /*
  * Increase the granularity value when there are more CPUs,
  * because with more CPUs the 'effective latency' as visible
kernel/sched/sched.h +0 -18
index a38ee0a..f1f6256 100644
@@ -892,24 +892,6 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
 #define WF_FORK		0x02		/* child wakeup after fork */
 #define WF_MIGRATED	0x4		/* internal use, task got migrated */
 
-static inline void update_load_add(struct load_weight *lw, unsigned long inc)
-{
-	lw->weight += inc;
-	lw->inv_weight = 0;
-}
-
-static inline void update_load_sub(struct load_weight *lw, unsigned long dec)
-{
-	lw->weight -= dec;
-	lw->inv_weight = 0;
-}
-
-static inline void update_load_set(struct load_weight *lw, unsigned long w)
-{
-	lw->weight = w;
-	lw->inv_weight = 0;
-}
-
 /*
  * To aid in avoiding the subversion of "niceness" due to uneven distribution
  * of tasks with abnormal "nice" values across CPUs the contribution that
#5 lore raw
In reply to Paul Gortmaker
Quoted 11 lines · Paul Gortmaker

Recent activity has had a focus on moving functionally related blocks of stuff out of sched/core.c into stand-alone files. The code relating to load calculations has grown significantly enough recently to warrant placing it in a separate file.

Here we do that, and in doing so, we shed ~20k of code from sched/core.c (~10%).

A couple small static functions in the core sched.h header were also localized to their singular user in sched/fair.c at the same time, with the goal to also reduce the amount of "broadcast" content in that sched.h file.

Quoted 8 lines

Paul.
---

v2 changes:

1) rebase from tip's sched/core (v3.9-rc1-38-gb329fd5) to today's

     tip master (v3.9-rc6-2031-g27f8b76).

2) rename file from load_avg.c to proc.c

Thanks, looks good to me. Note, I'll try to apply this after the initial round of trees went to Linus in the merge window, to reduce interactions between the trees. Please send me a friendly reminder if I forget about it! :-)

Thanks,

Ingo

#6 lore raw
Quoted 19 lines · Ingo Molnar
Quoted 16 lines · Paul Gortmaker

Recent activity has had a focus on moving functionally related blocks of stuff out of sched/core.c into stand-alone files. The code relating to load calculations has grown significantly enough recently to warrant placing it in a separate file.

Here we do that, and in doing so, we shed ~20k of code from sched/core.c (~10%).

A couple small static functions in the core sched.h header were also localized to their singular user in sched/fair.c at the same time, with the goal to also reduce the amount of "broadcast" content in that sched.h file.

Paul.
---

v2 changes:

Quoted 7 lines
Quoted 3 lines

1) rebase from tip's sched/core (v3.9-rc1-38-gb329fd5) to today's

     tip master (v3.9-rc6-2031-g27f8b76).

2) rename file from load_avg.c to proc.c

Thanks, looks good to me. Note, I'll try to apply this after the initial round of trees went to Linus in the merge window, to reduce interactions between the trees. [...]

Ok, all relevant trees are now upstream - mind sending a refreshed series against upstream merge commit 534c97b0950b or later?

Thanks,

Ingo

#7 lore raw
Quoted 26 lines · [Re: [PATCHv2 0/2] sched: move content out of core files for load…
Quoted 23 lines · Ingo Molnar
Quoted 19 lines · Paul Gortmaker

Recent activity has had a focus on moving functionally related blocks of stuff out of sched/core.c into stand-alone files. The code relating to load calculations has grown significantly enough recently to warrant placing it in a separate file.

Here we do that, and in doing so, we shed ~20k of code from sched/core.c (~10%).

A couple small static functions in the core sched.h header were also localized to their singular user in sched/fair.c at the same time, with the goal to also reduce the amount of "broadcast" content in that sched.h file.

Paul.
---

v2 changes:

1) rebase from tip's sched/core (v3.9-rc1-38-gb329fd5) to today's

     tip master (v3.9-rc6-2031-g27f8b76).

2) rename file from load_avg.c to proc.c

Quoted 6 lines
Quoted 3 lines

Thanks, looks good to me. Note, I'll try to apply this after the initial round of trees went to Linus in the merge window, to reduce interactions between the trees. [...]

Ok, all relevant trees are now upstream - mind sending a refreshed series against upstream merge commit 534c97b0950b or later?

Sure. After putting them on top of 534c97b095, I re-checked with a quick defconfig build. Also in comparison to v2, the patches are unchanged except for trivial line offset deltas. So it should be OK.

Thanks,
Paul.

---

The following changes since commit 534c97b0950b1967bca1c753aeaed32f5db40264:

Merge branch 'timers-nohz-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip (2013-05-05 13:23:27 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux.git for-ingo

for you to fetch changes up to 54aecbbcfcbea684257ebe674251f148ee340412:

sched: move update_load_[add/sub/set] from sched.h to fair.c (2013-05-06 09:39:50 -0400)

----------------------------------------------------------------
Paul Gortmaker (2):
sched: fork load calculation code from sched/core --> sched/proc
sched: move update_load_[add/sub/set] from sched.h to fair.c

 kernel/sched/Makefile |   2 +-
 kernel/sched/core.c   | 569 -------------------------------------------------
 kernel/sched/fair.c   |  18 ++
 kernel/sched/proc.c   | 578 ++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h  |  26 +--
 5 files changed, 605 insertions(+), 588 deletions(-)
 create mode 100644 kernel/sched/proc.c