From patchwork Fri Oct 14 06:15:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26812wrs; Thu, 13 Oct 2022 23:18:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OkWBBZHi3w69sBDWgBukRIhqJw3+oeuzakRdtCGifJ4juDkmNPmybzf1dnX9ofE8SrQmI X-Received: by 2002:a17:906:4fcd:b0:78d:8059:17c with SMTP id i13-20020a1709064fcd00b0078d8059017cmr2457047ejw.423.1665728322229; Thu, 13 Oct 2022 23:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728322; cv=none; d=google.com; s=arc-20160816; b=VR6/JDTM2hVls1u+53WXbwAMwgQ0gRPmTr/S6vO36hU9Trn3+pas1S14E9juDIUDic ujJuMipPrQYeCEhyaJaRCF50fmHJrSPNtz3C5k+7Djk0P81bHlSFgLK8CTNWTd1lJm7n ghV5G1grC6Ct9O0/3mjIqNgFGmUD2fQIQNE3+1p/vOufIibnlhGOcS2NqyLat/QV+btW HmryHMh9b5B5tjIvdf/u/ta9G1LCCL4FWqes/wWsayx/+ai+xIW3wlEEdur4S9lYT88b dXdR/EMr1lSNeeQHEW/R5uLDYZYUGNuJbQcFxI3d9EUF3F/qNfte6f213T3UHbq4NUB4 XJbw== 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=rHWFfD5uXAIuo8SM1relQgBWw32fsgzMn6vLvoZArhU=; b=MYGTTnjKQ6WaCdLJAm522G38rIEJZwG0iyMIIrTx0Wa4yJJGAj6vEfDvfzdw5TSNBx KdJs1kAebRAXcKegdkEPXbUj0whTLJK3EcUu76KKg5oOClLOJ5aA+IkQ/kET/l/ePF5M WfDXxDngPyQCoYNxCxfpaooZV3beBhv4niiIZCPdDMYGRme25c3iciZD9bAFyDaYauUu AjVKlcLXoCnD0M0yCCxd9dEuCVMg8kgqvFXU6GEMVGOD//5yMDtAhvzvlM8h0b4tDR2P 1PkjmBAkBVzwSNbP4JnM1t1sGbo+QdBHJey0i9A+sI84CL1DqkVZ621zmFFoMvrXscMg Vd5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RHJRhm6g; 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 mf26-20020a170906cb9a00b0077c2e5ea05dsi1390707ejb.267.2022.10.13.23.18.14; Thu, 13 Oct 2022 23:18:42 -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=RHJRhm6g; 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 S229777AbiJNGQA (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiJNGP6 (ORCPT ); Fri, 14 Oct 2022 02:15:58 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6231193EE0; Thu, 13 Oct 2022 23:15:54 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id b5so3489548pgb.6; Thu, 13 Oct 2022 23:15:54 -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=rHWFfD5uXAIuo8SM1relQgBWw32fsgzMn6vLvoZArhU=; b=RHJRhm6gb4zpIYhz4wfgoUEV5boxAePR7GAVqHy7ZqETvvPv6oYZ/KKIthRTUIC6r9 0atOmTyrK5jQwwlwMdXALJljCpmQj/AHZZVaFYNfcZ7f+hjYYqEsuUn/Qi7Wz5XACIK2 YGIB17pKZj2eY0DE6QSHFnYsg9ryHYmPLox1gzgmlVaeetHgqOvILkciANx2N1RBQ/Zp 4IlnvWVVG/mCFbPp33wxssQWkeByROFmbsZHe+COptJMXNZIxsAIAcHA7WluYbmd1OSm dDQlY2lV0/Bxd4isnP87yxIgFvShoK9E2l0JAP5qrg3+uTu043FNtnI8tkfVikL9rPdF LNxg== 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=rHWFfD5uXAIuo8SM1relQgBWw32fsgzMn6vLvoZArhU=; b=QCyHaXfq9K+AEbwOdx9/FE4Cm/TtK5zNENn/6Q1j/NrylS1FNRMmy96cbytBFryxJw bcQ2UJPuViLS8Bfxr3nk5MVUYx2LICKJLgwOoYa6+XeJCPMlx+A8wiqDVc5+Mzj72VWi /LHETfCYquaGKchoO7uJKgajsdxsKGBPAJc3CLSdH//YknfN3FS0317o5xiFeVGI64JL rI5lQjy4WrwOCyQVsK3GalFqhILMtM8D9ik3EvdAYnJ/nm7+w8qUqrBiuq39OnEpYKxr 4h1PygbwDtaLSd/Myz7NegFo43CMPepl3zDnowJTbYzAiGGt5RnLheSUyI9TkbTiPxFZ NcXQ== X-Gm-Message-State: ACrzQf2pTa9ufBdeYWm3CavogwQpS4MbFC1WEzZq976olJZZq3hfVNCa GN172QuBoekdRvlyHylUqWs= X-Received: by 2002:a05:6a02:10e:b0:43b:e57d:2bfa with SMTP id bg14-20020a056a02010e00b0043be57d2bfamr3143314pgb.263.1665728154111; Thu, 13 Oct 2022 23:15:54 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:15:53 -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 Subject: [PATCH 01/19] perf tools: Save evsel->pmu in parse_events() Date: Thu, 13 Oct 2022 23:15:32 -0700 Message-Id: <20221014061550.463644-2-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642741051896015?= X-GMAIL-MSGID: =?utf-8?q?1746642741051896015?= Now evsel has a pmu pointer, let's save the info and use it like in evsel__find_pmu(). Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 1 + tools/perf/util/pmu.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 76605fde3507..196f8e4859d7 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -467,6 +467,7 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->collect_stat = orig->collect_stat; evsel->weak_group = orig->weak_group; evsel->use_config_name = orig->use_config_name; + evsel->pmu = orig->pmu; if (evsel__copy_config_terms(evsel, orig) < 0) goto out_err; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 437389dacf48..9e704841273d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -263,6 +263,7 @@ __add_event(struct list_head *list, int *idx, evsel->core.own_cpus = perf_cpu_map__get(cpus); evsel->core.requires_cpu = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats; + evsel->pmu = pmu; if (name) evsel->name = strdup(name); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 74a2cafb4e8d..15bf5943083a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1048,11 +1048,15 @@ struct perf_pmu *evsel__find_pmu(struct evsel *evsel) { struct perf_pmu *pmu = NULL; + if (evsel->pmu) + return evsel->pmu; + while ((pmu = perf_pmu__scan(pmu)) != NULL) { if (pmu->type == evsel->core.attr.type) break; } + evsel->pmu = pmu; return pmu; } From patchwork Fri Oct 14 06:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26217wrs; Thu, 13 Oct 2022 23:17:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54yZ5raiM3/T15KjE6AOYGTCk8paFCzlLBNv7KN1DWL3GKu6aj9gat66o1V3e5irMMzSL5 X-Received: by 2002:a05:6402:538f:b0:444:c17b:1665 with SMTP id ew15-20020a056402538f00b00444c17b1665mr2978861edb.98.1665728235637; Thu, 13 Oct 2022 23:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728235; cv=none; d=google.com; s=arc-20160816; b=S8mFbALELEZHWwXJdTQ9knNJp2QM3VFEwqHiRbWemQtLBIPuGukNqYM0OwjKYp7//d f3O5pHbMsEsa/9asMiRhIpH3TQLPhBPzv8j8ufS6ro/hP/BjEDKxfuZ3csSwL84acQxP ia0lLH6J/NjPgsunG9m23dlX6Le4oqiO0nHImVBlI4+mE+g3mfdOq/57MirBSSNbfNZ6 z/xgeQUm1AKM50J4gs4hwV3qU2hUSNpSPoi+cjeNElQ23pNEAzG7iSEi1r5xVGgBSe/3 AM2VfWBqucGIhjkkzwaMGscymej6r6g/I0nCYJBpDlnh2AeUkvvlpEANAMgjli+ByrXY TXug== 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=MiMyw7YB2EnKoani26cg+4Uepi4pmm8Ijh9bPfSD/gc=; b=FKur+K595e3i3fvbF5Ubw2nK6+a/vQREHR1Jkp6Ci+WOkuz+qz0eipRTytMrGnKpIK S4eHHXM2srWANwhEJiNnWxv94EPArkJWMJ/UX0O7HmLP38yOa6pvU6m5m1TbyHGtuzan 4QQ4iXjpbDLxVP+o8EGhRBbHXWmhUjER5qSasY4k+H6mPH7QrUolz1/eoRNVNYXGW9F9 i4ot/JES+LI/ZYuNGd6yHUF8aBwBKTfDTp0JXbcDPqy2givNYN6sVN6ld0Hesz6uqX6A xjZrtfWuboSQ/holzdZTFSUO1g4pK3EBBo/j4g9r/sL1MVgbNVGGLLVC9Oovjzp1JM0Y 35dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jh8JYNdH; 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 nc33-20020a1709071c2100b00788166eaab6si1965881ejc.745.2022.10.13.23.16.50; Thu, 13 Oct 2022 23:17:15 -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=jh8JYNdH; 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 S229808AbiJNGQI (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiJNGP6 (ORCPT ); Fri, 14 Oct 2022 02:15:58 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EBC91ACAA3; Thu, 13 Oct 2022 23:15:56 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id gf8so4013412pjb.5; Thu, 13 Oct 2022 23:15:56 -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=MiMyw7YB2EnKoani26cg+4Uepi4pmm8Ijh9bPfSD/gc=; b=jh8JYNdHA1hyHQLhEMYdwS9V0KiqddfEclbPYcqBepEodjjQVy3LAQTVD53HUFJi6m 06J/TS8+cbDSP2NvlpeEltTnfyPURKTlhgg4yVy6CQGwStSpN+dEcJFOPmFHmefchgl3 xbJn0PAq2KHPmJqETYcOlIKty650+cYw9t5rHL3643GHW+qlWX7E+fb5cfLx6HFd6e+U zAhV8O2V5qs2dT1ALEOa6krnOkP5dEAYuhhtu8oQoHj2BuolfKl0sd2geR5mqdhCHxc0 aW36hrOz3vaLPjmQiMDBksKqLa03R6Z5t248WGHjJKn1GhoMSLFuhkdFHxOoQLlJKdyR YLeQ== 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=MiMyw7YB2EnKoani26cg+4Uepi4pmm8Ijh9bPfSD/gc=; b=oYW2k07A70PmZb9bR0y0yNkJZ+UmBnFcfNSLqoAMP+JPJPtbiJA7W4ynISdoI1UPTZ gw/Sg22pAgceJl0/hU+cgIA5APjqaoSPeaMSxRKXK4wcXvNaJ4M9B3LbiEiMDkY7yUcw KikZf970HCvCJfISqYb5WAT20oPmuIR6Gn1SoGaykU9jqfdVpdjikLAPuZSkPblUBlSW saGf0SSmxg4goad4RdgWUYrvW9+EzjZnBj3h1aIfnm5TKX4uhXNRM34vJZhJF09qEe8p CCwqub9kcTsW5dW3fmhLoobBr6lQYqh5y4xQoQHkzrherq4Nfem158PCulqSmX4pC79T pzwQ== X-Gm-Message-State: ACrzQf32rNcdv7u7BSom+u9MIAMuAAMBItosOsF84fxSJu2IQY4kq1Av k9Ud7KDn2hBOc/I02XG67Gw= X-Received: by 2002:a17:902:7102:b0:17f:3da:f18c with SMTP id a2-20020a170902710200b0017f03daf18cmr3590394pll.24.1665728155691; Thu, 13 Oct 2022 23:15:55 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:15:55 -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 Subject: [PATCH 02/19] perf tools: Use pmu info in evsel__is_hybrid() Date: Thu, 13 Oct 2022 23:15:33 -0700 Message-Id: <20221014061550.463644-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642650546881806?= X-GMAIL-MSGID: =?utf-8?q?1746642650546881806?= If evsel has pmu, it can use pmu->is_hybrid directly. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 196f8e4859d7..a6ea91c72659 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3132,6 +3132,9 @@ void evsel__zero_per_pkg(struct evsel *evsel) bool evsel__is_hybrid(struct evsel *evsel) { + if (evsel->pmu) + return evsel->pmu->is_hybrid; + return evsel->pmu_name && perf_pmu__is_hybrid(evsel->pmu_name); } From patchwork Fri Oct 14 06:15:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26239wrs; Thu, 13 Oct 2022 23:17:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71S3lrVuwIVfPXLQkNmLtllEmll+ooPz6PCB+MsyxKTxoVf54qKTYIPixr37MvZDLqffHf X-Received: by 2002:a17:907:a0e:b0:780:72bb:5ce4 with SMTP id bb14-20020a1709070a0e00b0078072bb5ce4mr2420868ejc.234.1665728240709; Thu, 13 Oct 2022 23:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728240; cv=none; d=google.com; s=arc-20160816; b=lh6TTHWBettdzmz5I+/amyFTllQr0WinXB8Tbl7onWUfTqL0N+OtuLp4vRgD4FBITU O28N0CTe5pX8sB0unWR0MvNODAuv/9SLZy8j8qCdkVnNnTN0DOaPntysw7rhgP5LTvLu t1bcaP0bb75qr+GaEzy6egU51Psos0PTHIOMqlLmeWYdRtvsnnMPSdkcb4bNG+HpG8wQ wcDMyp4uVE/6yLO3JaE2AMqUsdvYLw3NqobfiMjZUnW5Fi7m/qubVBXnf1lu+QGrD3Ar tyJlHvvzLObbC5COwk/7zf+AaOydFBL2aRZbZAgxLx8bqlbnec1M/Yo5JLwh6zFSos3A 2Rdg== 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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=JOTo3ukyVY/q2w2SMaa08aA48+0IRXi8lMyqLT1CUfZ8p05iYq19RUHACptARtnBhU Z8yvUOheOFTAsdU1r3QOC8n7SIAg46d4oaED3jhLrPZ66Yx0blTkaPCCdWXu2SF09GHi jC6nVbQOp+LP7oCQdGiqyNL2emA9WQK5lE4E8ZFSEUfafcf6lhu9vfnWEJzfB+8JDOLd Dy5RdoMMOhIiDie5y4ikgcS9iBzuNdYYx5ZyzRjV3ieGRRUyon3tubrsxpivKcOy+tSE MJO4d+JN6eofx4LCpk26YPuk7xXgnHAwQntx7Tr73W4apHJeUJeS1m5Ngc/a+Ne/d/kO X92A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TwXrnKSu; 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 g11-20020a17090669cb00b0073d710fec77si1516433ejs.251.2022.10.13.23.16.55; Thu, 13 Oct 2022 23:17:20 -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=TwXrnKSu; 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 S229811AbiJNGQL (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbiJNGP7 (ORCPT ); Fri, 14 Oct 2022 02:15:59 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1007219377A; Thu, 13 Oct 2022 23:15:58 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so3945389pjl.0; Thu, 13 Oct 2022 23:15:58 -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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=TwXrnKSuvAijT0wGUoX6E1+3vzdEONbdORaQDNvPrVtRO7OMGvxjk82QRt4aUQ0Yfk rSQrUvXO2FEm7H+R5V17F2Pzv0OVUD+vpkRyO+f1ZdVdrnsnXRs8MtiBiGvj4f4xqFQx eyOljFtXDoFGdHkzX2sx91HayO2YJergGxBr5ZL7uxvS+g52ntXPC5tWsnessLjZkO2L 1P57edaAWvnrypHYSJ7R8IuqKuWO5fyg1ikvjiZ6UCvIdwCB9fuYg5lcrlWKfXxR6j4X z3kFgkB2XWQZKtaWLDGpd/OBBbpLcH0g49/olHTdbDPzD5Fc/QL+I9vlrsBpI5sr2Lld SL3Q== 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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=h1NRRQ7dZYvq6d7caPwKmrhtcwZsvEaXfqRcxkWy+l4iF7xdD+eSLykNMehE9a4zRC jSvCPGkcDm4HTZZkcf+VWLL0dCDbbBb6vc7zcJEPk/Hjhn2Oy+4JgKcOnPTuk84kGE4p ExJC2bn4VVeCrXUklb/VYXri6fFE9DThSi+/beAxn9XLqSh0Hlp9JTA89hEbXDIGalUI 0+YlKE3NPtofkerhfSbFFM7Cu7cRMw2LawUTmOFdQfDgblXtabSqH+XUVL2Ptmyl430c jDipnq0fYV44Fm4tibCrQTGcdA0KYFpw38H0OIgIWpWRpOlV2jzZdUvPA/nBlWt4/HYq bf/g== X-Gm-Message-State: ACrzQf10smr3bJ4V6HrYA6t0ZIbDGokpa2fljfY2P215OLg2H2tZ9tlG +Zw/CJcGObI2NmYMva2sW4A= X-Received: by 2002:a17:902:ce86:b0:182:498f:afdb with SMTP id f6-20020a170902ce8600b00182498fafdbmr3895149plg.12.1665728157335; Thu, 13 Oct 2022 23:15:57 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:15:56 -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 Subject: [PATCH 03/19] perf stat: Use evsel__is_hybrid() more Date: Thu, 13 Oct 2022 23:15:34 -0700 Message-Id: <20221014061550.463644-4-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642655735709593?= X-GMAIL-MSGID: =?utf-8?q?1746642655735709593?= In the stat-display code, it needs to check if the current evsel is hybrid but it uses perf_pmu__has_hybrid() which can return true for non-hybrid event too. I think it's better to use evsel__is_hybrid(). Also remove a NULL check for the 'config' parameter in the hybrid_merge() since it's called after config->no_merge check. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5c47ee9963a7..4113aa86772f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -704,7 +704,7 @@ static void uniquify_event_name(struct evsel *counter) counter->name = new_name; } } else { - if (perf_pmu__has_hybrid()) { + if (evsel__is_hybrid(counter)) { ret = asprintf(&new_name, "%s/%s/", counter->pmu_name, counter->name); } else { @@ -744,26 +744,14 @@ static void collect_all_aliases(struct perf_stat_config *config, struct evsel *c } } -static bool is_uncore(struct evsel *evsel) -{ - struct perf_pmu *pmu = evsel__find_pmu(evsel); - - return pmu && pmu->is_uncore; -} - -static bool hybrid_uniquify(struct evsel *evsel) -{ - return perf_pmu__has_hybrid() && !is_uncore(evsel); -} - static bool hybrid_merge(struct evsel *counter, struct perf_stat_config *config, bool check) { - if (hybrid_uniquify(counter)) { + if (evsel__is_hybrid(counter)) { if (check) - return config && config->hybrid_merge; + return config->hybrid_merge; else - return config && !config->hybrid_merge; + return !config->hybrid_merge; } return false; From patchwork Fri Oct 14 06:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26981wrs; Thu, 13 Oct 2022 23:19:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gsxzWSUFcQx6ejwQ8n4g7bEVdwjWdLZaVaJ/wWP/rjtLQVBRW2grfDB2lYqD0bKah3WL7 X-Received: by 2002:a05:6402:5193:b0:45c:e2c6:6f0e with SMTP id q19-20020a056402519300b0045ce2c66f0emr2949201edd.29.1665728345605; Thu, 13 Oct 2022 23:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728345; cv=none; d=google.com; s=arc-20160816; b=Sv9l761Hpfr84jBLs/HxwE2eSe9VsRY/DAlDdGV/MZVWqMdCmt5yZWdG0s6vsD6u9Y IUHTiof9AFBuV7lHhoJoNmTvvOLG/OJswNMF76you4zOSo1q7mzFAYMsJ3yCOFJr6CoE 3xCJj59psiIZOzhsTKpzgoRbw3PLL5HdeWSbUHEh9qGzN798GUVMavMYGpg286oIMgrM 6ZEkBAcDmvZst0scNB0WkILTXiTLwRbXDB5uVr5mRnNSfgE+pFSnTiWXk4oICXNPD+Nc mHlpiI/OnW88nhW6n1cKV6lr1rbMqJFJKgk3JWeaLU6Y6g+ISvOKvBKyjcx2oMYS8q1J KWEA== 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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=V+DX9PDufahuTcrve7FG2eRKv0EjlQvJxzMzXYU7U8tWQzFAxDcvuP6rspLN9kg7qV 0duFWHTYKCIz/1ZmDuB6yl0h/GIxLLNZ2EpyuwfNM/XdY9i63AJ2LBzpE/7Vz/1zXzPr leatEH7KRr3FGP7RUUUQwX0Foig+yEal+GmaAfH4YqalQSeY+YiWSuFSz4+ze4djlwpu vekva4pc6FeSo1ClkrpS02XnHiPg5CQO+SHaUhYfarXHBlmy3y25xxoa+9bd4dp42GMm jF3qzOHG66NcrZIl4Etbjcm6q72QQSerkaeNMkzycVEg2B8OI1x2l3UYdnAOp76Nrno6 AH+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OLOExu1J; 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 ht14-20020a170907608e00b0078a00ad1e38si1607307ejc.876.2022.10.13.23.18.39; Thu, 13 Oct 2022 23:19:05 -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=OLOExu1J; 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 S229887AbiJNGQY (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiJNGQC (ORCPT ); Fri, 14 Oct 2022 02:16:02 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C425E1ABEFD; Thu, 13 Oct 2022 23:15:59 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so6998284pjg.1; Thu, 13 Oct 2022 23:15: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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=OLOExu1JcNz5OTXMM9pgi6ozCeYyjMxeb5lLczVoCS6UFTuSGeZBDBcuuMiEDCA2Cz T1sEIsiUX84qHgssrvxEwy/a/ubxdH4Gi5AYs+Qrox7CNBBW0ly+q+c54JZEzt0VGRbt rktmfssplx4MY2kOcWxwXbsOVGNOgRgwgWF+MWvPnAdKOj3usSHNnOaqwnPMuAjRYt8/ 9wLL/vJpQqQZTg6bUVCZ5jeZs+K9zCFpljEy9xxJLDd1jNNfgiL+brk34DIdKm0p8jka AhWjdzw88vAIo0JXEVmACljYC7K+Eoq5Wi3GeRqyU1shTWdYpwb9rYZsU2QqxRPa3A4M C5MQ== 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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=B37rn3XDbdAlO38u/NVwJrwMLbfBiCC2sEebwK9GDS/g4lzUFmgB3PeLpA5+nlJ2O0 aVM9Cgi8zSJhy13YzqYVfC8Eej+gCdOs1eR1s4rJQmpqbKhNYYpSxFY8FJURzWwKbyqo Oc70/+1sBabSLQv0GFQA3Ch2HRnitzT2CE34E2wUOZ03vJ2q/Su0CqzVEZudu3reXQu3 3e/aaHiAwifB7FKRXCNUlB464k3xWfa4BX3u0u4r+R2FdXr6w+XeGHTdoqnVPkza7aRF W0elGyF/s4ds33JBg8S8hzqUS0QCwEnkrd7LzbFKsprWsDh0FOsqa2TXmWGVK0QnXtrm vi2w== X-Gm-Message-State: ACrzQf3QLPX5I+54k23bfR16ZE+hgjweHD7K++P0NPljw9FaD4gsK0Ki COX1dC9s6WIlPT5DHiFPRRg= X-Received: by 2002:a17:903:1112:b0:178:a030:5f72 with SMTP id n18-20020a170903111200b00178a0305f72mr3885191plh.12.1665728158936; Thu, 13 Oct 2022 23:15:58 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:15:58 -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 Subject: [PATCH 04/19] perf stat: Add aggr id for global mode Date: Thu, 13 Oct 2022 23:15:35 -0700 Message-Id: <20221014061550.463644-5-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642765603422549?= X-GMAIL-MSGID: =?utf-8?q?1746642765603422549?= To make the code simpler, I'd like to use the same aggregation code for the global mode. We can simply add an id function to return cpu 0 and use print_aggr(). No functional change intended. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 36 ++++++++++++++++++++++++++++++++++-- tools/perf/util/cpumap.c | 10 ++++++++++ tools/perf/util/cpumap.h | 6 +++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 265b05157972..75d16e9705a4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1330,6 +1330,12 @@ static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __ return aggr_cpu_id__node(cpu, /*data=*/NULL); } +static struct aggr_cpu_id perf_stat__get_global(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return aggr_cpu_id__global(cpu, /*data=*/NULL); +} + static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { @@ -1366,6 +1372,12 @@ static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_config *co return perf_stat__get_aggr(config, perf_stat__get_node, cpu); } +static struct aggr_cpu_id perf_stat__get_global_cached(struct perf_stat_config *config, + struct perf_cpu cpu) +{ + return perf_stat__get_aggr(config, perf_stat__get_global, cpu); +} + static bool term_percore_set(void) { struct evsel *counter; @@ -1395,6 +1407,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) return NULL; case AGGR_GLOBAL: + return aggr_cpu_id__global; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1420,6 +1433,7 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) } return NULL; case AGGR_GLOBAL: + return perf_stat__get_global_cached; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1535,6 +1549,16 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, vo return id; } +static struct aggr_cpu_id perf_env__get_global_aggr_by_cpu(struct perf_cpu cpu __maybe_unused, + void *data __maybe_unused) +{ + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + /* it always aggregates to the cpu 0 */ + id.cpu = (struct perf_cpu){ .cpu = 0 }; + return id; +} + static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, struct perf_cpu cpu) { @@ -1558,6 +1582,12 @@ static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *conf return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env); } +static struct aggr_cpu_id perf_stat__get_global_file(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return perf_env__get_global_aggr_by_cpu(cpu, &perf_stat.session->header.env); +} + static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) { switch (aggr_mode) { @@ -1569,8 +1599,9 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) return perf_env__get_core_aggr_by_cpu; case AGGR_NODE: return perf_env__get_node_aggr_by_cpu; - case AGGR_NONE: case AGGR_GLOBAL: + return perf_env__get_global_aggr_by_cpu; + case AGGR_NONE: case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1590,8 +1621,9 @@ static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode) return perf_stat__get_core_file; case AGGR_NODE: return perf_stat__get_node_file; - case AGGR_NONE: case AGGR_GLOBAL: + return perf_stat__get_global_file; + case AGGR_NONE: case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8486ca3bec75..60209fe87456 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -354,6 +354,16 @@ struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __maybe_unu return id; } +struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data __maybe_unused) +{ + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + /* it always aggregates to the cpu 0 */ + cpu.cpu = 0; + id.cpu = cpu; + return id; +} + /* setup simple routines to easily access node numbers given a cpu number */ static int get_max_num(char *path, int *max) { diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 4a6d029576ee..b2ff648bc417 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -133,5 +133,9 @@ struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data); * cpu. The function signature is compatible with aggr_cpu_id_get_t. */ struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data); - +/** + * aggr_cpu_id__global - Create an aggr_cpu_id for global aggregation. + * The function signature is compatible with aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data); #endif /* __PERF_CPUMAP_H */ From patchwork Fri Oct 14 06:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26322wrs; Thu, 13 Oct 2022 23:17:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7WSPpNYjjDGPoFvuzZI/nR179ht6E2MPmSm9b9pTseE0d9mI9DGTsBWuZSoaVxKoBlIafW X-Received: by 2002:a05:6402:f83:b0:458:8c97:29af with SMTP id eh3-20020a0564020f8300b004588c9729afmr2914936edb.210.1665728253284; Thu, 13 Oct 2022 23:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728253; cv=none; d=google.com; s=arc-20160816; b=xoBCIUHEEkfLPi8855TjXRfwqoaF6u0oihaFxVhwl0IqN94Qzp5gWo9P6wB0U83/LC VmDNuxewPKaWUggvo1QTKG1K5sVT1k1pooAUv/0a7V6vk3JVHVFnab6FkFwuxfrSw8wA mSZxZ0OpfJGTVJtPjDkL8cabLOhm6AuxZLu+ZwXyG+As5V91UrFeuly5Cfn8OGqvGqJ3 +b2aPSJa1Gbi8096Cwgqm0h9rGAMLFY+mMekziNem8jSfBinQNGM7jen23lMNwKJcAmz kB8+R7F2ivFwfrHVjATTYPWHrBcTLoy4rFaIAo/HfU24WAu5rQvLfX4XixvuuwYBlXyY u0Lw== 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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=Zs88e0XqQX1oCeRPsxJaBHP2VxvwdBAGrrVCqsXFJVJgB282944G3lOdMOe7eOiu41 5tLodkSi78PyCJUNXQBWkrhYoSvWLwATVSf3fLHmCSj1s0nDyC8i96L5NWA0ZxhDVhdM jEIlyrNw3f5p33/ev5dBABr+HcrpqJs1PrYRJ4qFT5YGrFXj1HLWMgaXF2qHe2DjBlzG snO85V3f6IYkadcONrRg0HSulKEP3Zrh4gbPZRDzJtlH9GTdMhCD+P7V8CAIzElf3ZvT MknG2f87MmAvlLl4+9s+eMNJDppHUOSbQcWH+b9y2zpEbxWS8rasBNGqjjn3xaTytQ13 u7yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QtxezWOY; 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 f16-20020a056402151000b0045bdc422aeesi1487658edw.292.2022.10.13.23.17.08; Thu, 13 Oct 2022 23:17:33 -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=QtxezWOY; 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 S229846AbiJNGQ2 (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiJNGQD (ORCPT ); Fri, 14 Oct 2022 02:16:03 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60051905E7; Thu, 13 Oct 2022 23:16:01 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id x31-20020a17090a38a200b0020d2afec803so3915280pjb.2; Thu, 13 Oct 2022 23:16:01 -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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=QtxezWOYGoDhOhgLJEbpMtp6kBjPn+vSPV3bIAEKbVsjJb6ew6WVcgDNzTG+SRd5RH GhIctA17MH8wjL+xGS4cvlS9rOtJU62jkanPGO12iDbCYHye86DzS7drXUowKizpsDOS I0N/C0IDionhipVUeXeNqvo7csI2zktQUqbQxucTtwNFWTrJj2wlnRxGF/idXGnFCY2P DtcRsJRPcFH4D8jZYfuFoOKlMqZlqLk/la5VfYQtybwV3WkxMSdbh1GU7K5iHhTzHUO9 lK9wMeZCaB2gQpKuuzkQWTCeesvG/umgCAoi8MCF1LLku4ANAHnS0ckzi5GuXO8Ep611 I/XQ== 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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=vqwalq51q8Nu30ia9TwVz4sr6WQv8bkrJZXbDoF7z2H48vEWt40JtIIbtrt3BYZMhz ao++Sz1xgisVB/4Dl+ItA4E9P9BFd4pCJBxBYM8YE85vbXB8/E2lcrTqDSa0nNQxWhGE 8G1bos4JKsM6Lxl8IwsgI3X9qUcF7MPy46fOzUfkJiKOXcfF4HK4bwOgEKkpdI2eyKrV b27t+6Nc34bpdSiH1Jf5W0TFMz5+121sNK2HRGqeWF6luWxvD6Uys0tPZA5CWvWC6STg H6ng6Bu0qSxzoepglfYPsfklUokEbwG+DYRfoI6NC11kNB2holFCH4rW4RhCtr/Zd1MK j+ew== X-Gm-Message-State: ACrzQf1/BTw+k+S1tf8cToAvTyf0CfJV2YOp4uXYVG2Fs5IUWSTHJNH+ tZ7dZPHAgm+FpGtr1XqcmAU= X-Received: by 2002:a17:902:724b:b0:183:16f:fae4 with SMTP id c11-20020a170902724b00b00183016ffae4mr3830678pll.88.1665728160649; Thu, 13 Oct 2022 23:16:00 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:00 -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 Subject: [PATCH 05/19] perf stat: Add cpu aggr id for no aggregation mode Date: Thu, 13 Oct 2022 23:15:36 -0700 Message-Id: <20221014061550.463644-6-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642668953356869?= X-GMAIL-MSGID: =?utf-8?q?1746642668953356869?= Likewise, add an aggr_id for cpu for none aggregation mode. This is not used actually yet but later code will use to unify the aggregation code. No functional change intended. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 75d16e9705a4..b03b530fe9a6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1336,6 +1336,12 @@ static struct aggr_cpu_id perf_stat__get_global(struct perf_stat_config *config return aggr_cpu_id__global(cpu, /*data=*/NULL); } +static struct aggr_cpu_id perf_stat__get_cpu(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return aggr_cpu_id__cpu(cpu, /*data=*/NULL); +} + static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { @@ -1378,6 +1384,12 @@ static struct aggr_cpu_id perf_stat__get_global_cached(struct perf_stat_config * return perf_stat__get_aggr(config, perf_stat__get_global, cpu); } +static struct aggr_cpu_id perf_stat__get_cpu_cached(struct perf_stat_config *config, + struct perf_cpu cpu) +{ + return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); +} + static bool term_percore_set(void) { struct evsel *counter; @@ -1404,8 +1416,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) case AGGR_NONE: if (term_percore_set()) return aggr_cpu_id__core; - - return NULL; + return aggr_cpu_id__cpu; case AGGR_GLOBAL: return aggr_cpu_id__global; case AGGR_THREAD: @@ -1428,10 +1439,9 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) case AGGR_NODE: return perf_stat__get_node_cached; case AGGR_NONE: - if (term_percore_set()) { + if (term_percore_set()) return perf_stat__get_core_cached; - } - return NULL; + return perf_stat__get_cpu_cached; case AGGR_GLOBAL: return perf_stat__get_global_cached; case AGGR_THREAD: @@ -1541,6 +1551,26 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(struct perf_cpu cpu, vo return id; } +static struct aggr_cpu_id perf_env__get_cpu_aggr_by_cpu(struct perf_cpu cpu, void *data) +{ + struct perf_env *env = data; + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + if (cpu.cpu != -1) { + /* + * core_id is relative to socket and die, + * we need a global id. So we set + * socket, die id and core id + */ + id.socket = env->cpu[cpu.cpu].socket_id; + id.die = env->cpu[cpu.cpu].die_id; + id.core = env->cpu[cpu.cpu].core_id; + id.cpu = cpu; + } + + return id; +} + static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -1576,6 +1606,12 @@ static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *conf return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); } +static struct aggr_cpu_id perf_stat__get_cpu_file(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return perf_env__get_cpu_aggr_by_cpu(cpu, &perf_stat.session->header.env); +} + static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, struct perf_cpu cpu) { @@ -1602,6 +1638,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) case AGGR_GLOBAL: return perf_env__get_global_aggr_by_cpu; case AGGR_NONE: + return perf_env__get_cpu_aggr_by_cpu; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1624,6 +1661,7 @@ static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode) case AGGR_GLOBAL: return perf_stat__get_global_file; case AGGR_NONE: + return perf_stat__get_cpu_file; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: From patchwork Fri Oct 14 06:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp27453wrs; Thu, 13 Oct 2022 23:20:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5C25tnVj5dVky1bWNjCCyxU96OaKqmu9fkJp+R71ee9x+xZ+lsszjIjrPGaG5sohAVi0bb X-Received: by 2002:a17:907:9618:b0:78d:fa75:e2b8 with SMTP id gb24-20020a170907961800b0078dfa75e2b8mr2422072ejc.65.1665728422076; Thu, 13 Oct 2022 23:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728422; cv=none; d=google.com; s=arc-20160816; b=Zl8l9EFaZnrptU021p+9nouMVJjf6jT10qmN2Piw+FSLzWAvyAYy9Q2XJm5RPcFxGm VsGeGpdebmDCR8tIOySzmfnExTxh/nJLSDq3M2ctEI9UN6slnJyxQMzOPPhgNZ/rGPgr ku69o6e8nWgUmofqS5UCGrGkGaZtHGUlHKcRCtf0kcF0ztJprNHqHYHd5HJy+L+2lTY8 aNZGjQka22tBW7u8qw3iO4JwZpge7zvnJ7gC+OMjFDqwO/cukXn0XIiDJzzQtzy+Zvl2 Tf0OGz16TfMxbxvNlKkN39Lvb1vjLl+Fpe1iL017cIXeVdTEVIJjo40I9LUaDBSr9HpX jJLg== 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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=UCEX8+4DtKvjzpeGjCjNvRZfSVdikj6WeltMAM1MA+6ve1t5t5GOv5X4KstsowcuQR 702KL9T1rnHhEm2xl21FHNTzOdfpnT/M6j5V8S/JbkB5iPCzzNf+IgDti70bsV0ZvA90 Z3Vo/y3dwwqMBO7VaNb4nmDyH8Qa1CX240v3gUnKAphTZ4050NWfSyF98MhpuKKAWpOm kRhf1dhvucOU8/Ru3wLVLDAJX01ns51747veB/ZYO9hT8LTHPcLoGD/e+NLMU9PBLBy5 s6Yidti92QokFpugUJFA4Q4EQP+vTa0T5OvKueQ+Ar1KJD7OpjcI2dlZRasU73XMI/lx 4BFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ecdtNwOW; 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 sb18-20020a170906edd200b0077ffa45c01esi1326837ejb.725.2022.10.13.23.19.55; Thu, 13 Oct 2022 23:20:22 -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=ecdtNwOW; 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 S229782AbiJNGQ5 (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbiJNGQG (ORCPT ); Fri, 14 Oct 2022 02:16:06 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 732F61ACA97; Thu, 13 Oct 2022 23:16:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id pq16so4045794pjb.2; Thu, 13 Oct 2022 23:16:03 -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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=ecdtNwOW4la+h9gxPqzdVVZAAuOGaARVWg9USJMX5lUxWYwmEVVtZbAgCKLZL/Pa3j 5sfEZ6fdR9yqIQf00lGtAl3niatSqMfy31HSG44jXhwoN2Y5iEMIETJ150FB4xz2JU6+ 6eOxmCZJwx7rhe1ikhKzq1jxd9w/ylkwpPMGf5YDR9gXsZTW7DCxMIR1nFkEj1FaWtKu pxIYbqJO7XVDu8XQ3uvXy0TrGtI95Ss/AeG5UDt3/K/QqWPqQCRAgFGJclZDMsPN/6W1 iSeI+qPz2Qj44oqcrJe26m9uFHTZp1KVBaFHjPH1hhIvEOqQ7rj4C2xx4zpd/10Z7seI NKhA== 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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=vRYpZXjmnaf+eqI3GMc76VlhPlxmlYNFgO/QRULmh6aNT/RQDfO8DE+C4LJ2X7y+q7 alvOQeHVZ3Se87jNfidfIv983my/kpuaaPo3l2PVs+ow6RKaEAoB+Vyp24VICQtOT3Lr 5MK2LYkq4cAZc4CUJMGo9JAfmCmIUSm7u7llc7L5cZ+YstJa/EGlSY01yMKzZdCSFZrs M8teHabQg/4gO72VLchGUN5MHGcuHl/Eu3UUItQEpH3KqWeOs0nApZxYkfEh4Ph7luIU d/nmoQIyL/v5pMtJqiddDHd4+fUzrolaoAkBriHdzhoXo18GbvcyQmiuhhgmqPCm9q4B kj2w== X-Gm-Message-State: ACrzQf2JMHPoXPJ0grcwgY8xPx3TcvCMhHabiqUL5nk0duWmg8QPvjcd YPx3b6570DL+AGmxEluUprE= X-Received: by 2002:a17:903:2606:b0:180:8799:3685 with SMTP id jd6-20020a170903260600b0018087993685mr3520101plb.31.1665728162181; Thu, 13 Oct 2022 23:16:02 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:01 -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 Subject: [PATCH 06/19] perf stat: Add 'needs_sort' argument to cpu_aggr_map__new() Date: Thu, 13 Oct 2022 23:15:37 -0700 Message-Id: <20221014061550.463644-7-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642846022868131?= X-GMAIL-MSGID: =?utf-8?q?1746642846022868131?= In case of no aggregation, it needs to keep the original (cpu) ordering in the aggr_map so that it can be in sync with the cpu map. This will make the code easier to handle AGGR_NONE similar to others. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 7 +++++-- tools/perf/util/cpumap.c | 6 ++++-- tools/perf/util/cpumap.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b03b530fe9a6..9053fd4d15a7 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1458,8 +1458,9 @@ static int perf_stat_init_aggr_mode(void) aggr_cpu_id_get_t get_id = aggr_mode__get_aggr(stat_config.aggr_mode); if (get_id) { + bool needs_sort = stat_config.aggr_mode != AGGR_NONE; stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, - get_id, /*data=*/NULL); + get_id, /*data=*/NULL, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); return -1; @@ -1674,11 +1675,13 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) { struct perf_env *env = &st->session->header.env; aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); + bool needs_sort = stat_config.aggr_mode != AGGR_NONE; if (!get_id) return 0; - stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, get_id, env); + stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, + get_id, env, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); return -1; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 60209fe87456..6e3fcf523de9 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -234,7 +234,7 @@ static int aggr_cpu_id__cmp(const void *a_pointer, const void *b_pointer) struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, aggr_cpu_id_get_t get_id, - void *data) + void *data, bool needs_sort) { int idx; struct perf_cpu cpu; @@ -270,8 +270,10 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, if (trimmed_c) c = trimmed_c; } + /* ensure we process id in increasing order */ - qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); + if (needs_sort) + qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); return c; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index b2ff648bc417..da28b3146ef9 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -97,7 +97,7 @@ typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data) */ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, aggr_cpu_id_get_t get_id, - void *data); + void *data, bool needs_sort); bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b); bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a); From patchwork Fri Oct 14 06:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26587wrs; Thu, 13 Oct 2022 23:18:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Rz9Fuxbtlcw/jxSrHhwS3FXdyecyYAB1eMkkVwgrmedBRaZ9+pLQosUPvOcwKjYp+2/fp X-Received: by 2002:a17:907:7b94:b0:731:1b11:c241 with SMTP id ne20-20020a1709077b9400b007311b11c241mr2420414ejc.676.1665728290671; Thu, 13 Oct 2022 23:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728290; cv=none; d=google.com; s=arc-20160816; b=jA+pkLw1qvdM4uhukwI85zf3IN+DGCxfyrJJH4CU1iLcflokq9bscImaXZhYngYwbi miNU12F8vn+zffofb4pv/xCJ1XfkprhVvnPY6ng/My4NKBQXciDYI5axAMtS53nkaR+/ lQKyl12lM7MUt5VcLeuy0U6qktIRimTxm49IdnoG4gwPMXTlof056i0KmdvSCZp4WRJl ivcYJGcTOMcB8wMgf87lnOj2+pxv1RPFuUWuwAxHeiw3vQKImPP1+7n+PObU8aI+T+H6 6+zB+5mQBMhB6jytMpg05ggM8QMRoaoKdxgWJSWVlkStaErXbqoHM/6ODp3qS/mWG0Yr ai8A== 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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=KembgLXKTX2bqQbfrpq/Lf2qUVn6TH515qBmD5/RVpDmtIyEPeuFQmagCHw9QLzWBy burOd6hGBHEeK50CHyo72H1QWIGCZ1n9ILaLoUIsO9MY4h4isShNrNCbtQQxlI8z+X2N nD/L+8LVKzNNi5Gzuf87AnFb2SsZ1owO+0aaMW6IWuQ5bA48SEVh8DsvLXugPM8XZcxl VCw4+jx+kduSqbnU3hCnwi4kij3UQvddysrU+73rn0ZMjikkVyqD3sqbV/Ui0V4AVya9 EWTMorKB5uh/iR5oSBFyCe7XdFNZy8dKhHYMQrdmu7z0sENa8ZoRpvijEtA67B9k4/My tb9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UjyPEgCV; 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 w2-20020a05640234c200b00450bda7e3fdsi1849171edc.28.2022.10.13.23.17.45; Thu, 13 Oct 2022 23:18:10 -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=UjyPEgCV; 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 S229954AbiJNGQw (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbiJNGQI (ORCPT ); Fri, 14 Oct 2022 02:16:08 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4459017400; Thu, 13 Oct 2022 23:16:04 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d10so4021200pfh.6; Thu, 13 Oct 2022 23:16:04 -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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=UjyPEgCV/P4txxO8/7n0vXdf68rbMK9RCtZgyHbQegC7UZ2kGXIdQQjenFFTVQO1Sf 8SEMep9jfVxs9De7toZJTP2IbShr6e9YhUK8MiPCv6NnYvqARaSn6INvjq/BSq35Z4xJ 3+5Mh8YGJP4N5oWVuwbHaWzHxaUcX1jVZfwGGErMj0/kJ5IGX8UEoo7xKT5Hrv81Ab8x ARFSsZQCd4JwYFE/Zi/RoR0apsTWn+0JISeP5QVm7zT4AAgR0L+Fu0hxwZHJ5UUp2EJy tSh9V/c5Dcq4YhlMYAEywr5WGe2L0SFksWsqGcPoi9tzzFtP8lJ2G6OvYKtHUe2STDlP tCgQ== 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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=fhazD90KAX8yRVQVdSAaEseiROSuaaOLDxMtPM1ysYiITJ9atFeA6X2SWEUCxmHjC6 tQCyShoOe5HVw9mf69dlSEpZbvythQ90DD2gThAJsQCed8YpOHVs8uSUKY9A8ZDPZ1SH T3viPYeiKOJaOPzv82Sw2fEmkGlujEsxSTY7uj0zSiXjS9ZF00H7KObecjT4dDHB7at2 w/y6VonLrkWoYGNNZ+K2eArXjdwmp5mpf0DTfagkH85BH3oxG73KMsikNmCQgxPPo3F2 CwGxIt6fBuVS/qOMoKjh8luOealwYBzW3bzRMdWy1UHCtl9kWOe9PMSAKXs/MsInUy9k 3KTg== X-Gm-Message-State: ACrzQf2IQ6ECfHT+eVuIDsjSmqvH/WfqCjzcid7QqzgbXnHZKwmA7xsC Yogdlf8pWi6qESXcoqB3+tA= X-Received: by 2002:a63:5415:0:b0:439:e932:e025 with SMTP id i21-20020a635415000000b00439e932e025mr3177531pgb.63.1665728163957; Thu, 13 Oct 2022 23:16:03 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:03 -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 Subject: [PATCH 07/19] perf stat: Add struct perf_stat_aggr to perf_stat_evsel Date: Thu, 13 Oct 2022 23:15:38 -0700 Message-Id: <20221014061550.463644-8-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642708137261619?= X-GMAIL-MSGID: =?utf-8?q?1746642708137261619?= The perf_stat_aggr struct is to keep aggregated counter values and the states according to the aggregation mode. The number of entries is depends on the mode and this is a preparation for the later use. Signed-off-by: Namhyung Kim --- tools/perf/util/stat.c | 34 +++++++++++++++++++++++++++------- tools/perf/util/stat.h | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 8ec8bb4a9912..c9d5aa295b54 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -133,15 +133,33 @@ static void perf_stat_evsel_id_init(struct evsel *evsel) static void evsel__reset_stat_priv(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; + struct perf_stat_aggr *aggr = ps->aggr; init_stats(&ps->res_stats); + + if (aggr) + memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } -static int evsel__alloc_stat_priv(struct evsel *evsel) + +static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) { - evsel->stats = zalloc(sizeof(struct perf_stat_evsel)); - if (evsel->stats == NULL) + struct perf_stat_evsel *ps; + + ps = zalloc(sizeof(*ps)); + if (ps == NULL) return -ENOMEM; + + if (nr_aggr) { + ps->nr_aggr = nr_aggr; + ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); + if (ps->aggr == NULL) { + free(ps); + return -ENOMEM; + } + } + + evsel->stats = ps; perf_stat_evsel_id_init(evsel); evsel__reset_stat_priv(evsel); return 0; @@ -151,8 +169,10 @@ static void evsel__free_stat_priv(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; - if (ps) + if (ps) { + zfree(&ps->aggr); zfree(&ps->group_data); + } zfree(&evsel->stats); } @@ -181,9 +201,9 @@ static void evsel__reset_prev_raw_counts(struct evsel *evsel) perf_counts__reset(evsel->prev_raw_counts); } -static int evsel__alloc_stats(struct evsel *evsel, bool alloc_raw) +static int evsel__alloc_stats(struct evsel *evsel, int nr_aggr, bool alloc_raw) { - if (evsel__alloc_stat_priv(evsel) < 0 || + if (evsel__alloc_stat_priv(evsel, nr_aggr) < 0 || evsel__alloc_counts(evsel) < 0 || (alloc_raw && evsel__alloc_prev_raw_counts(evsel) < 0)) return -ENOMEM; @@ -196,7 +216,7 @@ int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw) struct evsel *evsel; evlist__for_each_entry(evlist, evsel) { - if (evsel__alloc_stats(evsel, alloc_raw)) + if (evsel__alloc_stats(evsel, 0, alloc_raw)) goto out_free; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index b0899c6e002f..42453513ffea 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -8,6 +8,7 @@ #include #include "cpumap.h" #include "rblist.h" +#include "counts.h" struct perf_cpu_map; struct perf_stat_config; @@ -42,9 +43,27 @@ enum perf_stat_evsel_id { PERF_STAT_EVSEL_ID__MAX, }; +/* hold aggregated event info */ +struct perf_stat_aggr { + /* aggregated values */ + struct perf_counts_values counts; + /* number of entries (CPUs) aggregated */ + int nr; + /* whether any entry has failed to read/process event */ + bool failed; +}; + +/* per-evsel event stats */ struct perf_stat_evsel { + /* used for repeated runs */ struct stats res_stats; + /* evsel id for quick check */ enum perf_stat_evsel_id id; + /* number of allocated 'aggr' */ + int nr_aggr; + /* aggregated event values */ + struct perf_stat_aggr *aggr; + /* used for group read */ u64 *group_data; }; From patchwork Fri Oct 14 06:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26423wrs; Thu, 13 Oct 2022 23:17:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ylit7I767iR/7JTmX5j/gPTBl8NwjoDkC8eKzyCCT36s/JmmZn7GC1o5yz3oxrN4/osqn X-Received: by 2002:a17:907:a052:b0:78d:8531:92b with SMTP id gz18-20020a170907a05200b0078d8531092bmr2481935ejc.37.1665728268066; Thu, 13 Oct 2022 23:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728268; cv=none; d=google.com; s=arc-20160816; b=KKF30oaG9oO21cA5854vRsTPbQR1/CiKGT4MMKr6d59gl+ctAJAwKwSwbTq3A7Fe1y 4i70KA+VXk5u0CpJakAp6O7SisfU0ZCB8X9er3IS7g0JO7TpAy1T1VHUI+DDy/ktMa4M 3rycy/RAwCan4JEPWoZykGKMotTXCitSwLbTybxvyb4zeEEfwEL5kzFR25mmJrcCQP9u KOhbVq4Qg+wCzx+Tee1hRJc6Zxh3XAByvwtJFge2ZxCvylwVCHF7G6jPyuuQ8jzR7YA1 XVWfahxKHUS8Q/mxKHDSBCc5kwnjAPmbB3tjjfTnS/Gbwh+QUT2fOVievjx7h8h4tvYI Z92Q== 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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=AparX5nx1c3LsgG/VjzHIpE6rcTaXV1p7/VbjcrgQj6B8hTSHyp0qyk43m7eTuYtLc sTPn4ahwGQu3j8et5uMLRPUjYt099rGCdrhNQJXcqQekBQZ2yTe9f81cIYPM0PteeFqO 7/uncrCVtYRunhtRtS6GC2svRsRer6LRfxDjzkVgtKLlTkWAFi2MHQfPhvSftWtL00Fm WkLrs7IuqP/2j7xotXK+c+07q0MY5kZZB+MgcOlUvL9rRVj0TTGwat2AhJ9P4BbUfdmx Y6cdgNvMzu2Mo6OFSUJupgC+qWzpg6mpzPqAX8v0tG/kosRQOUVK6SztOFWjKA9Qyx5j X5ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cqiWLYbY; 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 i20-20020a05640242d400b0045c93142111si2130982edc.70.2022.10.13.23.17.22; Thu, 13 Oct 2022 23:17:48 -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=cqiWLYbY; 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 S229627AbiJNGQd (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiJNGQT (ORCPT ); Fri, 14 Oct 2022 02:16:19 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0529117406; Thu, 13 Oct 2022 23:16:06 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id bh13so3497886pgb.4; Thu, 13 Oct 2022 23:16:06 -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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=cqiWLYbYVaZqA1AN5JxDT/T/fdaoDMt/9viiEZ70RhnVJMAhC6et+7dSvEPhDz9naQ MxxKsPwYPq2+alYkqJuN0OhwkBig/XsnASr6Qr+bUKu8TFvpuakQdFuZdHkKZfN219PM /ktu+5SurxQOYpC+rij/45vfwW+wBcimh/QC72HniikR5ApzFI2kKZRM+6iYmm0b2a2c GI5FyBx2h6T9sjw39qf25o9TaMKuF2Y0Wr+B1FWeBbd8DwScGYP2G7K0J133K0Dl1PXL ZKiogNWA92yuYpYdKe1m8rWfcr3oPSW4VtaIM/xizkxtPf3K9qld5irLzWcLwpafPLZ3 zxxQ== 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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=I5bsAi+fNp44bLZOF4Ct5acfRGpfWape9f0HhJ/jV2D0a3tN8g1cb1OZ/DmFHQNB2u BncnQlMTn7+WthlVtG2wFsc5p4ugh37x8k+8cBz8Kb/vjTacEBqOC/3iPagt4H/upqUU wUUAzEsJtuywiYJRvBQxLQ4cBfU2KlfXL8U1KFwZfJmRuvm6yy7BTVFhryJ2gcInwbhj QoA+yAK1cn+JlhbNJG57Mu8xFnFqOZqeKCnDrRVqY/zR4VGtxnca2PHMWv6bcdwvxqZz VioSqziqdLaUpYFk21vpbC6HhfXzlKIRy2V/pAcND0jOxKLK2Czi7b7Ur9RWPc7VGjz1 u1bg== X-Gm-Message-State: ACrzQf0eywLVwDsojzJTZOLyry8qtTF36PLUl8NOE8x/TlhrzoI1cZny 7SOZMSYfQIRjbju5rnNMKbo= X-Received: by 2002:a63:4e5a:0:b0:438:9513:da55 with SMTP id o26-20020a634e5a000000b004389513da55mr3121140pgl.381.1665728165550; Thu, 13 Oct 2022 23:16:05 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:05 -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 Subject: [PATCH 08/19] perf stat: Allocate evsel->stats->aggr properly Date: Thu, 13 Oct 2022 23:15:39 -0700 Message-Id: <20221014061550.463644-9-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642684545466109?= X-GMAIL-MSGID: =?utf-8?q?1746642684545466109?= The perf_stat_config.aggr_map should have a correct size of the aggregation map. Use it to allocate aggr_counts. Also AGGR_NONE with per-core events can be tricky because it doesn't aggreate basically but it needs to do so for per-core events only. So only per-core evsels will have stats->aggr data. Note that other caller of evlist__alloc_stat() might not have stat_config or aggr_map. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-script.c | 4 ++-- tools/perf/builtin-stat.c | 6 +++--- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 2 +- tools/perf/util/stat.c | 9 +++++++-- tools/perf/util/stat.h | 3 ++- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7ca238277d83..d7ec8c1af293 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2049,7 +2049,7 @@ static void perf_sample__fprint_metric(struct perf_script *script, u64 val; if (!evsel->stats) - evlist__alloc_stats(script->session->evlist, false); + evlist__alloc_stats(&stat_config, script->session->evlist, /*alloc_raw=*/false); if (evsel_script(leader)->gnum++ == 0) perf_stat__reset_shadow_stats(); val = sample->period * evsel->scale; @@ -3632,7 +3632,7 @@ static int set_maps(struct perf_script *script) perf_evlist__set_maps(&evlist->core, script->cpus, script->threads); - if (evlist__alloc_stats(evlist, true)) + if (evlist__alloc_stats(&stat_config, evlist, /*alloc_raw=*/true)) return -ENOMEM; script->allocated = true; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9053fd4d15a7..92a8e4512f98 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2121,7 +2121,7 @@ static int set_maps(struct perf_stat *st) perf_evlist__set_maps(&evsel_list->core, st->cpus, st->threads); - if (evlist__alloc_stats(evsel_list, true)) + if (evlist__alloc_stats(&stat_config, evsel_list, /*alloc_raw=*/true)) return -ENOMEM; st->maps_allocated = true; @@ -2568,10 +2568,10 @@ int cmd_stat(int argc, const char **argv) goto out; } - if (evlist__alloc_stats(evsel_list, interval)) + if (perf_stat_init_aggr_mode()) goto out; - if (perf_stat_init_aggr_mode()) + if (evlist__alloc_stats(&stat_config, evsel_list, interval)) goto out; /* diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 68f5a2a03242..21b7ac00d798 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -103,7 +103,7 @@ static int __compute_metric(const char *name, struct value *vals, if (err) goto out; - err = evlist__alloc_stats(evlist, false); + err = evlist__alloc_stats(/*config=*/NULL, evlist, /*alloc_raw=*/false); if (err) goto out; diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 097e05c796ab..5d0d3b239a68 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -889,7 +889,7 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e goto out_err; } - err = evlist__alloc_stats(evlist, false); + err = evlist__alloc_stats(/*config=*/NULL, evlist, /*alloc_raw=*/false); if (err) goto out_err; /* diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index c9d5aa295b54..374149628507 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -211,12 +211,17 @@ static int evsel__alloc_stats(struct evsel *evsel, int nr_aggr, bool alloc_raw) return 0; } -int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw) +int evlist__alloc_stats(struct perf_stat_config *config, + struct evlist *evlist, bool alloc_raw) { struct evsel *evsel; + int nr_aggr = 0; + + if (config && config->aggr_map) + nr_aggr = config->aggr_map->nr; evlist__for_each_entry(evlist, evsel) { - if (evsel__alloc_stats(evsel, 0, alloc_raw)) + if (evsel__alloc_stats(evsel, nr_aggr, alloc_raw)) goto out_free; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 42453513ffea..0980875b9be1 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -267,7 +267,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct runtime_stat *st); void perf_stat__collect_metric_expr(struct evlist *); -int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw); +int evlist__alloc_stats(struct perf_stat_config *config, + struct evlist *evlist, bool alloc_raw); void evlist__free_stats(struct evlist *evlist); void evlist__reset_stats(struct evlist *evlist); void evlist__reset_prev_raw_counts(struct evlist *evlist); From patchwork Fri Oct 14 06:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26451wrs; Thu, 13 Oct 2022 23:17:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5N9b9AJ3IyklSUUrUWmAFT3Q7HIijpG1C+sFVCLvyk4Je2ZIp9NsBdJblyByu0RP7Ct32A X-Received: by 2002:a05:6402:1853:b0:459:4e34:2ea5 with SMTP id v19-20020a056402185300b004594e342ea5mr2973891edy.191.1665728271967; Thu, 13 Oct 2022 23:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728271; cv=none; d=google.com; s=arc-20160816; b=C3gP6q6VjffV/TE832nixmsJiBXw4UWHDbZ1GqnIlN9Nfbl4V8/EWXQdBN9tB+aw4c PXvo7c0/1Co6ZDw3r9miWN1DMxLCrGyPR+VCrUpeXJ6h4ytTwN90KIIqlpxYmbGanfr7 48NoNxbFtyyJ5+X0KtWNHSJ7+fLwJz8QkxoGTtIw1ajrP7D49BcwmwQ6ZgPj1EoS8s7y /joSl0lDq9GI33SlLc5Dd347U2FoeMbHMH47/YUXLB9YWZl6VZGhtuwPR8ZEevLw6Enu /HrWaME0Fi6N0yTx8XukX35dZNCCCr9knWuSSQ/oHImqUv2DXNJ4HPfFwyYYHs3jcBDp lekw== 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=4xwiX9ikbazKVy6BuloKenXceW5yARy9JMuN2/w1Xq0=; b=wktrztUCmMT+PFa1kHvYBwY5gxTV3WO8AsF1Po+B6D+R+6yM1INElQU8+MPsNSzp9W oRi70Q3L/cuQ/j/Tzprk8JplEqAThlqjNxCxUTeFDdJzOn8+3TSwxlBtppPI8U3SMZnW 0hIOTACkmo/NiYOs0GkztondGScatkYNDtElChwPuFO1a3Vk9xNVUu8QpNG56lZHGyec rOIo9lJ6ll4KtWq2saJTidTP50jU18Ry5eW1D9ctCLLVyrusyaDVv+1JsOfGQaWX93MC RTR2f6yTE2lOVBdXlWaZ57pjctX/bLwNHgnQ1m6j3ZP9d4AEqHcHN6kndgQHvdi1isyN B7Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="disYc/44"; 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 di11-20020a170906730b00b00730a4246dd0si1672036ejc.593.2022.10.13.23.17.25; Thu, 13 Oct 2022 23:17:51 -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="disYc/44"; 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 S229915AbiJNGQj (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbiJNGQU (ORCPT ); Fri, 14 Oct 2022 02:16:20 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8A817414; Thu, 13 Oct 2022 23:16:08 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id 204so3997025pfx.10; Thu, 13 Oct 2022 23:16:08 -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=4xwiX9ikbazKVy6BuloKenXceW5yARy9JMuN2/w1Xq0=; b=disYc/44Yz0x0FeK2k4NIIzBi4ECqUdBJMwzsGzIJR/S6zLTSTIx0Wq1otNQ5jJwbj Ky4mFUADNHjYajOI6sd3j+LReOA/e435xteN8+CcRbVHMeMtVyCtRFOAIKUSnlJ/aIbJ kkULMBFrA8bvpSElA+mUdhgMcq7tJQZWVL19+5nzL5YVSh8QGodalUjws4nCpAgG77ZF UhClLXV357uG1ktv1mZMCQqZikOaIjjWp0cL7nW/79CLMwC8I/RQGqessfFkGjsf3r6G LhwRQENsJ0ysAeTA3/jwDW9UMHmIXkf0wqMwupySGaY6Jq2yklcUOcnfB+CtmKL2lw+U PDQg== 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=4xwiX9ikbazKVy6BuloKenXceW5yARy9JMuN2/w1Xq0=; b=AZJ/QkfNMZxdfO9Lvb14GgpyXZnORUs36Q7qXV+SHoqejNZVD8SMY/sAJ/mwJMjfGB wMyZCQ8nEPe6kYsUu+xNbchoUwFF8YJr3ohwnD44Pg9Xuxq0wrIjDdTzxKNEC6CoXcDS DucRt5ZQ97+nV5g6qa6n7DoQm4mO+g9nGImZoUEeFjmO5233CEaoPLac4wtNrjOhTUYf cml0yzXxEQ8CBH8SAz5xvK/EwFK95xE1gUCGSN37IUAHDFnKJRQMVuUaraPZpcyyCvu6 dWs5JvjIRIGbbrfPYD4Os3QAJ8CDrlT4AkTBnWKMf9I08nj9b15hOmmGwnAqMMwLfNx4 KLnw== X-Gm-Message-State: ACrzQf2YoOK913j7Q6h8vzas4CRvSJ9Gc6WeGqpDu8n/pYsWfapRohY0 0KeiDnIYPXaAVWx6GBqyaLg= X-Received: by 2002:a63:5322:0:b0:44e:11f7:b414 with SMTP id h34-20020a635322000000b0044e11f7b414mr3187757pgb.226.1665728167437; Thu, 13 Oct 2022 23:16:07 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:06 -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 Subject: [PATCH 09/19] perf stat: Aggregate events using evsel->stats->aggr Date: Thu, 13 Oct 2022 23:15:40 -0700 Message-Id: <20221014061550.463644-10-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642688442416332?= X-GMAIL-MSGID: =?utf-8?q?1746642688442416332?= Add a logic to aggregate counter values to the new evsel->stats->aggr. This is not used yet so shadow stats are not updated. But later patch will convert the existing code to use it. With that, we don't need to handle AGGR_GLOBAL specially anymore. It can use the same logic with counts, prev_counts and aggr_counts. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 3 -- tools/perf/util/evsel.c | 9 +--- .../scripting-engines/trace-event-python.c | 6 --- tools/perf/util/stat.c | 46 ++++++++++++++++--- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 92a8e4512f98..abede56d79b6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -963,9 +963,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) init_stats(&walltime_nsecs_stats); update_stats(&walltime_nsecs_stats, t1 - t0); - if (stat_config.aggr_mode == AGGR_GLOBAL) - evlist__save_aggr_prev_raw_counts(evsel_list); - evlist__copy_prev_raw_counts(evsel_list); evlist__reset_prev_raw_counts(evsel_list); perf_stat__reset_shadow_per_stat(&rt_stat); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a6ea91c72659..a1fcb3166149 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1526,13 +1526,8 @@ void evsel__compute_deltas(struct evsel *evsel, int cpu_map_idx, int thread, if (!evsel->prev_raw_counts) return; - if (cpu_map_idx == -1) { - tmp = evsel->prev_raw_counts->aggr; - evsel->prev_raw_counts->aggr = *count; - } else { - tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); - *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count; - } + tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count; count->val = count->val - tmp.val; count->ena = count->ena - tmp.ena; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 1f2040f36d4e..7bc8559dce6a 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1653,12 +1653,6 @@ static void python_process_stat(struct perf_stat_config *config, struct perf_cpu_map *cpus = counter->core.cpus; int cpu, thread; - if (config->aggr_mode == AGGR_GLOBAL) { - process_stat(counter, (struct perf_cpu){ .cpu = -1 }, -1, tstamp, - &counter->counts->aggr); - return; - } - for (thread = 0; thread < threads->nr; thread++) { for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { process_stat(counter, perf_cpu_map__cpu(cpus, cpu), diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 374149628507..99874254809d 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -387,6 +387,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, struct perf_counts_values *count) { struct perf_counts_values *aggr = &evsel->counts->aggr; + struct perf_stat_evsel *ps = evsel->stats; static struct perf_counts_values zero; bool skip = false; @@ -398,6 +399,44 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, if (skip) count = &zero; + if (!evsel->snapshot) + evsel__compute_deltas(evsel, cpu_map_idx, thread, count); + perf_counts_values__scale(count, config->scale, NULL); + + if (ps->aggr) { + struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); + struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); + struct perf_stat_aggr *ps_aggr; + int i; + + for (i = 0; i < ps->nr_aggr; i++) { + if (!aggr_cpu_id__equal(&aggr_id, &config->aggr_map->map[i])) + continue; + + ps_aggr = &ps->aggr[i]; + ps_aggr->nr++; + + /* + * 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) { + ps_aggr->counts.val = 0; + ps_aggr->counts.ena = 0; + ps_aggr->counts.run = 0; + ps_aggr->failed = true; + } + + if (!ps_aggr->failed) { + ps_aggr->counts.val += count->val; + ps_aggr->counts.ena += count->ena; + ps_aggr->counts.run += count->run; + } + break; + } + } + switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: @@ -405,9 +444,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, case AGGR_SOCKET: case AGGR_NODE: case AGGR_NONE: - if (!evsel->snapshot) - evsel__compute_deltas(evsel, cpu_map_idx, thread, count); - perf_counts_values__scale(count, config->scale, NULL); if ((config->aggr_mode == AGGR_NONE) && (!evsel->percore)) { perf_stat__update_shadow_stats(evsel, count->val, cpu_map_idx, &rt_stat); @@ -469,10 +505,6 @@ int perf_stat_process_counter(struct perf_stat_config *config, if (config->aggr_mode != AGGR_GLOBAL) return 0; - if (!counter->snapshot) - evsel__compute_deltas(counter, -1, -1, aggr); - perf_counts_values__scale(aggr, config->scale, &counter->counts->scaled); - update_stats(&ps->res_stats, *count); if (verbose > 0) { From patchwork Fri Oct 14 06:15:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26498wrs; Thu, 13 Oct 2022 23:17:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CtXdtxdwh2PjK1DxphrlJcg5NPLG42yz1BmdDk3wfWPrvo1aLxVy7fgruTF3gKizjmx1q X-Received: by 2002:aa7:dd45:0:b0:458:7474:1fbe with SMTP id o5-20020aa7dd45000000b0045874741fbemr2936063edw.334.1665728278744; Thu, 13 Oct 2022 23:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728278; cv=none; d=google.com; s=arc-20160816; b=Q9kYJpWbM5QNOslNI4+4ScLKtb7K+T+WEzX9IqmPerc2lmgykDkfGuDE8vexVpCE9Y YJwW/kwpC7QEQm2tfKxNbD/myq3hdPtusppJvHwYWxpRZG66oPCRVjxFuQbt7RjmVbzw W8VljKg2pDVpD8nIvZPe1irTsHp3SY07E9Wi2oTTOlYuA9UBt+3y3UlzqFAZz6XtRocM ksocNxq5bmzRHtjDjSkHX3G9ZynYiYqtRJpaPQJnhxP9CAVPNkHRxKHQZ0zpzfRa+vFj lcQXh5Fb5O5hDx0+/Oa6JoFGfmRM2iFFv493f2vHE3NKSgWJlA8z4wNAb/g3q8V/Wz5h gRJw== 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=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=L1gDf8fdxH0cBbW1PX9vfq871xvmpuL9XWzUs+1vYtLJMMAUYFeRn6FSrzgfQ+kB2k nRADKGScsj4CdIXhQhAUAZpzk3jWwR4rbdDed3deG2Y+TEShuGe2Z1UHCIKviKKjtSC9 O/w6e8ra33LW22dfFfBXvCM9uLpVWKGyyzVpFDTSlMalsXLMJiF+ntY1l6TwuCk3E0oV HxP2idHpLiPfLvBRrJGExL9vRkVStzfXWrykaglBYCoW3jYKgn73ei/5b9uImTXVGDuP HEtFB7CI9ZoO3DrRlSOyeS7Xr8hXjYXylvve+/9iM3/T7mhuH+u3qFfmRLE+zkAWkdVf WqFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RlaMO08o; 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 he19-20020a1709073d9300b0078bdbb52361si1919516ejc.209.2022.10.13.23.17.32; Thu, 13 Oct 2022 23:17:58 -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=RlaMO08o; 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 S229926AbiJNGQm (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJNGQW (ORCPT ); Fri, 14 Oct 2022 02:16:22 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E838517423; Thu, 13 Oct 2022 23:16:09 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id pq16so4046038pjb.2; Thu, 13 Oct 2022 23:16:09 -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=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=RlaMO08oW0Y/4ls0tD3F9i8Ffvq6PcyYUdkqEBiT+Nq8vy7gqVceZf2G4GZ5l18tde Ox0Vha0o0+aaUCGznLuwuGG65al57mrPWGxNizDW1mWEwsyEYjjMkY/0PQCeHcT4othb nawh0We3wf9UvtgKXVsvheJiEjLsJRMnj9PivffA1EiZ0frZU0Dq4jWmdVoXe+W7KDz6 cwEV2DOGrv7r1DnX8lXjU0hQEVVayAyZdAlKyYsn0MDYXrz4tZPfvjnPlG8fzFMNCGoH iEw4c/WIBiDYbYon8yOUwUyBpbHpSrk7QWfPqogQJCVtga018vkKqDYkOIpu3YvBMXNx kJbw== 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=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=xy4ga/3yUHtitwmiCS5zsPMDFibl2u8vB1i3dTRUueF/istKr6cudwEYduv3DHE0j6 H0FPIoPbWldRGUQMfiq6lpYG4thWZvE0/xeWHjSG2pjteXlWV7/AeiG4Om4BcP44xpA6 iT2JF3hg08l1EMIIAoZwscHLXN7j7Y94hlLEXnVWqaHdAEOwhUk2IUcHKZjSEzIXg0Xd AiKb3cjHrNeNW5jtyrPV5Hwh49C00Uqcql7qXPcjBjlmWbs+9S/Ap2Wkaiy26wdTTj6/ NyPqCMlT5ipITfWI7Zy6GDQQpsBK/aEawZ5+dVvHSXgpnF7qS/wHWTF/7N3ibTto/uiw AI9w== X-Gm-Message-State: ACrzQf0HkDARc6Vu4rjy9JWnP35JTpJZ71T3OMhgsxKHVXdu5JePza88 Z7/70KeABSLi4JTgtXYTFrM++J8Wn+k= X-Received: by 2002:a17:903:1207:b0:185:4042:23d2 with SMTP id l7-20020a170903120700b00185404223d2mr2852807plh.143.1665728168967; Thu, 13 Oct 2022 23:16:08 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:08 -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 Subject: [PATCH 10/19] perf stat: Aggregate per-thread stats using evsel->stats->aggr Date: Thu, 13 Oct 2022 23:15:41 -0700 Message-Id: <20221014061550.463644-11-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642695607684722?= X-GMAIL-MSGID: =?utf-8?q?1746642695607684722?= Per-thread aggregation doesn't use the CPU numbers but the logic should be the same. Initialize cpu_aggr_map separately for AGGR_THREAD and use thread map idx to aggregate counter values. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 31 +++++++++++++++++++++++++++++++ tools/perf/util/stat.c | 26 +++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index abede56d79b6..6777fef0d56c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1465,6 +1465,21 @@ static int perf_stat_init_aggr_mode(void) stat_config.aggr_get_id = aggr_mode__get_id(stat_config.aggr_mode); } + if (stat_config.aggr_mode == AGGR_THREAD) { + nr = perf_thread_map__nr(evsel_list->core.threads); + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + /* * The evsel_list->cpus is the base we operate on, * taking the highest cpu number to be the size of @@ -1674,6 +1689,22 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); bool needs_sort = stat_config.aggr_mode != AGGR_NONE; + if (stat_config.aggr_mode == AGGR_THREAD) { + int nr = perf_thread_map__nr(evsel_list->core.threads); + + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + if (!get_id) return 0; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 99874254809d..3593af403188 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -403,6 +403,24 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, evsel__compute_deltas(evsel, cpu_map_idx, thread, count); perf_counts_values__scale(count, config->scale, NULL); + if (config->aggr_mode == AGGR_THREAD) { + struct perf_counts_values *aggr_counts = &ps->aggr[thread].counts; + + /* + * Skip value 0 when enabling --per-thread globally, + * otherwise too many 0 output. + */ + if (count->val == 0 && config->system_wide) + return 0; + + ps->aggr[thread].nr++; + + aggr_counts->val += count->val; + aggr_counts->ena += count->ena; + aggr_counts->run += count->run; + goto update; + } + if (ps->aggr) { struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); @@ -417,10 +435,11 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ps_aggr->nr++; /* - * When any result is bad, make them all to give - * consistent output in interval mode. + * 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. */ - if (count->ena == 0 || count->run == 0 || + if (((count->ena == 0 || count->run == 0) && cpu.cpu != -1) || evsel->counts->scaled == -1) { ps_aggr->counts.val = 0; ps_aggr->counts.ena = 0; @@ -437,6 +456,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } +update: switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: From patchwork Fri Oct 14 06:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp26524wrs; Thu, 13 Oct 2022 23:18:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6353ViTHg9tv3xO3yxReDg77eXyNIK/7Vje2m05NooRDnBOCk2HODuwW/n8rDPzM0VeiIJ X-Received: by 2002:a17:906:5a48:b0:78e:18a1:32ba with SMTP id my8-20020a1709065a4800b0078e18a132bamr2394558ejc.346.1665728281138; Thu, 13 Oct 2022 23:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728281; cv=none; d=google.com; s=arc-20160816; b=YRiNLlNwG/ZcwNBz/qkixUu59VySVO7Cclll2Bmen2bRUADXfHK9n2zREhVZnXhysL mcx5HDYamjQKsG9NKfygN7BJuuB023sAPRzlwwTNwYgOw7KTxZEeQApgswaw0BokX8ik kFJ5DtDR3clAgvrdKHo+yxbhd1QQRkslUnsjGWQFFz6WsUq0e2Q790VS7FoaSCKberoo Ft7Egae2FWCiZtZdpVIPPXJO8dV6ejyZdyT8c0F/QukSWY6xhpsqEef/MEVypCLEoM5Q qfkR7yN3GsLAefrjqosAl/ffgNqZwLd91XJqAG9oK/sG1pS/xnh92KdZE14JkL5C0JAC 8zeQ== 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=1bVysEQHf7eswq/CEhQ6wbCV3Rg3qd7TUjqKNRIeNeE=; b=lNh02lh3La9xx7VKPYRDYzFa5vbYMPY003WfNS1AVjzhECNu4OdhsA1Tiq1h5iJb46 lHiWyA0m8KSLU+bP7qNzyt6qGZZrlL48HOenkF1kb64XtFMWo0+ElEGB+uQSitrkG+l9 9u2Gfroqp6Ieywq7KlbGiOqnQKjEMilgUFaDQpX9ul+cBRmXGodrYrf7BHf2NHMiXzdw A+9VwSaZ3azc5pUhvC7NsSY7dfX2bhPDjh8atXprTFZZjyoDsJgQ2FTTD2DYu3xK7TD2 Pm8bdVUKSJ9kmD2WPKHDPjoJOSF35FJkOfPR0ReTQEo71aK58t7FfkVitSZdVwI3JL56 ljPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GUH+jcz2; 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 y11-20020a056402440b00b00451bc675cc9si1975694eda.335.2022.10.13.23.17.36; Thu, 13 Oct 2022 23:18:01 -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=GUH+jcz2; 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 S229832AbiJNGQs (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiJNGQW (ORCPT ); Fri, 14 Oct 2022 02:16:22 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C1C17434; Thu, 13 Oct 2022 23:16:11 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id i3so3998913pfk.9; Thu, 13 Oct 2022 23:16:11 -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=1bVysEQHf7eswq/CEhQ6wbCV3Rg3qd7TUjqKNRIeNeE=; b=GUH+jcz2YrnwSsaJtxMkbKTcBz74pdxJwwFX8CexctZBDJc5Hh9YB3avVH6EZd33Em w2cBjLSRGRLgwGDCAO5RbiSEsmKFEvw+VsRir4V3rm8yJ+x+6349eTltQJG7XyENc2Gu pCb5dQ9d1O7ZQq17D7t6oBIG50I0fYkf3Ne4ExVT6V3cYPRldrqr4n9npruaCGt3aSWa 8NFoZrCLppFPjVpcPZSxw2XO7OglEfZzYYS0GGupH5Lav15TtXBWO2aikd6koAidrxnr t5crTOcNK9xYWh+2TsisSaf8golRNtwWfmQPJhb5spvb809lb2RLHhb4f/PdJdf7Do9K WDhA== 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=1bVysEQHf7eswq/CEhQ6wbCV3Rg3qd7TUjqKNRIeNeE=; b=RN75FvixC6Qxwx3/ukaQ/qHk0HWXG7g4J/Ev+rzy37F6FV5GtuRSEg+LryCqjtWkJ2 LJ3e0JtSGSdlwIpukRzAhQU5voarbVNfgf4tsuwR/hD9UNf6SrZuffEFRYTG4Y6iUNmn S01MR1mDVEbTED+iQ4GYu6UDNV/yv9Jqp8ouBymc/xR9a+98pIIYsv/UF9joSaHPR1GH Se+6b6kN4o/BwhaV0tNEA43HXiWuExFJZbvY1m9wixOTt2a7RoBzlP1qr4/zBVjrDabV OBf/K4I8RSLHvWppPbZ+i/DIqHVrqXwvEbt03mIpz4I2Cn+RtG/U7BAXv+xlOXLfq6AO s3IA== X-Gm-Message-State: ACrzQf2cYR5oi6sQLzRtqBW1H0IUZihTHpCjprGNHIRJT5nltXBN8Cc8 sjZ1Q7Frp52kxLJ+uoEE4X8= X-Received: by 2002:a63:534e:0:b0:44e:12bf:2df8 with SMTP id t14-20020a63534e000000b0044e12bf2df8mr3205202pgl.143.1665728170544; Thu, 13 Oct 2022 23:16:10 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:10 -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 Subject: [PATCH 11/19] perf stat: Allocate aggr counts for recorded data Date: Thu, 13 Oct 2022 23:15:42 -0700 Message-Id: <20221014061550.463644-12-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642698573057237?= X-GMAIL-MSGID: =?utf-8?q?1746642698573057237?= In the process_stat_config_event() it sets the aggr_mode that means the earlier evlist__alloc_stats() cannot allocate the aggr counts due to the missing aggr_mode. Do it after setting the aggr_map using evlist__alloc_aggr_stats(). Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 20 +++++++++++++++----- tools/perf/util/stat.c | 39 +++++++++++++++++++++++++++++++-------- tools/perf/util/stat.h | 2 ++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 6777fef0d56c..2a6a5d0c5563 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1342,7 +1342,11 @@ static struct aggr_cpu_id perf_stat__get_cpu(struct perf_stat_config *config __m static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { - struct aggr_cpu_id id = aggr_cpu_id__empty(); + struct aggr_cpu_id id; + + /* per-process mode - should use global aggr mode */ + if (cpu.cpu == -1) + return get_id(config, cpu); if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) config->cpus_aggr_map->map[cpu.cpu] = get_id(config, cpu); @@ -2125,17 +2129,23 @@ int process_stat_config_event(struct perf_session *session, if (perf_cpu_map__empty(st->cpus)) { if (st->aggr_mode != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); - return 0; - } - - if (st->aggr_mode != AGGR_UNSET) + } else if (st->aggr_mode != AGGR_UNSET) { stat_config.aggr_mode = st->aggr_mode; + } if (perf_stat.data.is_pipe) perf_stat_init_aggr_mode(); else perf_stat_init_aggr_mode_file(st); + if (stat_config.aggr_map) { + int nr_aggr = stat_config.aggr_map->nr; + + if (evlist__alloc_aggr_stats(session->evlist, nr_aggr) < 0) { + pr_err("cannot allocate aggr counts\n"); + return -1; + } + } return 0; } diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 3593af403188..d0e5c4c402aa 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -141,6 +141,31 @@ static void evsel__reset_stat_priv(struct evsel *evsel) memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } +static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr) +{ + struct perf_stat_evsel *ps = evsel->stats; + + if (ps == NULL) + return 0; + + ps->nr_aggr = nr_aggr; + ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); + if (ps->aggr == NULL) + return -ENOMEM; + + return 0; +} + +int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) { + if (evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) + return -1; + } + return 0; +} static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) { @@ -150,16 +175,14 @@ static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) if (ps == NULL) return -ENOMEM; - if (nr_aggr) { - ps->nr_aggr = nr_aggr; - ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); - if (ps->aggr == NULL) { - free(ps); - return -ENOMEM; - } + evsel->stats = ps; + + if (nr_aggr && evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) { + evsel->stats = NULL; + free(ps); + return -ENOMEM; } - evsel->stats = ps; perf_stat_evsel_id_init(evsel); evsel__reset_stat_priv(evsel); return 0; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 0980875b9be1..4c00f814bd79 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -275,6 +275,8 @@ void evlist__reset_prev_raw_counts(struct evlist *evlist); void evlist__copy_prev_raw_counts(struct evlist *evlist); void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); +int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); + int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); struct perf_tool; From patchwork Fri Oct 14 06:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp27452wrs; Thu, 13 Oct 2022 23:20:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CNU/OKyy6u+OA1j1T7D5uzykMAe3HOtIoiW5Dnj/abeKkcop021uWxtLTODpvPrlVVFMA X-Received: by 2002:a17:906:2a93:b0:78d:b87e:6aab with SMTP id l19-20020a1709062a9300b0078db87e6aabmr2354235eje.157.1665728422142; Thu, 13 Oct 2022 23:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728422; cv=none; d=google.com; s=arc-20160816; b=AJx/JhwIoWEQVfaf2P9cyXvULmOBi42vHhoTdvv0+/iaJiD8sFRoD2SWN5UWu07c4o dVVxaYzbDUrpux6yzuSBRMulV/TXmJ78T/35sFoOb3GOp8sNpX6r/XBfSgMDeg2Mh8Le jFxixGEzQjJ82017TuJP58Q3NbV7evBMmsKFVIpYVTLS5EnJ2ngcvnc2Szc3++/yYWHd B6L8jQnfoq96R5YR8C8V4ac5JU/5qGHKg5bpfrVX0h0pMp+nm/2dC32n9fH4Eplq0o+r TyHVzFaw0uQC1dgSUiMrSEkefWA83I5zVI7Yo/oSY4bUTK1EhRcdrj2a0CMC9isM4Jd2 fMZA== 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=lynXu2I6TliNPQCV9P5RsT9ATOJ+ZfidVJk5ANgD79M=; b=V4y0vY2hH6PhuQNrllzP3G7XJuFynFyIyw4UG2NSu2a8fZ7YRhL5LROdwuXTYQAstF RYvv8aUMndNpCZwCH0SnWg6DDy4XMQMuafj4yst5ZORpKKbOUwAQPYhUbzDaYTzwZKhi xkKCgBii/R4+EiQCYWKqZ84viwZH4ij9eV2LrKx+80UloQzO5zvE9zJVQzhH7+A1r105 mgYBEeIteIiErxpIfQdRUYclM+VLVB351MT1RHp3zRnRqoD2EMGhgS/lx32VERLUJAYc GnZZ8TPPKOdO/DjbnmTxx2bbcsV5AKBS+6LuXrZHdJI6S+bQGgPem4WGYQkLe5+JcL/3 gQKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OYcmKu3k; 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 12-20020a508e0c000000b0045d02c98c3bsi1380227edw.301.2022.10.13.23.19.55; Thu, 13 Oct 2022 23:20:22 -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=OYcmKu3k; 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 S229892AbiJNGRB (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiJNGQX (ORCPT ); Fri, 14 Oct 2022 02:16:23 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 955601743A; Thu, 13 Oct 2022 23:16:13 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id i3so3998961pfk.9; Thu, 13 Oct 2022 23:16:13 -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=lynXu2I6TliNPQCV9P5RsT9ATOJ+ZfidVJk5ANgD79M=; b=OYcmKu3kjB3HvGxuTTwLuam6FSSjVCZuSV6oKOoPqnGeJbykKHx5NC+IBUHAmHscaf dyrVG9ZkDvJZj0pPeh9n7UuFsY0ZXwZrvTU1dmbqOUEcR6XvmXIg7dZMiZLI1mDrDV6a ziASt0nvhqdbWBTkHkn+Krs5DDs/xRVbt8NUB8pKUgeNghMOtBnYWV45baqFXQutLZ98 m8DVfYo22kcKvfAF5Tb8zVbm4UHXsUhjW3aC+f+z4hi1v6CRJY9BcCa27nKiM/QxGXKd +1oUpmETzJvSBz5TErsy5/ASZo/+5oRa19A9Swx6dgR43/Y+Le3X2FMFtWahQgN1B2Uf g2JQ== 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=lynXu2I6TliNPQCV9P5RsT9ATOJ+ZfidVJk5ANgD79M=; b=FFYOFuTUJhc88GOvjHnLBzpRwcVAh3rLE6NMDO1mmlUUIbr2fkA6v9fzOQh+BkOQ2v 1ua1sxNMhCOPNIE8CHl4/JRMVN25/hF/hitxZa3/9W71uovkut+bgi9RQB/Bu7QD/Tya f1hSc8xFNfUNmPq7Fv7LqjPZchNRrOE+tUKmlFzMF8iJAMCRqGh0VgMkl8wMihwWgx2O jE2M0XzAfvcIQ/ie6wCQWDGi+piH+Z8RGdp+pE2yV/JzMntd2FACLO5ol5ZtqIVPzJJW Z6SieVCDAIrTRSteLbY7MPg3oQjo1bw2y7tI++09CMSEVw4rwBqqcJ5o/fCr3kZOm/DR xtmQ== X-Gm-Message-State: ACrzQf0idYlPKbvKowZqADAXf+2VVjZsQ6CTztgxDTXwfDMfbgYZIMqn YnvnQUNHDGFFOiAOgt4b9y0= X-Received: by 2002:a63:1750:0:b0:43a:9392:2676 with SMTP id 16-20020a631750000000b0043a93922676mr3221273pgx.463.1665728172135; Thu, 13 Oct 2022 23:16:12 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:11 -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 Subject: [PATCH 12/19] perf stat: Reset aggr counts for each interval Date: Thu, 13 Oct 2022 23:15:43 -0700 Message-Id: <20221014061550.463644-13-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642846121972504?= X-GMAIL-MSGID: =?utf-8?q?1746642846121972504?= The evsel->stats->aggr->count should be reset for interval processing since we want to use the values directly for display. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 3 +++ tools/perf/util/stat.c | 20 +++++++++++++++++--- tools/perf/util/stat.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2a6a5d0c5563..bff28a199dfd 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -492,6 +492,8 @@ static void process_interval(void) diff_timespec(&rs, &ts, &ref_time); perf_stat__reset_shadow_per_stat(&rt_stat); + evlist__reset_aggr_stats(evsel_list); + read_counters(&rs); if (STAT_RECORD) { @@ -965,6 +967,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) evlist__copy_prev_raw_counts(evsel_list); evlist__reset_prev_raw_counts(evsel_list); + evlist__reset_aggr_stats(evsel_list); perf_stat__reset_shadow_per_stat(&rt_stat); } else { update_stats(&walltime_nsecs_stats, t1 - t0); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index d0e5c4c402aa..847481cc3d5a 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -130,17 +130,23 @@ static void perf_stat_evsel_id_init(struct evsel *evsel) } } -static void evsel__reset_stat_priv(struct evsel *evsel) +static void evsel__reset_aggr_stats(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; struct perf_stat_aggr *aggr = ps->aggr; - init_stats(&ps->res_stats); - if (aggr) memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } +static void evsel__reset_stat_priv(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + + init_stats(&ps->res_stats); + evsel__reset_aggr_stats(evsel); +} + static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr) { struct perf_stat_evsel *ps = evsel->stats; @@ -276,6 +282,14 @@ void evlist__reset_stats(struct evlist *evlist) } } +void evlist__reset_aggr_stats(struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) + evsel__reset_aggr_stats(evsel); +} + void evlist__reset_prev_raw_counts(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 4c00f814bd79..809f9f0aff0c 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -276,6 +276,7 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist); void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); +void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); From patchwork Fri Oct 14 06:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp27471wrs; Thu, 13 Oct 2022 23:20:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5muikJLR1xuSPHelzvW5K30Y3hIsVEl8sr1nSOEhAQYpIq4vbBcnni/JbAtYsTW9uL8THn X-Received: by 2002:a17:907:3e14:b0:78d:b14b:6fa0 with SMTP id hp20-20020a1709073e1400b0078db14b6fa0mr2406906ejc.650.1665728426413; Thu, 13 Oct 2022 23:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728426; cv=none; d=google.com; s=arc-20160816; b=RMTY/Xtqp0602yvpyd44cv+ZMhtjjWDflEIpvOG0i4axu5xvJRWuKLk0LDFz4292+y PfEhT7mntYHWTzdf2qTkoZ94NDQGFc+nvVCmfLMygVaSeXPlZxbmlaPGajmi9RNPugyE n8Xl2eqyXgyRqWYIj2AqCzznX+FUJ2xwDgz99DQVzId0Vq5c7LuZcAiLswz3dUysPUvh ED8xrTbtRbyoiQQsqERgYt6p2OablkiakT4j56lq7OCMOcWZdctirzwAgjTlzo0bqOkm 4h9ThVBrQRaUBXAo2N710+E4e6H5/GPSepo5enn5/L8l+H0+07LqwUfE1AaAAQxIhWDl 00XA== 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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=NmKShe80vZaCjtXY2YffMRQuimAG3XXrA8C9ffVRfIgFbAfTfu1WPrKVFLk3sQ4rgp hhyRqBoYkKuSGo0mBF/otFM8LLwdT6mPsgTL3ZZBJZng4IrCuuT5+qzA69B75Y51He8Z n7kVj2tZQ2Edx0HIFOftt3tgQpFozPwomOhRiNxm2hS1fiu+cVdb7Nyq5m2CcbMOiSXY WdkqJxaju4DYbs2jjjvPc1cxRdE3ghbQMd8pjUaaWPuj7M+3cZPQ93l0zQdDheX6LlaU H7a5iJinWnw+sojPZpYIS2vMXepFyH6TIFUtzF0PCKgOltM/q+XtN1lQhZzMhU6HYYDf phaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=c3fIuwtm; 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 h7-20020aa7c947000000b00459400b7ae0si1376882edt.613.2022.10.13.23.20.01; Thu, 13 Oct 2022 23:20:26 -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=c3fIuwtm; 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 S229837AbiJNGRG (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiJNGQX (ORCPT ); Fri, 14 Oct 2022 02:16:23 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB77136403; Thu, 13 Oct 2022 23:16:14 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id o17-20020a17090aac1100b0020d98b0c0f4so5612453pjq.4; Thu, 13 Oct 2022 23:16:14 -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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=c3fIuwtmaBt9mfWZ4j5zR22hLm8LbjaLsAPWfJq4UrfiRVC3t7PgVzEwCrtyJanIlF /z7l+8220JoQ8hem3hUQVvRESKwaqi+G3cSvgnuYzshMj5gO73uD6Kk2035cA/ep61J4 IzoApHPcQGcUo801GKjkkLWPSw7npjAlyb2LNt1+gjcCuytoOcd0H0TYWDxlLQ+rK30/ 3V/oP8QAVfWXGXJBOd5nvWXf9DCp+CVCFTk0e2Q85lZSyauoVUVIVVr8gtgi2A6Bbm3e Fb7y2+UHbfWjGqlsHf+HNMLuqdqFwJWbeDVR9axTCik/I8/Od0OrJb6h9Rtq+7f7LBej n94Q== 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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=K/xskpqnx4xMcLBm76TrAW151l0Vx36VY9WQDjTs6Dc+WLMlEQN/ARCr0MaydraJTV BJJYbYbLSAj2VeuE1PdJRN8/me3a1CFa87R0H5Uao1/t6SmfGKc4dpRXMO7nicEwMvDI grKBdZvnlpeTsVy/84BY98iCinm4YS6sfYSp5FXX6EHE7B/AJXvMJJVQxywoAaQdC+Fz UEaAeuTgpAFTl9lkpUFXydR2980aVjvdwX3gjuKnJBdRDwPBiXgmzjeRAM91gq/c2fsk h3nlYnw/VUeQvprucr6/N/P6iBCIuCbEmuYFuRMZtvcvc+VEEFLN/XKsqsH1E2nZ9rSa LP9w== X-Gm-Message-State: ACrzQf1HMcfgd76qO5+aI+Ay3Q9giq6avqalAsC0OcNrnLh2TIUvPWAe lwCLqEFqXvPr5IwE3Clb/B0= X-Received: by 2002:a17:902:b944:b0:179:fdb0:1c39 with SMTP id h4-20020a170902b94400b00179fdb01c39mr3787948pls.98.1665728173755; Thu, 13 Oct 2022 23:16:13 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:13 -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 Subject: [PATCH 13/19] perf stat: Split process_counters() Date: Thu, 13 Oct 2022 23:15:44 -0700 Message-Id: <20221014061550.463644-14-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642850192286861?= X-GMAIL-MSGID: =?utf-8?q?1746642850192286861?= It'd do more processing with aggregation. Let's split the function so that it can be shared with by process_stat_round_event() too. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bff28a199dfd..838d29590bed 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -465,15 +465,19 @@ static int read_bpf_map_counters(void) return 0; } -static void read_counters(struct timespec *rs) +static int read_counters(struct timespec *rs) { - struct evsel *counter; - if (!stat_config.stop_read_counter) { if (read_bpf_map_counters() || read_affinity_counters(rs)) - return; + return -1; } + return 0; +} + +static void process_counters(void) +{ + struct evsel *counter; evlist__for_each_entry(evsel_list, counter) { if (counter->err) @@ -494,7 +498,8 @@ static void process_interval(void) perf_stat__reset_shadow_per_stat(&rt_stat); evlist__reset_aggr_stats(evsel_list); - read_counters(&rs); + if (read_counters(&rs) == 0) + process_counters(); if (STAT_RECORD) { if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL)) @@ -980,7 +985,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) * avoid arbitrary skew, we must read all counters before closing any * group leaders. */ - read_counters(&(struct timespec) { .tv_nsec = t1-t0 }); + if (read_counters(&(struct timespec) { .tv_nsec = t1-t0 }) == 0) + process_counters(); /* * We need to keep evsel_list alive, because it's processed @@ -2099,13 +2105,11 @@ static int process_stat_round_event(struct perf_session *session, union perf_event *event) { struct perf_record_stat_round *stat_round = &event->stat_round; - struct evsel *counter; struct timespec tsh, *ts = NULL; const char **argv = session->header.env.cmdline_argv; int argc = session->header.env.nr_cmdline; - evlist__for_each_entry(evsel_list, counter) - perf_stat_process_counter(&stat_config, counter); + process_counters(); if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL) update_stats(&walltime_nsecs_stats, stat_round->time); From patchwork Fri Oct 14 06:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp27451wrs; Thu, 13 Oct 2022 23:20:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xaKTQuJTtsPFosBNxyjPKmI9eE0lqKlURuCPR6AanjMDKuTE8SMnt2vM3EMpXckqhW36i X-Received: by 2002:a17:906:2681:b0:783:6a92:4c38 with SMTP id t1-20020a170906268100b007836a924c38mr2421505ejc.75.1665728421891; Thu, 13 Oct 2022 23:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728421; cv=none; d=google.com; s=arc-20160816; b=gEA2gL+BPifASkDIps2q995c9TvtByJLx80JDaCzwmsGfmLd6OFQJIuo2giZXf16av cLRWZA1x/L1xsHFm9ogJc7MDGKF0n7oXpCWXvAHGLDVj/NTFF3Aglp1XtBrhLj97ViVB CgQqFavpqfBNCKr5rLyAYUOaaJ9idCXz85wWqZWmxkSFsF3e6eUe0l3WqAAavzhrpZ5X yGzEw813rsaElrlt8671fjCMGiD+bU7NMuya4yzwfBFfbV2CrvQJyL6bNWdvRJ9IkQDv VaYJTBG6BDQy6uTUMER76xYXY7UfxyRV+o7x5adHlpQpP8rIgp1pQ+Y9dVJYsQFTdEne 5U2Q== 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=CinZ7zSYX9gn5zCAZvlRZM2c/7GGvF7Lz78MJtI/ScY=; b=wUprn6RK+qWp1t+rUpyNfKoaBr7NgDPI+6wn1BYrNoUlYXfLOO+C/RG8ICzKIXqBUQ Imn4rm1mV9ReOgHd+Nf8tXLoSm3cCVrbwbPbIARRTaa5VC1o8km6wvDBK3FzN/I4mu6P yiiqalrZMPQAU7+0kOgp1xKWtFl7+NRA4YOsu+edZBybrU5YCCL41RYs1HR7QDAjFwB3 n86lqXfIrdjg3G2Y6sKbVrLguJWFuCPevMPs+Nu631x0Dwol5YFBnfqSe99NdXq+fPlp NFRvYtmWGC8bP/204yeEl3SDSxDvOf9xvZPMxgU747UqbOr9G7rGy0rwSFxpd5rRVCv1 yC4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MZnIP39H; 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 go8-20020a1709070d8800b0078c4a968dedsi1937789ejc.739.2022.10.13.23.19.55; Thu, 13 Oct 2022 23:20:21 -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=MZnIP39H; 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 S229980AbiJNGRK (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiJNGQZ (ORCPT ); Fri, 14 Oct 2022 02:16:25 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACA3613640B; Thu, 13 Oct 2022 23:16:16 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id k9so3427730pll.11; Thu, 13 Oct 2022 23:16:16 -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=CinZ7zSYX9gn5zCAZvlRZM2c/7GGvF7Lz78MJtI/ScY=; b=MZnIP39HgO5U44cLy2QBsPw1/tXRBIdzuog0HVJ/taZsjhJSrPg0nsRmWYP3WCca3W HhE5xba6s0A3QBrQZeIdIC01qJCt+jDhOaAGv2fNJY76wYOBSHo7RGm3gNwlWhNVuKSg SQTxJlqpE+zKi2dS4onZq31YZhFWC8kDLkJvWzfzw+ed/nrRsVztjGNQQG5c+x7YX6tR 81L2oH9gB9iXIN/Cbj7fj1Kmel8WWiBcgM3g/SOsDLSPGcdiQVGNYjMFkrdgvSHWGBui 2zWbURDmxI401V+uqKh2MkknkLmeQUTqE13jeBDMNkh5VhCnWnVm34TGMPiLHKKcuM2f Y8kg== 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=CinZ7zSYX9gn5zCAZvlRZM2c/7GGvF7Lz78MJtI/ScY=; b=ru4UZAt5rw6+URaKS/WX8g+mzrrtHreRCZFbtVQQQhrNH8yT2ILwL76WVJ1TK0el5h adHGgT7hZaFb013Zcf20HBQTFM3ZneX/Wavn3ImFIXAWpMK9lbbIYxbav6mAH6zwODOg iYRhcfhddT43G9RHsMfNxO2rMPYIxGqoY5O+zO+/oYWcmlq7dL9m1ZvGqOdJ0qURuMtM tn4zxlR7UvDnlmD3f0uiHvCjD1PNdNLW5OzuzCQPhoVGDsQ7kdPwm0mWy17DSn5sxHv7 RsPgWobICwHb4G4SwNSNeUdAWogF16QtRTH33mMDRZRqu8CLAYVQB/uM/Y723aScpXlI T1Wg== X-Gm-Message-State: ACrzQf3cDkJBdW8w4MzHYZfpJNNJSEFETZarsTkOhsagmkFDKK0NhD6f wavzlZgXOVpCpp/bYMgaEEI= X-Received: by 2002:a17:90b:3901:b0:20b:210d:d5d9 with SMTP id ob1-20020a17090b390100b0020b210dd5d9mr3843661pjb.83.1665728175341; Thu, 13 Oct 2022 23:16:15 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:14 -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 Subject: [PATCH 14/19] perf stat: Add perf_stat_merge_counters() Date: Thu, 13 Oct 2022 23:15:45 -0700 Message-Id: <20221014061550.463644-15-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642845471125799?= X-GMAIL-MSGID: =?utf-8?q?1746642845471125799?= The perf_stat_merge_counters() is to aggregate the same events in different PMUs like in case of uncore or hybrid. The same logic is in the stat-display routines but I think it should be handled when it processes the event counters. As it works on the aggr_counters, it doesn't change the output yet. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 2 + tools/perf/util/stat.c | 96 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.h | 2 + 3 files changed, 100 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 838d29590bed..371d6e896942 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -486,6 +486,8 @@ static void process_counters(void) pr_warning("failed to process counter %s\n", counter->name); counter->err = 0; } + + perf_stat_merge_counters(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 847481cc3d5a..877107f5a820 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -577,6 +577,102 @@ int perf_stat_process_counter(struct perf_stat_config *config, return 0; } +static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias) +{ + struct perf_stat_evsel *ps_a = evsel->stats; + struct perf_stat_evsel *ps_b = alias->stats; + int i; + + if (ps_a->aggr == NULL && ps_b->aggr == NULL) + return 0; + + if (ps_a->nr_aggr != ps_b->nr_aggr) { + pr_err("Unmatched aggregation mode between aliases\n"); + return -1; + } + + for (i = 0; i < ps_a->nr_aggr; i++) { + struct perf_counts_values *aggr_counts_a = &ps_a->aggr[i].counts; + struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts; + + /* NB: don't increase aggr.nr for aliases */ + + aggr_counts_a->val += aggr_counts_b->val; + aggr_counts_a->ena += aggr_counts_b->ena; + aggr_counts_a->run += aggr_counts_b->run; + } + + return 0; +} +/* events should have the same name, scale, unit, cgroup but on different PMUs */ +static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b) +{ + if (strcmp(evsel__name(evsel_a), evsel__name(evsel_b))) + return false; + + if (evsel_a->scale != evsel_b->scale) + return false; + + if (evsel_a->cgrp != evsel_b->cgrp) + return false; + + if (strcmp(evsel_a->unit, evsel_b->unit)) + return false; + + if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b)) + return false; + + return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); +} + +static void evsel__merge_aliases(struct evsel *evsel) +{ + struct evlist *evlist = evsel->evlist; + struct evsel *alias; + + alias = list_prepare_entry(evsel, &(evlist->core.entries), core.node); + list_for_each_entry_continue(alias, &evlist->core.entries, core.node) { + /* Merge the same events on different PMUs. */ + if (evsel__is_alias(evsel, alias)) { + evsel__merge_aggr_counters(evsel, alias); + alias->merged_stat = true; + } + } +} + +static bool evsel__should_merge_hybrid(struct evsel *evsel, struct perf_stat_config *config) +{ + struct perf_pmu *pmu; + + if (!config->hybrid_merge) + return false; + + pmu = evsel__find_pmu(evsel); + return pmu && pmu->is_hybrid; +} + +static void evsel__merge_stats(struct evsel *evsel, struct perf_stat_config *config) +{ + /* this evsel is already merged */ + if (evsel->merged_stat) + return; + + if (evsel->auto_merge_stats || evsel__should_merge_hybrid(evsel, config)) + evsel__merge_aliases(evsel); +} + +/* merge the same uncore and hybrid events if requested */ +void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist) +{ + struct evsel *evsel; + + if (config->no_merge) + return; + + evlist__for_each_entry(evlist, evsel) + evsel__merge_stats(evsel, config); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 809f9f0aff0c..728bbc823b0d 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -280,6 +280,8 @@ void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); +void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); + struct perf_tool; union perf_event; struct perf_session; From patchwork Fri Oct 14 06:15:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp33144wrs; Thu, 13 Oct 2022 23:40:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kPX3P1Y9bIxRCJ599DTodyeYkQ4SHZmP7ggP258PSj2Xk5VUv3GdjZa6EFUfwrrHDOwtE X-Received: by 2002:a17:907:7e95:b0:78d:e9cf:82c7 with SMTP id qb21-20020a1709077e9500b0078de9cf82c7mr2537339ejc.724.1665729605163; Thu, 13 Oct 2022 23:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665729605; cv=none; d=google.com; s=arc-20160816; b=F0UlWTbdsfdthqw5rXEcUdajgVmeAViCJy6MuDsE5jiBPR44o+sfPT8AwcT2XuXXda UCTsMx1Y9xb9/H8uBu9peE0HcXgHHS1GOEHA3Svnna2wR13Gs86z9BIgjBQE6yKy24d4 jSRt7EQNcK8MJMDvP3kaXxJrHdel9N8QY8l7o2VAblg6JO3Gba3sJTlvHzwHLLl16RnJ BLbT/8mLSX9SM08Vl7BcgiqGANsUfdb34Kkk544cpY9kQtrV9OxTYPP7BYY4Mvp/BJXb z89mbr6v6RHHTyBwkx0q6trAifaUCjeL/AwKnnV11mtKBWtrtoZObWyD2rJzL9Jn6aIG G+KQ== 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=qUdiNdtmy8zezeJc09AIdo+G0m43f1JOi1LO86Cu4bw=; b=yQZk1i9a1VXYf3clTDiplpbDyD5lokHyPH/UCfn3KwRxpohWx0bEySPK9XfY1ElkrZ Q+EfX3S+y4VZPJGADyLUHROEWJMOFrfL+1QT+0RXQjQdX311LjzcL+PIQtSplj88k9KM 1CRTNe1yh3peWT9Q22/gsd2l63RQphpFQUxyhdTwh4/Ur9MN27RG2Wq2V1G5iWVNrMho rZVfz6+oCkbg+WaJ5SBV4sKBwV7pAIpP1MfRIucB/nlrvl65N2GHzLn5rd2bGOIaEnXJ h3ECca6y2yU51L+y70hDaLVqVF6O9XjusTmpz9qmQD+skehaXrn632I0m53BtLcaKl4i sLSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AWLUkGA9; 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 a1-20020a1709065f8100b0078d85777c4fsi1342816eju.700.2022.10.13.23.39.34; Thu, 13 Oct 2022 23:40:05 -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=AWLUkGA9; 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 S229941AbiJNGRb (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiJNGQn (ORCPT ); Fri, 14 Oct 2022 02:16:43 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93DED17415; Thu, 13 Oct 2022 23:16:18 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so3890440pjf.5; Thu, 13 Oct 2022 23:16:18 -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=qUdiNdtmy8zezeJc09AIdo+G0m43f1JOi1LO86Cu4bw=; b=AWLUkGA9ohhywgSiERCKEGD5fX0bBMA7Ie+PjnLZa6ISduMl4XH2odZ8/fu2letm3Q Z0fZbRfh94hey4ASPoZFXaY3kVQ2GOopBjGF/eDIlgkE46BTUVx7xZYuzbKxTMi0zecb 6pj7idlKrIRrg3TGf/fd2FiVikQ92Pu6gguCKAAo1lO3yJ9pw5xq+iJkuv/aeXiNubGH prYHwRbXzfflWapFPywjtVOmFHgZUugA7Z6DTemYOgHKuCqHEIeQ/mrLEcSp3fMSOGbR j0uoYtBvqjyEbv8hCRudwiHI+bQrFXygTLyG6SXQ0+ACP1cdH/V1qXtzQvG699scM49r sGgg== 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=qUdiNdtmy8zezeJc09AIdo+G0m43f1JOi1LO86Cu4bw=; b=XRgYiN7CJ+pgVWfDubT44pBK8rulQWAxjlTLD1pzDVbWemQf5LHIjHt9U2q75+t4oV t6Odaa0fos7bzgiJQII5onxiEaZdoonLFpyEa05XMquOUucKb2hdbq6MIr4jFCZLbtRf r576lax6rpERjhyITKxB24PN4yUPtNZOJ8QZk2RhDdZvGEWUXCu0Uho2GFIjQKGQuvkd P9HZlDjMAtsfRpkFlwmzvoHL6qKPnji2rgNV10oFr9XDrhlV49NR6knZVwA7wtroqu/D Y0F1QW9vBGiduWNkPDKkQBZolfmhr31rI3LZDBjnhl+Ck9fDt3xYmgZjEInDDOofnNZo NUVw== X-Gm-Message-State: ACrzQf14X8rTmMUkecMyqmCRvuh09jA1oMC+y1s8fkzBurK3bA5kk3HH SeG9uIuB+dv6QyQX8sfwvn96TF+8Ss8= X-Received: by 2002:a17:90b:4ac5:b0:20d:ae54:f08b with SMTP id mh5-20020a17090b4ac500b0020dae54f08bmr5709548pjb.174.1665728176900; Thu, 13 Oct 2022 23:16:16 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:16 -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 Subject: [PATCH 15/19] perf stat: Add perf_stat_process_percore() Date: Thu, 13 Oct 2022 23:15:46 -0700 Message-Id: <20221014061550.463644-16-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746644086787659013?= X-GMAIL-MSGID: =?utf-8?q?1746644086787659013?= The perf_stat_process_percore() is to aggregate counts for an event per-core even if the aggr_mode is AGGR_NONE. This is enabled when user requested it on the command line. To handle that, it keeps the per-cpu counts at first. And then it aggregates the counts that have the same core id in the aggr->counts and updates the values for each cpu back. Later, per-core events will skip one of the CPUs unless percore-show-thread option is given. In that case, it can simply print all cpu stats with the updated (per-core) values. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 1 + tools/perf/util/stat.c | 71 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.h | 3 ++ 3 files changed, 75 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 371d6e896942..d6a006e41da0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -488,6 +488,7 @@ static void process_counters(void) } perf_stat_merge_counters(&stat_config, evsel_list); + perf_stat_process_percore(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 877107f5a820..4ce457c94898 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -673,6 +673,77 @@ void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *ev evsel__merge_stats(evsel, config); } +static void evsel__update_percore_stats(struct evsel *evsel, struct aggr_cpu_id *core_id) +{ + struct perf_stat_evsel *ps = evsel->stats; + struct perf_counts_values counts = { 0, }; + struct aggr_cpu_id id; + struct perf_cpu cpu; + int idx; + + /* collect per-core counts */ + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + id = aggr_cpu_id__core(cpu, NULL); + if (!aggr_cpu_id__equal(core_id, &id)) + continue; + + counts.val += aggr->counts.val; + counts.ena += aggr->counts.ena; + counts.run += aggr->counts.run; + } + + /* update aggregated per-core counts for each CPU */ + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + id = aggr_cpu_id__core(cpu, NULL); + if (!aggr_cpu_id__equal(core_id, &id)) + continue; + + aggr->counts.val = counts.val; + aggr->counts.ena = counts.ena; + aggr->counts.run = counts.run; + + aggr->used = true; + } +} + +/* we have an aggr_map for cpu, but want to aggregate the counters per-core */ +static void evsel__process_percore(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + struct aggr_cpu_id core_id; + struct perf_cpu cpu; + int idx; + + if (!evsel->percore) + return; + + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + if (aggr->used) + continue; + + core_id = aggr_cpu_id__core(cpu, NULL); + evsel__update_percore_stats(evsel, &core_id); + } +} + +/* process cpu stats on per-core events */ +void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist) +{ + struct evsel *evsel; + + if (config->aggr_mode != AGGR_NONE) + return; + + evlist__for_each_entry(evlist, evsel) + evsel__process_percore(evsel); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 728bbc823b0d..d23f8743e442 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -51,6 +51,8 @@ struct perf_stat_aggr { int nr; /* whether any entry has failed to read/process event */ bool failed; + /* to mark this data is processed already */ + bool used; }; /* per-evsel event stats */ @@ -281,6 +283,7 @@ void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); +void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist); struct perf_tool; union perf_event; From patchwork Fri Oct 14 06:15:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp33954wrs; Thu, 13 Oct 2022 23:43:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7U5Y4RmKcBiqZaH7US9T/zGlAgltQl8AgBw4UJzSzjBqqbgkTzYtts70umnXCxk/rXLegU X-Received: by 2002:a17:907:d26:b0:78e:20c6:9f77 with SMTP id gn38-20020a1709070d2600b0078e20c69f77mr1818977ejc.243.1665729801352; Thu, 13 Oct 2022 23:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665729801; cv=none; d=google.com; s=arc-20160816; b=fg17n27CTlK2EPSs5g3PliHrX1iSypwdscgbyGpxHinA+mm+Lm7rckES2pLPmVDVHW o3KK1rqP+WNEzoxZmCmzNeBQ765NouY0VUL6P9cVmvPa8UxRxfZz4SliAWkQfJ3CjAdx hFYzkVjaoAneyK1Deg0LIFgymNinNc6rPlTqBK/YQK4wKVNP4NoaBrsspLG6oINwufjU AXNqU3TN4ZMwyF9kKZ8f3yXIkPsOc+9BYVUsf5cPcM/rhodSwJcqbHDDB7Dbo+iBsRww y5jJ/9pN6Khe3Cr2nvzxQ6emUZ1OoIk1Am2E4ooBw8QbO8dclkK7Z0FfoRBo0/JXw8WA Hg6A== 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=V7heBXOXJm9mLTCEwvj7mFFaDJuLKMS1VibwOeQN7Fg=; b=pGFzBYy9ST7VFHdDjN2TvZMRo5oYE+rVPThSE+mb8LTmttRc7KgZ1hzhDEDVFRL2/8 Emhv8vV9KBWAyqQaRUVgKsDxrdm2FDTALG0LfIghjKGNwugT3lw7ZfawO2g/N3EgpDOO zYdHjwjh86/a7WWwxYFxFxmM+rcspHZTSTCno4tz0t9tZxMnyjjL1DWL8uFey31RPao4 v4fVlA77cPupGCd6OgXuALLfxg1X6qYsY2ptT4tF6iXCNQ+xyXNmEVr1yNDATvZ/jBGT r6m3wqzm9I/USuKiHqcnK62EpNFxSyXuj3rE+gDf6ii9oJLyoZQRujAF7Sq3uMwgWmud cW0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Luvtdlbb; 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 hd44-20020a17090796ac00b0078cb8b09d34si1622957ejc.216.2022.10.13.23.42.55; Thu, 13 Oct 2022 23:43:21 -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=Luvtdlbb; 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 S229573AbiJNGRp (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbiJNGQz (ORCPT ); Fri, 14 Oct 2022 02:16:55 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A434136426; Thu, 13 Oct 2022 23:16:19 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d10so4021712pfh.6; Thu, 13 Oct 2022 23:16:19 -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=V7heBXOXJm9mLTCEwvj7mFFaDJuLKMS1VibwOeQN7Fg=; b=Luvtdlbbg1izMM3Eh/t7Tm1Apo74EXjzMCTiAifcFcl/9nCM8R13VFTxWIDeBv0Hic mT8Qd7zcK/k21PPf4eOvckoBxtn/8h2BW4hdajlyXxOXK5qKRedTdafQeZ715Oul2NCG UdGkW2avX6O2rdT7e9NW4jjdIqUNErxPfBpDL9cUf8dn4nTw0AG433IZ4cAcdUlGjbH2 RgeqDKCDhZnUz47RJO+JPaeaKaCuuweasZDT6mtUEKRYZPhnNhbyZEXehM+35a2cyHb3 FeJf6il3j0/Mi1yQPVB6s2lFTLUxqIyaChcAHt1jZeWkKKQQvZy3uetsxwuDvSmvxAvW Z4vA== 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=V7heBXOXJm9mLTCEwvj7mFFaDJuLKMS1VibwOeQN7Fg=; b=CTKDj+v9Vnouhkk1eMnh9o74tEfxWyQQ5dUFrsopFbwPxEBgc/wopDj4Q9yPGG2Bn6 xxGctXIj26AK6Xch3A8uLX6zXqCd85RJRBwp35bR7BKrSCJWCY9K0MLAOgfs7M160uST gH0/YoWGULrQ3fp6uWlZCLhMGaZ/pi8ojBGMR8gTJux+9SruAnEMzP62Sqhfbsk+0iYs 66cINlSyy2MbMbNZ9NqdoLjPCqFy9Db9Mb/Q43Gj2Sq53zLfOCwr/CwRkUVvt4HSj9Sk eDCBPczOf63auclh5LqwnEOBvGeMaSWV36opmq3CNd2aLNkTjK1srr2AST3ZW5K7NQa+ KKow== X-Gm-Message-State: ACrzQf32Fvm3BsMpNUONf7aVxdAXSx0QzwlY/5ynCEyoutaFvPasyQuC v3ObiaU19dt/NGf0YMAl+EM= X-Received: by 2002:a63:e74d:0:b0:440:6c50:eab7 with SMTP id j13-20020a63e74d000000b004406c50eab7mr3214767pgk.308.1665728178347; Thu, 13 Oct 2022 23:16:18 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:18 -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 Subject: [PATCH 16/19] perf stat: Add perf_stat_process_shadow_stats() Date: Thu, 13 Oct 2022 23:15:47 -0700 Message-Id: <20221014061550.463644-17-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746644292179983269?= X-GMAIL-MSGID: =?utf-8?q?1746644292179983269?= This function updates the shadow stats using the aggregated counts uniformly since it uses the aggr_counts for the every aggr mode. It'd have duplicate shadow stats for each items for now since the display routines will update them once again. But that'd be fine as it shows the average values and it'd be gone eventually. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 1 + tools/perf/util/stat.c | 50 ++++++++++++++++++++------------------- tools/perf/util/stat.h | 1 + 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d6a006e41da0..d7c52cef70a3 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -489,6 +489,7 @@ static void process_counters(void) perf_stat_merge_counters(&stat_config, evsel_list); perf_stat_process_percore(&stat_config, evsel_list); + perf_stat_process_shadow_stats(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 4ce457c94898..d51ba63b9ab2 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -455,7 +455,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, aggr_counts->val += count->val; aggr_counts->ena += count->ena; aggr_counts->run += count->run; - goto update; + return 0; } if (ps->aggr) { @@ -493,32 +493,10 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } -update: - switch (config->aggr_mode) { - case AGGR_THREAD: - case AGGR_CORE: - case AGGR_DIE: - case AGGR_SOCKET: - case AGGR_NODE: - case AGGR_NONE: - if ((config->aggr_mode == AGGR_NONE) && (!evsel->percore)) { - perf_stat__update_shadow_stats(evsel, count->val, - cpu_map_idx, &rt_stat); - } - - if (config->aggr_mode == AGGR_THREAD) { - perf_stat__update_shadow_stats(evsel, count->val, - thread, &rt_stat); - } - break; - case AGGR_GLOBAL: + if (config->aggr_mode == AGGR_GLOBAL) { aggr->val += count->val; aggr->ena += count->ena; aggr->run += count->run; - case AGGR_UNSET: - case AGGR_MAX: - default: - break; } return 0; @@ -744,6 +722,30 @@ void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *e evsel__process_percore(evsel); } +static void evsel__update_shadow_stats(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + int i; + + if (ps->aggr == NULL) + return; + + for (i = 0; i < ps->nr_aggr; i++) { + struct perf_counts_values *aggr_counts = &ps->aggr[i].counts; + + perf_stat__update_shadow_stats(evsel, aggr_counts->val, i, &rt_stat); + } +} + +void perf_stat_process_shadow_stats(struct perf_stat_config *config __maybe_unused, + struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) + evsel__update_shadow_stats(evsel); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index d23f8743e442..3d413ba8c68a 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -284,6 +284,7 @@ int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist); +void perf_stat_process_shadow_stats(struct perf_stat_config *config, struct evlist *evlist); struct perf_tool; union perf_event; From patchwork Fri Oct 14 06:15:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp28009wrs; Thu, 13 Oct 2022 23:22:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5RxSg7Gt61FT0INbmrJQAmGTcG3RwcLvxKgDjesgJCkq0Pfn8mqZqPQWdYDwv/asH6mIaJ X-Received: by 2002:a05:6402:540d:b0:450:bda7:f76e with SMTP id ev13-20020a056402540d00b00450bda7f76emr2952776edb.249.1665728522100; Thu, 13 Oct 2022 23:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665728522; cv=none; d=google.com; s=arc-20160816; b=lk088yKHfF88Cm0n3I9tk/ohD9wOkdvALSpEs5H5vxy+FURTVu/3cyqThYVadxiLL8 sABzeEh2Me7b3tTfpS+ltn86GPRTxw8dniuGfA95kUs73UQxpZcVvxUWxEX/gNGyM51r +Kvm4elpcwhI92juckTpQAZZgcXwKJoWu6Z3qupRKjyPggBm+3/Ilh9RAaf45Q0C3PXV wWky/Qpo2gRMrDu0hzATbiRM/Eifp6EzICG4PwuKjmvUPWMg2H8WYNK8b0nLqHxfzcpl rptNYaasR/piPVTcV2Tc0XQCG4Zuh8MA1sH8gNuIuUvGMYqnR8M8Jgoxkcy6uN473omi BD/Q== 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=0TpYGmLjxsoDh71AysgWMehQSciwSLZiLMMGzRGki0c=; b=JxhErPsnqSBUJInytxG09RJM2OY8FflTgaDOuQCDgmH4+CYqkWYeFSNbEqqD8h9Gmt /IPVkOSqeiH8Kyb+lTC1K7TKaybtqCejywWJid63vk18CqKwtAeVPQx7yYWk1WWk6Szn 64wNyRfbV5zRrG+E8N9jFpnrL46qulVczGgMrpRAPnwAdy32OvGPpKGC5gky6OJjlrcm tZ3t06Vu/8mKDFZ7JU8UmtDE1D3lPWYYoS2UG5loy7zJzOD9Fcxg4+f6afmQ8DoBr36K nS7RfTQThS/MGVsmDDavmBw6MvwUzm0cueoC/P1hunUmVrRAeO6kxGjI/OrT3LM1jmQE wtYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CrmmEIvb; 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 b12-20020a056402278c00b0045b68639617si1760392ede.608.2022.10.13.23.21.36; Thu, 13 Oct 2022 23:22:02 -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=CrmmEIvb; 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 S229992AbiJNGRV (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbiJNGQd (ORCPT ); Fri, 14 Oct 2022 02:16:33 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7555D1740E; Thu, 13 Oct 2022 23:16:21 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so7034097pjs.0; Thu, 13 Oct 2022 23:16:21 -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=0TpYGmLjxsoDh71AysgWMehQSciwSLZiLMMGzRGki0c=; b=CrmmEIvb9J1RibS5N4QEGMIgjYQgp+0QH59nuiepx7vpzAJyt907ojP5AsHPYVsGPm 1SiArCisL33YkwcYBAJqEVja9pgqts7dWxz2RHE/JDOs3cNAdYOKDTPRJBGN+WAcPWy0 jCLMTaJVASNNFq4jOsmsQ9kuysg2VbLTXtYVzpS9A4+0MHV1q01dUMbrxjQugoQginE1 Y6q267REA7/UvcHZFg046isN3I/azV+CO6NdBJYqBGLJJY/D49HDaFEf+XV5e4VClRS3 +3vjwV6Oaj3la2lGigtkdaMLuTRCeZo6Ta1iv6QMSbSDIyg17dOi6fMWC3QztXmCL1q2 FodA== 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=0TpYGmLjxsoDh71AysgWMehQSciwSLZiLMMGzRGki0c=; b=RVkjCg4qP+xoJxTSq5xTXEV70s3m8AcxP+BGsBxBdcwhP9lmxANztKrCPuxLDNTHHg vtZDXrY+FlVxxDDO7J77qutJaDHpBpAeyxW3EWoI2o5pbTg7AtprfEaTVeY1T772qy4V uPaa1p4A9jNzCF9yTE72ShNPt33cgSKTAdGJJRXD3JU+ZX1GTEkTXvw7F8Js9Xd1Pp30 /1mml3vJWt8sQLv01Trcd2Vq00M9wgC5I/CeGUMlHyHXAi34oGdQHczXbVcIMCuHaPyv fIEGGsPMqnltwJXl0es9UXfZisXZdLN64gqmFk4Op93afY2tq8Sx14X3yZveCFQCTjTs XAAg== X-Gm-Message-State: ACrzQf3Osv563gIgaZo4fEQIJQuzGirW8Jm5cdxRPKEWYr0epZgjGaiW dh7eEIBDqB0KoAgkZa5GI+A= X-Received: by 2002:a17:902:d58c:b0:17f:998a:76cd with SMTP id k12-20020a170902d58c00b0017f998a76cdmr3765902plh.155.1665728180342; Thu, 13 Oct 2022 23:16:20 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:19 -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 Subject: [PATCH 17/19] perf stat: Display event stats using aggr counts Date: Thu, 13 Oct 2022 23:15:48 -0700 Message-Id: <20221014061550.463644-18-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746642950533455452?= X-GMAIL-MSGID: =?utf-8?q?1746642950533455452?= Now aggr counts are ready for use. Convert the display routines to use the aggr counts and update the shadow stat with them. It doesn't need to aggregate counts or collect aliases anymore during the display. Get rid of now unused struct perf_aggr_thread_value. Note that there's a difference in the display order among the aggr mode. For per-core/die/socket/node aggregation, it shows relevant events in the same unit together, whereas global/thread/no aggregation it shows the same events for different units together. So it still uses separate codes to display them due to the ordering. One more thing to note is that it breaks per-core event display for now. The next patch will fix it to have identical output as of now. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 421 ++++----------------------------- tools/perf/util/stat.c | 5 - tools/perf/util/stat.h | 9 - 3 files changed, 49 insertions(+), 386 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 4113aa86772f..d9cd2db1398b 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -442,31 +442,6 @@ static void print_metric_header(struct perf_stat_config *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } -static int first_shadow_map_idx(struct perf_stat_config *config, - struct evsel *evsel, const struct aggr_cpu_id *id) -{ - struct perf_cpu_map *cpus = evsel__cpus(evsel); - struct perf_cpu cpu; - int idx; - - if (config->aggr_mode == AGGR_NONE) - return perf_cpu_map__idx(cpus, id->cpu); - - if (config->aggr_mode == AGGR_THREAD) - return id->thread_idx; - - if (!config->aggr_get_id) - return 0; - - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - struct aggr_cpu_id cpu_id = config->aggr_get_id(config, cpu); - - if (aggr_cpu_id__equal(&cpu_id, id)) - return idx; - } - return 0; -} - static void abs_printout(struct perf_stat_config *config, struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg) { @@ -537,7 +512,7 @@ static bool is_mixed_hw_group(struct evsel *counter) static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int nr, struct evsel *counter, double uval, char *prefix, u64 run, u64 ena, double noise, - struct runtime_stat *st) + struct runtime_stat *st, int map_idx) { struct perf_stat_output_ctx out; struct outstate os = { @@ -648,8 +623,7 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int print_running(config, run, ena); } - perf_stat__print_shadow_stats(config, counter, uval, - first_shadow_map_idx(config, counter, &id), + perf_stat__print_shadow_stats(config, counter, uval, map_idx, &out, &config->metric_events, st); if (!config->csv_output && !config->metric_only && !config->json_output) { print_noise(config, counter, noise); @@ -657,34 +631,6 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int } } -static void aggr_update_shadow(struct perf_stat_config *config, - struct evlist *evlist) -{ - int idx, s; - struct perf_cpu cpu; - struct aggr_cpu_id s2, id; - u64 val; - struct evsel *counter; - struct perf_cpu_map *cpus; - - for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; - evlist__for_each_entry(evlist, counter) { - cpus = evsel__cpus(counter); - val = 0; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpu); - if (!aggr_cpu_id__equal(&s2, &id)) - continue; - val += perf_counts(counter->counts, idx, 0)->val; - } - perf_stat__update_shadow_stats(counter, val, - first_shadow_map_idx(config, counter, &id), - &rt_stat); - } - } -} - static void uniquify_event_name(struct evsel *counter) { char *new_name; @@ -721,137 +667,51 @@ static void uniquify_event_name(struct evsel *counter) counter->uniquified_name = true; } -static void collect_all_aliases(struct perf_stat_config *config, struct evsel *counter, - void (*cb)(struct perf_stat_config *config, struct evsel *counter, void *data, - bool first), - void *data) +static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) { - struct evlist *evlist = counter->evlist; - struct evsel *alias; - - alias = list_prepare_entry(counter, &(evlist->core.entries), core.node); - list_for_each_entry_continue (alias, &evlist->core.entries, core.node) { - /* Merge events with the same name, etc. but on different PMUs. */ - if (!strcmp(evsel__name(alias), evsel__name(counter)) && - alias->scale == counter->scale && - alias->cgrp == counter->cgrp && - !strcmp(alias->unit, counter->unit) && - evsel__is_clock(alias) == evsel__is_clock(counter) && - strcmp(alias->pmu_name, counter->pmu_name)) { - alias->merged_stat = true; - cb(config, alias, data, false); - } - } + return evsel__is_hybrid(evsel) && !config->hybrid_merge; } -static bool hybrid_merge(struct evsel *counter, struct perf_stat_config *config, - bool check) +static void uniquify_counter(struct perf_stat_config *config, struct evsel *counter) { - if (evsel__is_hybrid(counter)) { - if (check) - return config->hybrid_merge; - else - return !config->hybrid_merge; - } - - return false; -} - -static bool collect_data(struct perf_stat_config *config, struct evsel *counter, - void (*cb)(struct perf_stat_config *config, struct evsel *counter, void *data, - bool first), - void *data) -{ - if (counter->merged_stat) - return false; - cb(config, counter, data, true); - if (config->no_merge || hybrid_merge(counter, config, false)) + if (config->no_merge || hybrid_uniquify(counter, config)) uniquify_event_name(counter); - else if (counter->auto_merge_stats || hybrid_merge(counter, config, true)) - collect_all_aliases(config, counter, cb, data); - return true; -} - -struct aggr_data { - u64 ena, run, val; - struct aggr_cpu_id id; - int nr; - int cpu_map_idx; -}; - -static void aggr_cb(struct perf_stat_config *config, - struct evsel *counter, void *data, bool first) -{ - struct aggr_data *ad = data; - int idx; - struct perf_cpu cpu; - struct perf_cpu_map *cpus; - struct aggr_cpu_id s2; - - cpus = evsel__cpus(counter); - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - struct perf_counts_values *counts; - - s2 = config->aggr_get_id(config, cpu); - if (!aggr_cpu_id__equal(&s2, &ad->id)) - continue; - if (first) - ad->nr++; - counts = perf_counts(counter->counts, idx, 0); - /* - * When any result is bad, make them all to give - * consistent output in interval mode. - */ - if (counts->ena == 0 || counts->run == 0 || - counter->counts->scaled == -1) { - ad->ena = 0; - ad->run = 0; - break; - } - ad->val += counts->val; - ad->ena += counts->ena; - ad->run += counts->run; - } } static void print_counter_aggrdata(struct perf_stat_config *config, struct evsel *counter, int s, char *prefix, bool metric_only, - bool *first, struct perf_cpu cpu) + bool *first) { - struct aggr_data ad; FILE *output = config->output; u64 ena, run, val; - int nr; - struct aggr_cpu_id id; double uval; + struct perf_stat_evsel *ps = counter->stats; + struct perf_stat_aggr *aggr = &ps->aggr[s]; + struct aggr_cpu_id id = config->aggr_map->map[s]; + double avg = aggr->counts.val; - ad.id = id = config->aggr_map->map[s]; - ad.val = ad.ena = ad.run = 0; - ad.nr = 0; - if (!collect_data(config, counter, aggr_cb, &ad)) + if (aggr->nr == 0) return; - if (perf_pmu__has_hybrid() && ad.ena == 0) - return; + uniquify_counter(config, counter); + + val = aggr->counts.val; + ena = aggr->counts.ena; + run = aggr->counts.run; - nr = ad.nr; - ena = ad.ena; - run = ad.run; - val = ad.val; if (*first && metric_only) { *first = false; - aggr_printout(config, counter, id, nr); + aggr_printout(config, counter, id, aggr->nr); } if (prefix && !metric_only) fprintf(output, "%s", prefix); uval = val * counter->scale; - if (cpu.cpu != -1) - id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); - printout(config, id, nr, counter, uval, - prefix, run, ena, 1.0, &rt_stat); + printout(config, id, aggr->nr, counter, uval, + prefix, run, ena, avg, &rt_stat, s); + if (!metric_only) fputc('\n', output); } @@ -869,8 +729,6 @@ static void print_aggr(struct perf_stat_config *config, if (!config->aggr_map || !config->aggr_get_id) return; - aggr_update_shadow(config, evlist); - /* * With metric_only everything is on a single line. * Without each counter has its own line. @@ -881,188 +739,36 @@ static void print_aggr(struct perf_stat_config *config, first = true; evlist__for_each_entry(evlist, counter) { + if (counter->merged_stat) + continue; + print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, (struct perf_cpu){ .cpu = -1 }); + prefix, metric_only, + &first); } if (metric_only) fputc('\n', output); } } -static int cmp_val(const void *a, const void *b) -{ - return ((struct perf_aggr_thread_value *)b)->val - - ((struct perf_aggr_thread_value *)a)->val; -} - -static struct perf_aggr_thread_value *sort_aggr_thread( - struct evsel *counter, - int *ret, - struct target *_target) -{ - int nthreads = perf_thread_map__nr(counter->core.threads); - int i = 0; - double uval; - struct perf_aggr_thread_value *buf; - - buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value)); - if (!buf) - return NULL; - - for (int thread = 0; thread < nthreads; thread++) { - int idx; - u64 ena = 0, run = 0, val = 0; - - perf_cpu_map__for_each_idx(idx, evsel__cpus(counter)) { - struct perf_counts_values *counts = - perf_counts(counter->counts, idx, thread); - - val += counts->val; - ena += counts->ena; - run += counts->run; - } - - uval = val * counter->scale; - - /* - * Skip value 0 when enabling --per-thread globally, - * otherwise too many 0 output. - */ - if (uval == 0.0 && target__has_per_thread(_target)) - continue; - - buf[i].counter = counter; - buf[i].id = aggr_cpu_id__empty(); - buf[i].id.thread_idx = thread; - buf[i].uval = uval; - buf[i].val = val; - buf[i].run = run; - buf[i].ena = ena; - i++; - } - - qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val); - - if (ret) - *ret = i; - - return buf; -} - -static void print_aggr_thread(struct perf_stat_config *config, - struct target *_target, - struct evsel *counter, char *prefix) -{ - FILE *output = config->output; - int thread, sorted_threads; - struct aggr_cpu_id id; - struct perf_aggr_thread_value *buf; - - buf = sort_aggr_thread(counter, &sorted_threads, _target); - if (!buf) { - perror("cannot sort aggr thread"); - return; - } - - for (thread = 0; thread < sorted_threads; thread++) { - if (prefix) - fprintf(output, "%s", prefix); - - id = buf[thread].id; - printout(config, id, 0, buf[thread].counter, buf[thread].uval, - prefix, buf[thread].run, buf[thread].ena, 1.0, - &rt_stat); - fputc('\n', output); - } - - free(buf); -} - -struct caggr_data { - double avg, avg_enabled, avg_running; -}; - -static void counter_aggr_cb(struct perf_stat_config *config __maybe_unused, - struct evsel *counter, void *data, - bool first __maybe_unused) -{ - struct caggr_data *cd = data; - struct perf_counts_values *aggr = &counter->counts->aggr; - - cd->avg += aggr->val; - cd->avg_enabled += aggr->ena; - cd->avg_running += aggr->run; -} - -/* - * Print out the results of a single counter: - * aggregated counts in system-wide mode - */ -static void print_counter_aggr(struct perf_stat_config *config, - struct evsel *counter, char *prefix) -{ - bool metric_only = config->metric_only; - FILE *output = config->output; - double uval; - struct caggr_data cd = { .avg = 0.0 }; - - if (!collect_data(config, counter, counter_aggr_cb, &cd)) - return; - - if (prefix && !metric_only) - fprintf(output, "%s", prefix); - - uval = cd.avg * counter->scale; - printout(config, aggr_cpu_id__empty(), 0, counter, uval, prefix, cd.avg_running, - cd.avg_enabled, cd.avg, &rt_stat); - if (!metric_only) - fprintf(output, "\n"); -} - -static void counter_cb(struct perf_stat_config *config __maybe_unused, - struct evsel *counter, void *data, - bool first __maybe_unused) -{ - struct aggr_data *ad = data; - - ad->val += perf_counts(counter->counts, ad->cpu_map_idx, 0)->val; - ad->ena += perf_counts(counter->counts, ad->cpu_map_idx, 0)->ena; - ad->run += perf_counts(counter->counts, ad->cpu_map_idx, 0)->run; -} - -/* - * Print out the results of a single counter: - * does not use aggregated count in system-wide - */ static void print_counter(struct perf_stat_config *config, struct evsel *counter, char *prefix) { - FILE *output = config->output; - u64 ena, run, val; - double uval; - int idx; - struct perf_cpu cpu; - struct aggr_cpu_id id; - - perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { - struct aggr_data ad = { .cpu_map_idx = idx }; - - if (!collect_data(config, counter, counter_cb, &ad)) - return; - val = ad.val; - ena = ad.ena; - run = ad.run; + bool metric_only = config->metric_only; + bool first = false; + int s; - if (prefix) - fprintf(output, "%s", prefix); + /* AGGR_THREAD doesn't have config->aggr_get_id */ + if (!config->aggr_map) + return; - uval = val * counter->scale; - id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); - printout(config, id, 0, counter, uval, prefix, - run, ena, 1.0, &rt_stat); + if (counter->merged_stat) + return; - fputc('\n', output); + for (s = 0; s < config->aggr_map->nr; s++) { + print_counter_aggrdata(config, counter, s, + prefix, metric_only, + &first); } } @@ -1081,6 +787,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config, u64 ena, run, val; double uval; struct aggr_cpu_id id; + struct perf_stat_evsel *ps = counter->stats; int counter_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); if (counter_idx < 0) @@ -1093,13 +800,13 @@ static void print_no_aggr_metric(struct perf_stat_config *config, aggr_printout(config, counter, id, 0); first = false; } - val = perf_counts(counter->counts, counter_idx, 0)->val; - ena = perf_counts(counter->counts, counter_idx, 0)->ena; - run = perf_counts(counter->counts, counter_idx, 0)->run; + val = ps->aggr[counter_idx].counts.val; + ena = ps->aggr[counter_idx].counts.ena; + run = ps->aggr[counter_idx].counts.run; uval = val * counter->scale; printout(config, id, 0, counter, uval, prefix, - run, ena, 1.0, &rt_stat); + run, ena, 1.0, &rt_stat, counter_idx); } if (!first) fputc('\n', config->output); @@ -1135,8 +842,8 @@ static void print_metric_headers(struct perf_stat_config *config, }; bool first = true; - if (config->json_output && !config->interval) - fprintf(config->output, "{"); + if (config->json_output && !config->interval) + fprintf(config->output, "{"); if (prefix && !config->json_output) fprintf(config->output, "%s", prefix); @@ -1379,31 +1086,6 @@ static void print_footer(struct perf_stat_config *config) "the same PMU. Try reorganizing the group.\n"); } -static void print_percore_thread(struct perf_stat_config *config, - struct evsel *counter, char *prefix) -{ - int s; - struct aggr_cpu_id s2, id; - struct perf_cpu_map *cpus; - bool first = true; - int idx; - struct perf_cpu cpu; - - cpus = evsel__cpus(counter); - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpu); - for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; - if (aggr_cpu_id__equal(&s2, &id)) - break; - } - - print_counter_aggrdata(config, counter, s, - prefix, false, - &first, cpu); - } -} - static void print_percore(struct perf_stat_config *config, struct evsel *counter, char *prefix) { @@ -1416,15 +1098,14 @@ static void print_percore(struct perf_stat_config *config, return; if (config->percore_show_thread) - return print_percore_thread(config, counter, prefix); + return print_counter(config, counter, prefix); for (s = 0; s < config->aggr_map->nr; s++) { if (prefix && metric_only) fprintf(output, "%s", prefix); print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, (struct perf_cpu){ .cpu = -1 }); + prefix, metric_only, &first); } if (metric_only) @@ -1469,17 +1150,13 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf print_aggr(config, evlist, prefix); break; case AGGR_THREAD: - evlist__for_each_entry(evlist, counter) { - print_aggr_thread(config, _target, counter, prefix); - } - break; case AGGR_GLOBAL: if (config->iostat_run) iostat_print_counters(evlist, config, ts, prefix = buf, - print_counter_aggr); + print_counter); else { evlist__for_each_entry(evlist, counter) { - print_counter_aggr(config, counter, prefix); + print_counter(config, counter, prefix); } if (metric_only) fputc('\n', config->output); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index d51ba63b9ab2..14c45f4cfdd3 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -547,11 +547,6 @@ int perf_stat_process_counter(struct perf_stat_config *config, evsel__name(counter), count[0], count[1], count[2]); } - /* - * Save the full runtime - to allow normalization during printout: - */ - perf_stat__update_shadow_stats(counter, *count, 0, &rt_stat); - return 0; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 3d413ba8c68a..382a1ab92ce1 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -224,15 +224,6 @@ static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rus struct evsel; struct evlist; -struct perf_aggr_thread_value { - struct evsel *counter; - struct aggr_cpu_id id; - double uval; - u64 val; - u64 run; - u64 ena; -}; - bool __perf_stat_evsel__is(struct evsel *evsel, enum perf_stat_evsel_id id); #define perf_stat_evsel__is(evsel, id) \ From patchwork Fri Oct 14 06:15:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp33361wrs; Thu, 13 Oct 2022 23:40:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pAIikgGfYrnVfkRovP+TDhF9Zrg3UIEfAKv+TdC04jUEePiaVpole0HpFZEWeYyyIiOkE X-Received: by 2002:a17:907:72d3:b0:78d:2153:648a with SMTP id du19-20020a17090772d300b0078d2153648amr2505081ejc.513.1665729655212; Thu, 13 Oct 2022 23:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665729655; cv=none; d=google.com; s=arc-20160816; b=pOiM9qkO1TIG7WxT78+wvc5BUMbaj9/R8zJLpG0K+H6+ocUuHgyCv2wPXnFM29mR+K u3DnW88TOuga9soD1TKkEA62louSvkSFocue10euFDpDk4fttj45hJbTB9LrWtfS8fZy Cr3ca44fHcQltish+WIOJt0uqwKVCnKPVHjxmUdLWg/G6tyt6sBiciRy7siy8Q7qtVSk t18lIuwyxXjjhwTlzwEFF0E+Ye0qk6ytrK2SHWycPTnjzaSEu16M6mYAajDwGr5Z3I8M n62QyT7jYVEDeg2Di4ZqYg0dsck06/lfyIaiekVv+qdDTuuHZx6iult1F76p8xFcYuA7 apLQ== 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=yu3prLTu/0wI4ZAj0BQDozCdKSFjzz2EwrQUPjw2yl8=; b=eNGX2TbqGwI/sZTwkLyatA8sNo/yMmhPsTs8L7NE3ck2mKLmULwSI10Q3U9/2bFE0f uChkEryeJK5ON+fF/cKA4w/E0TADu0kBRGeufd6/+ld7obXyAu7jK5+hvQp3t4HL969v wN9Gc4fh2rclJD1oEPv48LDv+d+4l3cedw5gwh7rG2pSK9/SZKPjYkQV3ELiA4OUwh9O eP2f38j5nA8mtsB50+nmZG5dZBvUpPphHlfOMf1D5AwZhzDiz6dyKB+UksGMCtffKXRq inuLoJRwh82xXLUZmleZxUhmyIe3yFLLFqKDEhWIuvfJyeEsZjKpIZaigFG/C5Z+mLbi hkxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p0wbLICe; 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 l15-20020a170906794f00b007882926848bsi1765466ejo.818.2022.10.13.23.40.29; Thu, 13 Oct 2022 23:40:55 -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=p0wbLICe; 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 S229934AbiJNGRZ (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbiJNGQm (ORCPT ); Fri, 14 Oct 2022 02:16:42 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C1DD17404; Thu, 13 Oct 2022 23:16:24 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id 129so3494496pgc.5; Thu, 13 Oct 2022 23:16:24 -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=yu3prLTu/0wI4ZAj0BQDozCdKSFjzz2EwrQUPjw2yl8=; b=p0wbLICet0xmjRTI26DrsdMAyYXjDIpbrzhLgPVgYyOq1HJB7ARzIjSXPU/njCdeQU K/G1HsDb3gu6aWFc0yL7SUSWM8aTjy4Rrjx3E8OpZBSLxcbrIOhly1H6sFxIfotNhLwD aHJKeOqH1dEMPQEikmSICxqaTGOvuL9206L7AvgAXPMd9ehkj63Bwb/5aDBgtlt6znaR imN37iU680rjvHxp9fMuXmjxaJjF7rcII+K5rvridUjzmXbwJps9Hc5YL2Ui1gdeJrJi lRc85aQmF+SDXevgNk3oo61n5gsY63Sv6DXWMmWB0bYpCPMgBATabqrlSySu0Z4O7TOk 0uUg== 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=yu3prLTu/0wI4ZAj0BQDozCdKSFjzz2EwrQUPjw2yl8=; b=0gu3aXcuM7FK1IWn42q72Q/or1bOr0JyhzPF5Q9dfjyqzvIIrUt0AKVrSf4A22r7hF 339VsHf+iUcOSwHBQZrWiBFg/kfnXqLsy1o3T1mrNk1tIcSZAFayhq0eGoxh6hgTFh4i 87Idfb60j/bKGraX4jXBaXF2ncO0ZmrnJ4ETPQznuMRSeMwmGGtQoMAFJkidwLnDMsCN ChTK/uHPKUUU1ek1rlkPHtZ15UxMowztrLIpLw5vqlkBUTH8jhFY1xeluam/FoKkvgg7 My6uhZY4s0BWQ5DPdRTtxxmL5i2nM+zEzl0SBmz7LVSPRb59xzfCfdxK/1hjlD2c7DQ1 0U5g== X-Gm-Message-State: ACrzQf030NIYxZCP4ZbBQz2pOgDbCnsya7aWnlU7mzKggsksEd4ttkDP pp1Tl4bptjzmRENHps8+0ps= X-Received: by 2002:a05:6a00:acc:b0:530:e79e:fc27 with SMTP id c12-20020a056a000acc00b00530e79efc27mr3533437pfl.61.1665728181904; Thu, 13 Oct 2022 23:16:21 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:21 -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 Subject: [PATCH 18/19] perf stat: Display percore events properly Date: Thu, 13 Oct 2022 23:15:49 -0700 Message-Id: <20221014061550.463644-19-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746644138853331395?= X-GMAIL-MSGID: =?utf-8?q?1746644138853331395?= The recent change in the perf stat broke the percore event display. Note that the aggr counts are already processed so that the every sibling thread in the same core will get the per-core counter values. Check percore evsels and skip the sibling threads in the display. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 16 ---------------- tools/perf/util/stat-display.c | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d7c52cef70a3..9d35a3338976 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1404,18 +1404,6 @@ static struct aggr_cpu_id perf_stat__get_cpu_cached(struct perf_stat_config *con return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); } -static bool term_percore_set(void) -{ - struct evsel *counter; - - evlist__for_each_entry(evsel_list, counter) { - if (counter->percore) - return true; - } - - return false; -} - static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) { switch (aggr_mode) { @@ -1428,8 +1416,6 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) case AGGR_NODE: return aggr_cpu_id__node; case AGGR_NONE: - if (term_percore_set()) - return aggr_cpu_id__core; return aggr_cpu_id__cpu; case AGGR_GLOBAL: return aggr_cpu_id__global; @@ -1453,8 +1439,6 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) case AGGR_NODE: return perf_stat__get_node_cached; case AGGR_NONE: - if (term_percore_set()) - return perf_stat__get_core_cached; return perf_stat__get_cpu_cached; case AGGR_GLOBAL: return perf_stat__get_global_cached; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index d9cd2db1398b..acdd14ac26db 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1091,7 +1091,8 @@ static void print_percore(struct perf_stat_config *config, { bool metric_only = config->metric_only; FILE *output = config->output; - int s; + struct cpu_aggr_map *core_map; + int s, c, i; bool first = true; if (!config->aggr_map || !config->aggr_get_id) @@ -1100,13 +1101,35 @@ static void print_percore(struct perf_stat_config *config, if (config->percore_show_thread) return print_counter(config, counter, prefix); - for (s = 0; s < config->aggr_map->nr; s++) { + core_map = cpu_aggr_map__empty_new(config->aggr_map->nr); + if (core_map == NULL) { + fprintf(output, "Cannot allocate per-core aggr map for display\n"); + return; + } + + for (s = 0, c = 0; s < config->aggr_map->nr; s++) { + struct perf_cpu curr_cpu = config->aggr_map->map[s].cpu; + struct aggr_cpu_id core_id = aggr_cpu_id__core(curr_cpu, NULL); + bool found = false; + + for (i = 0; i < c; i++) { + if (aggr_cpu_id__equal(&core_map->map[i], &core_id)) { + found = true; + break; + } + } + if (found) + continue; + if (prefix && metric_only) fprintf(output, "%s", prefix); print_counter_aggrdata(config, counter, s, prefix, metric_only, &first); + + core_map->map[c++] = core_id; } + free(core_map); if (metric_only) fputc('\n', output); From patchwork Fri Oct 14 06:15:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 2531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp31333wrs; Thu, 13 Oct 2022 23:32:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4minU8VtBMga7Kq+yR8Z2eWhVI4ji0AL22LT5cxlpOG1FoGGwkPzmxwGA0CPcYkYzhUQPb X-Received: by 2002:a17:906:5d10:b0:784:b6c5:78d0 with SMTP id g16-20020a1709065d1000b00784b6c578d0mr2471614ejt.348.1665729171792; Thu, 13 Oct 2022 23:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665729171; cv=none; d=google.com; s=arc-20160816; b=te1YU9K6ydJXA2PQZUktNcNyFST9Uq8RS2B6TRUy8YzgJufzk7OEvikrOaEIxGQxwR U4b6n/2W6HCrULR0lCu1YlOky/NvVeqDcZMQanh79DGhXiTO//zP3A1kk2ydI0SNvF0Z qCKpGK0eiCZSjYSyf/M8qqERwquZJOldmGN5a+zrUdYj68G6scxtayovFkJXqTTSWp+e CXOisrKBf2xlExytEyZAxrqvvtBSekbVPxbGynnCPml9LhKZI3Z9bxMlxz8rrXk+VL75 YuRUa/9NZfucs78rG4dhX8A1DnioHFDteVTaWmagGboq2s3QApitske2DoGbGlsK354G 6+8w== 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=deC1Ch/LRE/b9oWyC7BPXVLD02u5pO6qtdU3irPGc8w=; b=ZZqtRkc+JSEHAG8zWyeV7NSy72nMUbVk5EL5TnAhfQFWOhfRKJ1yN5UOP/02PFRG3s suvTwtA0QYppq2RqDXdXnAUtWvw8Io7Wa37IYtBLPvm1FyfIzfWlvmhX5zDU18rs0W7k 87YvSoemGHMXxWlTJB8Bwiw/t0yYsucPCK4b/KQWFcidrZsfnj2/wDnL8W7KwFP3InRp Zy2t4mfuISQxl6m7VgtYUQ+ywHncvatciK7T+gYTqfgpMv51oVMeKzUHc/nfzR8lU26r TD0yQCcjyqEiGawHB6IxFD/qZgnGPzhSPQZUKGMPfHeXzvyksl6l71Xw/mIz5lCc26ER KPUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KHSL8W0n; 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 gb2-20020a170907960200b007882926c090si1994108ejc.773.2022.10.13.23.32.00; Thu, 13 Oct 2022 23:32:51 -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=KHSL8W0n; 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 S230013AbiJNGRf (ORCPT + 99 others); Fri, 14 Oct 2022 02:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiJNGQo (ORCPT ); Fri, 14 Oct 2022 02:16:44 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67B291905E7; Thu, 13 Oct 2022 23:16:25 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id 204so3997552pfx.10; Thu, 13 Oct 2022 23:16:25 -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=deC1Ch/LRE/b9oWyC7BPXVLD02u5pO6qtdU3irPGc8w=; b=KHSL8W0nox/llcdMA89ep9ycYbcTlAQhpmmj5AhrLmIoNRE77aU1JGyXgDMUWxMiFz 1NsYYb5Y7WGy5+NrqV+xIezxghWtnpWS4HphitnlesYX5be5V/ySfGkzWoFN6XYdOV73 IgoYD9YKua+kRAHO3f9x2+mrkXBVAg/mxn2fyQOC6sDt6Og+PYcu78S6Kk0mW4kyHjq2 tsloPvFQsErWaGvERJXSbloRQNUnRI5JAYu0eoAX+Hz3C5JojFVdHpGKTfYsZby6reJp pcO2e2eyYOFRYhOhjDFznW5zUHJJgKypr3KoSxGNkMU5DdGRdNv2MRvYoj7tU+V5PZ03 sNPg== 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=deC1Ch/LRE/b9oWyC7BPXVLD02u5pO6qtdU3irPGc8w=; b=qezwmBILhJYC5dHRUTWo/BSarKQgg5hBIJ91/4tfnSbpaxMxBzFRDY/P0GCLYCuyZC FMJySs5adEk/969SnaqD0O/34tSekasIc29ZVPXStdkbQg8pq/rrBGeTCsi0cJuIw6uH 1KYAXpGRH0rd4PM/WlMZFhoKm85BCO777+rX43XTtkpIp9buoQmfJUr6kPielC2uqWOR dWIVQLDcjaAYLmpUFdysWmQItC8Qt4fi++gRrvEaDQQEaawCNas1+ALYZtdr99te5Evt HC4v4uDMTehuNS4Rc2fDUUhpmGSHka+CMqMdVAu+zU3pCuQrxl1QwBbG/ZBA7eMXNTwp u08w== X-Gm-Message-State: ACrzQf2bD44m9jRt/2Y2Hqs7cgXuYtq9meY3vPEZ2uChSCNLwQyk15nw QExwlY1+gnoO+3pSK/mxtEE= X-Received: by 2002:a63:b5d:0:b0:45f:d7d0:5808 with SMTP id a29-20020a630b5d000000b0045fd7d05808mr3203471pgl.330.1665728183760; Thu, 13 Oct 2022 23:16:23 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:23 -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 Subject: [PATCH 19/19] perf stat: Remove unused perf_counts.aggr field Date: Thu, 13 Oct 2022 23:15:50 -0700 Message-Id: <20221014061550.463644-20-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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?1746643632166245010?= X-GMAIL-MSGID: =?utf-8?q?1746643632166245010?= The aggr field in the struct perf_counts is to keep the aggregated value in the AGGR_GLOBAL for the old code. But it's not used anymore. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/counts.c | 1 - tools/perf/util/counts.h | 1 - tools/perf/util/stat.c | 35 ++--------------------------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c index 7a447d918458..11cd85b278a6 100644 --- a/tools/perf/util/counts.c +++ b/tools/perf/util/counts.c @@ -48,7 +48,6 @@ void perf_counts__reset(struct perf_counts *counts) { xyarray__reset(counts->loaded); xyarray__reset(counts->values); - memset(&counts->aggr, 0, sizeof(struct perf_counts_values)); } void evsel__reset_counts(struct evsel *evsel) diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index 5de275194f2b..42760242e0df 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -11,7 +11,6 @@ struct evsel; struct perf_counts { s8 scaled; - struct perf_counts_values aggr; struct xyarray *values; struct xyarray *loaded; }; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 14c45f4cfdd3..6ab9c58beca7 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -308,8 +308,6 @@ static void evsel__copy_prev_raw_counts(struct evsel *evsel) *perf_counts(evsel->prev_raw_counts, idx, thread); } } - - evsel->counts->aggr = evsel->prev_raw_counts->aggr; } void evlist__copy_prev_raw_counts(struct evlist *evlist) @@ -320,26 +318,6 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist) evsel__copy_prev_raw_counts(evsel); } -void evlist__save_aggr_prev_raw_counts(struct evlist *evlist) -{ - struct evsel *evsel; - - /* - * To collect the overall statistics for interval mode, - * we copy the counts from evsel->prev_raw_counts to - * evsel->counts. The perf_stat_process_counter creates - * aggr values from per cpu values, but the per cpu values - * are 0 for AGGR_GLOBAL. So we use a trick that saves the - * previous aggr value to the first member of perf_counts, - * then aggr calculation in process_counter_values can work - * correctly. - */ - evlist__for_each_entry(evlist, evsel) { - *perf_counts(evsel->prev_raw_counts, 0, 0) = - evsel->prev_raw_counts->aggr; - } -} - static size_t pkg_id_hash(const void *__key, void *ctx __maybe_unused) { uint64_t *key = (uint64_t *) __key; @@ -423,7 +401,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, int cpu_map_idx, int thread, struct perf_counts_values *count) { - struct perf_counts_values *aggr = &evsel->counts->aggr; struct perf_stat_evsel *ps = evsel->stats; static struct perf_counts_values zero; bool skip = false; @@ -493,12 +470,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } - if (config->aggr_mode == AGGR_GLOBAL) { - aggr->val += count->val; - aggr->ena += count->ena; - aggr->run += count->run; - } - return 0; } @@ -523,13 +494,10 @@ static int process_counter_maps(struct perf_stat_config *config, int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter) { - struct perf_counts_values *aggr = &counter->counts->aggr; struct perf_stat_evsel *ps = counter->stats; - u64 *count = counter->counts->aggr.values; + u64 *count; int ret; - aggr->val = aggr->ena = aggr->run = 0; - if (counter->per_pkg) evsel__zero_per_pkg(counter); @@ -540,6 +508,7 @@ int perf_stat_process_counter(struct perf_stat_config *config, if (config->aggr_mode != AGGR_GLOBAL) return 0; + count = ps->aggr[0].counts.values; update_stats(&ps->res_stats, *count); if (verbose > 0) {