Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp382682rdh; Tue, 13 Feb 2024 22:38:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUUqHJXLeUlW7EbKvDuqv2ga6rK/69ItIazYtJXv/he0Zsw5Pu2QBdON9AVI6DyXVjwhOB6CDLOJDEcYEr9ZcPJyFyuqknvYVK4q3Pkhw== X-Google-Smtp-Source: AGHT+IFYxOQu/qeoIxIkz5lzoO++wSw74cOFgT2OjUTsMec/vVTf1Evdb2GR8aQ77sW8G81Si3mE X-Received: by 2002:a17:906:5fd0:b0:a3d:5161:515a with SMTP id k16-20020a1709065fd000b00a3d5161515amr308546ejv.36.1707892721226; Tue, 13 Feb 2024 22:38:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707892721; cv=pass; d=google.com; s=arc-20160816; b=pOgzo/xH44o02rTZ1yr0KounkwIQ4WwOeGJnbTvjcF3uB0heN2FeEiunEHftFoF0Lz jN4oRhHY86YTwr7k+IP9c0aqWHHurmfdlHPfJRDHbv+DElqNZ5vJdUwsB36wOWjxZE5B TBfdN/oKozA4GlED+eJ3gLWbj4jQTbMlefnZLGLwsm/s7WvXjOeX8LZDyNpkvb+t7tth hzxonHY9pU3/hEceB5C93D+LTcnigfTAd8NMJyLmKiFAlkP05+4+hvUvrYWP1PynXcU2 M/HVBuA+XVMqLOskYwHt2RAi5n9ukyOYR7RDSg6/hQ2pqqRDvb/R3iNt9rl7PS8gNpvY GUww== 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=VZC75fzSKnLOcOdvEmiJR26JJ9Cyn2cw2nBv54DIcSM=; fh=loitugL++I2gONRw0dX6QjLcq/fQizwKEdB0NYrQvVQ=; b=Og515Tm5ykjbrCu+Ts/Iodo/R0pC8l/YPE10QonSGTCepY5+P9GBce8CEA2ZZZKQ/e R6Cv737C14hkQn5+IF8I7kilza8uH8sUTzs6O7MYMs8z2qlGANYbrIFVqqMiRWZBmmJo TKalJIU3oNKKomgBtSu8Bx6ecMc2epVhwH93eZLfcixEgg4VJ8iPyoYSm5w/M0WZgWmG 0o+91p1D0DMt1vy4H5XIKu0o1A5BXbrioauq4oGyKpySJ7qUAknDQ0vn8nOkp6A/p9gT 9oyolYyh6FQ6xUCFgMBZpwJatCuA25Uyow6Gugaibo2hpX6YXENiYvG6rAL7LJS5TJh0 OwYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Y1ONCkJ2; 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-64797-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCX3XI1aDQtxPRCOhHCHJmWMtohIiO+ZaP8tmcRz4UM/iZF/eI6IMWYIA74LWOxjDB7MVeU41Q4BbOZqgLOaqAbBNR3gx2JG9ScMbhQaWw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b20-20020a170906d11400b00a3d52681373si182755ejz.805.2024.02.13.22.38.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 22:38:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64797-linux.lists.archive=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=Y1ONCkJ2; 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-64797-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64797-linux.lists.archive=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 C49A11F21C7B for ; Wed, 14 Feb 2024 06:38:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67F1F12E44; Wed, 14 Feb 2024 06:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Y1ONCkJ2" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 AAE7E125D8 for ; Wed, 14 Feb 2024 06:37:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707892648; cv=none; b=TJoBxJY1Kl5CALnRqUdI0qkZ4jjra+tl2lPNurAWDQRAkAynZ6npq5VmuZJiseIuag2C8E06lqSlcTZefS7Zgs9r3AC6BLszKX4NhfrEQGvZ2ICDk437D5Z+DaJWh37fH0FF019J4TBU/XT7Ea8gdgsDH1VUjOA5wQoCv0fokeE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707892648; c=relaxed/simple; bh=Xqgs303n2TD+hO6ata6FdmAxJD9pFTCMplqiFePigLM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=szM9k9MxuGwsrH/MXp3xDLZ3DuZodTBnUkkOFKLgGAPXoD2TJ3A1qqIAQIcmIAZ1j0OZtMFJXouE20UvIpbIXv11IxlwW8z6JWuIJZKizln8tXKZF801L6fYa6WXfXU+/3/DB88IML0E86IK/11161DXSy7aQG0JigTqfUXMGoE= 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=Y1ONCkJ2; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc4563611cso2980463276.3 for ; Tue, 13 Feb 2024 22:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707892645; x=1708497445; 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=VZC75fzSKnLOcOdvEmiJR26JJ9Cyn2cw2nBv54DIcSM=; b=Y1ONCkJ2OAX+WN00azK6e3AHlxqO+fHpojweUxt07+clWH7PSgGrETM9/2sm+KGohF 0jYRE6Qj+uE1CDzkgbvlGsM3QB2yHBfOO/Ah4VRhtBYolaqAhxXu0cQMs7UVWUP9rfy0 yiSxVrNs2SS+rWNSdx934q7umTgZdzeBr9/2GHsdG4avcbR/LdG00G3J2V/4gH2hcNYt vjYaQRCaBOC4X267+3I0y3JJikfpqiJ3wMUfOO7BPQ0zRLkJm45Wj63zKpkDFb3+j90a YDlxWMlzmhSDBNc//O2H5XN0ooLn1MwxjK1J6fWRSXiA8okiJdw3gnSkbayNSt0FaDJB WdVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707892645; x=1708497445; 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=VZC75fzSKnLOcOdvEmiJR26JJ9Cyn2cw2nBv54DIcSM=; b=slYHfAGRMOvgO6RL49FLCEYkDk7ihCGDWr44y7Dcn2qhT3GUL80h8a/hfL0JTGj8Nl CQi0osrSQODzK3LdKqVVfa25UkD++yMIdWwTFeo99mP6VOI4MfWl7qxrPkKFPAPfV9NO ub44xo28q8ddegnpNtWPnSVApWKsovkkTGwBsbviyGBeLyM/ld25LW5clj1Js74szYQr rAs+Y0n/8Nsm4zzkv2/IG5K9pyZH8TRNF60meXHzTNdfc7YyyE21R/g7UhhMGIAQLLhz v6Ogn4glmeJhyC38OiO4xygj8VIkTnNfJp0pYqV7jDNgIwYc98Ej3anV/wpZVPp7l/lJ gjTQ== X-Forwarded-Encrypted: i=1; AJvYcCWsXS3piuRd/0iCC0YOcvl+G60jfFhgUQzWgsSDhBQvbLw7PCoMFHPyEAP6u3jQg2bM5xgUCBGzZj4tIItWEtxQwWS2jfL5AwFa5+rm X-Gm-Message-State: AOJu0Ywldk9I4mqVFMNx0TVJWJro8SuLuYOHcVQ80ecSqgGckW2wp8NX OHI7jnoZD/dPi0mIMsdafHLNbrTllbFH1VBpnJ1WgW7lmhXoN9870fApLL23LIKIpnzWR75MTgl NfUv/6Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6d92:85eb:9adc:66dd]) (user=irogers job=sendgmr) by 2002:a05:6902:114d:b0:dc6:d2c8:6e50 with SMTP id p13-20020a056902114d00b00dc6d2c86e50mr330849ybu.7.1707892645603; Tue, 13 Feb 2024 22:37:25 -0800 (PST) Date: Tue, 13 Feb 2024 22:37:04 -0800 In-Reply-To: <20240214063708.972376-1-irogers@google.com> Message-Id: <20240214063708.972376-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: <20240214063708.972376-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v1 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 , Oliver Upton , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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_ */ -- 2.43.0.687.g38aa6559b0-goog