Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp206369ybf; Wed, 26 Feb 2020 11:32:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwExpoHL+IYue4SKAeRPTnVE1T7hUD7ngHhRwIolY1EaMfK1siprHG8ADeyrNVXeoEzalsR X-Received: by 2002:a05:6830:1d6e:: with SMTP id l14mr323638oti.32.1582745524513; Wed, 26 Feb 2020 11:32:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582745524; cv=none; d=google.com; s=arc-20160816; b=aP7Ii+6iT7Jal214x5Hr9gkOwNTgN1keBKI3bfTCBMVYaFcXyCqPmO+TxRHf2UMfxg NeVulC+qz9DVvAhOOXi+sRGuxJ5T/gYjve5nMeSbIUYT+LnDpQWPIXMfQbwrPt6SsFxg RWu+Qa8GJzitQNJ5LjYLlEguE42S5Y1ZJW3UqXhxfrSWyyHCyH3FMF0EBEOP2ow6jBH2 cki+NSuLc23ftu/LFjW0lLbMNL2qsdyvp0tI+9yGZ1wkTLLOQCkmXsgJ8Q9L/Y453GQz KFUl/D81hFEVjiG2w+scTcDVs3io8vZo05fO9fQy9wCQ6kLMMai3n97WzeI/KtLAqCpU ZaRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tim9X+F9vYHdlPOoRw/qRUISublgBCciYQagSlRF/BQ=; b=JXXbMdfZOBAK1SkDLUo/iQvZSRyoC2E5l12F40nvktH09tLjNYp4TQyBGNB+0qUUBZ khNoN0oS1rFmvi8BYhMKSC/u2uNY5SjQdb80xuDxwXClYxgvP8/lhFSwbOyovMl4U1cN mf1tZmCDnSIj56+/t9EtoViw3K5KsXQJo/wzBnsEtXT1uN15fv2/Eu8jz3K4li0miXIR 6q4ApPdmn9nm+D2JNQ4fSX7PxvE+Vc0G8oqwRwhiyjPyFNqOI7eUdbylyB4nlEEfgobk J5LjCQfb8OchxjuhQTs5YY8iintsobbcHzl6Q2IjsGdez/FmtRutmqtfa4w4GktISMTf mB7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fk3KALdk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si236296oto.205.2020.02.26.11.31.51; Wed, 26 Feb 2020 11:32:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fk3KALdk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbgBZTbP (ORCPT + 99 others); Wed, 26 Feb 2020 14:31:15 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:35707 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727221AbgBZTbP (ORCPT ); Wed, 26 Feb 2020 14:31:15 -0500 Received: by mail-ed1-f68.google.com with SMTP id c7so221698edu.2 for ; Wed, 26 Feb 2020 11:31:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tim9X+F9vYHdlPOoRw/qRUISublgBCciYQagSlRF/BQ=; b=fk3KALdk6grE6nY7sZB/mMhkpi/EHCV27nxRPV1AsjEZqMQpBreIX+rtoBJ44sqDsI vwaPGdgc9e+qyka2BcLNlAw6JmpyAGGFeMkNWbUTpaUbGv+vC490mp74n2El5r9njbus ZrytAHK6bEILXuEJk7nUY94hlCx9kNrpyoUxSmX6QzGbTH6kpoiNBAln+vygx0sG3UJd T5ZB/60MxFqThgIC7vlB7egYA6gXLZ+Np1G6L4KFxfD7ILoWF7nINBayxNrqJbENzIRx fMd+lYihMK62FUi+kkvaPGabjSMUzGSu9NiHxhrIG9ZUif+QJLbs1918ZJMIE1F52og8 oTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tim9X+F9vYHdlPOoRw/qRUISublgBCciYQagSlRF/BQ=; b=A6cGlpbumhoWFqpRAWUrWynAsVLo3Ecm5CkmgNu/XY1ZALDaI1vh3vduk+KRlV6A0q ddDHxGRMwr75pTBlg/6D2/KclfnWuvaoHqhd0NP0eSB6S7WqDusBrvSwvxFA7zBpr3NK zHOrxoRRzH5PmhkDf1mrTa5A5a01L/j62/mNDRK2lBw2HzPfD/z58RLC/dUoDJUTHAqO Gbm9bq5Y6aX7ueJy6V4xkI0Q2wi8nKyioaiAIPwrYVRbM8D68YyMCexoixXii1munKf3 zqlvzm4iICBMB5eRW57J4qWKkqOef1sivVMvpzMNDOCOlREqPk706A1AK6T/JQMtBQQV TMNw== X-Gm-Message-State: APjAAAX+366oR6lYNQykNw0eDivEBQwlIFjZ1fCDm7NLEvUEWO+QiHib Z2zbCI6DgOkvfLZZW37+st+ZHr0rkRT1rz+hps35hQ== X-Received: by 2002:a17:906:b7c4:: with SMTP id fy4mr284770ejb.139.1582745473140; Wed, 26 Feb 2020 11:31:13 -0800 (PST) MIME-Version: 1.0 References: <20200226134637.31670-1-lrizzo@google.com> <20200226134637.31670-2-lrizzo@google.com> <20200226161941.GZ18400@hirez.programming.kicks-ass.net> In-Reply-To: <20200226161941.GZ18400@hirez.programming.kicks-ass.net> From: Luigi Rizzo Date: Wed, 26 Feb 2020 11:31:01 -0800 Message-ID: Subject: Re: [PATCH v2 1/2] kstats: kernel metric collector To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Masami Hiramatsu , Andrew Morton , Greg KH , naveen.n.rao@linux.ibm.com, ardb@kernel.org, Luigi Rizzo , Paolo Abeni , giuseppe.lettieri@unipi.it, =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Jesper Dangaard Brouer , mingo@redhat.com, acme@kernel.org, Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 8:19 AM Peter Zijlstra wrote: > > 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. the above is perhaps one excellent argument to why it may deserve to be in: so that people don't need to write the measurement code time and again, or, as I have done myself multiple times, use some inferior hack (racy counter, coarse buckets) or give up measuring things and rely on guessing. > 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. And this is possibly another good argument: sometimes the systems where it would be interesting to collect data are not accessible to the developers with skills to write the monitoring code and run a modified kernel. cheers luigi