summaryrefslogtreecommitdiff
path: root/tools/perf/util/threads.h
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2024-02-29 21:36:43 -0800
committerNamhyung Kim <namhyung@kernel.org>2024-03-03 22:51:55 -0800
commit93bb5b0d9394cbf49b76823c48ed8b815a5d899c (patch)
treece9c6dbf87ee883bb3ba931a4483950ed0d44a4e /tools/perf/util/threads.h
parentd436f90a64f3e6b47464acc7821ce2b8a515a2ae (diff)
perf threads: Move threads to its own files
Move threads out of machine and into its own file. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240301053646.1449657-6-irogers@google.com
Diffstat (limited to 'tools/perf/util/threads.h')
-rw-r--r--tools/perf/util/threads.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/perf/util/threads.h b/tools/perf/util/threads.h
new file mode 100644
index 0000000000000..ed67de6275782
--- /dev/null
+++ b/tools/perf/util/threads.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PERF_THREADS_H
+#define __PERF_THREADS_H
+
+#include <linux/rbtree.h>
+#include "rwsem.h"
+
+struct thread;
+
+#define THREADS__TABLE_BITS 8
+#define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)
+
+struct threads_table_entry {
+ struct rb_root_cached entries;
+ struct rw_semaphore lock;
+ unsigned int nr;
+ struct thread *last_match;
+};
+
+struct threads {
+ struct threads_table_entry table[THREADS__TABLE_SIZE];
+};
+
+void threads__init(struct threads *threads);
+void threads__exit(struct threads *threads);
+size_t threads__nr(struct threads *threads);
+struct thread *threads__find(struct threads *threads, pid_t tid);
+struct thread *threads__findnew(struct threads *threads, pid_t pid, pid_t tid, bool *created);
+void threads__remove_all_threads(struct threads *threads);
+void threads__remove(struct threads *threads, struct thread *thread);
+int threads__for_each_thread(struct threads *threads,
+ int (*fn)(struct thread *thread, void *data),
+ void *data);
+
+#endif /* __PERF_THREADS_H */