From patchwork Fri Feb 2 06:15:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 195589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp238269dyc; Thu, 1 Feb 2024 22:18:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9+8mXmjQeQJybrQGe/wX2CtEYNJ8bEGZclicboK8aYBtLXnv+1tMz0QDsE7HHXPUUzkFW X-Received: by 2002:aa7:c0cd:0:b0:55f:eae0:17ec with SMTP id j13-20020aa7c0cd000000b0055feae017ecmr799320edp.22.1706854710554; Thu, 01 Feb 2024 22:18:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706854710; cv=pass; d=google.com; s=arc-20160816; b=GhUtT+u3/MOBuSrKCM0R2cOQSNvkMdXcHqp70xIk1nf7AlppT+1TvEwlVl1EMkpzvy 6tAil9sjBpuP4TVW+WGe9/eFsKDmPCUxMT8IUd/3TAWpvpi7DonUKdUXK2eJK6E7vEaP 8CgzJ0w3on+gwzEvhDjZfk+8wPzAy38PcHEAVsJzmVaBzhfKhtJTW/yGty9rXwLQwfqy 501dFNtQwmr1anyLlvWA3nBlmsR2cqPessy3J1gLnrjXBgoFq4twNELyBlB44nLwJroB UGTovKU/mQisjGasbI3PpwnBupbHCexbs4PDMIO4Y3PF4msPLS83gu4NQe8mHrFdvxnn MoBA== 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=tJud4au3Z9PjBuOB/8R+QNGS64GphjM5sRn/EZb5fRM=; fh=nSG3W/6vzARscgUZP2fyq4aQ4tt9BizlnOUuAruEN+0=; b=PZAvF6ufPOtQO/sXntF6cxMsTQ8C7iCc7TOY4gAgzu161p/nwjIVV51rYMEZAJPfbX 64lx7Hh0xy6/1DO7EyJoBCOwp4vS7HpFvhnoqD05OIuju0m+nFD0c5g+p+B4wkhgtvjv VKWIichaYrGmS+NQ+yzDzxtEv4U7EzrLsiSbUHLa4i5VuyWo9aLLxEd2yZwhmLqNSEUv 0PwUa5AiUXVSbDypa3acKSYVx9wzw9ydVpxwZ0VJBImDebtRoKzjEITyJ7ubJmISeBpR 4DhyQkSv+cnsxatO0vVeHDdb7GqOKFfj3fHCrK3rkkv/FLgbG2BtwnntlgNACHCpup6q jxjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bwIKQ4lO; 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-49248-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49248-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCV74A3vYD6f1bEygC1Ur0eQOYeuVURtpegLCVC79Nz+vpAwM1l9oOm6PTzUzNXv5JDR2r/VrM2rnohcX817KrO6+aV98w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r6-20020a50c006000000b0055d0a061200si521838edb.21.2024.02.01.22.18.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:18:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49248-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bwIKQ4lO; 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-49248-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49248-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 00DF01F23664 for ; Fri, 2 Feb 2024 06:18:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA8B81A27E; Fri, 2 Feb 2024 06:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bwIKQ4lO" 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 3588618651 for ; Fri, 2 Feb 2024 06:16:08 +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=1706854571; cv=none; b=IY10Yr05jNfhVm7FJK9tQ2gskENBtech51/feaaObXCrmPt8jUmBkoVkc2cTN8ap3kgI4w1zLSlODaE5JCLszjCfWpo7oM0aSD5kAksNlBheuzzz0ll+Of0Bv/1uqtrKPIActQUugYz19JTzIENnMQHUxLk/VK5ff6xFE0w8ljs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706854571; c=relaxed/simple; bh=BXiX9gzQs5k0E5V5XLiwe7g8s/r2aLi/zeI/x5SxZBA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CVGx9ZnVMXYmRo57ZbqZDB3XigrS+xH9KfyIIcdkLNZyVBm27yNTRbDudgLi/z9p4bQPBmUTb17NuKCKDHrOyipRwTkefvrt4jXJZGL1qYJuiQ0uajave0wrn4csdv6sGQWXaZsaLmGhfFLPXVgosbom3lNU98JocPXLTe0mznM= 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=bwIKQ4lO; 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-60402c8d651so28172417b3.3 for ; Thu, 01 Feb 2024 22:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706854567; x=1707459367; 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=tJud4au3Z9PjBuOB/8R+QNGS64GphjM5sRn/EZb5fRM=; b=bwIKQ4lOnlXCNbe+z4MZSVuDTdCQLKCcoWXtOf/mVaHtk6rKX+hW4+Pp2KygBDj0fc MBiqGQj6DEn9O0GZbgh8mlw+fGkwArNnZOZnN108ePq5b8tpcCiRo60+d0HE3+vU6+it wBglhEb+W6MqKDlqff1QfYe9piq4qUwGYOU51yG2GbYK9Y663A7TjxCb24ROcLv0LtoC btqLaggyRUqBW7A/VcXIRtV00DSi1rWPKq9gcFrzwQsxV6NK7O0JOr1YLBYomP9B1gaG AZHWkWLGehH7DPT+a09klMs3dIq5xBUd9rRIosL598TyECrz72EPeraE1Btj5SIYZZEU M0GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706854567; x=1707459367; 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=tJud4au3Z9PjBuOB/8R+QNGS64GphjM5sRn/EZb5fRM=; b=bZ4l37S6FPQCCDX1mZ5PoLaQF/R5VvIs/rEfOz5Yqp4p1o3J99X/8oazn06g6st6EK 0hGFX5mDd0KQKyFwblRCP6P1N7kcDPeYiruVSFc4MisJeuyyjK2cKTj6HKytmBEbPtPY pyLhUE2YuZvxH2/iD+/ndV1afvKClCnO2+QAUdMxXHd+/zlimTy1cu7xlUBnwQbjoNiV H/9auBTyDrg52k2P/gsrwnHpUrO1oLscfWEOLgr1pCZUXGc86SzdZ3gNI+TrXneJUOqa InKcuIpkuKEhPAwN4bL41/czgENoKiEcN7qrHAa3Kty9jbQ7wtSaodQ4lkhGYzVAY9u6 gIPA== X-Gm-Message-State: AOJu0YzkpH0nuwuNvBqoaMyFsaMROZBp3mkqZaFx18ia0RI1Nvf6USjT RI7Hmkwr0MkTb42iFGnXNdLBR2bpF3s5LPDByu4K/nkgHS0J6HRpBYc4nl00Qpm71SS2phE9Hzs lVog6DQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a85f:db1d:a66b:7f53]) (user=irogers job=sendgmr) by 2002:a81:9a47:0:b0:5fb:5605:494a with SMTP id r68-20020a819a47000000b005fb5605494amr777271ywg.7.1706854567242; Thu, 01 Feb 2024 22:16:07 -0800 (PST) Date: Thu, 1 Feb 2024 22:15:16 -0800 In-Reply-To: <20240202061532.1939474-1-irogers@google.com> Message-Id: <20240202061532.1939474-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: <20240202061532.1939474-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v8 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 , "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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789766885182470103 X-GMAIL-MSGID: 1789766885182470103 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_ */