From: Peter Zijlstra <peterz@infradead.org>
To: Luigi Rizzo <lrizzo@google.com>
Cc: linux-kernel@vger.kernel.org, mhiramat@kernel.org,
akpm@linux-foundation.org, gregkh@linuxfoundation.org,
naveen.n.rao@linux.ibm.com, ardb@kernel.org, rizzo@iet.unipi.it,
pabeni@redhat.com, giuseppe.lettieri@unipi.it, toke@redhat.com,
hawk@kernel.org, mingo@redhat.com, acme@kernel.org,
rostedt@goodmis.org
Subject: Re: [PATCH v2 1/2] kstats: kernel metric collector
Date: Wed, 26 Feb 2020 17:19:41 +0100 [thread overview]
Message-ID: <20200226161941.GZ18400@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200226134637.31670-2-lrizzo@google.com>
On Wed, Feb 26, 2020 at 05:46:36AM -0800, Luigi Rizzo wrote:
> kstats is a helper to accumulate in-kernel metrics (timestamps, sizes,
> etc.) and show distributions through debugfs.
> Set CONFIG_KSTATS=m or y to enable it.
>
> Creating a metric takes one line of code (and one to destroy it):
>
> struct kstats *key = kstats_new("foo", 3 /* frac_bits */);
> ...
> kstats_delete(key);
>
> The following line records a u64 sample:
>
> kstats_record(key, value);
>
> kstats_record() is cheap (5ns hot cache, 250ns cold cache). Samples are
> accumulated in a per-cpu array with 2^frac_bits slots for each power
> of 2. Using frac_bits = 3 gives about 30 slots per decade.
So I think everybody + dog has written code like this, although I never
bothered with the log2 based buckets myself. Nor have I ever bothered
with doing a debugfs interface.
I find it very hard to convince myself something like this deserves to
live upstream, vs. remaining in the local debug/hack toolbox.
Tracing has an aggregator (histogram), you can dump the raw deltas, or
you can hack up a custom aggregator in a few lines, or you do BPF if
you're so inclined.
Why do we need this specific one?
next prev parent reply other threads:[~2020-02-26 16:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-26 13:46 [PATCH v2 0/2] " Luigi Rizzo
2020-02-26 13:46 ` [PATCH v2 1/2] " Luigi Rizzo
2020-02-26 16:19 ` Peter Zijlstra [this message]
2020-02-26 19:31 ` Luigi Rizzo
2020-02-27 2:10 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200226161941.GZ18400@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=giuseppe.lettieri@unipi.it \
--cc=gregkh@linuxfoundation.org \
--cc=hawk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lrizzo@google.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=naveen.n.rao@linux.ibm.com \
--cc=pabeni@redhat.com \
--cc=rizzo@iet.unipi.it \
--cc=rostedt@goodmis.org \
--cc=toke@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®