Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1388851imm; Wed, 6 Jun 2018 15:25:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJPJNuXkbjazb4n/3U7a4X+bCN9jkH7o5prMXZLxGw1bBdMqZ//jOYxdsHkyzrOJ83wtiX6 X-Received: by 2002:a63:70a:: with SMTP id 10-v6mr4118968pgh.216.1528323933002; Wed, 06 Jun 2018 15:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528323932; cv=none; d=google.com; s=arc-20160816; b=ZGPMi6DzlESj6vYmTw/796zR2Qo4EPc1aOthF4CWhJBnblBl3RT4rO/CTimPNOtEF6 GCr5452CzlSQN9IECkC277Jg9UmVjptlB0Jnpm4Fp+WsIAN7XdXq1qxSEp+gqmucejCW FId00Z1NXLkxjxF9RYx4/k2o3O6Fa8t5jfFl6pDXJEBe81CTmQu2Wktwb/9m0emCFUS+ lauHMSTTIWXZRnB05u8nYzGI7ZTbnfoO7VHTMV0o0ET6FZtZ9x65nphQsk44ijzoVn+C ilKbG/MGsKt4LmyMW94UMHPBzf8qV6JcsQKOJ2H1OFY5bxUZdkzDIS/84/ViCDMUO6kv T/BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=aBppquLJEHx7qDiTd3YzK1tMrwUfpBieJnBoeHuh6jA=; b=WNQ73mi/oOYgOOgY24xEoikKTK3YRMpbIvIsXMNa7CoR5UyMFsdtzQtEupnqhijseN 6I+I0iddWJHlGfGOdCzNIcWe76LpAEqviSxRSQYkY835TL3u62vjTcg2QbQ7Yb5WF7cf jCkjAN+WTaqm9/xOEDR9jZYRboeHpPlkZdHSjNUFKyBIPmci9IgSzWl3vWY+kF/wNHmc kWzPZnFJ64rPKrguCPyEGU6+1Ol1RRKlDSoIlgsg6Ddh0NsJqOz5FloYeWUq90OyOgMY duVw3leIeJwpn/c9l2gXkF2bUYiKzWVSf9hRbv+lm336ah/W8j7jq/XI26yq2jkuv5R5 c30w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si53219842pfm.167.2018.06.06.15.25.15; Wed, 06 Jun 2018 15:25:32 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752137AbeFFWPU (ORCPT + 99 others); Wed, 6 Jun 2018 18:15:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55764 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751878AbeFFWPT (ORCPT ); Wed, 6 Jun 2018 18:15:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 538BB805A531; Wed, 6 Jun 2018 22:15:18 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-89.brq.redhat.com [10.40.204.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61A802026DEF; Wed, 6 Jun 2018 22:15:14 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo , Peter Zijlstra Cc: lkml , Ingo Molnar , Namhyung Kim , David Ahern , Alexander Shishkin , Stephane Eranian , Milian Wolff , Andi Kleen , Frederic Weisbecker Subject: [RFC 00/10] perf: Add cputime events/metrics Date: Thu, 7 Jun 2018 00:15:03 +0200 Message-Id: <20180606221513.11302-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 06 Jun 2018 22:15:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 06 Jun 2018 22:15:18 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@kernel.org' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hi, so.. I failed to make work reliably the exclude_idle bit for cpu-clock event using the idle's process sum_exec_runtime as Peter outlined in his patch [1]. The time jumped up and down and I couldn't make it stable. But I noticed we actually have IDLE stats (and many more) available for each CPU (enum cpu_usage_stat), we just can't reach them by perf yet. So this patchset adds 'cputime' perf software PMU, that provides CPUTIME_* stats via events that mirrors their names: # perf list | grep cputime cputime/guest/ [Kernel PMU event] cputime/guest_nice/ [Kernel PMU event] cputime/idle/ [Kernel PMU event] cputime/iowait/ [Kernel PMU event] cputime/irq/ [Kernel PMU event] cputime/nice/ [Kernel PMU event] cputime/softirq/ [Kernel PMU event] cputime/steal/ [Kernel PMU event] cputime/system/ [Kernel PMU event] cputime/user/ [Kernel PMU event] I had some issues with IDLE counter being miscounted due to stopping of the idle tick. I tried to solve it in this patch (it's part of the patchset): perf/cputime: Don't stop idle tick if there's live cputime event but I'm pretty sure it's wrong and there's better solution. However most of the counts look ok so far and here's few of my favorite commands I've been playing with: # perf stat --top -I 1000 # time Idle System User Irq Softirq IO wait 1.001692690 100.0% 0.0% 0.0% 0.7% 0.2% 0.0% 2.002994039 98.9% 0.0% 0.0% 0.9% 0.2% 0.0% 3.004164038 98.5% 0.2% 0.2% 0.9% 0.2% 0.0% 4.005312773 98.9% 0.0% 0.0% 0.9% 0.2% 0.0% # perf stat --top-full -I 1000 # time Idle System User Irq Softirq IO wait Guest Guest nice Nice Steal 1.001750803 100.0% 0.0% 0.0% 0.7% 0.2% 0.0% 0.0% 0.0% 0.0% 0.0% 2.003159490 99.0% 0.0% 0.0% 0.9% 0.2% 0.0% 0.0% 0.0% 0.0% 0.0% 3.004358366 99.0% 0.0% 0.0% 0.9% 0.2% 0.0% 0.0% 0.0% 0.0% 0.0% 4.005592436 98.9% 0.0% 0.0% 0.9% 0.2% 0.0% 0.0% 0.0% 0.0% 0.0% # perf stat -e cpu-clock,cputime/system/,cputime/user/,cputime/idle/ -a sleep 10 Performance counter stats for 'system wide': 240070.828221 cpu-clock (msec) # 23.999 CPUs utilized 208,910,979,120 ns cputime/system/ # 87.0% System 20,589,603,359 ns cputime/user/ # 8.6% User 8,813,416,821 ns cputime/idle/ # 3.7% Idle 10.003261054 seconds time elapsed # perf stat -e cpu-clock,cputime/system/,cputime/user/ yes > /dev/null ^Cyes: Interrupt Performance counter stats for 'yes': 3483.824364 cpu-clock (msec) # 1.000 CPUs utilized 2,460,117,205 ns cputime/system/ # 70.6% System 1,018,360,669 ns cputime/user/ # 29.2% User 3.484554149 seconds time elapsed 1.018525000 seconds user 2.460515000 seconds sys # perf stat --top -I 1000 --interval-clear # perf stat --top -I 1000 --interval-clear --per-core # perf stat --top -I 1000 --interval-clear --per-socket # perf stat --top -I 1000 --interval-clear -A It's also available in here: git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git perf/fixes My current plan is now to read those counters in perf top/record/report to show (at least) the idle percentage for the current profile. thoughts? ;-) thanks, jirka [1] https://marc.info/?l=linux-kernel&m=152397251027433&w=2 --- Jiri Olsa (10): perf tools: Uniquify the event name if there's no other matched event perf tools: Fix error index for pmu event parser perf stat: Add --interval-clear option perf stat: Use only color_fprintf call in print_metric_only perf stat: Fix metric column display perf stat: Allow to specify specific metric column len perf stat: Add event parsing error handling to add_default_attributes perf/cputime: Add cputime pmu perf/cputime: Don't stop idle tick if there's live cputime event perf stat: Add cputime metric support include/linux/perf_event.h | 3 ++ kernel/events/Makefile | 2 +- kernel/events/core.c | 1 + kernel/events/cputime.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/time/tick-sched.c | 4 +++ tools/perf/Documentation/perf-stat.txt | 68 ++++++++++++++++++++++++++++++++++++ tools/perf/builtin-stat.c | 104 ++++++++++++++++++++++++++++++++++++++++++++----------- tools/perf/util/parse-events.y | 5 +++ tools/perf/util/stat-shadow.c | 70 +++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.c | 10 ++++++ tools/perf/util/stat.h | 10 ++++++ 11 files changed, 467 insertions(+), 21 deletions(-) create mode 100644 kernel/events/cputime.c