tools/perf/util/threads.c
Source file repositories/reference/linux-study-clean/tools/perf/util/threads.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/threads.c- Extension
.c- Size
- 4781 bytes
- Lines
- 191
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
threads.hmachine.hthread.h
Detected Declarations
function key_hashfunction key_equalfunction threads__initfunction threads__exitfunction threads__nrfunction __threads_table_entry__set_last_matchfunction threads_table_entry__set_last_matchfunction threads__remove_all_threadsfunction hashmap__for_each_entry_safefunction threads__removefunction threads__for_each_threadfunction hashmap__for_each_entry
Annotated Snippet
if (hashmap__add(&table->shard, tid, res)) {
/* Add failed. Assume a race so find other entry. */
thread__put(res);
res = NULL;
if (hashmap__find(&table->shard, tid, &res))
res = thread__get(res);
} else {
res = thread__get(res);
*created = true;
}
if (res)
__threads_table_entry__set_last_match(table, res);
}
up_write(&table->lock);
return res;
}
void threads__remove_all_threads(struct threads *threads)
{
for (int i = 0; i < THREADS__TABLE_SIZE; i++) {
struct threads_table_entry *table = &threads->table[i];
struct hashmap_entry *cur, *tmp;
size_t bkt;
down_write(&table->lock);
__threads_table_entry__set_last_match(table, NULL);
hashmap__for_each_entry_safe(&table->shard, cur, tmp, bkt) {
struct thread *old_value;
hashmap__delete(&table->shard, cur->key, /*old_key=*/NULL, &old_value);
thread__put(old_value);
}
up_write(&table->lock);
}
}
void threads__remove(struct threads *threads, struct thread *thread)
{
struct threads_table_entry *table = threads__table(threads, thread__tid(thread));
struct thread *old_value;
down_write(&table->lock);
if (table->last_match && RC_CHK_EQUAL(table->last_match, thread))
__threads_table_entry__set_last_match(table, NULL);
hashmap__delete(&table->shard, thread__tid(thread), /*old_key=*/NULL, &old_value);
thread__put(old_value);
up_write(&table->lock);
}
int threads__for_each_thread(struct threads *threads,
int (*fn)(struct thread *thread, void *data),
void *data)
{
for (int i = 0; i < THREADS__TABLE_SIZE; i++) {
struct threads_table_entry *table = &threads->table[i];
struct hashmap_entry *cur;
size_t bkt;
down_read(&table->lock);
hashmap__for_each_entry(&table->shard, cur, bkt) {
int rc = fn((struct thread *)cur->pvalue, data);
if (rc != 0) {
up_read(&table->lock);
return rc;
}
}
up_read(&table->lock);
}
return 0;
}
Annotation
- Immediate include surface: `threads.h`, `machine.h`, `thread.h`.
- Detected declarations: `function key_hash`, `function key_equal`, `function threads__init`, `function threads__exit`, `function threads__nr`, `function __threads_table_entry__set_last_match`, `function threads_table_entry__set_last_match`, `function threads__remove_all_threads`, `function hashmap__for_each_entry_safe`, `function threads__remove`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.