tools/perf/builtin-lock.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-lock.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-lock.c- Extension
.c- Size
- 66300 bytes
- Lines
- 2766
- 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.hbuiltin.hperf.hutil/evlist.hutil/evsel.hutil/symbol.hutil/thread.hutil/header.hutil/target.hutil/cgroup.hutil/callchain.hutil/lock-contention.hutil/bpf_skel/lock_data.hsubcmd/pager.hsubcmd/parse-options.hutil/trace-event.hutil/tracepoint.hutil/debug.hutil/session.hutil/tool.hutil/data.hutil/string2.hutil/map.hutil/util.hstdio.hsys/types.hsys/prctl.hsemaphore.hmath.hlimits.hctype.h
Detected Declarations
struct lock_keystruct trace_lock_handlerenum broken_stateenum acquire_flagsfunction thread_stat_insertfunction lock_stat_key_wait_time_minfunction lock_stat_key_print_timefunction lock_stat_key_print_wait_time_minfunction select_keyfunction add_output_fieldfunction setup_output_fieldfunction combine_lock_statsfunction insert_tofunction insert_to_resultfunction list_for_each_entryfunction get_key_by_aggr_mode_simplefunction get_key_by_aggr_modefunction report_lock_acquire_eventfunction report_lock_acquired_eventfunction report_lock_contended_eventfunction report_lock_release_eventfunction get_symbol_name_offsetfunction lock_contention_callerfunction callchain_idfunction report_lock_contention_begin_eventfunction report_lock_contention_end_eventfunction evsel__process_lock_acquirefunction evsel__process_lock_acquiredfunction evsel__process_lock_contendedfunction evsel__process_lock_releasefunction evsel__process_contention_beginfunction evsel__process_contention_endfunction print_bad_eventsfunction print_resultfunction list_for_each_entryfunction dump_threadsfunction compare_mapsfunction dump_mapfunction hlist_for_each_entryfunction dump_infofunction process_event_updatefunction process_sample_eventfunction combine_resultfunction hlist_for_each_entryfunction sort_resultfunction hlist_for_each_entryfunction lock_filter_finishfunction sort_contention_result
Annotated Snippet
struct lock_key {
/*
* name: the value for specify by user
* this should be simpler than raw name of member
* e.g. nr_acquired -> acquired, wait_time_total -> wait_total
*/
const char *name;
/* header: the string printed on the header line */
const char *header;
/* len: the printing width of the field */
int len;
/* key: a pointer to function to compare two lock stats for sorting */
int (*key)(struct lock_stat*, struct lock_stat*);
/* print: a pointer to function to print a given lock stats */
void (*print)(struct lock_key*, struct lock_stat*);
/* list: list entry to link this */
struct list_head list;
};
static void lock_stat_key_print_time(unsigned long long nsec, int len)
{
static const struct {
float base;
const char *unit;
} table[] = {
{ 1e9 * 3600, "h " },
{ 1e9 * 60, "m " },
{ 1e9, "s " },
{ 1e6, "ms" },
{ 1e3, "us" },
{ 0, NULL },
};
/* for CSV output */
if (len == 0) {
fprintf(lock_output, "%llu", nsec);
return;
}
for (int i = 0; table[i].unit; i++) {
if (nsec < table[i].base)
continue;
fprintf(lock_output, "%*.2f %s", len - 3, nsec / table[i].base, table[i].unit);
return;
}
fprintf(lock_output, "%*llu %s", len - 3, nsec, "ns");
}
#define PRINT_KEY(member) \
static void lock_stat_key_print_ ## member(struct lock_key *key, \
struct lock_stat *ls) \
{ \
fprintf(lock_output, "%*llu", key->len, (unsigned long long)ls->member);\
}
#define PRINT_TIME(member) \
static void lock_stat_key_print_ ## member(struct lock_key *key, \
struct lock_stat *ls) \
{ \
lock_stat_key_print_time((unsigned long long)ls->member, key->len); \
}
PRINT_KEY(nr_acquired)
PRINT_KEY(nr_contended)
PRINT_TIME(avg_wait_time)
PRINT_TIME(wait_time_total)
PRINT_TIME(wait_time_max)
static void lock_stat_key_print_wait_time_min(struct lock_key *key,
struct lock_stat *ls)
{
u64 wait_time = ls->wait_time_min;
if (wait_time == ULLONG_MAX)
wait_time = 0;
lock_stat_key_print_time(wait_time, key->len);
}
static const char *sort_key = "acquired";
static int (*compare)(struct lock_stat *, struct lock_stat *);
static struct rb_root sorted; /* place to store intermediate data */
static struct rb_root result; /* place to store sorted data */
static LIST_HEAD(lock_keys);
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `builtin.h`, `perf.h`, `util/evlist.h`, `util/evsel.h`, `util/symbol.h`, `util/thread.h`.
- Detected declarations: `struct lock_key`, `struct trace_lock_handler`, `enum broken_state`, `enum acquire_flags`, `function thread_stat_insert`, `function lock_stat_key_wait_time_min`, `function lock_stat_key_print_time`, `function lock_stat_key_print_wait_time_min`, `function select_key`, `function add_output_field`.
- 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.