mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
procfs: add num_to_str() to speed up /proc/stat
== stat_check.py
num = 0
with open("/proc/stat") as f:
while num < 1000 :
data = f.read()
f.seek(0, 0)
num = num + 1
==
perf shows
20.39% stat_check.py [kernel.kallsyms] [k] format_decode
13.41% stat_check.py [kernel.kallsyms] [k] number
12.61% stat_check.py [kernel.kallsyms] [k] vsnprintf
10.85% stat_check.py [kernel.kallsyms] [k] memcpy
4.85% stat_check.py [kernel.kallsyms] [k] radix_tree_lookup
4.43% stat_check.py [kernel.kallsyms] [k] seq_printf
This patch removes most of calls to vsnprintf() by adding num_to_str()
and seq_print_decimal_ull(), which prints decimal numbers without rich
functions provided by printf().
On my 8cpu box.
== Before patch ==
[root@bluextal test]# time ./stat_check.py
real 0m0.150s
user 0m0.026s
sys 0m0.121s
== After patch ==
[root@bluextal test]# time ./stat_check.py
real 0m0.055s
user 0m0.022s
sys 0m0.030s
[[email protected]: remove incorrect comment, use less statck in num_to_str(), move comment from .h to .c, simplify seq_put_decimal_ull()]
[[email protected]: avoid breaking the ABI in /proc/stat]
Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
Signed-off-by: Andrea Righi <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Glauber Costa <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Turner <[email protected]>
Cc: Russell King <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
59a32e2ce5
commit
1ac101a5d6
5 changed files with 84 additions and 29 deletions
|
|
@ -212,6 +212,26 @@ char *put_dec(char *buf, unsigned long long num)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert passed number to decimal string.
|
||||
* Returns the length of string. On buffer overflow, returns 0.
|
||||
*
|
||||
* If speed is not important, use snprintf(). It's easy to read the code.
|
||||
*/
|
||||
int num_to_str(char *buf, int size, unsigned long long num)
|
||||
{
|
||||
char tmp[21]; /* Enough for 2^64 in decimal */
|
||||
int idx, len;
|
||||
|
||||
len = put_dec(tmp, num) - tmp;
|
||||
|
||||
if (len > size)
|
||||
return 0;
|
||||
for (idx = 0; idx < len; ++idx)
|
||||
buf[idx] = tmp[len - idx - 1];
|
||||
return len;
|
||||
}
|
||||
|
||||
#define ZEROPAD 1 /* pad with zero */
|
||||
#define SIGN 2 /* unsigned/signed long */
|
||||
#define PLUS 4 /* show plus */
|
||||
|
|
|
|||
Loading…
Reference in a new issue