From patchwork Mon Nov 27 22:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 170459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3500854vqx; Mon, 27 Nov 2023 14:14:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPlxg2kKjqe1d4UQu9X7TyXltkOH1H0a31M76Gcp0s3bakMNe7pm2n52HdCB/ikybUnV2y X-Received: by 2002:a05:6808:10ce:b0:3ab:73a6:1469 with SMTP id s14-20020a05680810ce00b003ab73a61469mr18964610ois.14.1701123255450; Mon, 27 Nov 2023 14:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123255; cv=none; d=google.com; s=arc-20160816; b=iXg5UMxteEf81D//WFgV/zGwFpKEoDSpd5Jou6NlOJlm3Ve/cnTjgZ4yHLxOH0GINQ Y6UiTIAHlcyCe8HU+RK5jsdbQn8sWA/W9BLCA6FaSE5fxhkm5EYsKqJcr9knC+11Ulmj TGIsIj0925NGfD6libgj4347HPkRKMgoEnc5qU901DsjvSj3scT2j5DWEtL8renvvTnF ovh1nEre+nnjEUgjGw35YV07IKYmJYtA+O4+4HIcX+pX6LbXtvCt6mTj0IOo76+aFCgv a4djKBcGIwLTAQisH66PwDrR86XmoK9uY/fydXrRWGeWgkjhp+bihdW8TckezoXvQFwe MbhQ== 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=r3twY0uvBPOzHwJLVb2BMNzOWz+K3rhS0UQd7tzXJ1M=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=WtUqjrkzYIViaufVNBqEjUNNqTniPgcfsJVukyTtwlzGUhcPOIE0ZtYrMsxJFaoLu3 /N7chPdHjI+0ar0GX548ci/zW9u+MDg1Ezu+161JGRqHv7Q6nbWmuGZZ4LR9nRnXq0HK rPgBVVFs1f0iYlnKJGBMMy2BPbwgy25Dul2igrsYdIiqydjIGCryIrwzAYN6L1VgcZY3 Xykjf8OaiWO2u2DK2RUg5pqQeysOrd26ASXGzGNpzpoVB3fMpaKkCv+R8X+MCU6KVtWy 1sx2AUvXNEquKPgn6h3DGXTt/KwDsunmWv9zFYHVtw1oJcY98EpRysINjRaCvsTcnNI8 ReLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HTiwxl7r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g4-20020a635204000000b005be1ee5c3f2si10399846pgb.289.2023.11.27.14.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:14:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HTiwxl7r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 8E060805A5D8; Mon, 27 Nov 2023 14:14:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233867AbjK0WNa (ORCPT + 99 others); Mon, 27 Nov 2023 17:13:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233855AbjK0WMl (ORCPT ); Mon, 27 Nov 2023 17:12:41 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3C32729 for ; Mon, 27 Nov 2023 14:10:40 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cd0a4fba39so57347787b3.1 for ; Mon, 27 Nov 2023 14:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123039; x=1701727839; 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=r3twY0uvBPOzHwJLVb2BMNzOWz+K3rhS0UQd7tzXJ1M=; b=HTiwxl7rfRbjsqEWMZ7Upc3NL1leZE/IrDiO/xhJXJVjdavxvhHQEPW0ewRDahfDTG MU7q9s73888ixd/3lXOiTzblB/hks7KA3iQX2C9HM2P+xb9+H+Ose9FGmifIzSe7A06d TiKpdlKC9Nz2/RAHy0k52m9jwiz/Z5y9UZDwpfq0oTHIpriBE6qsf3OrYKezEQeMkUHp zsLQJcYnmMT6Z4gK6gpWCBzzC6Ww8FaZvJpxB/SqSvArGI0YBofkh6fYYCXxoOchqSKu Zm3fzhJBhI2mF62iRrUqxe6zFfPE47IHn9qJwg8tNTYl7UhQE8t3gPnyDuiQbaAj/7eF sdyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123039; x=1701727839; 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=r3twY0uvBPOzHwJLVb2BMNzOWz+K3rhS0UQd7tzXJ1M=; b=gPrplsffh78aPghVeEM8eOYpC77vCyE5Ee0uY7a8rhBj4E+7U6go6osz6tZ0pq7SFp 9xJiDWIjvdcFy4KsA4QuTIi/OvdaGbNvkFwZ/NyOclVksiUlT163Ri37MIAXWcHn/olt BgTw9/EYMeAKKnXCvbcIFqJzCZ045rvN+tw1p7PsBZNa1QjvurHUN3aSDqngOvDx7SLN 4S7Uq/m6OPzH5XUxiTJD5I8W7VfoWgJ/0gBMlMsoBtjN/HFI572Dftnm+7QmIFjOUyQT YICSoH1kA8AKimFioirSQu+a0pKpmCT0yiFVlaA6yF900J7K2jF3wZv1ubsPfE2vmfmj TFFg== X-Gm-Message-State: AOJu0YweWruUds0yYlYp3SNaRwR/3CTHKiqBe81JLB3kbhfCzqjt+bn0 OtkdETgA5XrUPKMIVTW+ECxP5FS2cIsz X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:f84:b0:5ca:ad72:2d78 with SMTP id df4-20020a05690c0f8400b005caad722d78mr503602ywb.8.1701123039435; Mon, 27 Nov 2023 14:10:39 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:45 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-34-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 33/50] 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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:14:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783757018607376148 X-GMAIL-MSGID: 1783757018607376148 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 e541d0e2777a..e9ff78b331fe 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -4314,34 +4315,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_ */