Received: by 10.213.65.68 with SMTP id h4csp1776565imn; Mon, 19 Mar 2018 12:59:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELsO+gNZEA2dFmH2/UNhrtPFrGKttEWNobysFEncfmwhdMdkPyTWOylNlIMWArGc8X5Zizue X-Received: by 2002:a17:902:3124:: with SMTP id w33-v6mr14076963plb.119.1521489582804; Mon, 19 Mar 2018 12:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521489582; cv=none; d=google.com; s=arc-20160816; b=aQtLuRV94k3rRw8prHi84ygL0UREAe8tFdDkOf/gdYx6JvKVK/QG/+hJHDqihkYhB0 0vIkXi2h6mU9HPa7i3O8qJWPaPXincr6XfVmjWF0URFRdWm6JavvWWpoKtoE231Iyz+8 vKVkssCW46LdRodwHY5tAlu6XStQUQZ7qGO8UTVvVJOyVcT4UgBo4LJECu4rdSMrMEzD eBqnuLvjetw2mC3ndTT7oGdHRfrJoJaghAIGe0/ATCI6w0s6JoCnRYzg4Rr670JbYjHp DpgSNQuPcW7drYijkWlImIFusxxhyeMcMuRVEesukMYiYtUr3x3wt8I9FR9d8SmtsAiA OPaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XkqPXvpWNns8/CzQ8nhiEgkgjiDYaO3PCMJxh7ImzxM=; b=uCqPM5HiHLZb3Pfyusks4UA6YUjG+wzYGYzzRcmAxqzUuMBP6n+vn1QoljoFsuLIml u22ceyqadEpI3oT1BCOUS1m4wNlUiGMHEcIKr6/+d8xEPmGcwma8j5oPhcm/xHoyKqVU 6h7ZGFwNCvsnTUMVpBHwqv6Z5+/mE9Bg09lz9c0Wt9XvrjD0OTFsSRX0RdCn+vo6R7+5 cEOCapixiJDEHs5cAJrC8Q05MRZEWC4Kw3m9ttv7uUfBdeGxhofWUxi5y43Ug9RRDdAX 5PRoqEDSPpucLmSHsSRj2kcl/NHdNn+eUs4k9SpQhqxROf6Ex37AyhhcsWcZ4JXkExh2 YKNA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si444004pgc.757.2018.03.19.12.59.28; Mon, 19 Mar 2018 12:59:42 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936087AbeCST5i (ORCPT + 99 others); Mon, 19 Mar 2018 15:57:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46708 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030893AbeCSSSw (ORCPT ); Mon, 19 Mar 2018 14:18:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A5DA91092; Mon, 19 Mar 2018 18:18:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Borislav Petkov , Ingo Molnar , Arnaldo Carvalho de Melo , Peter Zijlstra , Robert Richter , Vince Weaver , Sasha Levin Subject: [PATCH 4.9 003/241] perf stat: Issue a HW watchdog disable hint Date: Mon, 19 Mar 2018 19:04:28 +0100 Message-Id: <20180319180751.316243264@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Borislav Petkov [ Upstream commit 02d492e5dcb72c004d213756eb87c9d62a6d76a7 ] When using perf stat on an AMD F15h system with the default hw events attributes, some of the events don't get counted: Performance counter stats for 'sleep 1': 0.749208 task-clock (msec) # 0.001 CPUs utilized 1 context-switches # 0.001 M/sec 0 cpu-migrations # 0.000 K/sec 54 page-faults # 0.072 M/sec 1,122,815 cycles # 1.499 GHz 286,740 stalled-cycles-frontend # 25.54% frontend cycles idle stalled-cycles-backend (0.00%) ^^^^^^^^^^^^ instructions (0.00%) ^^^^^^^^^^^^ branches (0.00%) branch-misses (0.00%) 1.001550070 seconds time elapsed The reason is that we have the HW watchdog consuming one PMU counter and when perf tries to schedule 6 events on 6 counters and some of those counters are constrained to only a specific subset of PMCs by the hardware, the event scheduling fails. So issue a hint to disable the HW watchdog around a perf stat session. Committer note: Testing it... # perf stat -d usleep 1 Performance counter stats for 'usleep 1': 1.180203 task-clock (msec) # 0.490 CPUs utilized 1 context-switches # 0.847 K/sec 0 cpu-migrations # 0.000 K/sec 54 page-faults # 0.046 M/sec 184,754 cycles # 0.157 GHz 714,553 instructions # 3.87 insn per cycle 154,661 branches # 131.046 M/sec 7,247 branch-misses # 4.69% of all branches 219,984 L1-dcache-loads # 186.395 M/sec 17,600 L1-dcache-load-misses # 8.00% of all L1-dcache hits (90.16%) LLC-loads (0.00%) LLC-load-misses (0.00%) 0.002406823 seconds time elapsed Some events weren't counted. Try disabling the NMI watchdog: echo 0 > /proc/sys/kernel/nmi_watchdog perf stat ... echo 1 > /proc/sys/kernel/nmi_watchdog # Signed-off-by: Borislav Petkov Acked-by: Ingo Molnar Tested-by: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Robert Richter Cc: Vince Weaver Link: http://lkml.kernel.org/r/20170211183218.ijnvb5f7ciyuunx4@pd.tnic Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/builtin-stat.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -146,6 +146,7 @@ static aggr_get_id_t aggr_get_id; static bool append_file; static const char *output_name; static int output_fd; +static int print_free_counters_hint; struct perf_stat { bool record; @@ -1109,6 +1110,9 @@ static void printout(int id, int nr, str counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, csv_sep); + if (counter->supported) + print_free_counters_hint = 1; + fprintf(stat_config.output, "%-*s%s", csv_output ? 0 : unit_width, counter->unit, csv_sep); @@ -1477,6 +1481,13 @@ static void print_footer(void) avg_stats(&walltime_nsecs_stats)); } fprintf(output, "\n\n"); + + if (print_free_counters_hint) + fprintf(output, +"Some events weren't counted. Try disabling the NMI watchdog:\n" +" echo 0 > /proc/sys/kernel/nmi_watchdog\n" +" perf stat ...\n" +" echo 1 > /proc/sys/kernel/nmi_watchdog\n"); } static void print_counters(struct timespec *ts, int argc, const char **argv)