tools/perf/util/ordered-events.c
Source file repositories/reference/linux-study-clean/tools/perf/util/ordered-events.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/ordered-events.c- Extension
.c- Size
- 9906 bytes
- Lines
- 418
- 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
errno.hinttypes.hlinux/list.hlinux/compiler.hlinux/string.hordered-events.hsession.hasm/bug.hdebug.hui/progress.h
Detected Declarations
function queue_eventfunction __free_dup_eventfunction free_dup_eventfunction ordered_events__new_eventfunction ordered_events__deletefunction ordered_events__queuefunction do_flushfunction list_for_each_entry_safefunction __ordered_events__flushfunction ordered_events__flushfunction ordered_events__flush_timefunction ordered_events__first_timefunction ordered_events__initfunction ordered_events_buffer__freefunction ordered_events__freefunction ordered_events__reinit
Annotated Snippet
while (last->timestamp <= timestamp) {
p = last->list.next;
if (p == &oe->events) {
list_add_tail(&new->list, &oe->events);
oe->max_timestamp = timestamp;
return;
}
last = list_entry(p, struct ordered_event, list);
}
list_add_tail(&new->list, &last->list);
} else {
while (last->timestamp > timestamp) {
p = last->list.prev;
if (p == &oe->events) {
list_add(&new->list, &oe->events);
return;
}
last = list_entry(p, struct ordered_event, list);
}
list_add(&new->list, &last->list);
}
}
static union perf_event *__dup_event(struct ordered_events *oe,
union perf_event *event)
{
union perf_event *new_event = NULL;
if (oe->cur_alloc_size < oe->max_alloc_size) {
new_event = memdup(event, event->header.size);
if (new_event)
oe->cur_alloc_size += event->header.size;
}
return new_event;
}
static union perf_event *dup_event(struct ordered_events *oe,
union perf_event *event)
{
return oe->copy_on_queue ? __dup_event(oe, event) : event;
}
static void __free_dup_event(struct ordered_events *oe, union perf_event *event)
{
if (event) {
oe->cur_alloc_size -= event->header.size;
free(event);
}
}
static void free_dup_event(struct ordered_events *oe, union perf_event *event)
{
if (oe->copy_on_queue)
__free_dup_event(oe, event);
}
#define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct ordered_event))
static struct ordered_event *alloc_event(struct ordered_events *oe,
union perf_event *event)
{
struct list_head *cache = &oe->cache;
struct ordered_event *new = NULL;
union perf_event *new_event;
size_t size;
new_event = dup_event(oe, event);
if (!new_event)
return NULL;
/*
* We maintain the following scheme of buffers for ordered
* event allocation:
*
* to_free list -> buffer1 (64K)
* buffer2 (64K)
* ...
*
* Each buffer keeps an array of ordered events objects:
* buffer -> event[0]
* event[1]
* ...
*
* Each allocated ordered event is linked to one of
* following lists:
* - time ordered list 'events'
* - list of currently removed events 'cache'
*
* Allocation of the ordered event uses the following order
* to get the memory:
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `linux/list.h`, `linux/compiler.h`, `linux/string.h`, `ordered-events.h`, `session.h`, `asm/bug.h`.
- Detected declarations: `function queue_event`, `function __free_dup_event`, `function free_dup_event`, `function ordered_events__new_event`, `function ordered_events__delete`, `function ordered_events__queue`, `function do_flush`, `function list_for_each_entry_safe`, `function __ordered_events__flush`, `function ordered_events__flush`.
- 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.