Received: by 10.213.65.68 with SMTP id h4csp1722604imn; Mon, 19 Mar 2018 11:27:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELuytau0wC2nX7AvtP6QqL9a/ECCMaiZC+iPrzWMe//ph0lp13thtj7P1bpro3WVjDAxr9qB X-Received: by 2002:a17:902:144:: with SMTP id 62-v6mr13663881plb.202.1521484036286; Mon, 19 Mar 2018 11:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484036; cv=none; d=google.com; s=arc-20160816; b=OVOoLbFYk6/gfcYmrQoOqv57CsozYjMGH2P4eNLyYkaUdNqrBHiRY5Gr1k3obDZgw2 uPM61xOkEb7+Zo3qq25lnZaIygSMZO4s3QRjkjaZQU4OyG16zLG7G5z6sDwaau5SbIBm Ail+9pHNjOxx3XMQT5Vec6B91b+caw2MDXsP7jPoJ2ul3POMIfko1G4jAOqfKiIJJ3Hb GmURdgfniej4vZM7FS/+Db4m6mXAZcG8agYGhnD4A048ca6vgHF1xPDGYRKrWHWBAwjd AxlmtkJ0VWcBVOF+c0yI9qdhf8egOZOPVHTtcM9C4X+oDhMA51iLzZ2WAgH7y1sQ+5ob 4hOA== 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=BhVeHyA160/+ue5KAPW+jp2NGBka90tCx2kClizS46M=; b=V625ijY2ZYDP2gF1Aa2y+2lDjePlmg159YMnACVdlVT76/ethx3MJ8qMMAFZqkyERh Bhm3yuml1NM6WI0V2wdxhBrJTWWZpePJPjIwvKXZXmnfXyFuDLXeVdizoQs1HXx3xkxy CtjvmjqBgRz2mX30rkkIU5ERT7NITGc/A9DJ9Hq2I3gc3XMxB1s0IWt355/n80pNIDvn WHHdpnUBtyN3yFG+/AYI1lpR7H10nL6AyYbMQ65iot2rn0vIqvDQSEs0qdd0EyQ7CtiK kQIz11sBgiHH/zJDEz5UBCqhE92LUme5kqdRojOtg05Hh7xaQgXkx4PNu5aoPveJ+DPN McyQ== 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 r7si302009pgp.212.2018.03.19.11.27.01; Mon, 19 Mar 2018 11:27:16 -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 S969723AbeCSSZ1 (ORCPT + 99 others); Mon, 19 Mar 2018 14:25:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50274 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031358AbeCSSZL (ORCPT ); Mon, 19 Mar 2018 14:25:11 -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 E7D56D09; Mon, 19 Mar 2018 18:25:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , David Carrillo-Cisneros , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Andi Kleen , Mathieu Poirier , Paul Turner , Peter Zijlstra , Wang Nan , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 162/241] perf stat: Fix bug in handling events in error state Date: Mon, 19 Mar 2018 19:07:07 +0100 Message-Id: <20180319180757.870200065@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: Stephane Eranian [ Upstream commit db49a71798a38f3ddf3f3462703328dca39b1ac7 ] (This is a patch has been sitting in the Intel CQM/CMT driver series for a while, despite not depend on it. Sending it now independently since the series is being discarded.) When an event is in error state, read() returns 0 instead of sizeof() buffer. In certain modes, such as interval printing, ignoring the 0 return value may cause bogus count deltas to be computed and thus invalid results printed. This patch fixes this problem by modifying read_counters() to mark the event as not scaled (scaled = -1) to force the printout routine to show . Signed-off-by: Stephane Eranian Reviewed-by: David Carrillo-Cisneros Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Mathieu Poirier Cc: Paul Turner Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/20170412182301.44406-1-davidcc@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/builtin-stat.c | 12 +++++++++--- tools/perf/util/evsel.c | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -311,8 +311,12 @@ static int read_counter(struct perf_evse struct perf_counts_values *count; count = perf_counts(counter->counts, cpu, thread); - if (perf_evsel__read(counter, cpu, thread, count)) + if (perf_evsel__read(counter, cpu, thread, count)) { + counter->counts->scaled = -1; + perf_counts(counter->counts, cpu, thread)->ena = 0; + perf_counts(counter->counts, cpu, thread)->run = 0; return -1; + } if (STAT_RECORD) { if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { @@ -337,12 +341,14 @@ static int read_counter(struct perf_evse static void read_counters(void) { struct perf_evsel *counter; + int ret; evlist__for_each_entry(evsel_list, counter) { - if (read_counter(counter)) + ret = read_counter(counter); + if (ret) pr_debug("failed to read counter %s\n", counter->name); - if (perf_stat_process_counter(&stat_config, counter)) + if (ret == 0 && perf_stat_process_counter(&stat_config, counter)) pr_warning("failed to process counter %s\n", counter->name); } } --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1221,7 +1221,7 @@ int perf_evsel__read(struct perf_evsel * if (FD(evsel, cpu, thread) < 0) return -EINVAL; - if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) < 0) + if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0) return -errno; return 0; @@ -1239,7 +1239,7 @@ int __perf_evsel__read_on_cpu(struct per if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0) return -ENOMEM; - if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) + if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0) return -errno; perf_evsel__compute_deltas(evsel, cpu, thread, &count);