From patchwork Thu Dec 7 01:17:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 174860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4489046vqy; Wed, 6 Dec 2023 17:22:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGH9ryvCVtdSD/n23Wsm9QQQ64e4jgQfhv5G6bv96A9Zs3p48fQsHLsdKKetNvEzkAoTpM9 X-Received: by 2002:a17:90b:4a8f:b0:280:cd7b:1fa5 with SMTP id lp15-20020a17090b4a8f00b00280cd7b1fa5mr1497232pjb.4.1701912137472; Wed, 06 Dec 2023 17:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701912137; cv=none; d=google.com; s=arc-20160816; b=tzDLwvt0eRNkGebyqbCYiJhw8ka4AH1IUDYBfB/rk36dO5Ek6CrApfa0QVHMRYPwGq q65M++/8VuUNgP04CjSVLSyQpieSy1My7zvNjxonBCki9a0/g6JoGK9bTZdPAIUL8KqX FTkbDVmvjw4R9e45/Q7hlFvNWd928V4h6eAQ+k6xrBPvsWVZ+3jeCuNsglFfRrMDcB6W JTsyWvlWQr77Y/xPR1xww2I70dhk6ELtdXkk3JZH4/RWzZ0cGz8h8Ai7/DEdzSfoJgH9 GXaGH608IMVtal1UlYIGx26rKgrXI8azP3TXDLij6HACEgkj+xWYErzXUvv4ShixjNL9 y4Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=1eb9Sth/5ufQgSBSs/vYHmQiQlg9BE62KSRUCpFldRs=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=rNeiSY6plSYpAvCPEW4S6m2BS8Uub941LVIy9q0xTHW96L1dmRXbu6NmNd9QZWZjA2 pLzlrthV4VGMffFGAE+5aTiWpZfbhl9Y5f0BRHJGVCSrO+k79u19WsQ1f4YsIRxKsY/C z4P9tD72nON7uG7UhA4GniG3SXC8QukEAx6Yu+WD4sil0mf+22vBzrPTd0to46vrKsxp /LcBKsA4sFdoudk+de3d8VM0bkjgfC3d+xxVgAHtEYFcpSaArvIF3FKs+ZCbaluvhEoX V3PCJXeYi51HpEvqWKYqtHZEqs7CWP76/HNJwFAUaNBO/HvH/UjhEaMIYj41IZGXGfrV ikGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nu6hgpd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id qa6-20020a17090b4fc600b00288704afe2fsi102124pjb.67.2023.12.06.17.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:22:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nu6hgpd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 70E2581F32AF; Wed, 6 Dec 2023 17:21:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442062AbjLGBTs (ORCPT + 99 others); Wed, 6 Dec 2023 20:19:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443096AbjLGBTI (ORCPT ); Wed, 6 Dec 2023 20:19:08 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D561981 for ; Wed, 6 Dec 2023 17:18:40 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db99bac23cdso551958276.1 for ; Wed, 06 Dec 2023 17:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911919; x=1702516719; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1eb9Sth/5ufQgSBSs/vYHmQiQlg9BE62KSRUCpFldRs=; b=nu6hgpd5NgOIEfOSzyx3pVPozmpAahYzTrR0+WrVIXYkJxpHmoNDpqRjjISQeFZGFV wdE8BbpVKFyluSOpEQLKLsFzjRCfR2e0scbZqxuRE799kU3Ue/tu0o+t5iiMLbaOOhlX 59VUW5LhzjHAkjCDCxa0GaIbSe2w4PLHGgZ0nDeUgd/0m1FDw6dv92iM2cZKwUpMrSBd +7mc8GaEqYzuS/R+RMVcboAoael2/4llX4cuHSLrwI+iSLE9iQ/lxMQdgIfuHrgsxXr2 bXsu0VUbA9nFbudFJPPmyHKxv8fbPBIywTcQNE9PV7i2+lm1AhtRgU1hoJpm01ARu2ux 8I6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911919; x=1702516719; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1eb9Sth/5ufQgSBSs/vYHmQiQlg9BE62KSRUCpFldRs=; b=c4hhRDK0a9JKuc+sTnqS6mJYYhNS/QpYQ/UqNcR3GUEkZ0LYaj1Gbyio1fTVEyg8VZ 9w1xNcDg0ibr5Sd0rXOnHJc4gECGwvoZmOa6tMOpdiSuac8GoFDYwArVvpUgL9QQ49Gu NRaacdPcscWmYdhY6kWbh86gJxNpKFebh64DQaMMPBUW1ixt0uv/hcGrdckLwJ2JpcNC D8fy+5xkvPm+fPLqS0wdgVNr0VLD4ElriLW1wxUqvWGeqfWds2ywrfwy6Dke+VN9rJq5 BwX+ul5rPuHPB4KIQ/rxrF+a3QYEHVgJnqJ1O0G4U9wfKm5FBkNkh7d0fhC+29ZLrBxo 48SQ== X-Gm-Message-State: AOJu0YwJAQUHNNCgZW9fzbCInW7brhfn2fwboxN0Jk3L0VUi2rGPttyX 0k00jn3Z10uAIhh6jDB7y8PxiobYFor0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a25:ca94:0:b0:db5:3b4b:ad1e with SMTP id a142-20020a25ca94000000b00db53b4bad1emr29235ybg.10.1701911919286; Wed, 06 Dec 2023 17:18:39 -0800 (PST) Date: Wed, 6 Dec 2023 17:17:05 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-32-irogers@google.com> Mime-Version: 1.0 References: <20231207011722.1220634-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v6 31/47] perf trace: Ignore thread hashing in summary From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:21:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784584221450842199 X-GMAIL-MSGID: 1784584221450842199 Commit 91e467bc568f ("perf machine: Use hashtable for machine threads") made the iteration of thread tids unordered. The perf trace --summary output sorts and prints each hash bucket, rather than all threads globally. Change this behavior by turn all threads into a list, sort the list by number of trace events then by tids, finally print the list. This also allows the rbtree in threads to be not accessed outside of machine. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 41 +++++++++++++++++++++---------------- tools/perf/util/rb_resort.h | 5 ----- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 109b8e64fe69..90eaff8c0f6e 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -4312,34 +4313,38 @@ static unsigned long thread__nr_events(struct thread_trace *ttrace) return ttrace ? ttrace->nr_events : 0; } -DEFINE_RESORT_RB(threads, - (thread__nr_events(thread__priv(a->thread)) < - thread__nr_events(thread__priv(b->thread))), - struct thread *thread; -) +static int trace_nr_events_cmp(void *priv __maybe_unused, + const struct list_head *la, + const struct list_head *lb) { - entry->thread = rb_entry(nd, struct thread_rb_node, rb_node)->thread; + struct thread_list *a = list_entry(la, struct thread_list, list); + struct thread_list *b = list_entry(lb, struct thread_list, list); + unsigned long a_nr_events = thread__nr_events(thread__priv(a->thread)); + unsigned long b_nr_events = thread__nr_events(thread__priv(b->thread)); + + if (a_nr_events != b_nr_events) + return a_nr_events < b_nr_events ? -1 : 1; + + /* Identical number of threads, place smaller tids first. */ + return thread__tid(a->thread) < thread__tid(b->thread) + ? -1 + : (thread__tid(a->thread) > thread__tid(b->thread) ? 1 : 0); } static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) { size_t printed = trace__fprintf_threads_header(fp); - struct rb_node *nd; - int i; - - for (i = 0; i < THREADS__TABLE_SIZE; i++) { - DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i); + LIST_HEAD(threads); - if (threads == NULL) { - fprintf(fp, "%s", "Error sorting output by nr_events!\n"); - return 0; - } + if (machine__thread_list(trace->host, &threads) == 0) { + struct thread_list *pos; - resort_rb__for_each_entry(nd, threads) - printed += trace__fprintf_thread(fp, threads_entry->thread, trace); + list_sort(NULL, &threads, trace_nr_events_cmp); - resort_rb__delete(threads); + list_for_each_entry(pos, &threads, list) + printed += trace__fprintf_thread(fp, pos->thread, trace); } + thread_list__delete(&threads); return printed; } diff --git a/tools/perf/util/rb_resort.h b/tools/perf/util/rb_resort.h index 376e86cb4c3c..d927a0d25052 100644 --- a/tools/perf/util/rb_resort.h +++ b/tools/perf/util/rb_resort.h @@ -143,9 +143,4 @@ struct __name##_sorted *__name = __name##_sorted__new DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries.rb_root, \ __ilist->rblist.nr_entries) -/* For 'struct machine->threads' */ -#define DECLARE_RESORT_RB_MACHINE_THREADS(__name, __machine, hash_bucket) \ - DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries.rb_root, \ - __machine->threads[hash_bucket].nr) - #endif /* _PERF_RESORT_RB_H_ */