Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp34717ybf; Wed, 26 Feb 2020 08:21:42 -0800 (PST) X-Google-Smtp-Source: APXvYqwMTew0g6g3O4BfIdYYvvRpG/gfllafGy4BzFo4iTKdKVTnLs9XfIz8mEv9yxYSIkcQuQnL X-Received: by 2002:a54:4f16:: with SMTP id e22mr3948655oiy.170.1582734102697; Wed, 26 Feb 2020 08:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582734102; cv=none; d=google.com; s=arc-20160816; b=z/s4PPj1fAez7zBZW/NJyS/pK/w3SrNqJlxmqjAVXj4KLzydzxraft0r5hGK2aMos+ FfPhnYpTRFB6hwkuJTehMaAwWCFixteqYJkHfqlcexRuX/kf7Ftelr7SMRTujsEdg01x ojlxRB/qlj6FhsDDjTLQQryHJW/Y0NtuFSXXPnHH9qPuGR8Cce5ntfRAlaMe3zJ+86FR EcbXjUA/KsDfJqoCoJWP3X3s0LvtP9+mcpQTCWWR0zXKCty63wKA5LrMfG8lvwwr60Fz ajeJM/whnLNJd7Nmj52fN5+CiualTIMaLMNKt6ZQW+0kQZddqJx6iFbxLc1Etg8sroeI kHhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pLcMLY+l8Jn014Qw6oW/1gcX4+lXMwKFovCkSJaWe78=; b=WQBik39eS24eOSzwC8G00wmo7a0tZCz4EOPkWPsNYo6shKkLiLXNmtjym1y9Y2p0kM 6zHsSO2PX3QdE54xUqic5Z7JEts4T0lcPnJzbI4+9z9rP/2EKvw3ZK+lVS4x49DlQyY0 bAKxNSGcD9bzk8zJG6Fd0HcOjBloP/JBDhlUcPHWlS3sHX+W5YjV3QRJ2/pLVVYZU0jW 4FMo78eJqk/b7pFCYjgc4fzpzLYNN1ORART/fUBPp7j2xQOeKuOu9dXOVbN7yShsfbb8 QDO2xMYmED7XkPb/w8acCB4KsuEj6sjMt/8rQwuMWjWFl/Bkjy4BrrZsAkrVdJtJHuLZ fWxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=sx4t934S; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f141si1495795oib.125.2020.02.26.08.21.28; Wed, 26 Feb 2020 08:21:42 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=sx4t934S; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbgBZQUT (ORCPT + 99 others); Wed, 26 Feb 2020 11:20:19 -0500 Received: from merlin.infradead.org ([205.233.59.134]:56544 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726148AbgBZQUT (ORCPT ); Wed, 26 Feb 2020 11:20:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=pLcMLY+l8Jn014Qw6oW/1gcX4+lXMwKFovCkSJaWe78=; b=sx4t934StzYnAVVNNCrqTLwGEm YBfgRrLQz3W8A1lHn+TV3zDVjWaw4chqU00r3OfTafA50YWMqhNCvN9tABO6ZKRR+2zIKGCz5IG4q P8fnPl/WEIHSu88kboKd/UIgbtCFCSwH0lqTUlgpzVK7C8JAms7ctFteU79TuQQcapOTPqEqGdX1H xn85Vd6KYb7mXNDQiEqJhmWx+sUjMoLXyZxDrHzoQor1PQDC16+OVMHHHJgwcFEvj+Zv0Np7UL5q1 xOs0Q+vYa4KOl9Byl+9uQWbYYaGP40cdlEx/68yA+Z96i9NJRopWEb0vLfnoW7JUzq4s1xlZc/su8 AgNh80AQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6zPU-00017f-TM; Wed, 26 Feb 2020 16:19:45 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3FCC4305EFE; Wed, 26 Feb 2020 17:17:46 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8BBA12B7418A0; Wed, 26 Feb 2020 17:19:41 +0100 (CET) Date: Wed, 26 Feb 2020 17:19:41 +0100 From: Peter Zijlstra To: Luigi Rizzo 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 Message-ID: <20200226161941.GZ18400@hirez.programming.kicks-ass.net> References: <20200226134637.31670-1-lrizzo@google.com> <20200226134637.31670-2-lrizzo@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226134637.31670-2-lrizzo@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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 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?