All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] kstats: kernel metric collector
@ 2020-02-26 13:50 Luigi Rizzo
  2020-02-26 13:50 ` [PATCH v3 1/2] " Luigi Rizzo
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Luigi Rizzo @ 2020-02-26 13:50 UTC (permalink / raw)
  To: linux-kernel, mhiramat, akpm, gregkh, naveen.n.rao, ardb, rizzo,
	pabeni, giuseppe.lettieri, toke, hawk, mingo, acme, rostedt,
	peterz
  Cc: Luigi Rizzo


This patchset introduces a small library to collect per-cpu samples and
accumulate distributions to be exported through debugfs.

This v3 series addresses some initial comments (mostly style fixes in the
code) and revises commit logs.

Note that use case and performance are orthogonal to those of the
perf/tracing architecture, which is why this is proposed as a standalone
component.

I have used this to trace the execution times of small sections of code
(network stack functions, drivers and xdp processing, ...), whole functions,
or notification latencies (e.g. IPI dispatch, etc.).  The fine granularity
of the aggregation helps identifying outliers, multimodal distributions,
caching effects and general performance-related issues.

Samples are 64-bit values that are aggregated into per-cpu logarithmic buckets
with configurable density (typical sample collectors use one buckets for
each power of 2, powers of 2, but that is very coarse and corresponds
to 1 significant bit per value; in quickstats one can specify the number
of significant bits, up to 5, which is useful for finer grain measurements).

There are two ways to trace a block of code: manual annotations has the best
performance at runtime and is done as follows:

	// create metric and entry in debugfs
	struct kstats *key = kstats_new("foo", frac_bits);

	...
	// instrument the code
	u64 t0 = ktime_get_ns();        // about 20ns
	<section of code to measure>
	t0 = ktime_get_ns() - t0;       // about 20ns
	kstats_record(key, t0);         // 5ns hot cache, 300ns cold

This method has an accuracy of about 20-30ns (inherited from the clock)
and an overhead with hot/cold cache as show above.

Values can be read from debugfs in an easy to parse format

	# cat /sys/kernel/debug/kstats/foo
	...
	slot 55  CPU  0    count      589 avg      480 p 0.027613
	slot 55  CPU  1    count       18 avg      480 p 0.002572
	slot 55  CPU  2    count       25 avg      480 p 0.003325
	...
	slot 55  CPUS 28   count      814 avg      480 p 0.002474
	...
	slot 97  CPU  13   count     1150 avg    20130 p 0.447442
	slot 97  CPUS 28   count   152585 avg    19809 p 0.651747
	...

Writing STOP, START, RESET to the file executes the corresponding action

	echo RESET > /sys/kernel/debug/kstats/foo

The second instrumentation mechanism uses kretrprobes or tracepoints and
lets tracing be enabled or removed at runtime from the command line for
any globally visible function

	echo trace some_function bits 3 > /sys/kernel/debug/kstats/_control

Data are exported or controlled in the same way as above. Accuracy is
worse due to the presence of kretprobe trampolines: 90ns with hot cache,
500ns with cold cache. The overhead on the traced function is 250ns hot,
1500ns cold.

Hope you find this useful.


Luigi Rizzo (2):
  kstats: kernel metric collector
  kstats: kretprobe and tracepoint support

 include/linux/kstats.h |  62 ++++
 lib/Kconfig.debug      |   7 +
 lib/Makefile           |   1 +
 lib/kstats.c           | 654 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 724 insertions(+)
 create mode 100644 include/linux/kstats.h
 create mode 100644 lib/kstats.c

-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-03-11  3:30 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 13:50 [PATCH v3 0/2] kstats: kernel metric collector Luigi Rizzo
2020-02-26 13:50 ` [PATCH v3 1/2] " Luigi Rizzo
2020-02-26 14:48   ` Paolo Abeni
2020-03-10 13:58   ` kbuild test robot
2020-03-10 13:58     ` kbuild test robot
2020-03-10 16:44   ` kbuild test robot
2020-03-10 16:44     ` kbuild test robot
2020-03-11  0:08   ` kbuild test robot
2020-03-11  0:08     ` kbuild test robot
2020-03-11  3:30   ` kbuild test robot
2020-03-11  3:30     ` kbuild test robot
2020-02-26 13:50 ` [PATCH v3 2/2] kstats: kretprobe and tracepoint support Luigi Rizzo
2020-02-26 15:00 ` [PATCH v3 0/2] kstats: kernel metric collector Toke Høiland-Jørgensen
2020-02-26 16:31   ` Alexei Starovoitov
2020-02-26 17:26   ` Luigi Rizzo
2020-02-26 19:14     ` Peter Zijlstra
2020-02-26 20:49     ` Alexei Starovoitov
2020-02-26 23:11     ` Toke Høiland-Jørgensen
2020-02-27 10:31       ` Luigi Rizzo
2020-02-27 12:13         ` Toke Høiland-Jørgensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.