FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu Kernel Team

 
 
LinkBack Thread Tools
 
Old 01-18-2011, 02:34 PM
Stefan Bader
 
Default sched: Prevent divide by zero when cpu_power is 0

From: Andrew Dickinson <whydna@whydna.net>

This is a patch to fix the corner case where we're crashing with
divide_error in find_busiest_group.

I don't fully understand what the case is that causes sds.total_pwr to
be zero in find_busiest_group, but this patch guards against the
divide-by-zero bug.

I also added safe-guarding around other routines in the scheduler code
where we're dividing by power; that's more of a just-in-case and I'm
definitely open for debate on that.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=16991
BugLink: http://bugs.launchpad.net/bugs/614853

Signed-off-by: Andrew Dickinson <whydna@whydna.net>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
kernel/sched.c | 10 +++++++---
kernel/sched_fair.c | 4 +++-
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 7dd8aad..d4a4b14 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3836,7 +3836,9 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
}

/* Adjust by relative CPU power of the group */
- sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE) / group->cpu_power;
+ sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE);
+ if (group->cpu_power)
+ sgs->avg_load /= group->cpu_power;

/*
* Consider the group unbalanced when the imbalance is larger
@@ -4119,7 +4121,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
if (balance && !(*balance))
goto ret;

- if (!sds.busiest || sds.busiest_nr_running == 0)
+ if (!sds.busiest || sds.busiest_nr_running == 0 || sds.total_pwr == 0)
goto out_balanced;

if (sds.this_load >= sds.max_load)
@@ -4184,7 +4186,9 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
* the load can be moved away from the cpu that is potentially
* running at a lower capacity.
*/
- wl = (wl * SCHED_LOAD_SCALE) / power;
+ wl = (wl * SCHED_LOAD_SCALE);
+ if (power)
+ wl /= power;

if (wl > max_load) {
max_load = wl;
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 01e311e..3087249 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1344,7 +1344,9 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
}

/* Adjust by relative CPU power of the group */
- avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power;
+ avg_load = (avg_load * SCHED_LOAD_SCALE);
+ if (group->cpu_power)
+ avg_load /= group->cpu_power;

if (local_group) {
this_load = avg_load;
--
1.7.0.4


--
kernel-team mailing list
kernel-team@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/kernel-team
 
Old 01-19-2011, 01:14 PM
Andy Whitcroft
 
Default sched: Prevent divide by zero when cpu_power is 0

On Tue, Jan 18, 2011 at 04:34:22PM +0100, Stefan Bader wrote:
> From: Andrew Dickinson <whydna@whydna.net>
>
> This is a patch to fix the corner case where we're crashing with
> divide_error in find_busiest_group.
>
> I don't fully understand what the case is that causes sds.total_pwr to
> be zero in find_busiest_group, but this patch guards against the
> divide-by-zero bug.
>
> I also added safe-guarding around other routines in the scheduler code
> where we're dividing by power; that's more of a just-in-case and I'm
> definitely open for debate on that.
>
> BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=16991
> BugLink: http://bugs.launchpad.net/bugs/614853
>
> Signed-off-by: Andrew Dickinson <whydna@whydna.net>
> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
> ---
> kernel/sched.c | 10 +++++++---
> kernel/sched_fair.c | 4 +++-
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched.c b/kernel/sched.c
> index 7dd8aad..d4a4b14 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -3836,7 +3836,9 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
> }
>
> /* Adjust by relative CPU power of the group */
> - sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE) / group->cpu_power;
> + sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE);
> + if (group->cpu_power)
> + sgs->avg_load /= group->cpu_power;
>
> /*
> * Consider the group unbalanced when the imbalance is larger
> @@ -4119,7 +4121,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
> if (balance && !(*balance))
> goto ret;
>
> - if (!sds.busiest || sds.busiest_nr_running == 0)
> + if (!sds.busiest || sds.busiest_nr_running == 0 || sds.total_pwr == 0)
> goto out_balanced;
>
> if (sds.this_load >= sds.max_load)
> @@ -4184,7 +4186,9 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
> * the load can be moved away from the cpu that is potentially
> * running at a lower capacity.
> */
> - wl = (wl * SCHED_LOAD_SCALE) / power;
> + wl = (wl * SCHED_LOAD_SCALE);
> + if (power)
> + wl /= power;
>
> if (wl > max_load) {
> max_load = wl;
> diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
> index 01e311e..3087249 100644
> --- a/kernel/sched_fair.c
> +++ b/kernel/sched_fair.c
> @@ -1344,7 +1344,9 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
> }
>
> /* Adjust by relative CPU power of the group */
> - avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power;
> + avg_load = (avg_load * SCHED_LOAD_SCALE);
> + if (group->cpu_power)
> + avg_load /= group->cpu_power;
>
> if (local_group) {
> this_load = avg_load;

This one looks ok. Seems to avoid doing the divide when it would trip
by zero.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw

--
kernel-team mailing list
kernel-team@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/kernel-team
 

Thread Tools




All times are GMT. The time now is 01:50 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org