kernel/trace/tracing_map.c
Source file repositories/reference/linux-study-clean/kernel/trace/tracing_map.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/tracing_map.c- Extension
.c- Size
- 30900 bytes
- Lines
- 1137
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/vmalloc.hlinux/jhash.hlinux/slab.hlinux/sort.hlinux/kmemleak.htracing_map.htrace.h
Detected Declarations
function Copyrightfunction tracing_map_add_sum_fieldfunction tracing_map_add_varfunction tracing_map_add_varfunction tracing_map_add_varfunction tracing_map_add_varfunction tracing_map_cmp_stringfunction tracing_map_cmp_nonefunction tracing_map_cmp_atomic64function tracing_map_cmp_numfunction tracing_map_add_fieldfunction tracing_map_update_sumfunction tracing_map_update_varfunction tracing_map_add_key_fieldfunction tracing_map_array_clearfunction tracing_map_array_freefunction tracing_map_elt_clearfunction tracing_map_elt_init_fieldsfunction __tracing_map_elt_freefunction tracing_map_elt_freefunction tracing_map_free_eltsfunction tracing_map_alloc_eltsfunction keys_matchfunction __tracing_map_insertfunction specifiedfunction tracing_map_insertfunction tracing_map_destroyfunction tracing_map_clearfunction set_sort_keyfunction elementsfunction tracing_map_add_sum_fieldfunction cmp_entries_dupfunction cmp_entries_sumfunction cmp_entries_keyfunction destroy_sort_entryfunction tracing_map_sort_entriesfunction create_sort_entryfunction detect_dupsfunction is_keyfunction sort_secondaryfunction tracing_map_sort_entries
Annotated Snippet
if (IS_ERR(*(TRACING_MAP_ELT(map->elts, i)))) {
*(TRACING_MAP_ELT(map->elts, i)) = NULL;
tracing_map_free_elts(map);
return -ENOMEM;
}
}
return 0;
}
static inline bool keys_match(void *key, void *test_key, unsigned key_size)
{
bool match = true;
if (memcmp(key, test_key, key_size))
match = false;
return match;
}
static inline struct tracing_map_elt *
__tracing_map_insert(struct tracing_map *map, void *key, bool lookup_only)
{
u32 idx, key_hash, test_key;
int dup_try = 0;
struct tracing_map_entry *entry;
struct tracing_map_elt *val;
key_hash = jhash(key, map->key_size, 0);
if (key_hash == 0)
key_hash = 1;
idx = key_hash >> (32 - (map->map_bits + 1));
while (1) {
idx &= (map->map_size - 1);
entry = TRACING_MAP_ENTRY(map->map, idx);
test_key = entry->key;
if (test_key && test_key == key_hash) {
val = READ_ONCE(entry->val);
if (val &&
keys_match(key, val->key, map->key_size)) {
if (!lookup_only)
atomic64_inc(&map->hits);
return val;
} else if (unlikely(!val)) {
/*
* The key is present. But, val (pointer to elt
* struct) is still NULL. which means some other
* thread is in the process of inserting an
* element.
*
* On top of that, it's key_hash is same as the
* one being inserted right now. So, it's
* possible that the element has the same
* key as well.
*/
dup_try++;
if (dup_try > map->map_size) {
atomic64_inc(&map->drops);
break;
}
continue;
}
}
if (!test_key) {
if (lookup_only)
break;
if (!cmpxchg(&entry->key, 0, key_hash)) {
struct tracing_map_elt *elt;
elt = get_free_elt(map);
if (!elt) {
atomic64_inc(&map->drops);
entry->key = 0;
break;
}
memcpy(elt->key, key, map->key_size);
/*
* Ensure the initialization is visible and
* publish the elt.
*/
smp_wmb();
WRITE_ONCE(entry->val, elt);
atomic64_inc(&map->hits);
Annotation
- Immediate include surface: `linux/vmalloc.h`, `linux/jhash.h`, `linux/slab.h`, `linux/sort.h`, `linux/kmemleak.h`, `tracing_map.h`, `trace.h`.
- Detected declarations: `function Copyright`, `function tracing_map_add_sum_field`, `function tracing_map_add_var`, `function tracing_map_add_var`, `function tracing_map_add_var`, `function tracing_map_add_var`, `function tracing_map_cmp_string`, `function tracing_map_cmp_none`, `function tracing_map_cmp_atomic64`, `function tracing_map_cmp_num`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.