tools/perf/util/pmus.c
Source file repositories/reference/linux-study-clean/tools/perf/util/pmus.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/pmus.c- Extension
.c- Size
- 24563 bytes
- Lines
- 888
- 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
linux/list.hlinux/list_sort.hlinux/string.hlinux/zalloc.hapi/io_dir.hsubcmd/pager.hsys/types.hctype.hpthread.hstring.hunistd.hcpumap.hdebug.hdrm_pmu.hevsel.hpmus.hpmu.hhwmon_pmu.htool_pmu.hprint-events.hstrbuf.hstring2.h
Detected Declarations
struct seventstruct events_callback_statestruct build_format_string_argsenum perf_tool_pmu_typefunction pmu_name_len_no_suffixfunction pmu_name_cmpfunction perf_pmus__destroyfunction list_for_each_entry_safefunction list_for_each_entryfunction pmus_cmpfunction pmu_read_sysfsfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entry_continuefunction cmp_seventfunction pmu_alias_is_duplicatefunction perf_pmus__print_pmu_events__callbackfunction perf_pmus__print_pmu_eventsfunction build_format_stringfunction perf_pmus__print_raw_pmu_eventsfunction perf_pmus__have_eventfunction perf_pmus__num_core_pmusfunction __perf_pmus__supports_extended_typefunction perf_pmus__init_supports_extended_typefunction perf_pmus__supports_extended_type
Annotated Snippet
struct sevent {
/** PMU for event. */
const struct perf_pmu *pmu;
const char *name;
const char* alias;
const char *scale_unit;
const char *desc;
const char *long_desc;
const char *encoding_desc;
const char *topic;
const char *pmu_name;
const char *event_type_desc;
bool deprecated;
};
static int cmp_sevent(const void *a, const void *b)
{
const struct sevent *as = a;
const struct sevent *bs = b;
bool a_iscpu, b_iscpu;
int ret;
/* Put extra events last. */
if (!!as->desc != !!bs->desc)
return !!as->desc - !!bs->desc;
/* Order by topics. */
ret = strcmp(as->topic ?: "", bs->topic ?: "");
if (ret)
return ret;
/* Order CPU core events to be first */
a_iscpu = as->pmu ? as->pmu->is_core : true;
b_iscpu = bs->pmu ? bs->pmu->is_core : true;
if (a_iscpu != b_iscpu)
return a_iscpu ? -1 : 1;
/* Order by PMU name. */
if (as->pmu != bs->pmu) {
ret = strcmp(as->pmu_name ?: "", bs->pmu_name ?: "");
if (ret)
return ret;
}
/* Order by event name. */
return strcmp(as->name, bs->name);
}
static bool pmu_alias_is_duplicate(struct sevent *a, struct sevent *b)
{
/* Different names -> never duplicates */
if (strcmp(a->name ?: "//", b->name ?: "//"))
return false;
/* Don't remove duplicates for different PMUs */
return strcmp(a->pmu_name, b->pmu_name) == 0;
}
struct events_callback_state {
struct sevent *aliases;
size_t aliases_len;
size_t index;
};
static int perf_pmus__print_pmu_events__callback(void *vstate,
struct pmu_event_info *info)
{
struct events_callback_state *state = vstate;
struct sevent *s;
if (state->index >= state->aliases_len) {
pr_err("Unexpected event %s/%s/\n", info->pmu->name, info->name);
return 1;
}
assert(info->pmu != NULL || info->name != NULL);
s = &state->aliases[state->index];
s->pmu = info->pmu;
#define COPY_STR(str) s->str = info->str ? strdup(info->str) : NULL
COPY_STR(name);
COPY_STR(alias);
COPY_STR(scale_unit);
COPY_STR(desc);
COPY_STR(long_desc);
COPY_STR(encoding_desc);
COPY_STR(topic);
COPY_STR(pmu_name);
COPY_STR(event_type_desc);
#undef COPY_STR
s->deprecated = info->deprecated;
state->index++;
Annotation
- Immediate include surface: `linux/list.h`, `linux/list_sort.h`, `linux/string.h`, `linux/zalloc.h`, `api/io_dir.h`, `subcmd/pager.h`, `sys/types.h`, `ctype.h`.
- Detected declarations: `struct sevent`, `struct events_callback_state`, `struct build_format_string_args`, `enum perf_tool_pmu_type`, `function pmu_name_len_no_suffix`, `function pmu_name_cmp`, `function perf_pmus__destroy`, `function list_for_each_entry_safe`, `function list_for_each_entry`, `function pmus_cmp`.
- 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.