From patchwork Tue Oct 18 02:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734799wrs; Mon, 17 Oct 2022 19:05:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YeE9A4XCzK6jPc7ip+veGRCaIyHd6Kowtyvb/RYTHRbE31RsGHsnFzMtphU3jUX1/kx5d X-Received: by 2002:a05:6402:370c:b0:453:9fab:1b53 with SMTP id ek12-20020a056402370c00b004539fab1b53mr530189edb.28.1666058712040; Mon, 17 Oct 2022 19:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058712; cv=none; d=google.com; s=arc-20160816; b=Zjj3wTNz7dqyX5G4bHdc2dTn012XDDx49qsSU+7VBJ1QcqHwfuZf3COUlXeaLeAXFW YK/8rMB7FHDnMe3tDoa9JOS4uPqOToPYseIyLvoTTObHGQV3t4W69xR8XW0gCi1pAyQm wv32PMf8IuqkF2lrzzmVfnILLW0UrnxNh7R58f1INDOp4tehFVJ+acLE0m0/vMbIYsvp +veXvJExTeu94pOcATXLTKGTw1Yw49NYtYYcIqM7snFBgvS49r4DRxXwpcq2HtBPcALp dBd2wAnmqbEGMQFoFAWPGHn3YRlWMrj+kGkAYPVyKNxLJhQjqKe0uBtyYtFfRRo5S6J0 bxsA== 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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=IRSf12/F3KhhN25AKGacRBswopvblZfFdL9C50mNW0coZRCAynObQ9pCQG5HIhkidq 3zy1BaSfBjE1zQaZ4HHZfSDY6g55U85r10jFd2LhUbLuzzOkbQO5IhmkSJGLVBUXGcNy ghl48HHIhKq1Xmiw6GlqxwiBkDHjaL2kbJPZVpqTRg5n52cjkI1SuluFv+7Z0lxXWKIW ZKhlMjfoNJz0hOQUGJv7hHG37T/mizwiPytRIuSrr2aDuBz5k+Hn724k33a6jq29fmKt VEIlZM8MP2CzLUkST/3lgjCzYAQo+MawQA3Oq7T/megy9jfC05MoAQKoTuhFIF5iCYar SCBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GOtlBAru; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k23-20020a508ad7000000b00458d1c48708si9227364edk.303.2022.10.17.19.04.46; Mon, 17 Oct 2022 19:05:12 -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=GOtlBAru; 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 S231184AbiJRCDd (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbiJRCDI (ORCPT ); Mon, 17 Oct 2022 22:03:08 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4329D8C47B; Mon, 17 Oct 2022 19:02:49 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id l6so12051308pgu.7; Mon, 17 Oct 2022 19:02:49 -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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=GOtlBAruGtyUlmZCBd0mozdiBCEJAZrxCoMmN9RuJYsOiaEr3K9+17PXsDtwoBVxvs AJ2d2EImfPf37t3cMPiWwLoVTX9XxiyayscH4j7GJdZRwUcrQj88Oelyysf33334NNUA wdJy4fI3SjWF8NrdW5nljbbgtrW61MdL5F3HNgnz17XkaKj8k3YoXeNn0Phraw4mlLMS gYHiEHSdwFgN/Lx65E9+qPXInDKTkfHVSrLtmi6nTn8mlzTh645g9gpUWfaDuXOYkIiY YhMu+gGmHzwDPK6cmw3II5yV5fb3TtjN3ogeyb8k1ul0TjOb16zvAkejXh0jYTV4HAj2 59zw== 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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=X3UDAI67gC4SDyVnHWChswC5Yjqf1P9bUoCCsES+RWBwz4TepWSdfmdov6xR8drtLQ PtcgeNcsttm8jkJ+28aNSAYW+v7RgzYWdDMjz/fvhzKxEzYRacLtJz9kV64RBRO/Hf5x Z5sVFQr7sUnyCZXZKgU1JTTPfrnnrECyKHFm3XjT4sxYuymNAmQ/Uu74TOOXeBm4xFs6 y/mJ9RZdFIbypPz8g3A3hhlJvPYc5bXDyLruUc1XkVxfwpxNHwsXIar3OCEHRqtkMf7J Zvsv9rk2gThpxLRrbEyzh7/qUytvmzvTovTcfZYfKeNg0vBVCCMUBb3BDFzgG4AMkaM+ aogA== X-Gm-Message-State: ACrzQf1YmW81CrRu0QKW/UyJKCsz8MxqlkGCMeJqgAtZgRFcGduVhHwR Fktr2lGswERRqX793ShlQg4= X-Received: by 2002:a63:4e18:0:b0:43c:2fc7:2eea with SMTP id c24-20020a634e18000000b0043c2fc72eeamr661184pgb.119.1666058568896; Mon, 17 Oct 2022 19:02:48 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1f90:85c4:58f0:7a81:6bb5]) by smtp.gmail.com with ESMTPSA id t4-20020a655544000000b00464858cf6b0sm6851564pgr.54.2022.10.17.19.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:48 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa 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 , Michael Petlan Subject: [PATCH 10/20] perf stat: Factor out evsel__count_has_error() Date: Mon, 17 Oct 2022 19:02:17 -0700 Message-Id: <20221018020227.85905-11-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018020227.85905-1-namhyung@kernel.org> References: <20221018020227.85905-1-namhyung@kernel.org> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746989179533979876?= X-GMAIL-MSGID: =?utf-8?q?1746989179533979876?= 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 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 99874254809d..dc075d5a0f72 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -381,6 +381,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, @@ -420,8 +439,7 @@ 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. */ - if (count->ena == 0 || count->run == 0 || - 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;