kernel: replace seq_puts by seq_putc
PATCH RESEND 1/1 kernel: replace seq_puts by seq_putc
Using seq_putc for single characters is faster and more appropriate than seq_puts, since only one character is passed and there is no need to use a more powerful and less fast function.
Signed-off-by Maxim Moskalets <[email protected]>
--- kernel/bpf/arraymap.c | 6 +++--- kernel/bpf/bpf_struct_ops.c | 2 +- kernel/bpf/hashtab.c | 4 ++-- kernel/bpf/local_storage.c | 4 ++-- kernel/cgroup/cgroup.c | 2 +- kernel/cgroup/debug.c | 6 +++--- kernel/latencytop.c | 2 +- kernel/locking/lockdep_proc.c | 24 ++++++++++++------------ kernel/module/procfs.c | 4 ++-- kernel/module/tracking.c | 2 +- kernel/sched/cpuacct.c | 4 ++-- kernel/sched/debug.c | 14 +++++++------- kernel/time/test_udelay.c | 2 +- kernel/trace/trace_events_hist.c | 26 +++++++++++++------------- kernel/trace/trace_events_user.c | 8 ++++---- kernel/trace/trace_hwlat.c | 4 ++-- 16 files changed, 57 insertions(+), 57 deletions(-)
kernel/bpf/arraymap.c +3 -3
@@ -457,7 +457,7 @@ static void array_map_seq_show_elem(struct bpf_map *map, void *key,if (map->btf_key_type_id)seq_printf (m,"%u: " , *(u32 *)key);btf_type_seq_show (map->btf, map->btf_value_type_id, value, m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );rcu_read_unlock (); }
@@ -478,7 +478,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,seq_printf (m,"\tcpu%d: " , cpu);btf_type_seq_show (map->btf, map->btf_value_type_id,per_cpu_ptr (pptr, cpu), m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }seq_puts (m,"}\n" );
@@ -955,7 +955,7 @@ static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key, prog_id =prog_fd_array_sys_lookup_elem (ptr);btf_type_seq_show (map->btf, map->btf_value_type_id, &prog_id, m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } }
kernel/bpf/bpf_struct_ops.c +1 -1
@@ -833,7 +833,7 @@ static void bpf_struct_ops_map_seq_show_elem(struct bpf_map *map, void *key,btf_type_seq_show (st_map->btf, map->btf_vmlinux_value_type_id, value, m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }kfree (value);
kernel/bpf/hashtab.c +2 -2
@@ -1577,7 +1577,7 @@ static void htab_map_seq_show_elem(struct bpf_map *map, void *key,btf_type_seq_show (map->btf, map->btf_key_type_id, key, m);seq_puts (m,": " );btf_type_seq_show (map->btf, map->btf_value_type_id, value, m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );rcu_read_unlock (); }
@@ -2421,7 +2421,7 @@ static void htab_percpu_map_seq_show_elem(struct bpf_map *map, void *key,seq_printf (m,"\tcpu%d: " , cpu);btf_type_seq_show (map->btf, map->btf_value_type_id,per_cpu_ptr (pptr, cpu), m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }seq_puts (m,"}\n" );
kernel/bpf/local_storage.c +2 -2
@@ -431,7 +431,7 @@ static void cgroup_storage_seq_show_elem(struct bpf_map *map, void *key,seq_puts (m,": " );btf_type_seq_show (map->btf, map->btf_value_type_id, &READ_ONCE (storage->buf)->data[0 ], m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }else {seq_puts (m,": {\n" );for_each_possible_cpu (cpu) {
@@ -439,7 +439,7 @@ static void cgroup_storage_seq_show_elem(struct bpf_map *map, void *key,btf_type_seq_show (map->btf, map->btf_value_type_id,per_cpu_ptr (storage->percpu_buf, cpu), m); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }seq_puts (m,"}\n" ); }
kernel/cgroup/cgroup.c +1 -1
@@ -6300,7 +6300,7 @@ int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns,seq_puts (m, buf); }else { -seq_puts (m,"/" ); +seq_putc (m,'/' ); }if (cgroup_on_dfl (cgrp) &&cgroup_is_dead (cgrp))
kernel/cgroup/debug.c +3 -3
@@ -55,7 +55,7 @@ static int current_css_set_read(struct seq_file *seq, void *v)seq_printf (seq,"css_set %pK %d" , cset, refcnt);if (refcnt > cset->nr_tasks)seq_printf (seq," +%d" , refcnt - cset->nr_tasks); -seq_puts (seq,"\n" ); +seq_putc (seq,'\n' );/* * Print the css'es stored in the current css_set.
@@ -159,7 +159,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v) extra_refs += extra; } } -seq_puts (seq,"\n" ); +seq_putc (seq,'\n' );list_for_each_entry (task, &cset->tasks, cg_list) {if (count++ <=MAX_TASKS_SHOWN_PER_CSS )
@@ -189,7 +189,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)if (!dead_cnt && !extra_refs && !threaded_csets)return 0 ; -seq_puts (seq,"\n" ); +seq_putc (seq,'\n' );if (threaded_csets)seq_printf (seq,"threaded css_sets = %d\n" , threaded_csets);if (extra_refs)
kernel/latencytop.c +1 -1
@@ -261,7 +261,7 @@ static int lstats_show(struct seq_file *m, void *v)seq_printf (m," %ps" , (void *)bt); } -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } }return 0 ;
kernel/locking/lockdep_proc.c +12 -12
@@ -101,17 +101,17 @@ static int l_show(struct seq_file *m, void *v)seq_printf (m,": " );print_name (m, class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );if (IS_ENABLED (CONFIG_PROVE_LOCKING )) {list_for_each_entry (entry, &class->locks_after, entry) {if (entry->distance ==1 ) {seq_printf (m," -> [%p] " , entry->class->key);print_name (m, entry->class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } } -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }return 0 ;
@@ -175,9 +175,9 @@ static int lc_show(struct seq_file *m, void *v)seq_printf (m,"[%p] " , class->key);print_name (m, class); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
@@ -379,7 +379,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v)/* * Zapped classes and lockdep data buffers reuse statistics. */ -seq_puts (m,"\n" ); +seq_putc (m,'\n' );seq_printf (m," zapped classes: %11lu\n" , nr_zapped_classes);#ifdef CONFIG_PROVE_LOCKING
@@ -422,10 +422,10 @@ static void seq_line(struct seq_file *m, char c, int offset, int length)int i;for (i =0 ; i < offset; i++) -seq_puts (m," " ); +seq_putc (m,' ' );for (i =0 ; i < length; i++)seq_printf (m,"%c" , c); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }static void snprint_time (char *buf,size_t bufsiz,s64 nr)
@@ -512,7 +512,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)seq_lock_time (m, &stats->write_waittime);seq_printf (m," %14lu " , stats->bounces[bounce_acquired_write]);seq_lock_time (m, &stats->write_holdtime); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }if (stats->read_holdtime.nr) {
@@ -521,7 +521,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)seq_lock_time (m, &stats->read_waittime);seq_printf (m," %14lu " , stats->bounces[bounce_acquired_read]);seq_lock_time (m, &stats->read_holdtime); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }if (stats->read_waittime.nr + stats->write_waittime.nr ==0 )
@@ -561,9 +561,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data) ip, (void *)class->contending_point[i]); }if (i) { -seq_puts (m,"\n" ); +seq_putc (m,'\n' );seq_line (m,'.' ,0 ,40 +1 +12 * (14 +1 )); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } }
kernel/module/procfs.c +2 -2
@@ -35,7 +35,7 @@ static inline void print_unload_info(struct seq_file *m, struct module *mod) }if (!printed_something) -seq_puts (m,"-" ); +seq_putc (m,'-' ); }#else /* !CONFIG_MODULE_UNLOAD */ static inline void print_unload_info (struct seq_file *m,struct module *mod)
@@ -99,7 +99,7 @@ static int m_show(struct seq_file *m, void *p)if (mod->taints)seq_printf (m," %s" ,module_flags (mod, buf, true)); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
kernel/module/tracking.c +1 -1
@@ -95,7 +95,7 @@ static int unloaded_tainted_modules_seq_show(struct seq_file *m, void *p) buf[l++] ='\0' ;seq_printf (m,"%s (%s) %llu" , mod_taint->name, buf, mod_taint->count); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
kernel/sched/cpuacct.c +2 -2
@@ -245,14 +245,14 @@ 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) {seq_printf (m,"%d" , cpu);for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++)seq_printf (m," %llu" ,cpuacct_cpuusage_read (ca, cpu, index)); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); }return 0 ; }
kernel/sched/debug.c +7 -7
@@ -62,7 +62,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 ; }
@@ -251,15 +251,15 @@ static int sched_dynamic_show(struct seq_file *m, void *v)for (i =0 ; i <ARRAY_SIZE (preempt_modes); i++) {if (preempt_dynamic_mode == i) -seq_puts (m,"(" ); +seq_putc (m,'(' );seq_puts (m, preempt_modes[i]);if (preempt_dynamic_mode == i) -seq_puts (m,")" ); +seq_putc (m,')' ); -seq_puts (m," " ); +seq_putc (m,' ' ); } -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
@@ -389,9 +389,9 @@ static int sd_flags_show(struct seq_file *m, void *v)for_each_set_bit (idx, &flags, __SD_FLAG_CNT) {seq_puts (m, sd_flag_debug[idx].name); -seq_puts (m," " ); +seq_putc (m,' ' ); } -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
kernel/time/test_udelay.c +1 -1
@@ -59,7 +59,7 @@ static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters) (usecs * 1000) - allowed_error_ns, min, avg, max);if (fail_count)seq_printf (s," FAIL=%d" , fail_count); -seq_puts (s,"\n" ); +seq_putc (s,'\n' );return 0 ; }
kernel/trace/trace_events_hist.c +13 -13
@@ -4898,14 +4898,14 @@ static void print_action_spec(struct seq_file *m,for (i =0 ; i < hist_data->n_save_vars; i++) {seq_printf (m,"%s" , hist_data->save_vars[i]->var->var.name);if (i < hist_data->n_save_vars -1 ) -seq_puts (m,"," ); +seq_putc (m,',' ); } }else if (data->action ==ACTION_TRACE ) {if (data->use_trace_keyword)seq_printf (m,"%s" , data->synth_event_name);for (i =0 ; i < data->n_params; i++) {if (i || data->use_trace_keyword) -seq_puts (m,"," ); +seq_putc (m,',' );seq_printf (m,"%s" , data->params[i]); } }
@@ -4924,7 +4924,7 @@ static void print_track_data_spec(struct seq_file *m,print_action_spec (m, hist_data, data); -seq_puts (m,")" ); +seq_putc (m,')' ); } static void print_onmatch_spec(struct seq_file *m,
@@ -4938,7 +4938,7 @@ static void print_onmatch_spec(struct seq_file *m,print_action_spec (m, hist_data, data); -seq_puts (m,")" ); +seq_putc (m,')' ); } static bool actions_match(struct hist_trigger_data *hist_data,
@@ -5413,9 +5413,9 @@ static void hist_trigger_print_key(struct seq_file *m, }if (!multiline) -seq_puts (m," " ); +seq_putc (m,' ' ); -seq_puts (m,"}" ); +seq_putc (m,'}' ); }/* Get the 100 times of the percentage of @val in @total */
@@ -5511,13 +5511,13 @@ static void hist_trigger_entry_print(struct seq_file *m,if (flags &HIST_FIELD_FL_VAR || flags &HIST_FIELD_FL_EXPR )continue ; -seq_puts (m," " ); +seq_putc (m,' ' );hist_trigger_print_val (m, i, field_name, flags, stats, elt); }print_actions (m, hist_data, elt); -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); } static int print_entries(struct seq_file *m,
@@ -5971,7 +5971,7 @@ static int event_hist_trigger_print(struct seq_file *m, field = hist_data->fields[i];if (i > hist_data->n_vals) -seq_puts (m,"," ); +seq_putc (m,',' );if (field->flags &HIST_FIELD_FL_STACKTRACE ) {if (field->field)
@@ -5997,7 +5997,7 @@ static int event_hist_trigger_print(struct seq_file *m,seq_puts (m,"hitcount" ); }else {if (show_val) -seq_puts (m,"," ); +seq_putc (m,',' );hist_field_print (m, field); } show_val = true;
@@ -6006,14 +6006,14 @@ static int event_hist_trigger_print(struct seq_file *m,if (have_var) {unsigned int n =0 ; -seq_puts (m,":" ); +seq_putc (m,':' );for_each_hist_val_field (i, hist_data) { field = hist_data->fields[i];if (field->flags &HIST_FIELD_FL_VAR ) {if (n++) -seq_puts (m,"," ); +seq_putc (m,',' );hist_field_print (m, field); } }
@@ -6035,7 +6035,7 @@ static int event_hist_trigger_print(struct seq_file *m,return -EINVAL ;if (i >0 ) -seq_puts (m,"," ); +seq_putc (m,',' );if (idx ==HITCOUNT_IDX )seq_puts (m,"hitcount" );
kernel/trace/trace_events_user.c +4 -4
@@ -1779,7 +1779,7 @@ static int user_event_show(struct seq_file *m, struct dyn_event *ev)list_for_each_entry_reverse (field, head, link) {if (depth ==0 ) -seq_puts (m," " ); +seq_putc (m,' ' );else seq_puts (m,"; " );
@@ -1791,7 +1791,7 @@ static int user_event_show(struct seq_file *m, struct dyn_event *ev) depth++; } -seq_puts (m,"\n" ); +seq_putc (m,'\n' );return 0 ; }
@@ -2644,13 +2644,13 @@ static int user_seq_show(struct seq_file *m, void *p) busy++; } -seq_puts (m,"\n" ); +seq_putc (m,'\n' ); active++; }mutex_unlock (&group->reg_mutex); -seq_puts (m,"\n" ); +seq_putc (m,'\n' );seq_printf (m,"Active: %d\n" , active);seq_printf (m,"Busy: %d\n" , busy);
kernel/trace/trace_hwlat.c +2 -2
@@ -636,14 +636,14 @@ static int s_mode_show(struct seq_file *s, void *v)seq_printf (s,"%s" , thread_mode_str[mode]);if (mode <MODE_MAX -1 )/* if mode is any but last */ -seq_puts (s," " ); +seq_putc (s,' ' );return 0 ; }static void s_mode_stop (struct seq_file *s,void *v) { -seq_puts (s,"\n" ); +seq_putc (s,'\n' );mutex_unlock (&hwlat_data.lock); }
Signature · 1 line
2.34.1
Steven Rostedt
maintainerQuoted 15 lines · On Mon, 25 Mar 2024 22:28:29 +0300 Maxim Moskalets <[email protected]> wrote:
Using
seq_putcfor single characters is faster and more appropriate thanseq_puts, since only one character is passed and there is no need to use a more powerful and less fast function.Signed-off-by Maxim Moskalets <[email protected]>--- kernel/bpf/arraymap.c | 6 +++--- kernel/bpf/bpf_struct_ops.c | 2 +- kernel/bpf/hashtab.c | 4 ++-- kernel/bpf/local_storage.c | 4 ++-- kernel/cgroup/cgroup.c | 2 +- kernel/cgroup/debug.c | 6 +++--- kernel/latencytop.c | 2 +- kernel/locking/lockdep_proc.c | 24 ++++++++++++------------ kernel/module/procfs.c | 4 ++--
Quoted 9 lines
kernel/module/tracking.c | 2 +- kernel/sched/cpuacct.c | 4 ++-- kernel/sched/debug.c | 14 +++++++------- kernel/time/test_udelay.c | 2 +- kernel/trace/trace_events_hist.c | 26 +++++++++++++------------- kernel/trace/trace_events_user.c | 8 ++++---- kernel/trace/trace_hwlat.c | 4 ++-- 16 files changed, 57 insertions(+), 57 deletions(-)
It's probably better to break this up per sub-system and send them out as separate patches. At least that way the maintainers of the subsystems can take the patch. Otherwise, nobody is going to take ownership of this.
-- Steve
Quoted 1 line
kernel/bpf/arraymap.c +0
-0