Received: by 10.223.185.116 with SMTP id b49csp1099507wrg; Sat, 3 Mar 2018 15:32:08 -0800 (PST) X-Google-Smtp-Source: AG47ELvjrlcAwpZRVaYfyHsdRe8i/RWgyo6oyd1VCR9N+eOA2e3aefAOmr8F25ZhAGHvvtLdj/qq X-Received: by 10.99.124.68 with SMTP id l4mr8319260pgn.225.1520119928087; Sat, 03 Mar 2018 15:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520119928; cv=none; d=google.com; s=arc-20160816; b=uqtLYDVLVUN6GenT0EdPdmWIx5aA9YbNwMRAOgO8h3HFSLKsvhAgSJ6WkByY6PZjcX uY2wRwROzuWwiuLzfwVzj5rOHMHB1T+TB+0d7n+ZdyNAGFLh+oxHbiCLdnGyxNDpbnJl 6W+Trd4vfJ8dAaKdcoaU0FM1BWSnhpWK9bhZFasr295yZV/qJ6IoV5djSW7nMU+Ea1ph rfEHw0+AoQN8bXuY/JuvTQpFUxjquHfqkb6kCEe5q1zaoUudDaKfP4TPtmKGman3NrJj 9vgdZspGBl1CRIgrM5MEfFg4IbkjPAJTFBSybNh9PUAmWTP/tiwEX2y0Bx7wJhHxn0qV 5JRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DGHh8vItsZFmKILuvcxpKPbjUqd2WyeuuhGpH4creQQ=; b=KDc7l9KI9F6qRYegbkEMJV0+so6T6rLbBtLvZy7/bZsA8tE73MkYu62niWHxni0obj xdcjgEVgTWDVr2zIIjQP14beY8PLavRsXtostzduIcoF8SrtUhYhRhv1hNEhlU2WMEdk 6bI316uiVLlBvRIuydGmk9uCrdwzN7BJtgEpGHOQOAjsZHhiiBWzgTwIqksqhxa5e0Py E/13wvSnH0N65LIWlTLyuP9CNX99mRQCB11TqNfWKxQpayzhuFXYhqjP+XWX7QUM9Iul IAnoD1KyvlZQoIQ0Sj12z82PaM6vbTvUVCsSbjmel7MInAiq3Tun3H6YVhs/FPRTVU5Z A9PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=RDlNetum; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c63si7473606pfd.51.2018.03.03.15.31.53; Sat, 03 Mar 2018 15:32:08 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=RDlNetum; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934536AbeCCXap (ORCPT + 99 others); Sat, 3 Mar 2018 18:30:45 -0500 Received: from mail-bn3nam01on0139.outbound.protection.outlook.com ([104.47.33.139]:45280 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934540AbeCCWgO (ORCPT ); Sat, 3 Mar 2018 17:36:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DGHh8vItsZFmKILuvcxpKPbjUqd2WyeuuhGpH4creQQ=; b=RDlNetumy5G8zLP0WrRe+RRt0zXziIQ41zyJ+byqDhmCASRYKwR2oshaBRFu+xSK3zJMn5FnwBaNdKSFq7NYMaXNOqZWNYXq48ppF8XyaOfXsQj4LTG5LFhqxuJZbQ88gZVNbxrQj9o4tGX13wxP9WH8l5jOEWEPJSqZpLSubzM= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.3; Sat, 3 Mar 2018 22:36:03 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:36:03 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Stephane Eranian , Adrian Hunter , Alexander Shishkin , Andi Kleen , Mathieu Poirier , Paul Turner , Peter Zijlstra , Wang Nan , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 169/219] perf stat: Fix bug in handling events in error state Thread-Topic: [PATCH AUTOSEL for 4.9 169/219] perf stat: Fix bug in handling events in error state Thread-Index: AQHTsz8bBwlRahIClE2EJ/yaNZU72w== Date: Sat, 3 Mar 2018 22:29:35 +0000 Message-ID: <20180303222716.26640-169-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1034;7:ijKJc56UHB5EnRC47bpMwdswUiyEtogLsV7k+6B8UHlXlZR5Gv8C8WFXHk/lpAQR1IXbJVc9bajYzN5hgWGCBmuu1ff2dgLLMpPwFbVdIdszTSQFOGAOqzh933Oay8qCo62+rn40GtSqNjIxjnhZzrjLR1WAPGfYDbliW6tf1xC/R/Px4h1NRI4j9DL/nzyuIGC+Pz8vbNrX5usEzVC/1yYI9Xbd1Oo8T/9TzxnW5fEPCwx4O3naKRQq2iVua9Kr x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 91967515-f636-4e75-33d5-08d581572587 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1034; x-ms-traffictypediagnostic: MW2PR2101MB1034: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(50582790962513)(211936372134217)(42068640409301)(153496737603132)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(3231220)(944501244)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:MW2PR2101MB1034;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1034; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(346002)(39860400002)(39380400002)(366004)(396003)(199004)(189003)(99286004)(22452003)(72206003)(316002)(3846002)(6116002)(186003)(26005)(478600001)(76176011)(54906003)(110136005)(102836004)(97736004)(1076002)(2501003)(966005)(3660700001)(66066001)(5250100002)(5660300001)(86362001)(10090500001)(10290500003)(86612001)(6506007)(7416002)(68736007)(106356001)(25786009)(8676002)(4326008)(59450400001)(6512007)(305945005)(2906002)(14454004)(107886003)(8936002)(7736002)(81166006)(3280700002)(53936002)(105586002)(81156014)(6666003)(6486002)(6306002)(36756003)(2900100001)(6436002)(2950100002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1034;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: zqSlxLWZ0v0+YGcR/eXWFe+uNJxv2L4n1+4rN5EKEqWAmX4DE3y9ImsWlMgoh+AR5m61XAP2Dk9hI7wG4wlhuhM+hV/IU89/iUBV2322J8Z2sLfp8h7cOwdDPwnGTtqs6JaWUhF+oT63EYehnQ7aMkuasSuxcUwVHYR27RS4hrs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91967515-f636-4e75-33d5-08d581572587 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:29:35.6507 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1034 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D -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 --- tools/perf/builtin-stat.c | 12 +++++++++--- tools/perf/util/evsel.c | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c241167c76c9..5b60ec669e73 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -311,8 +311,12 @@ static int read_counter(struct perf_evsel *counter) struct perf_counts_values *count; =20 count =3D 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 =3D -1; + perf_counts(counter->counts, cpu, thread)->ena =3D 0; + perf_counts(counter->counts, cpu, thread)->run =3D 0; return -1; + } =20 if (STAT_RECORD) { if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { @@ -337,12 +341,14 @@ static int read_counter(struct perf_evsel *counter) static void read_counters(void) { struct perf_evsel *counter; + int ret; =20 evlist__for_each_entry(evsel_list, counter) { - if (read_counter(counter)) + ret =3D read_counter(counter); + if (ret) pr_debug("failed to read counter %s\n", counter->name); =20 - if (perf_stat_process_counter(&stat_config, counter)) + if (ret =3D=3D 0 && perf_stat_process_counter(&stat_config, counter)) pr_warning("failed to process counter %s\n", counter->name); } } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 539724c7d30b..bce80f866dd0 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1221,7 +1221,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cp= u, int thread, if (FD(evsel, cpu, thread) < 0) return -EINVAL; =20 - if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) < 0) + if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <=3D 0) return -errno; =20 return 0; @@ -1239,7 +1239,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evse= l, if (evsel->counts =3D=3D NULL && perf_evsel__alloc_counts(evsel, cpu + 1,= thread + 1) < 0) return -ENOMEM; =20 - if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) + if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <=3D 0) return -errno; =20 perf_evsel__compute_deltas(evsel, cpu, thread, &count); --=20 2.14.1