Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp947600pxa; Wed, 5 Aug 2020 17:17:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx99XDQhgwwP2grTE9MA+jA3wBonaMJqMgK4QodyQX1Dd8aeLZPExWL9f2RwlhZe84Urn1D X-Received: by 2002:a17:906:2e8d:: with SMTP id o13mr1793321eji.279.1596673075167; Wed, 05 Aug 2020 17:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596673075; cv=none; d=google.com; s=arc-20160816; b=MnGJM5cyIM0Eo1N0Ve0FYNXcCxQ4y0Bs8c+i3NsvQi33X80EzDXM6tSSbixeTy5NNT JJ85C+oegbQ/ZYBUgINvskNecMTe3eX+UA0DBJZDC1NH6dsMq2i7bIkfsCEL2yiYhcp6 AaakIpyXKX9We2BDp72TO/5EqbRP3oMBpAZiQP4BXszNEseLQhX6uIrPMwtrBGKfPgB4 w3aNYNX9Beg1nLy0jr7828sgaV9j4mJvJrDZuRgfBpmCewaC7JCnEKFHD6V83LFg5MUh HPhgRsm0f1sPVaqxCej8x1AhcnNHEnFgg+kWSjm9OKfak2d6REuNNrxXMwVaF765FkcL auUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=iVslrzv4xFzBXNEn359Z/Whm6d2iMTLeHC3W31lAdWA=; b=vcKGt+yfBRjvgB9WuDtVQ4VaeVr1RCRzYNK9m1Imj5sUyJ1IHq3RFwZYjBGMeqdz7q /KHmGd2lHbZ8BVWsWUNmT7dpwDSoNFu4gAW8W2evE9sastKmyrQ9BxWf6Zz/iiKv69RL JfFT8NMLVHZJdqqXKG60G7h7Rga07bUE+uoDXxk1jiCijekDvlkuYxGRvKhycqa6Ps+G 9A7w5evscQAsqE+tX1aysQxDLqhY3lO6LLNh086tluPtm9jXhH4PBY45eQkWD6v16+Mb JRDTc2TSC6ZoSJ6MVLLcbeydzDiUgrsOABLVYfyAe6IIsLOJZTUX6W3kppFOkVQH0xq7 +kmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="C/SP0oGO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id h11si2157604edr.606.2020.08.05.17.17.32; Wed, 05 Aug 2020 17:17:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="C/SP0oGO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726948AbgHFAPx (ORCPT + 99 others); Wed, 5 Aug 2020 20:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbgHFAOt (ORCPT ); Wed, 5 Aug 2020 20:14:49 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F93C0617A0 for ; Wed, 5 Aug 2020 17:14:48 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d26so26401548yba.20 for ; Wed, 05 Aug 2020 17:14:48 -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=C/SP0oGOW1Or0jT1oy8iTM7UpU1UdLCVB8XtXPbbhM8nUGF/k9zuT96H8/k1S2BPKz GH5kyP4tdhCcsLhgn8rcadoYQlTO83PD9GurtMSGz+82arCK0ifyqSXg8TZyHvUT4g+e +k4VMFJphoSzYgDTwtYuYzosOEyZMlvPAM+opXYtnM/8i5eXMcqXDWbrgHh3H4hgN6ur 5ydu82s+kCbf12Ocmgq1tZDBYQzWVBiShHlJEbsTOnLSQmCiDniGXpO2VNiZGWV5aQ+5 K8kUk72cHvQAzLwAVzFnwSI06Ek+xEWFPcxTlNM8G7BoLXXbXC4tSuIo7jY5To7ZNcVV QcsQ== 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=PStpmtNG5l0gOnfJPDVsPqCZ5KvS2xEyyF23/3eFo1LfrwpQXXf9D9oDDidXE563qX siy/FDzDXdMS5BciTB4aYCglov6wJqikOd3A1p1aYc1QxqUcyKpPXsMFisLtxpd548kW PCTcQkRUEM/Q0JqoELXGTILcLARH8hJhGgMgM870DU5qTpwAXheBITAlzzyIF8K647pf ktdGJCzwEM0Q9q+iO+RhXZEduJp3OifzJLt4FGpDfs6t+UoOdbrQRadJ4WSHNnWkfnrU abtupGPn8wpfn+sSOFNcQGP7m0q5OooABS2XU80YxtNLJRbDiOAART3Owy3ucWCdqv7l 2ZQQ== X-Gm-Message-State: AOAM532gbKHL4AgmXF7NP0mMJj2TqZg5XNslX+el+660RJjo2HSWPDqI 9SvSi74sPc0qyfFdx9+2U2XNahd3hdSLSiPQ0aeEHmM53OzhuJD4J6rqUN2IfEWfysxi11pngq8 mG8clfhBGvfF29L7oTk0f/pz9NwRqq2O9sR5eT2rECZQjxnlLJ1Cfmwc9c8ZRawPQyP2K1xg= X-Received: by 2002:a25:32d6:: with SMTP id y205mr9190286yby.77.1596672887452; Wed, 05 Aug 2020 17:14:47 -0700 (PDT) Date: Wed, 5 Aug 2020 17:14:29 -0700 In-Reply-To: <20200806001431.2072150-1-jwadams@google.com> Message-Id: <20200806001431.2072150-6-jwadams@google.com> Mime-Version: 1.0 References: <20200806001431.2072150-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 Cc: kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , David Rientjes , Jonathan Adams 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 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 -- 2.28.0.236.gb10cc79966-goog