From patchwork Thu Feb 29 06:32:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208212 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp209585dyb; Wed, 28 Feb 2024 22:34:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXZjFHMEU1vwGmythbFjWM4Ez83aWrJlXNF8tAzAQfQqemXBAwsyRyHfbDLgm+CVUnXDL7HS/mDc5iMydUNEzZRYAQ8Ow== X-Google-Smtp-Source: AGHT+IEJQnWVuU8msITsQRFoT5GnQ9DMVGh/ASaB3pii0wfuKliQ2+iIyCrpjJaqxqoxqL+e3WHe X-Received: by 2002:a17:906:6bd8:b0:a44:44ff:5dd5 with SMTP id t24-20020a1709066bd800b00a4444ff5dd5mr446618ejs.21.1709188455626; Wed, 28 Feb 2024 22:34:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709188455; cv=pass; d=google.com; s=arc-20160816; b=Un2TPRH7Cw9Rek+2L5JIiUVkP8wnF90HzRapuDzmzToHbBaiiujpo12LTtcUEoJgTD hT4qQ+baHGfUmBJmWqlLUvlNbs9uSZb05wy7zhX+SBT1K3lda7jsHamO0B9nYEs1PI92 tJufh2w7dbyn0fc/IHxMXfFKlyD9cgClkWyWlScgUGcOx3+Djtkfk0DZggLyUkSzhxUm Npk595zdkZFkDX3GOXKWpLZViVitZ8d8/u+/3pb2KbuJdxs7KGhoAQbVlxQfnBQIL+15 vr5q0M3v6gn+Gn/qnKRxlp0EhUbmmZyWHPWxXaH4itmF2u+hzzPL1dqCqgAJVOUsZNdx glYQ== 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=PNUKULeG9/C87hYSBckf3Qqec26ArMTCNQSbpXWGPLo=; b=CtiLxux5t2pLKLkEVI1F77T3reHgAIw6wZqhDvE24wB4Fh+PdX2Y7RdxdeUwI3zkpJ ZZKm5l092MaC9SVEFY2gVW4t0GJT+GdvPDWNdz3a4fsp3Y7YF9E56KrUrwpieK1WoNp9 0+exgmyze2xhmXdhpmEFouNc07u4MY05VHjSCYukVlhlD0JM4oi++K2YoIYLFDmLZyJt YaMfWruwuKSXCL3mdfTESqI6bZojGOwfw0Tb0zZzQywvUXbOQG8GzymT3NFyZmAI2mmy RQjdATOg0hf7UoPJXBnHdfDQrA+xBAUF7dfu0pLKOoEHB/CIV/diM4B5xPw9GXKEcxM5 4Nhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="si/v60O4"; 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-86173-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86173-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p2-20020a17090628c200b00a430f28eb9fsi298893ejd.323.2024.02.28.22.34.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 22:34:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86173-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="si/v60O4"; 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-86173-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86173-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 38B7D1F231F0 for ; Thu, 29 Feb 2024 06:34:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1E71446D3; Thu, 29 Feb 2024 06:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="si/v60O4" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 DE45036B0A for ; Thu, 29 Feb 2024 06:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188387; cv=none; b=N7XJ4qmtX8SlG2tXkviw06WHTraG7UafwyAI9sbMMiSnVwcNIpbBN+/NXwCEkX7lfahAuBY952+US2ygZxemB0FosecCtIDZnH39RUIPZQ0SI0ZbVs8z1lmCqL7lQGXIyhWrI/10O4hFhxumuL0X87MuUnKDgXGaxjVqopPlHNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188387; c=relaxed/simple; bh=soASIs7D8iQcX2U2s2M4JC6RaqIvyHatWg6UktdKnSI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jwEpkgqlAo0ZTIXRroAIlBGFW/jCSkbsRhqTNoht8tWUd+alEmv3RA17dfg5UuTmGRNidWueRV6RVTEfh+JlI3XFkRaQEDNuoV/2LAuwxQehgvKR0+pd5D435nhpprMsvKOr4rEsGOmVlDvgruBi1JwflbAljfl68DGRemTaRtg= 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=si/v60O4; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-608d6ffc64eso8227417b3.0 for ; Wed, 28 Feb 2024 22:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709188385; x=1709793185; 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=si/v60O4T4V4NmN75HXUfiMGRA9yqMoIC6MhzoEKci3e3TsIm5gsdGpa2QMiFDMMl+ zM0a143rYO7SbCCbaaVEspF6PKF/ZyIsiFkXMLpc0KCMSMMiNvxckdBRkvciWMeJjaUP IM2M6rrVRWWTLLZkF75NcuPqsdCstzYZSJLk7XgJZ1pSe1Mk7GpohBbXTJwiq2nVRg29 V61ypgV4lCsIAjylpjlcNsevdSQoByXqhwdSzF3FawkaR4jYMm2X0yOf9tCmkB62JWJY nk6E+A6le+CAMBn36CeMfaxP6V0Y1w5jZB7u8rOwIg2P5UTESCLjcF9Cbm/snbySb+vU I3SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709188385; x=1709793185; 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=Ui+v3lhhzDBWvxZASAGx9p03TtIvb2ftEw/hRvDjaTQc/83Otu58ArpBa1XjEYBD/O an0sWRzmSwlmGaqsMO69azpxiv7dDQdNSoVxjaw86ZjaBf4OrkwB0xbKlom4Z9wbaOcI IA/+7vxCLDUHnWzNeZgv+EsiH36NjZI2uk3jykMxzLrSjYdjwTqgqlsb3aj1JrSfIX0s Ya6XXqf69lPXsK6/HI4Qb+ba4sMOul4bcJ4WCeNwCFAn0NTOADLV9uraySb24EyIj8cM ra8n5Rb8rGv+U+ZmAkeAjccMq1WlA4V8SDruGHGp6+eSKit+0JtG15Kj97vIzh+2hdfM laJg== X-Forwarded-Encrypted: i=1; AJvYcCW5oyZuDPyTekv8i9HTFyGo0QFI46mlqO7cDEjFbfb+odRM1Ke0LTX2mgjIheE5rHVjRbWyh0xJh1eWYYwMKaMJj03I0LC0uP1e5htZ X-Gm-Message-State: AOJu0Yx/XM8iuhh3RG7gPx5KW6AAbWYRim5lQYDCPPTd3sutz3d1bWKd uljIPMw5jWjRH7ABloC0krCtLfeCRs/s6XD0Iw64wapbp31QKatTtCOjoVnRrSOvdg54gsh7sxv Eoi1LSg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a0d:c346:0:b0:609:3a1f:e852 with SMTP id f67-20020a0dc346000000b006093a1fe852mr169734ywd.2.1709188384986; Wed, 28 Feb 2024 22:33:04 -0800 (PST) Date: Wed, 28 Feb 2024 22:32:48 -0800 In-Reply-To: <20240229063253.561838-1-irogers@google.com> Message-Id: <20240229063253.561838-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: <20240229063253.561838-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v3 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: 1792213994220854534 X-GMAIL-MSGID: 1792213994220854534 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_ */