Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp558929rdb; Thu, 2 Nov 2023 11:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7abOg6DVydn1GjDCmA80GkvxriZW/xOudfQ8uRJ0oWuCUSkfok2tt1UrQN13PK8Rsa+XH X-Received: by 2002:a17:90a:f198:b0:27d:60b1:4f2c with SMTP id bv24-20020a17090af19800b0027d60b14f2cmr15934566pjb.4.1698948369300; Thu, 02 Nov 2023 11:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948369; cv=none; d=google.com; s=arc-20160816; b=iiAfsVpILfe+nGG042t5hWpqiLe0HCmzL7X30ZOTMcNeFGtDOfTUIsxsv1mkxJSH49 lMwzUJTohibT9Sf+GzZarpZo4So64/qOnLB9csnePT53jzy/ct3TW+VcrxJlYnccM2zd Y0pcli3NT9Lo0FZ4gtL2H6Gt13myhZ9PX0oz/53ouaw9ey08PwLZasVFkS7RoeZVHtwl yF5n237Mfq5z9uC0rdgzoaJ0bJ1xeEV/1TG5rg+9eMOPjOL1ewptJNODfikuDcBUnfKA kWIZcDYx6HNiWm+CwfbGMK18PtM5ZSjcDuDMGd06xbp4RyosMGpTVqXnNiPfPoF/WfWN MBZw== 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=P522BWcPedC1rbHa5TGjvOW04gaVYccbN3SjyINhw4g=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=yePM/HEMYIwUKB+01Z8MjViDc/9HxIQU5vdZ3oLj2BGxi7utv1uCOQpKGHIGQi1i5d xMvEzwIO9DSMCPoZ+gv+LuKzmL6fpO6SBIfgfBhUoq/5xxMZ6ZJa3Q3+pxBde0Sq3D8M jkX56RD0c43FKeOVdxZt4moe9b4Y9kkahAp7G6yq4zq1vaIVcUrJ3t4uxPJcMQPA20wf L2BjcTC4XpPA69KV4YMmFCJkrUrdxgZk/nk6PAAguqOr1seUSc+JBNfriF4+S1LygGAo YNagDCzFjFM1/YYb/dN2dTtt0G+eHVhIxSDoefzJ8z61fibIzMfIRDqI+6ZnBT1LFODD BO9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=boxKydr7; 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id lt13-20020a17090b354d00b0026f4d1e6940si208015pjb.160.2023.11.02.11.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:06:09 -0700 (PDT) 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=boxKydr7; 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 8624C8135BDC; Thu, 2 Nov 2023 11:05:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233906AbjKBSDf (ORCPT + 99 others); Thu, 2 Nov 2023 14:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235549AbjKBSDP (ORCPT ); Thu, 2 Nov 2023 14:03:15 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976371BD3 for ; Thu, 2 Nov 2023 10:59:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da04fb79246so1435961276.2 for ; Thu, 02 Nov 2023 10:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947959; x=1699552759; 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=P522BWcPedC1rbHa5TGjvOW04gaVYccbN3SjyINhw4g=; b=boxKydr746HE7NlHswNdVShFgInZ1q4okiUpW72Pa+tTtsnfMahNNc6vypcBG78BSW LM4rIAoGwjNoKAZKC0Nv0fGOf/TekYfqTBxDJPzy9ivW229NMYNIfu1DDzsh5w6l6kK0 OxMWT8MW1pWbFkvwCKZB8NdnAGccgVYb3lXELkNQHDREugtTPSbIruPmOBIAylEcO2Rl PE4EilM6p4Xq2kcgjDaSOsjFPVvya1oL0WoLcOqyrNoASblCvn4AZFVjWjUcEBeLO02Y 806hFj3v5ZKdhRljhQn58jXu5AltbVUkG67sWHUpMj5/6Vspz1jBUh5p2Ev9vnXhrmku 6sPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947959; x=1699552759; 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=P522BWcPedC1rbHa5TGjvOW04gaVYccbN3SjyINhw4g=; b=D87W84N/+ZKMF76/x6ATMf/+2cRzVyVu55G2neb/tCbnhmuxmq1D71izQEiSbxKj5R 66hPDrAZZkOYX12TUipR+8PeU8xa43Pm3d7dRgVIH4DwCg9NzTsi990p77ZD6k8ODi3q DvJGc+AEpVLnawuR3F+9HjwVWkwHZdleh0v1WHDOQbUvVJvJXhdIKI6okecWg7QKxJgx JG/hW4nZ/UsTNaA/ffZu2DpwsHm10pd6v+njM3kFjlVB6Nwyf4E6sBN4Gh5XnkH0qvYm hcrM4sEo7lnAhfChjxoTS++Zdr4PyoZiJ61as/S/teChw3QdCxdL4cjV5oJTgvDKvRN4 NVwg== X-Gm-Message-State: AOJu0YyeFfNxtC9LFC3znNfV0e/mjLaF4mv0ODKw21pqpv3pY5mebKTP H1nSwqOfy6pO/iPOFj4fzHxaLSpmAZ5i X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a25:7909:0:b0:da3:ab41:304a with SMTP id u9-20020a257909000000b00da3ab41304amr137736ybc.4.1698947959039; Thu, 02 Nov 2023 10:59:19 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:18 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-37-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 36/53] 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 Content-Type: text/plain; charset="UTF-8" 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]); Thu, 02 Nov 2023 11:05:01 -0700 (PDT) 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 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.869.gea05f2083d-goog