From patchwork Fri Mar 1 05:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp876042dyb; Thu, 29 Feb 2024 21:37:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWLAauR+1ddACXx2JgB5sG1khiUoQX7IBMmD2TOYI1slrEcelg7GP6QD7xmCbs0p5QjAlwsSVbBKn0TV9FoNb0cVUDqvQ== X-Google-Smtp-Source: AGHT+IFjYOvwGIiaHQno6Rgftp+tAcRmwXao1pZwGYsmDDAyqWLj4+i6xXTnGRyGQaeo6fEMkzd4 X-Received: by 2002:a05:622a:243:b0:42e:c2fd:5748 with SMTP id c3-20020a05622a024300b0042ec2fd5748mr883602qtx.0.1709271462408; Thu, 29 Feb 2024 21:37:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709271462; cv=pass; d=google.com; s=arc-20160816; b=QoVVhoCdK9ckZNEySsuWR+dRDPUnbg5NZPvjlin6qCJk5Mf/fnUVYfDmXVTUE/Xq1y d5H6UnXN9wV97l3IxNKLlYkhHz45gxBoyswbgb0rcCU5rFM1h7G+3nkjD31xSFoQbiGf 4iRW04laV2okhTQ1eoVxkvDDmKnIQF1o8J1GabDROOCqo1UzEh+2ZTvZl7WAEuZG9K7z U6irvkQ5rBqtBLBhGlsOLSYrkf8vr4dEDpFXl6z5136g/z2sujiaQwh5Lsl9AVpDL6G2 xvK+QwfZ4oD1hpn4uhyzHkESkHdOtMw0ciUIlgmEMAg0SHB+Pok29EyK4faLhuUqS3xc Ow6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=eHNbX5Xyi/VqeebJOw+lK9eWaYZye24FQe0AyXZlgyM=; fh=mCzYfL24NoKdYsbJOTqLao+z/Jx0C5ajeSi6DF0yKD8=; b=TRzU7bteH/HsSBSn/aFJEyN0BXKJHmuGjiKEwF6F1abC4DT1mPumV8Nt0G9ZAeDrZQ ZEr/09B0esCiQYlZ3oNTe5rdQM1Wnl1eNTedsK8xwtOGhM9hXv+QSbZZoIcouSP6cIBo S5+zXHCur+84j5ZIelMEnyj+mJIn2ZTzc8cttjOBRZoakD7DAq7KlGF3iZNJGfnsPryp hVQXgJwbTdJ9b5v1hOxuayMaqdV1SGSAVt307Bj3vSehmww2pwxTSucuRY0tbdgR3nT6 PEk7FoFLoe/jwM1cNwVIOCLoCsrWEq6X5xaRGPsNZru829UvBDJDHKIbkGqptEWBe0Nc UEtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yN7KMJk/"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-87931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87931-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j12-20020ac85c4c000000b0042eb87223bdsi3178791qtj.621.2024.02.29.21.37.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 21:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yN7KMJk/"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-87931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87931-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 008461C20FF8 for ; Fri, 1 Mar 2024 05:37:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68EFE537E3; Fri, 1 Mar 2024 05:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yN7KMJk/" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B48AE524DC for ; Fri, 1 Mar 2024 05:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709271418; cv=none; b=Efr6sdheOtF3iqmS8mAQBxWx5DgFQk4OFMV+UWd8sFzlXFUlh07UYfdvwj2QKNf6z2URytk3CYWxbms54GT/Xi2sJZZV6funUqJ9xYvw/Rmbnvf8W5HHgy1YZTwe0U1zaCNTeqkC+6Q6x6AXnLYjYa+ooBOpz8pkhHNsVCfEHt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709271418; c=relaxed/simple; bh=soASIs7D8iQcX2U2s2M4JC6RaqIvyHatWg6UktdKnSI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=H4YqecEeGXRwKqR43M6kApAMjx05amQfi3IonNhTM2nGocxWUURPlTTI1rp4eLRwrOzoHBoObMkfkVSKZCX5X4Y7PpihUwaH5HgyLgLClrvjzX1hsAW9YIyWRRZjVSvx5AYY+sZ9umzpXlWLkUSwB7/7Gy3MYJaMdy8j+/o2AJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yN7KMJk/; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-607e8e8c2f1so29944327b3.3 for ; Thu, 29 Feb 2024 21:36:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709271416; x=1709876216; 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=eHNbX5Xyi/VqeebJOw+lK9eWaYZye24FQe0AyXZlgyM=; b=yN7KMJk/IHZ+SdUXNslVSy2elnT6d/xwvd0JH4r6vu66eSR5ydG4HVIi75O3BlwTNL Uwbo94ENq5eW5S90oqq09DQW7csC+fcbD8dqOhDKP+bAdOquKxYNlDsJ31AA4iWYxHpY W1D5+P9j0ImqaXsUgkbPKGJg5swOOEbWF1oFAqSRG8eOem/TFaqy555JwMvYf7qncDJW mI5KM92xfgaLSUDX+B0xaPBjQxAs6Q7kDh8IO3LLUEfRQIlmdfWFnw3ZChKthuNRBMV3 c4dy8zILmVp+xFYbA4kvg5SYvHtRNbJbPpYaBYqmP8yn3yAQfZ6+1nc3fNnWEp54qiX1 teIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709271416; x=1709876216; 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=eHNbX5Xyi/VqeebJOw+lK9eWaYZye24FQe0AyXZlgyM=; b=FTPQegILu1gsxmPtnbo4EjqimJSzQCvc5wJFw5Z7bxQNW9THP0RdOV6URwq9sPaKKV 9Dwu3f1PRU+KH9d692AJnwDOf2fEJA+icVTu5iPAJMRl/uxslgEPhVbmM5AAneXV2mpN ic+t1R+kFbh2ebQZlk5O/sS2Jqrdbu1nz/Y/oc47CfSy41FJaEIBAu0ONDkyOlfc+U+N KwOdilSyFU0zQXwps7DoWR8kn6heEgTqs22cNLMtxv3+2cglRD/XhxQVDkxZ0hCsuGlJ R4GTz5fg7CHA20gdaj6KonnUWAhs3oRU8c3bg4FNLEdTz8SEfGiWbUJYdjYs853eInNF qcww== X-Forwarded-Encrypted: i=1; AJvYcCVEjQUkwaoFf60f18mIiWN2g8XZwfKrj5XqWUM8GMVyUq5tuKdBtvXTBYApCYY1mT/tRcimS+jUYNkH+1e05OFKBWof0zv8XJMg6rMh X-Gm-Message-State: AOJu0YywelTtjFm9mOf7gs7neqOj8bxSnglr9EfU9Egzy3yUOYM1vE7W nJh6D0qAZIGl9yszksspJamhRmIaUi1aG1MVWuEGfb0ZM48w+NgNNUedKS/bpySo2SEaeiNKeZ5 yExcXpQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a81:9950:0:b0:609:4d6f:7c0b with SMTP id q77-20020a819950000000b006094d6f7c0bmr114933ywg.4.1709271415925; Thu, 29 Feb 2024 21:36:55 -0800 (PST) Date: Thu, 29 Feb 2024 21:36:40 -0800 In-Reply-To: <20240301053646.1449657-1-irogers@google.com> Message-Id: <20240301053646.1449657-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301053646.1449657-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v4 2/7] perf trace: Ignore thread hashing in summary From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Oliver Upton , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792301032473406744 X-GMAIL-MSGID: 1792301032473406744 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_ */