Hi,
Here are few minor cleanups for the sched core. The first three tries to avoid reinitializing memory which is already set to zero and the last one drops an unused statement.
-- viresh
Viresh Kumar (4): sched: topology: drop memset() from init_rootdomain() sched: cpudeadline: don't re-initialize struct cpudl sched: cpupri: don't re-initialize struct cpupri sched: core: drop useless expression from sched_init()
kernel/sched/core.c | 1 - kernel/sched/cpudeadline.c | 2 -- kernel/sched/cpupri.c | 3 --- kernel/sched/topology.c | 4 +--- 4 files changed, 1 insertion(+), 9 deletions(-)
There are only two callers of init_rootdomain(). One of them passes a global to it and another one sends dynamically allocated root-domain.
There is no need to memset the root-domain in the first case as the structure is already reset.
Update alloc_rootdomain() to allocate the memory with kzalloc() and remove the memset() call from init_rootdomain().
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- kernel/sched/topology.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 1b0b4fb12837..a2497702e628 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -242,8 +242,6 @@ void rq_attach_root(struct rq *rq, struct root_domain *rd)
static int init_rootdomain(struct root_domain *rd) { - memset(rd, 0, sizeof(*rd)); - if (!zalloc_cpumask_var(&rd->span, GFP_KERNEL)) goto out; if (!zalloc_cpumask_var(&rd->online, GFP_KERNEL)) @@ -292,7 +290,7 @@ static struct root_domain *alloc_rootdomain(void) { struct root_domain *rd;
- rd = kmalloc(sizeof(*rd), GFP_KERNEL); + rd = kzalloc(sizeof(*rd), GFP_KERNEL); if (!rd) return NULL;
The struct cpudl passed to cpudl_init() is already initialized to zero. Don't do that again.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- kernel/sched/cpudeadline.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c index fba235c7d026..a51e91bf3907 100644 --- a/kernel/sched/cpudeadline.c +++ b/kernel/sched/cpudeadline.c @@ -246,9 +246,7 @@ int cpudl_init(struct cpudl *cp) { int i;
- memset(cp, 0, sizeof(*cp)); raw_spin_lock_init(&cp->lock); - cp->size = 0;
cp->elements = kcalloc(nr_cpu_ids, sizeof(struct cpudl_item),
The struct cpupri passed to cpupri_init() is already initialized to zero. Don't do that again.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- kernel/sched/cpupri.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c index 981fcd7dc394..d6165d87ef3e 100644 --- a/kernel/sched/cpupri.c +++ b/kernel/sched/cpupri.c @@ -209,12 +209,9 @@ int cpupri_init(struct cpupri *cp) { int i;
- memset(cp, 0, sizeof(*cp)); - for (i = 0; i < CPUPRI_NR_PRIORITIES; i++) { struct cpupri_vec *vec = &cp->pri_to_cpu[i];
- atomic_set(&vec->count, 0); if (!zalloc_cpumask_var(&vec->mask, GFP_KERNEL)) goto cleanup; }
'ptr' is never used after setting 'rt_rq' and there is no need to update it.
Signed-off-by: Viresh Kumar viresh.kumar@linaro.org --- kernel/sched/core.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6d6cad9a46af..bd33a05d038b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5992,7 +5992,6 @@ void __init sched_init(void) ptr += nr_cpu_ids * sizeof(void **);
root_task_group.rt_rq = (struct rt_rq **)ptr; - ptr += nr_cpu_ids * sizeof(void **);
#endif /* CONFIG_RT_GROUP_SCHED */ }
On Thu, Mar 23, 2017 at 05:05:55PM +0530, Viresh Kumar wrote:
Hi,
Here are few minor cleanups for the sched core. The first three tries to avoid reinitializing memory which is already set to zero and the last one drops an unused statement.
I'm OK with the kzalloc/memset thing, but I'd prefer to keep all those other bits.
Yes they're superfluous, but this is init code, so nobody cares about performance and having those things explitic makes it easier to read.
As to the very latest patch, that's there so that if/when we extend that array we can simply continue. Also its more symmetric/consistent. Any half sane DCE pass should get rid of it anyway, as the result is unused.
On 27-03-17, 15:58, Peter Zijlstra wrote:
On Thu, Mar 23, 2017 at 05:05:55PM +0530, Viresh Kumar wrote:
Hi,
Here are few minor cleanups for the sched core. The first three tries to avoid reinitializing memory which is already set to zero and the last one drops an unused statement.
I'm OK with the kzalloc/memset thing,
I assume that you are fine with removal of memset as done in the first 3 patches. Or you are fine with just the first patch?
but I'd prefer to keep all those other bits.
Yes they're superfluous, but this is init code, so nobody cares about performance and having those things explitic makes it easier to read.
Sure.
As to the very latest patch, that's there so that if/when we extend that array we can simply continue. Also its more symmetric/consistent. Any half sane DCE pass should get rid of it anyway, as the result is unused.
But we aren't going to extend the array all the time and keeping a statement like that just for symmetry doesn't sound that great :). Anyway, I will drop the last patch as you suggested.
linaro-kernel@lists.linaro.org