Skip to content

Commit a06e4ad

Browse files
cobrien7mikeNG
authored andcommitted
ANDROID: cpufreq: times: optimize proc files
The majority of the time spent reading /proc/uid_time_in_state is due to seq_printf calls. Use the faster seq_put_* variations instead. Also skip empty hash buckets in uid_seq_next for a further performance improvement. Bug: 111216804 Test: Read /proc/uid_time_in_state and confirm output is sane Test: Compare read times to confirm performance improvement Change-Id: If8783b498ed73d2ddb186a49438af41ac5ab9957 Signed-off-by: Connor O'Brien <[email protected]>
1 parent 29daf36 commit a06e4ad

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/cpufreq/cpufreq_times.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,12 @@ static void *uid_seq_start(struct seq_file *seq, loff_t *pos)
193193

194194
static void *uid_seq_next(struct seq_file *seq, void *v, loff_t *pos)
195195
{
196-
(*pos)++;
196+
do {
197+
(*pos)++;
197198

198-
if (*pos >= HASH_SIZE(uid_hash_table))
199-
return NULL;
199+
if (*pos >= HASH_SIZE(uid_hash_table))
200+
return NULL;
201+
} while (hlist_empty(&uid_hash_table[*pos]));
200202

201203
return &uid_hash_table[*pos];
202204
}
@@ -220,7 +222,8 @@ static int uid_time_in_state_seq_show(struct seq_file *m, void *v)
220222
if (freqs->freq_table[i] ==
221223
CPUFREQ_ENTRY_INVALID)
222224
continue;
223-
seq_printf(m, " %d", freqs->freq_table[i]);
225+
seq_put_decimal_ull(m, " ",
226+
freqs->freq_table[i]);
224227
}
225228
}
226229
seq_putc(m, '\n');
@@ -229,13 +232,16 @@ static int uid_time_in_state_seq_show(struct seq_file *m, void *v)
229232
rcu_read_lock();
230233

231234
hlist_for_each_entry_rcu(uid_entry, (struct hlist_head *)v, hash) {
232-
if (uid_entry->max_state)
233-
seq_printf(m, "%d:", uid_entry->uid);
235+
if (uid_entry->max_state) {
236+
seq_put_decimal_ull(m, "", uid_entry->uid);
237+
seq_putc(m, ':');
238+
}
234239
for (i = 0; i < uid_entry->max_state; ++i) {
240+
u64 time;
235241
if (freq_index_invalid(i))
236242
continue;
237-
seq_printf(m, " %lu", (unsigned long)cputime_to_clock_t(
238-
uid_entry->time_in_state[i]));
243+
time = cputime_to_clock_t(uid_entry->time_in_state[i]);
244+
seq_put_decimal_ull(m, " ", time);
239245
}
240246
if (uid_entry->max_state)
241247
seq_putc(m, '\n');

0 commit comments

Comments
 (0)