Skip to content

Commit f178ffd

Browse files
captain5050namhyung
authored andcommitted
perf trace: Ignore thread hashing in summary
Commit 91e467b ("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 <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Oliver Upton <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2f1e20f commit f178ffd

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

tools/perf/builtin-trace.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <linux/err.h>
7575
#include <linux/filter.h>
7676
#include <linux/kernel.h>
77+
#include <linux/list_sort.h>
7778
#include <linux/random.h>
7879
#include <linux/stringify.h>
7980
#include <linux/time64.h>
@@ -4312,34 +4313,38 @@ static unsigned long thread__nr_events(struct thread_trace *ttrace)
43124313
return ttrace ? ttrace->nr_events : 0;
43134314
}
43144315

4315-
DEFINE_RESORT_RB(threads,
4316-
(thread__nr_events(thread__priv(a->thread)) <
4317-
thread__nr_events(thread__priv(b->thread))),
4318-
struct thread *thread;
4319-
)
4316+
static int trace_nr_events_cmp(void *priv __maybe_unused,
4317+
const struct list_head *la,
4318+
const struct list_head *lb)
43204319
{
4321-
entry->thread = rb_entry(nd, struct thread_rb_node, rb_node)->thread;
4320+
struct thread_list *a = list_entry(la, struct thread_list, list);
4321+
struct thread_list *b = list_entry(lb, struct thread_list, list);
4322+
unsigned long a_nr_events = thread__nr_events(thread__priv(a->thread));
4323+
unsigned long b_nr_events = thread__nr_events(thread__priv(b->thread));
4324+
4325+
if (a_nr_events != b_nr_events)
4326+
return a_nr_events < b_nr_events ? -1 : 1;
4327+
4328+
/* Identical number of threads, place smaller tids first. */
4329+
return thread__tid(a->thread) < thread__tid(b->thread)
4330+
? -1
4331+
: (thread__tid(a->thread) > thread__tid(b->thread) ? 1 : 0);
43224332
}
43234333

43244334
static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
43254335
{
43264336
size_t printed = trace__fprintf_threads_header(fp);
4327-
struct rb_node *nd;
4328-
int i;
4329-
4330-
for (i = 0; i < THREADS__TABLE_SIZE; i++) {
4331-
DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
4337+
LIST_HEAD(threads);
43324338

4333-
if (threads == NULL) {
4334-
fprintf(fp, "%s", "Error sorting output by nr_events!\n");
4335-
return 0;
4336-
}
4339+
if (machine__thread_list(trace->host, &threads) == 0) {
4340+
struct thread_list *pos;
43374341

4338-
resort_rb__for_each_entry(nd, threads)
4339-
printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
4342+
list_sort(NULL, &threads, trace_nr_events_cmp);
43404343

4341-
resort_rb__delete(threads);
4344+
list_for_each_entry(pos, &threads, list)
4345+
printed += trace__fprintf_thread(fp, pos->thread, trace);
43424346
}
4347+
thread_list__delete(&threads);
43434348
return printed;
43444349
}
43454350

tools/perf/util/rb_resort.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,4 @@ struct __name##_sorted *__name = __name##_sorted__new
143143
DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries.rb_root, \
144144
__ilist->rblist.nr_entries)
145145

146-
/* For 'struct machine->threads' */
147-
#define DECLARE_RESORT_RB_MACHINE_THREADS(__name, __machine, hash_bucket) \
148-
DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries.rb_root, \
149-
__machine->threads[hash_bucket].nr)
150-
151146
#endif /* _PERF_RESORT_RB_H_ */

0 commit comments

Comments
 (0)