Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2186730rda; Tue, 24 Oct 2023 15:29:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFw8XD0PeZUQcKNmZYw6ikhhGT7fDH8726muVf89+lyJPzTTtiuuZvOyu5suI++04dILMfu X-Received: by 2002:a17:902:bf4b:b0:1c9:b338:8073 with SMTP id u11-20020a170902bf4b00b001c9b3388073mr12067747pls.15.1698186557884; Tue, 24 Oct 2023 15:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186557; cv=none; d=google.com; s=arc-20160816; b=uksqvLAvhJfNBk0d7/lUOucVK3yxsVVbOCuWkUS2hmHrj5Cw9XM8wz6GSAg16wQfB6 ozaUTGwmNWmkGJXhaz9cLMrDzc6lnksgeVHHY5yAcrlpRTJPWEe8AOX/BUmif2UokeMc /VqTsNVxLQMst9BF/EApuWBHMB9rSUYVUq1CKvr1xwCQLnBReZNgfORNIfEA9ioHm2Eq +PkkhIUYgikHr/F2PfiudsLOyzdC9YY0ITmuy1+QMVefOH4Gn1EaqVvHn+52DEsbbaST sGEZerqEu8ZG1xiJaX3dwH+poSeKa764GkIOCiC+ROdgudYghRwAum4Fqj8nntm0ICGl RksA== 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=zfK3LtQ16zflZ7X6ZyHLcdZIKlRk/T+4AhzfwFPXJCs=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=vL5u/6TM0OfLfkppAdDq6DCQ86/WQV/uBgWQR/DjJP2EHvjY1QumK7CVpqbVL4OqKz PW0lZGSLRHDJuv2iJKuZYFGq8amLrhKc+JczeEAcvecjrHQyR3rrFPy6LWX/UQMvQXCr UTJU4l1FiB2WcKhwkIyStE3qAype4O/NERLyGijJpsBHCzLXmvY6F4KivBdhDC3L2W+g SX1ECKPUakUWVHFRz+SXEWpt/QpOLa7Ekd5MMcMDr1tV5qxMc03nkIxckRbOd066nBN2 GJKatDo0W3KGX+0u9VOtnHYm5odAitodT72rgVE0wqCsz5KnqdWCuDDlDuDfnR2u35p5 UFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RV9yKrDE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id w4-20020a170902e88400b001c474ff2fdesi9484899plg.378.2023.10.24.15.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:29:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RV9yKrDE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id EF5D8801E1E5; Tue, 24 Oct 2023 15:29:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344619AbjJXW1v (ORCPT + 99 others); Tue, 24 Oct 2023 18:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344621AbjJXW1b (ORCPT ); Tue, 24 Oct 2023 18:27:31 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A7C2123 for ; Tue, 24 Oct 2023 15:25:57 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a824ef7a83so63952917b3.0 for ; Tue, 24 Oct 2023 15:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186356; x=1698791156; 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=zfK3LtQ16zflZ7X6ZyHLcdZIKlRk/T+4AhzfwFPXJCs=; b=RV9yKrDEYbXWbK14zY0h2vfn3sAT9COKGFiwGstrJyhnFT52zdLDk7d1OIuh8fQ09r 4iTla9UXEXP8WZcemGiFT5IVEyE7UIQDEZ9mT5KZoHs0Q3fASFL4HGkNvp9S8C6eHHmQ PufFX1ZstrOYfV/QK9EA02rpS8MwRMOeIUv+DoiOcNiNUihkchVYsOBz4LyKjBB8ouHj XcMB11cZNS8OaDVyfhSaWTUXd9oxowEAHsYZX7358tk93oaIQArrGpjiBKrgg38khrXo zhmXsgpBpwUHfNTt7ldI/ftSZ14RdPB49xp45OcO0BPOW2izuoPeed5re4146xn7IVK4 4Bdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186356; x=1698791156; 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=zfK3LtQ16zflZ7X6ZyHLcdZIKlRk/T+4AhzfwFPXJCs=; b=LnHovuL+gIo8Y4yubY0fqyutU218PTCOhjHgiTqZ+6vc3tbw2yMTn0q/TVrUEIestm 2A5WDyZMC8BOMgNpS02/pWfX/swxghFCPkJ73j2ibeN6TZOzAaHRmz+qsiytSrvo/QCY h5wHWq5U0eJgvTBslMgyW/R0Z7jwefROJArsZ/h/j62wU0/IiZnsIrVFXSgYqvDmqaFB 6k9ds50ikj5EWFT1MN7yGb4h8PI0Tc5j+bKiRQQ0MO4BE1CSB8IP78Q4uWd0ulrUc3UY c/3mWex2pzNvxZkf7ySUujR9Oe120Qb2vCcGB+hXm5m+BdFTe7NVpP7OgMEkQBg3slt3 Apxw== X-Gm-Message-State: AOJu0YyrKVnCo+8MaATbJGByY6+RLNM48talGjFSZRyvxM+TXgwKvOq7 /eVQI8TI1mZnZIUPq/8Y56I900oqjrBD X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a05:6902:1083:b0:d9a:47ea:69a5 with SMTP id v3-20020a056902108300b00d9a47ea69a5mr366432ybu.1.1698186356515; Tue, 24 Oct 2023 15:25:56 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:49 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-47-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 46/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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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,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 fry.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 (fry.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:29:10 -0700 (PDT) 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_ */ -- 2.42.0.758.gaed0368e0e-goog