2008-10-17 10:22:09

by Miao Xie

[permalink] [raw]
Subject: [PATCH] sched: fix the wrong mask_len

If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
domains by catting /proc/schedstat. This is caused by the wrong mask_len.

This patch fix it.

Signed-off-by: Miao Xie <[email protected]>

---
kernel/sched_stats.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
index 8385d43..81365b3 100644
--- a/kernel/sched_stats.h
+++ b/kernel/sched_stats.h
@@ -9,7 +9,7 @@
static int show_schedstat(struct seq_file *seq, void *v)
{
int cpu;
- int mask_len = NR_CPUS/32 * 9;
+ int mask_len = (NR_CPUS/32 + 1) * 9;
char *mask_str = kmalloc(mask_len, GFP_KERNEL);

if (mask_str == NULL)
--
1.5.4.rc3


2008-10-17 10:26:14

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH] sched: fix the wrong mask_len

> If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
> domains by catting /proc/schedstat. This is caused by the wrong mask_len.
>
> This patch fix it.
>
> Signed-off-by: Miao Xie <[email protected]>
>
> ---
> kernel/sched_stats.h | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
> index 8385d43..81365b3 100644
> --- a/kernel/sched_stats.h
> +++ b/kernel/sched_stats.h
> @@ -9,7 +9,7 @@
> static int show_schedstat(struct seq_file *seq, void *v)
> {
> int cpu;
> - int mask_len = NR_CPUS/32 * 9;
> + int mask_len = (NR_CPUS/32 + 1) * 9;
> char *mask_str = kmalloc(mask_len, GFP_KERNEL);
>

DIV_ROUND_UP() is better?


2008-10-17 10:27:11

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH] sched: fix the wrong mask_len


* Miao Xie <[email protected]> wrote:

> If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
> domains by catting /proc/schedstat. This is caused by the wrong mask_len.
>
> This patch fix it.
>
> Signed-off-by: Miao Xie <[email protected]>

applied to tip/sched/urgent, thanks!

Ingo

2008-10-17 10:33:07

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH] sched: fix the wrong mask_len

On Fri, 2008-10-17 at 19:25 +0900, KOSAKI Motohiro wrote:
> > If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
> > domains by catting /proc/schedstat. This is caused by the wrong mask_len.
> >
> > This patch fix it.
> >
> > Signed-off-by: Miao Xie <[email protected]>
> >
> > ---
> > kernel/sched_stats.h | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
> > index 8385d43..81365b3 100644
> > --- a/kernel/sched_stats.h
> > +++ b/kernel/sched_stats.h
> > @@ -9,7 +9,7 @@
> > static int show_schedstat(struct seq_file *seq, void *v)
> > {
> > int cpu;
> > - int mask_len = NR_CPUS/32 * 9;
> > + int mask_len = (NR_CPUS/32 + 1) * 9;
> > char *mask_str = kmalloc(mask_len, GFP_KERNEL);
> >
>
> DIV_ROUND_UP() is better?

Agreed

2008-10-17 10:58:19

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH] sched: fix the wrong mask_len

On Fri, 2008-10-17 at 12:33 +0200, Peter Zijlstra wrote:
> On Fri, 2008-10-17 at 19:25 +0900, KOSAKI Motohiro wrote:
> > > If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
> > > domains by catting /proc/schedstat. This is caused by the wrong mask_len.
> > >
> > > This patch fix it.
> > >
> > > Signed-off-by: Miao Xie <[email protected]>
> > >
> > > ---
> > > kernel/sched_stats.h | 2 +-
> > > 1 files changed, 1 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
> > > index 8385d43..81365b3 100644
> > > --- a/kernel/sched_stats.h
> > > +++ b/kernel/sched_stats.h
> > > @@ -9,7 +9,7 @@
> > > static int show_schedstat(struct seq_file *seq, void *v)
> > > {
> > > int cpu;
> > > - int mask_len = NR_CPUS/32 * 9;
> > > + int mask_len = (NR_CPUS/32 + 1) * 9;
> > > char *mask_str = kmalloc(mask_len, GFP_KERNEL);
> > >
> >
> > DIV_ROUND_UP() is better?
>
> Agreed


---
Subject: sched: fix the wrong mask_len
From: Peter Zijlstra <[email protected]>
Date: Fri Oct 17 12:55:57 CEST 2008

If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
domains by catting /proc/schedstat. This is caused by the wrong mask_len.

Reported-by: Miao Xie <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
---
kernel/sched_stats.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/kernel/sched_stats.h
===================================================================
--- linux-2.6.orig/kernel/sched_stats.h
+++ linux-2.6/kernel/sched_stats.h
@@ -9,7 +9,7 @@
static int show_schedstat(struct seq_file *seq, void *v)
{
int cpu;
- int mask_len = NR_CPUS/32 * 9;
+ int mask_len = DIV_ROUND_UP(NR_CPUS, 32) * 9;
char *mask_str = kmalloc(mask_len, GFP_KERNEL);

if (mask_str == NULL)

2008-10-17 11:02:17

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH] sched: fix the wrong mask_len

> ---
> Subject: sched: fix the wrong mask_len
> From: Peter Zijlstra <[email protected]>
> Date: Fri Oct 17 12:55:57 CEST 2008
>
> If the NR_CPUS isn't a multiple of 32, we get a truncated string of sched
> domains by catting /proc/schedstat. This is caused by the wrong mask_len.
>
> Reported-by: Miao Xie <[email protected]>
> Signed-off-by: Peter Zijlstra <[email protected]>
> ---
> kernel/sched_stats.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux-2.6/kernel/sched_stats.h
> ===================================================================
> --- linux-2.6.orig/kernel/sched_stats.h
> +++ linux-2.6/kernel/sched_stats.h
> @@ -9,7 +9,7 @@
> static int show_schedstat(struct seq_file *seq, void *v)
> {
> int cpu;
> - int mask_len = NR_CPUS/32 * 9;
> + int mask_len = DIV_ROUND_UP(NR_CPUS, 32) * 9;
> char *mask_str = kmalloc(mask_len, GFP_KERNEL);
>
> if (mask_str == NULL)

Acked-by: KOSAKI Motohiro <[email protected]>