From patchwork Fri Aug 7 21:29:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Adams X-Patchwork-Id: 11706107 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 875321392 for ; Fri, 7 Aug 2020 21:30:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C9B02224D for ; Fri, 7 Aug 2020 21:30:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PMRwb4Nm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727962AbgHGVa2 (ORCPT ); Fri, 7 Aug 2020 17:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727800AbgHGV3r (ORCPT ); Fri, 7 Aug 2020 17:29:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32BC1C061A32 for ; Fri, 7 Aug 2020 14:29:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id v65so4333964ybv.9 for ; Fri, 07 Aug 2020 14:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=iVslrzv4xFzBXNEn359Z/Whm6d2iMTLeHC3W31lAdWA=; b=PMRwb4NmL4IuF15MfQo+H9K6Qn15ZHpQlFswnPN/N1ayXiu4uDc5kMokYO7brGLnRA 34RvfsEoemKACz3SSygAzLYTNbPPn+yIpaRuSfUJO3w/L09IMlBjOoCkem7/IpMbKm91 3tnCRlvu1GYumA3TL/IePEohcsP++2ix3zFqbldToEgq6dgZMV4QKsaTJNHgQklhmjho RiYMb0G9JJB5PuWtxMP2x+5xImZ7zwdyFPtjEb+0+uDgMjrZjvWSbKKrc2w0PINSFFvQ 2uMQCw5nkyPclDnu8N0xl4fHSznqCH2Buiusi1bTDSmqxwryDPA95mriJfyN/ApwQxy2 NuDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iVslrzv4xFzBXNEn359Z/Whm6d2iMTLeHC3W31lAdWA=; b=mXibgS12B4M1GnII7E/adfDkp2E4yLIrQuNJXVCdyoFojg13dujpOwnhR65SQTaC5p vuDyjzf0jymay+Tls20BLFYyk4QZKNMIG4Ax4JxXpJztRUCGkhQ32t6CjCNo5x3dYJ8R qMpGzSyOH12zcwrcqkNwRr3QXTndMiF8kHwcz6+5hQkId2F9IcyMCH9ci8cmZIh1A9l7 KYamSHBNUt96EwRtcCbe3KgCOb/5JL4JJsP+yZPA6p/nfiQ1TpXtr9FAfhi6c6JqSR1Y 87plozuNVryNYLspjOOl22W/sbsY3v5BIiNYILdtEFwe6t0HDTta4rc62yxBbWcVFOWK w+jg== X-Gm-Message-State: AOAM531iMmV9QuyJrzHvCh4KMZ88agdZ4mxQtYkFZpnqlW7f47Oi5sJb RylnCk4HD53IXFltzCil4bVsrXt9XOo= X-Google-Smtp-Source: ABdhPJxcSm5w8AA6P4+MwGuTbTjPOW9Gn09XxR/9hjwAMXQFwA18Lv9fE2jFeD1Vp1hTVPD0RBmh1mdiBy15 X-Received: by 2002:a25:37c8:: with SMTP id e191mr20472648yba.230.1596835783402; Fri, 07 Aug 2020 14:29:43 -0700 (PDT) Date: Fri, 7 Aug 2020 14:29:14 -0700 In-Reply-To: <20200807212916.2883031-1-jwadams@google.com> Message-Id: <20200807212916.2883031-6-jwadams@google.com> Mime-Version: 1.0 References: <20200807212916.2883031-1-jwadams@google.com> X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [RFC PATCH 5/7] core/metricfs: expose scheduler stat information through metricfs From: Jonathan Adams To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: netdev@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Greg KH , Jim Mattson , David Rientjes , Jonathan Adams Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add metricfs support for displaying percpu scheduler counters. The top directory is /sys/kernel/debug/metricfs/stat (analogous to /proc/stat). Then there is a subdirectory for each scheduler stat. For example: cat /sys/kernel/debug/metricfs/stat/user/values Signed-off-by: Jonathan Adams --- jwadams@google.com: rebased to 5.8-pre6 This is work originally done by another engineer at google, who would rather not have their name associated with this patchset. They're okay with me sending it under my name. --- fs/proc/stat.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 46b3293015fe..deb378507b0b 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -13,6 +13,7 @@ #include #include #include +#include #ifndef arch_irq_stat_cpu #define arch_irq_stat_cpu(cpu) 0 @@ -237,3 +238,59 @@ static int __init proc_stat_init(void) return 0; } fs_initcall(proc_stat_init); + +#ifdef CONFIG_METRICFS +#define METRICFS_ITEM(name, field, desc) \ +static void \ +metricfs_##name(struct metric_emitter *e, int cpu) \ +{ \ + int64_t v = kcpustat_field(&kcpustat_cpu(cpu), field, cpu); \ + METRIC_EMIT_PERCPU_INT(e, cpu, v); \ +} \ +METRIC_EXPORT_PERCPU_COUNTER(name, desc, metricfs_##name) + +#define METRICFS_FUNC_ITEM(name, func, desc) \ +static void \ +metricfs_##name(struct metric_emitter *e, int cpu) \ +{ \ + struct kernel_cpustat cpustat; \ + int64_t v; \ + kcpustat_cpu_fetch(&cpustat, cpu); \ + v = func(&cpustat, cpu); \ + METRIC_EMIT_PERCPU_INT(e, cpu, v); \ +} \ +METRIC_EXPORT_PERCPU_COUNTER(name, desc, metricfs_##name) + +METRICFS_ITEM(user, CPUTIME_USER, "time in user mode (nsec)"); +METRICFS_ITEM(nice, CPUTIME_NICE, "time in user mode niced (nsec)"); +METRICFS_ITEM(system, CPUTIME_SYSTEM, "time in system calls (nsec)"); +METRICFS_ITEM(irq, CPUTIME_IRQ, "time in interrupts (nsec)"); +METRICFS_ITEM(softirq, CPUTIME_SOFTIRQ, "time in softirqs (nsec)"); +METRICFS_ITEM(steal, CPUTIME_STEAL, "time in involuntary wait (nsec)"); +METRICFS_ITEM(guest, CPUTIME_GUEST, "time in guest mode (nsec)"); +METRICFS_ITEM(guest_nice, CPUTIME_GUEST_NICE, + "time in guest mode niced (nsec)"); +METRICFS_FUNC_ITEM(idle, get_idle_time, "time in idle (nsec)"); +METRICFS_FUNC_ITEM(iowait, get_iowait_time, "time in iowait (nsec)"); + +static int __init init_stat_metricfs(void) +{ + struct metricfs_subsys *subsys; + + subsys = metricfs_create_subsys("stat", NULL); + metric_init_user(subsys); + metric_init_nice(subsys); + metric_init_system(subsys); + metric_init_irq(subsys); + metric_init_softirq(subsys); + metric_init_steal(subsys); + metric_init_guest(subsys); + metric_init_guest_nice(subsys); + metric_init_idle(subsys); + metric_init_iowait(subsys); + + return 0; +} +module_init(init_stat_metricfs); + +#endif