From patchwork Wed Jan 3 05:06:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 184610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4837434dyb; Tue, 2 Jan 2024 21:10:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZrJU9z6U2f6oqRs3U5fwcBiVMuwV4zQyGlQKpSg4YJvx6wdqOUP3wd3cGqHPrUH4KGo9Z X-Received: by 2002:ac8:574e:0:b0:428:319a:2577 with SMTP id 14-20020ac8574e000000b00428319a2577mr1935563qtx.112.1704258601765; Tue, 02 Jan 2024 21:10:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704258601; cv=none; d=google.com; s=arc-20160816; b=eiTxM1rrsrgCL5nsM40lgvLJh+XL3+WV8eQkQjkB+WxkYtXN7rCVVQJoO5GQLxF1Ot g/I5WBWJ1At/Cg7K7dWPoh+y7FSwNrVHlvpN/DMOSCg7EIB6p5MvwaRF/I4g2jt+YeC9 2E1ggrT1wj2AIaZzbL19UTTjBvMPXK/5mtElPrX72Prs2l/YxmXVDbVauLctpxdU8WKw dlw0j3lvZmLUJNCfCHvQukp8uhgN5XuIQZXBQB2nG64J/jfG6zV/8vIPJ0PZCxkUnkKR QioRL25mmc7/kBU6FZ6V6Q7k/ZFABWtO8zsz/03HIh9/2RRXBixxpe8uPBjNVBPVU03I 7r2g== ARC-Message-Signature: i=1; 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=PLBS0bfcXDysRSFRe9D62doHa12DeA2H7mxGFwgYFqE=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=FxCAoTG+MAupqQzTnxECi/MxCFVasHJXXeshqTzcZKDAd+QDRBZwqiY7BjLECn4c1j bIGhp0Kpc6QgujWypqfirpkRKHJF2r1rXEmvoW7eZTTBQAFjWTuHrLSYT1bRAQQtdoCo gaAIKwiSTFkzhOdc4Nzw5moNQ8E/Jh9lrfuPfzm/HWk5/j2VyiMcRxmN8dQjXj047ftQ YwV1Fiv395rvpnUMvpOuB6yCrrHCkQ81BrdIIWNyRYW3MlpIdrpcMa61hhLM+mxzLTSp 4Kuw7Jj0GY0yZ5KBTuPtdc9TvXgMHen3qP13FQnzitGCRETxQz6YqkuBPnQtdLc5m3kA pyyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FXDcze+q; spf=pass (google.com: domain of linux-kernel+bounces-15168-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15168-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 fy25-20020a05622a5a1900b004280c1bb425si9870373qtb.411.2024.01.02.21.10.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 21:10:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15168-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=FXDcze+q; spf=pass (google.com: domain of linux-kernel+bounces-15168-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15168-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 4CE031C21976 for ; Wed, 3 Jan 2024 05:10:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CDB818E31; Wed, 3 Jan 2024 05:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FXDcze+q" X-Original-To: linux-kernel@vger.kernel.org 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 812A718C11 for ; Wed, 3 Jan 2024 05:07:08 +0000 (UTC) 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-dbe053d5d91so8320812276.2 for ; Tue, 02 Jan 2024 21:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704258427; x=1704863227; 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=PLBS0bfcXDysRSFRe9D62doHa12DeA2H7mxGFwgYFqE=; b=FXDcze+qVZy522orh8e2CNjCeOKqLdLyM2wzuqZcTRnTofC8GwSBSs6QNQhnGryE8R wZptsQZ0dcH7vJ2XC7fcrdPN9UzF7+b/zZTlEzikF5v8q0bD9eZdulf+TAjXjT5WxiKN lP6AYyQTUhy0pFv2sPmrBuO9jtvQOAkBw+RRhwncGPjQsMqgVMC1UIsa83aaHw59EIr0 03sUw+kZA1ZfI3jCrimUuZkzp1mw/+t/l3Cj/CSk8I8BVnRcLw9E/b5g8GspUCp8gscD aAVmnYT0cIYCRcUCSpwnT1+BBDwjcnn4eZaL6/EqCX2BwtnmCOVHuRSPLiJfN2FRSPoo yxxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704258427; x=1704863227; 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=PLBS0bfcXDysRSFRe9D62doHa12DeA2H7mxGFwgYFqE=; b=FhdYOBdOrWd+AoAB3zkAK5ISUYI5wdIw5eIOGmh6Ot2ujmz976VQoeoNsiLOq99/sa rTTcSeT3Fw2v5KjpjBUALjzcy40Hio2OwaVmHfGjT46Onq+4np/y7CXKY1SiAxx7dY5T zGys+U2LzmisemVsIZu7LK2QUAJ6QxlhPTzzuBE1TRlHBWRa0jWDJLSGSayJfkr0bUmv Dh/7X9ON7JhOFsOltAFI9DF/bHf3LH2mj5PWEqXbaHHtZtpu6pjRQHEWD7HgPRyqVKbS xcbDG1xEgPfXciVdS3VC93A7wwjSVD3dr/J1D25nYvFaxpgQDMfeOYeCeUVBEAoxWS8F C1mg== X-Gm-Message-State: AOJu0Yx56Pv2GcAzMBGjkxKZsYcwUTrNKBbhVboahKQpcampKoP8RlOy K/H+Az2t/thVrRekBmdnaImZEob/vreQyHUWf60= X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e2bd:f1f6:8ea6:8d6c]) (user=irogers job=sendgmr) by 2002:a25:664a:0:b0:db5:4766:e363 with SMTP id z10-20020a25664a000000b00db54766e363mr7354854ybm.6.1704258427453; Tue, 02 Jan 2024 21:07:07 -0800 (PST) Date: Tue, 2 Jan 2024 21:06:19 -0800 In-Reply-To: <20240103050635.391888-1-irogers@google.com> Message-Id: <20240103050635.391888-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240103050635.391888-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v7 09/25] 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787044667794302094 X-GMAIL-MSGID: 1787044667794302094 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_ */