From patchwork Tue Feb 27 22:01:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 207460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2989528dyb; Tue, 27 Feb 2024 14:03:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0qw7iKMC1pOrFtlf3qjlltjB5TGaEqQQWYLp6KrqTqls2MsfuE91VJ60L2DfNzLvnI+PfK5jppjuu7flP3HDINaCFiQ== X-Google-Smtp-Source: AGHT+IHEYzjC6uKBYxqAx6sv8wnFC85LWE1im+SuhuUKGBCTniY+stRewLwfmrJy08+zPZ8BwJQr X-Received: by 2002:a05:6a00:1ca4:b0:6e3:b4a5:4b53 with SMTP id y36-20020a056a001ca400b006e3b4a54b53mr11457265pfw.24.1709071421874; Tue, 27 Feb 2024 14:03:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709071421; cv=pass; d=google.com; s=arc-20160816; b=drdbACEx+5g/U6zLednySEJ0F3YXJurCxGpOhz1+Y+uyNJyCcpYVwUxn1KVATDu9aT eZSqYWIA1KbqUJ4JZCbvzJ7hbaF5gi7br9UohZZxnBsbb49RT6hYr/DzBmvsWEq8WD5F iTvBNU3FWDaaYn1j+Iz6lmMlJB9W6cYLezhEj/TBMExCY2eWI3aX9Di/hfo/A/kGpNUf qGsYG2S10eGLeQIq8266XLlrA1002GbO7gb2OYw/ywsCbA7oWn5UZyfDzQgLhfhYYcSo 6tV3ANZccMn7lBgK8NcBAk6hr9R9op3VeQtEFmWKuVY4F0QRfPve5lfaIhnJN2JfpjNr U88Q== 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=/FMLMbsrzbdkn9O9XsKWx3S12UuVwdsAjVLGeB/eBZI=; fh=KR8WpDK4eRHNmDZ2AzJon79UgK3uJAsB/I9iLRS70jQ=; b=dfy/U1muydd+PxlCEgnRWVSYDv0TzCBKsSPvu9nlNNmh2uVD6IUPAdVp6JraoRkj3Q 4lj16UiwuRC5/QYEsXbgSaibJ0GPe4c0GUMjxCN0BT578bPPIp4kxWTWrALpEJJvupT5 XCBAJ7h4WGOFO2U/C6BWrtd5V8ZHLCRoZpt6CdmbO3Bb4tCbE7n8RDKHdhhwh/2A/bVn 4eutyB1Gl02TDxd/+WiKC/22rznIBxuEnbNJW/3V6mQGNEAafMFJTM0VrQIkLr6ELW9J 1UIV6xeHm6SPJHqlRWahVt2TPLjBeioMv5N9RQS/MHVPknisjhd0LMZmPSmQJ+QXvAU2 F7aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2+ezsV03; 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-84081-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84081-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s39-20020a056a0017a700b006e5571cfb33si698831pfg.311.2024.02.27.14.03.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:03:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84081-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2+ezsV03; 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-84081-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84081-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4923D285E1E for ; Tue, 27 Feb 2024 22:03:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91E8A155A39; Tue, 27 Feb 2024 22:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2+ezsV03" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 006C8151CD9 for ; Tue, 27 Feb 2024 22:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709071328; cv=none; b=KQiNNqCEjICtn4Pz9ff/j/DFEcVtcL1gLSNFnIWLWcvmEEzCE52e1qbAG10T3WlE4U3xKDt4Hg+mK6BAWtMwmcjDaXNMgwd8vFZItLJ3IdF2tr4m6PDJmUibeKR5cgMwkm6T9xgsJpgjoIs2++VhQXHzFe0PvFMTGR7mr1ZEwXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709071328; c=relaxed/simple; bh=louA5ITf0PB9gTEbmjxtVgELJEkk9dAW1fzHeRrbwTQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=J3nS7AHnbYs4nGVEwpuFL/5+ViUMdl8/tMuy1L6A3Zxf3yTY7KVAT29AJ0KAhwDzB6SyPqMxgAypU6ZYn0ebEtaeywfohUHEM/Q1Icoy5FESoQcdQqtv06i36ZGh+iRN6wAJow3d0CcrB8J7oqCy2PGZS4wLwNeaKosKecEdY68= 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=2+ezsV03; arc=none smtp.client-ip=209.85.219.202 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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcf22e5b70bso8605973276.1 for ; Tue, 27 Feb 2024 14:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709071326; x=1709676126; 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=/FMLMbsrzbdkn9O9XsKWx3S12UuVwdsAjVLGeB/eBZI=; b=2+ezsV035YYGdi1fQZHX7QXaKBcwAriZoTOm1Sw5aUUGe11VbnONJEpYnrxzRBBpMI 7XnFs5/BAIKzXCWsVn0eGJd+XMsXToE666mzs7qrh2LvC75PUwEqEDOschKvFabrIwVw jxEXQe/4v763Le9x3rOLQirCC1CZzYKcYNum2o0SOEYRo77jGnEAMHGhP3dETMKEeifx wgXhasDLkcqJde9u5QKillgECiqwXCsabDYG/3BoETwLijhHQvLL2A6g9g8tsGZA8ciV I5JLi8SAN25d9vBP/m+kQh/+XxV+Vm66FEslpn8lo/GQJcm0iih/jKtsAhnIMbs5Dgkr 0W4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071326; x=1709676126; 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=/FMLMbsrzbdkn9O9XsKWx3S12UuVwdsAjVLGeB/eBZI=; b=OKEHgZvZZ6tsgClrVipgT1b+DppbMcnx2zfmpuepx9+9HWXE3pDejg6L/Lq4jj5ZXQ jzf+4Sp3fo/E+P2P5pf0dvNPGRVK2fGTJdTdkKwmRqBozJ7eq04qhbv8LGogLFq/L/8T qUVc4cq4/QyzZ8A+NR4hYGwc69SwL/gTa/QBTzFUhHD36jXhUnTnvTm82pvkZw41Wtku BfWa9A5hIKJqdFtpycW+VVOfXED1aDjbly9XqmIFpgbq/r/0zJ7kZaEhIDTUJvTUyKSD nR81OjFy2h/7QPcC39K7RyHD91an9wdNec+s8ejhsQiHhGC2noRXzR2vH1PqErRaEJa2 ChTg== X-Forwarded-Encrypted: i=1; AJvYcCUiKVt9jeu4bZHyAsMZDlCAPd6YQYV+xJfv9UADWnG3tIS+7ZcfzSE+EZkBhcobFrB9c+bPFqLCHa0n9e9qBaDa5vka0QynpZtT+rxy X-Gm-Message-State: AOJu0Yx3ca20WTyVUq315RaZX0VCgLJm2+Oso6rztZNBmBolOKN5DFzM pToj4TOP2P0R7RrXHguXmzFGtdiegeYOkdjGTvrsmYW3+YLAG/M+57KzI86c3ebV2QvjaH5ltsV EgRwYvQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4ff1:8af6:9e1a:6382]) (user=irogers job=sendgmr) by 2002:a05:6902:150a:b0:dc6:d9eb:6422 with SMTP id q10-20020a056902150a00b00dc6d9eb6422mr32279ybu.10.1709071326081; Tue, 27 Feb 2024 14:02:06 -0800 (PST) Date: Tue, 27 Feb 2024 14:01:46 -0800 In-Reply-To: <20240227220150.3876198-1-irogers@google.com> Message-Id: <20240227220150.3876198-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: <20240227220150.3876198-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Subject: [PATCH v2 2/6] 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 , Kan Liang , Oliver Upton , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792091275035654140 X-GMAIL-MSGID: 1792091275035654140 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_ */