From patchwork Tue Oct 18 02:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734624wrs; Mon, 17 Oct 2022 19:04:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vW2bOKZx7cJ+2qzkKT+cok63L4cs9J6yAcQoLdTPk7t01ItHQ625i5mwLAgByD60aVzIE X-Received: by 2002:a05:6a00:27a0:b0:566:9cd9:3843 with SMTP id bd32-20020a056a0027a000b005669cd93843mr780438pfb.17.1666058685725; Mon, 17 Oct 2022 19:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058685; cv=none; d=google.com; s=arc-20160816; b=y2j32al85w/wLmcEev2LcdITiGmYQB3QyqsC/z5foSVvulEhcSjztfo9IteBXwwxHx nGirVTJRjAYgkdaVP9pjPk9cG4iq8Roz2IyWfXrqdkJ4UgOXmko0YY2lVgzdGzME2Qxx ZfMa/IyExA4n5av9JIURp/Bz4RkwHeoIX1seS4Qmu3buWmcutPM3PFwLKq2tYc+svaYh 23Dmd0X9FaWMTasd5odeuAmtRyQTXCFg+ldBqGf+IL9nA65MEF3aPlIECpxlrqlucR9G BlyIpgY6a4VydAIASbzF2kLYinGiozFs1ODY0iPm6TYUA5XdZSjD3xsCheQyse0oOfxL +jkA== 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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=eEIa+Twx3HtJ8KCuhgJ8bk/Dd5PqZ69IEOskhuzYFxpu/kMl0oVdOXxSJzRLoDvmlL oqnHoAASJX/k1DM8eCzjuqycjG/L1JvVejwKig1VBktOiulwZsV2DXzIXuj0ENhKWLqV lZQVEZGww4hSYSUyU1uMH7Jwb/3NA+FLgt16WmET0svEV/yfxojonQfn0Rq4MlQ2ea+m xfYtm40BXzwmWkw/5iMFaRs02TCkDGcGlDmBHoNYtiu3WDaeQLlnJ101Vjgp7i1/UOdB UB98LRNl/zMAdiIzdtpKzl/jRgnVGg9g3ARGVqQlroXCMI8A3/x92hn/OBVlQqPLSgbz jDcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VmAnUG4z; 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-20020a6541cc000000b00464a9874658si14471039pgq.6.2022.10.17.19.04.32; Mon, 17 Oct 2022 19:04:45 -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=VmAnUG4z; 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 S230493AbiJRCD2 (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbiJRCDF (ORCPT ); Mon, 17 Oct 2022 22:03:05 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6FD8D0D1; Mon, 17 Oct 2022 19:02:51 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id e129so12045281pgc.9; Mon, 17 Oct 2022 19:02:51 -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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=VmAnUG4z5Z6AXUZcsN63rFYP0NsmchwMa/HFryoXD/HSSq+dJkary9Gg70Qt/685tH vkCaJWXPzwUIXlSLJOjXBEDrKoJMFdIn1xAKZFBVTM8qzEh0gdwBDO4SHGQIe49GHq25 lqZzKmBlf0+p9gxmZVNll8zaogCh86p/9dUCbhO4mHBRWlnbVqvXQENR6b2zGnbRV+RT nYPT8l84baJ/Iq06t0knKxAbL7G8a3giP3F/2JOZsHh8ihibt3LPGBlT4OeLNVsKoa7l CXG/pFXRdoVeK/EBbRFvDyFqJVZ/5TyHYrzwBUGg86VR1QhTc0CX33ttMl2N33BADo5b Z+Tw== 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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=Hvtv+xLFjXcDi+FcEZLv7OGJPlFQlch7eS6fMDtIpvhHd4MzwfRs3W4HY6kchtjlbj EDQ/+mS+5QyxcG+f3Vvka2xPo016J8jUuVNSOZkVz36c+st5v6ue7gia1+Xtu9tApytT LHjyAXre2s7k9GxzwSLuXiQEAmMVRpktyefFgmsLkLqRTuNzcCeA/f3j4zVCRqEPSwKw HjrN2LqynXdKXWaBpi7sP2zJcvTmrQN+ZDZosSxlv2OkvhDBdxGV9Jso2IW+hcuWjpMR TkpdjP0sFqIechTBP35Uwi5ruNUELLglXTc6PcQ6hLwO7JLgTONougVsL2I5NPwB7l/c d2yw== X-Gm-Message-State: ACrzQf1XSQB6/sfFejAzDg0FmNscjnxsSKOCL9cz7pp4H7C5AJKd9bfc jOfvgA/N6bD23q0OEE6T41g= X-Received: by 2002:a63:6a48:0:b0:43a:18ce:4e08 with SMTP id f69-20020a636a48000000b0043a18ce4e08mr670865pgc.432.1666058570704; Mon, 17 Oct 2022 19:02:50 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1f90:85c4:58f0:7a81:6bb5]) by smtp.gmail.com with ESMTPSA id t4-20020a655544000000b00464858cf6b0sm6851564pgr.54.2022.10.17.19.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:50 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan , Andi Kleen , Athira Rajeev , James Clark , Xing Zhengjun , Michael Petlan Subject: [PATCH 11/20] perf stat: Aggregate per-thread stats using evsel->stats->aggr Date: Mon, 17 Oct 2022 19:02:18 -0700 Message-Id: <20221018020227.85905-12-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018020227.85905-1-namhyung@kernel.org> References: <20221018020227.85905-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746989152580557714?= X-GMAIL-MSGID: =?utf-8?q?1746989152580557714?= 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 | 24 ++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 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 dc075d5a0f72..5b04c9d16156 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -422,6 +422,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); @@ -436,8 +454,9 @@ 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 (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) { ps_aggr->counts.val = 0; @@ -455,6 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } +update: switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: