Skip to contentSkip to conversation

sched: Minor cleanups

PATCH Superseded Viresh Kumar 2 participants 7 messages Mar 23, 2017 – Apr 10, 2017 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover sched: Minor cleanups

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(-)
Signature · 1 line
2.12.0.432.g71c3a4f4ba37
#1 lore raw

PATCH 1/4 sched: topology: drop memset() from init_rootdomain()

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().

---
 kernel/sched/topology.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/topology.c +1 -3
index 1b0b4fb12837..a2497702e628 100644
@@ -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;
 
Signature · 1 line
2.12.0.432.g71c3a4f4ba37
#2 lore raw

PATCH 2/4 sched: cpudeadline: don't re-initialize struct cpudl

In reply to Viresh Kumar

The struct cpudl passed to cpudl_init() is already initialized to zero. Don't do that again.

---
 kernel/sched/cpudeadline.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/cpudeadline.c +0 -2
index fba235c7d026..a51e91bf3907 100644
@@ -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),
Signature · 1 line
2.12.0.432.g71c3a4f4ba37
#3 lore raw

PATCH 3/4 sched: cpupri: don't re-initialize struct cpupri

In reply to Viresh Kumar

The struct cpupri passed to cpupri_init() is already initialized to zero. Don't do that again.

---
 kernel/sched/cpupri.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/sched/cpupri.c +0 -3
index 981fcd7dc394..d6165d87ef3e 100644
@@ -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;
 	}
Signature · 1 line
2.12.0.432.g71c3a4f4ba37
#4 lore raw

PATCH 4/4 sched: core: drop useless expression from sched_init()

In reply to Viresh Kumar

'ptr' is never used after setting 'rt_rq' and there is no need to update it.

---
 kernel/sched/core.c | 1 -
 1 file changed, 1 deletion(-)
kernel/sched/core.c +0 -1
index 6d6cad9a46af..bd33a05d038b 100644
@@ -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 */
 	}
Signature · 1 line
2.12.0.432.g71c3a4f4ba37
maintainer
#5 lore raw
In reply to Viresh Kumar
Quoted 6 lines · Viresh Kumar

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.

#6 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 6 lines · Viresh Kumar

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?

Quoted 5 lines

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.

Quoted 3 lines

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.

Signature · 1 line
viresh