kernel-sched: Fine-tuning for eight function implementations
Subsystems (2)
cover kernel-sched: Fine-tuning for eight function implementations
From: Markus Elfring <[email protected]>
Date: Sat, 6 May 2017 21:35:45 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Use seq_putc() in three functions
Adjust four checks for null pointers
Combine two seq_printf() calls into one in show_schedstat()
kernel/sched/cpuacct.c | 6 +++--- kernel/sched/debug.c | 11 +++++------ kernel/sched/stats.c | 14 +++++--------- 3 files changed, 13 insertions(+), 18 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/3 kernel-sched: Use seq_putc() in three functions
From: Markus Elfring <[email protected]>
Date: Sat, 6 May 2017 20:45:35 +0200
Four single characters (line breaks) should be put into a sequence. Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- kernel/sched/cpuacct.c | 6 +++--- kernel/sched/debug.c | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-)
kernel/sched/cpuacct.c +3 -3
@@ -221,7 +221,7 @@ static int __cpuacct_percpu_seq_show(struct seq_file *m, percpu =cpuacct_cpuusage_read (ca, i, index);seq_printf (m,"%llu " , (unsigned long long ) percpu); } -seq_printf (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
@@ -249,7 +249,7 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)seq_puts (m,"cpu" );for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++)seq_printf (m," %s" , cpuacct_stat_desc[index]); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );for_each_possible_cpu (cpu) {struct cpuacct_usage *cpuusage =per_cpu_ptr (ca->cpuusage, cpu);
@@ -271,7 +271,7 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)raw_spin_unlock_irq (&cpu_rq (cpu)->lock);#endif } -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }return 0 ; }
kernel/sched/debug.c +1 -2
@@ -78,8 +78,7 @@ static int sched_feat_show(struct seq_file *m, void *v)seq_puts (m,"NO_" );seq_printf (m,"%s " , sched_feat_names[i]); } -seq_puts (m,"\n" ); - +seq_putc (m,'\n' );return 0 ; }
Signature · 1 line
2.12.2
PATCH 2/3 kernel-sched: Adjust four checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 6 May 2017 21:17:36 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code place.
--- kernel/sched/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/sched/debug.c +4 -4
@@ -231,7 +231,7 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)for (entry = *tablep; entry->mode; entry++) {if (entry->child)sd_free_ctl_entry (&entry->child); -if (entry->proc_handler =NULL ) +if (!entry->proc_handler)kfree (entry->procname); }
@@ -265,7 +265,7 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd) {struct ctl_table *table =sd_alloc_ctl_entry (14 ); -if (table =NULL ) +if (!table)return NULL ; set_table_entry(&table[0], "min_interval", &sd->min_interval,
@@ -311,7 +311,7 @@ static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)for_each_domain (cpu, sd) domain_num++; entry = table =sd_alloc_ctl_entry (domain_num +1 ); -if (table =NULL ) +if (!table)return NULL ; i =0 ;
@@ -336,7 +336,7 @@ void register_sched_domain_sysctl(void)WARN_ON (sd_ctl_dir[0 ].child); sd_ctl_dir[0 ].child = entry; -if (entry =NULL ) +if (!entry)return ;for_each_possible_cpu (i) {
Signature · 1 line
2.12.2
PATCH 3/3 kernel-sched: Combine two seq_printf() calls into one in show_schedstat()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 6 May 2017 21:26:19 +0200
Some data were put into a sequence by two separate function calls. Print the same data by a single function call instead.
This issue was detected by using the Coccinelle software.
--- kernel/sched/stats.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
kernel/sched/stats.c +5 -9
@@ -30,15 +30,11 @@ static int show_schedstat(struct seq_file *seq, void *v)/* runqueue-specific stats */ seq_printf (seq, -"cpu%d %u 0 %u %u %u %u %llu %llu %lu" , - cpu, rq->yld_count, - rq->sched_count, rq->sched_goidle, - rq->ttwu_count, rq->ttwu_local, - rq->rq_cpu_time, - rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount); - -seq_printf (seq,"\n" ); - +"cpu%d %u 0 %u %u %u %u %llu %llu %lu\n" , + cpu, rq->yld_count, rq->sched_count, + rq->sched_goidle, rq->ttwu_count, rq->ttwu_local, + rq->rq_cpu_time, rq->rq_sched_info.run_delay, + rq->rq_sched_info.pcount);#ifdef CONFIG_SMP /* domain-specific stats */ rcu_read_lock ();
Signature · 1 line
2.12.2