Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1010199rwi; Fri, 14 Oct 2022 11:29:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Pzy2eIUmzs2qdGTLtKadKCOAgzLXxR/CAsz7Lz96qXHc4n9r2sjx8oHxALxSTH1jf0RMi X-Received: by 2002:a17:90a:e7c4:b0:20d:451f:a988 with SMTP id kb4-20020a17090ae7c400b0020d451fa988mr6989202pjb.57.1665772174651; Fri, 14 Oct 2022 11:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665772174; cv=none; d=google.com; s=arc-20160816; b=VdNSee8ddW2GxIaRltv/WoUVmYuLMJbHkMvNwjhHdbgawzjPHfHpySAfacRD3/DXj0 icSTtPScnu67wqtH68KePvAk5o82aXFRaeOxQMhK2Gx7sQjf9SC+YTJqsEDIi+Cg8Tg0 vYZY3i1smrFCVL9l95sdjnJT+63H5FgeSeM/APpEFge7auZ996hzuyGoydZilektGdT6 9rv8I8wmKvl9oobFra11xnQnRM6PPMEohdN3W/B2ZzzzYf+KJtLeYdrVQxMIiGzbLs9c CPvwrgkwI4ptYOcxaeUsw94JGHhm1Yn7dhZB6l+5roeQK4Pay093UVKNQggRIHH+F7Xo xlSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=h8lu99TreD62VQY25U22MDIq+Ln7QdQfqyolDbpUShM=; b=CJm3SlbPVnetxEupaljDmkj0zUgZ5YlDdqBFVBjv62pxvT9W+0T4l9fRdEFCc+wI2s YR3rxlen7klqj0YN83QyOgET0BlrG1FSx7W65InE85U8pKrM/lWYZ5VzLm7ONsOdF2Pg 6KJwUE4NVZ9pdxUwQrgvzikZPPl76RmQE0NQ8wHsGXHAodzrBk1ShomLSakhZFoHQbvl ytDRHNnR2lQfy0/SKz4VPuG2VVzrhCzj1nFAfbBp1+9zXi6LSDFK7VLhpIkANrnBcHgi I0DysZGN4ADitS1rQ7Pg1k9HSDUrYBt+fDxCFNl0srivwYmkP5N1yK6RN3KoYtbtYXa/ i46w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IxfH68BU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a17090a098400b001fe27fb63d5si8360636pjo.40.2022.10.14.11.29.18; Fri, 14 Oct 2022 11:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IxfH68BU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbiJNSRE (ORCPT + 99 others); Fri, 14 Oct 2022 14:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbiJNSRC (ORCPT ); Fri, 14 Oct 2022 14:17:02 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FC862C64A; Fri, 14 Oct 2022 11:16:59 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id fw14so5631052pjb.3; Fri, 14 Oct 2022 11:16:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=h8lu99TreD62VQY25U22MDIq+Ln7QdQfqyolDbpUShM=; b=IxfH68BU48muWWR3n0/1IfsZ+6nK93/nbIFlczi0zRbxn9AaHXbhz5qE7G4anwchkF SDg9elaLPNnhsfVtfjQDT42WNwLhfrAZdkFzgluT5J6SgIFgNtv86WCxX0aYoFrdztx4 pfx0KHHx6ExECUsq8gcdUpk/DcZGghigqtMimsB+AkL9VC23Al4WWeWFMsZKmfn30DVT tp3r6bwXKVFLp8Qd7+8/VH0SSJsvw4oNdf1TQzGz93yaLI9Z7XZpQ8qH2nyMZAFOZTJc AzDe4qcr6TOkV6s2ZrpRgi2owcdeUVhhVlffi2ePFCIdGENwsrbO3WnxHy5NPC93W5ba uuXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=h8lu99TreD62VQY25U22MDIq+Ln7QdQfqyolDbpUShM=; b=mHnkI8VCgbK3G6CohI+jplp6Z2V8tEyZDr0yvz+ZIt33MijyJTg38b03wdxQX+83Hv L0yehkH/AkGp8XsLDekZRnO/QdH2M/LHYowH/5nRb14DVZGwbihOqnbJg5Sw/5IW/Bud ByWExjWfkiy1deypCAh0onkgbeSHcsmWE0kZ8PWUuXP24thxOgv/nS647vgUwovRFdQT RBV6Kke5/MZrk3IQCvBpA5uuBjWiQkF1jLeWRe+b0+N6NgDeWyye3U0FO490AOBHEe5g QWMyUFpNLVaalTddkbSMhwCd8TiJfzMllY/LgEFUrFYBPiyVB2qulXbIOh7myw19r/BI rJBQ== X-Gm-Message-State: ACrzQf0kH+1mhwYec7PSNBdeHbhzDHBFO5MqLDwdTFA9kpO3Cz3cpm0f 4x241SS8LAl9HCYQt61+s3k= X-Received: by 2002:a17:902:8309:b0:17a:695:b5bf with SMTP id bd9-20020a170902830900b0017a0695b5bfmr6138455plb.35.1665771419037; Fri, 14 Oct 2022 11:16:59 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:f2c0:9a9f:e007:3520]) by smtp.gmail.com with ESMTPSA id g18-20020aa79dd2000000b0056149203b60sm2058940pfq.46.2022.10.14.11.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 11:16:58 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan , Andi Kleen , Athira Rajeev , James Clark , Xing Zhengjun Subject: [PATCH 20/19] perf stat: Factor out evsel__count_has_error() Date: Fri, 14 Oct 2022 11:16:55 -0700 Message-Id: <20221014181655.771612-1-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible to have 0 enabled/running time for some per-task or per-cgroup events since it's not scheduled on any CPU. Treating the whole event as failed would not work in this case. Thinking again, the code only existed when any CPU-level aggregation is enabled (like per-socket, per-core, ...). To make it clearer, factor out the condition check into the new evsel__count_has_error() function and add some comments. Signed-off-by: Namhyung Kim --- tools/perf/util/stat.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 6ab9c58beca7..9dfa8cac6bc4 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -396,6 +396,25 @@ static int check_per_pkg(struct evsel *counter, struct perf_counts_values *vals, return ret; } +static bool evsel__count_has_error(struct evsel *evsel, + struct perf_counts_values *count, + struct perf_stat_config *config) +{ + /* the evsel was failed already */ + if (evsel->err || evsel->counts->scaled == -1) + return true; + + /* this is meaningful for CPU aggregation modes only */ + if (config->aggr_mode == AGGR_GLOBAL) + return false; + + /* it's considered ok when it actually ran */ + if (count->ena != 0 && count->run != 0) + return false; + + return true; +} + static int process_counter_values(struct perf_stat_config *config, struct evsel *evsel, int cpu_map_idx, int thread, @@ -450,11 +469,9 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, /* * When any result is bad, make them all to give consistent output - * in interval mode. But per-task counters can have 0 enabled time - * when some tasks are idle. + * in interval mode. */ - if (((count->ena == 0 || count->run == 0) && cpu.cpu != -1) || - evsel->counts->scaled == -1) { + if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) { ps_aggr->counts.val = 0; ps_aggr->counts.ena = 0; ps_aggr->counts.run = 0; -- 2.38.0.413.g74048e4d9e-goog