mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
7bfc84b23e
The threads data structure is an array of hashmaps, previously
rbtrees. The two levels allows for a fixed outer array where access is
guarded by rw_semaphores. Commit 91e467bc56
("perf machine: Use
hashtable for machine threads") sized the outer table at 256 entries
to avoid future scalability problems, however, this means the threads
struct is sized at 30,720 bytes. As the hashmaps allow O(1) access for
the common find/insert/remove operations, lower the number of entries
to 8. This reduces the size overhead to 960 bytes.
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-8-irogers@google.com
35 lines
1 KiB
C
35 lines
1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __PERF_THREADS_H
|
|
#define __PERF_THREADS_H
|
|
|
|
#include "hashmap.h"
|
|
#include "rwsem.h"
|
|
|
|
struct thread;
|
|
|
|
#define THREADS__TABLE_BITS 3
|
|
#define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)
|
|
|
|
struct threads_table_entry {
|
|
/* Key is tid, value is struct thread. */
|
|
struct hashmap shard;
|
|
struct rw_semaphore lock;
|
|
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 */
|