tools/testing/selftests/powerpc/pmu/event.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/pmu/event.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/pmu/event.c- Extension
.c- Size
- 3223 bytes
- Lines
- 149
- 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
unistd.hsys/syscall.hstring.hstdio.hstdbool.hsys/ioctl.hevent.h
Detected Declarations
function perf_event_openfunction __event_init_optsfunction event_init_optsfunction event_init_namedfunction event_initfunction event_init_samplingfunction event_open_with_optionsfunction event_open_with_groupfunction event_open_with_pidfunction event_open_with_cpufunction event_openfunction event_closefunction event_enablefunction event_disablefunction event_resetfunction event_readfunction event_report_justifiedfunction event_report
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2013, Michael Ellerman, IBM Corp.
*/
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include "event.h"
int perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu,
int group_fd, unsigned long flags)
{
return syscall(__NR_perf_event_open, attr, pid, cpu,
group_fd, flags);
}
static void __event_init_opts(struct event *e, u64 config,
int type, char *name, bool sampling)
{
memset(e, 0, sizeof(*e));
e->name = name;
e->attr.type = type;
e->attr.config = config;
e->attr.size = sizeof(e->attr);
/* This has to match the structure layout in the header */
e->attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | \
PERF_FORMAT_TOTAL_TIME_RUNNING;
if (sampling) {
e->attr.sample_period = 1000;
e->attr.sample_type = PERF_SAMPLE_REGS_INTR;
e->attr.disabled = 1;
}
}
void event_init_opts(struct event *e, u64 config, int type, char *name)
{
__event_init_opts(e, config, type, name, false);
}
void event_init_named(struct event *e, u64 config, char *name)
{
event_init_opts(e, config, PERF_TYPE_RAW, name);
}
void event_init(struct event *e, u64 config)
{
event_init_opts(e, config, PERF_TYPE_RAW, "event");
}
void event_init_sampling(struct event *e, u64 config)
{
__event_init_opts(e, config, PERF_TYPE_RAW, "event", true);
}
#define PERF_CURRENT_PID 0
#define PERF_NO_PID -1
#define PERF_NO_CPU -1
#define PERF_NO_GROUP -1
int event_open_with_options(struct event *e, pid_t pid, int cpu, int group_fd)
{
e->fd = perf_event_open(&e->attr, pid, cpu, group_fd, 0);
if (e->fd == -1) {
perror("perf_event_open");
return -1;
}
return 0;
}
int event_open_with_group(struct event *e, int group_fd)
{
return event_open_with_options(e, PERF_CURRENT_PID, PERF_NO_CPU, group_fd);
}
int event_open_with_pid(struct event *e, pid_t pid)
{
return event_open_with_options(e, pid, PERF_NO_CPU, PERF_NO_GROUP);
}
int event_open_with_cpu(struct event *e, int cpu)
Annotation
- Immediate include surface: `unistd.h`, `sys/syscall.h`, `string.h`, `stdio.h`, `stdbool.h`, `sys/ioctl.h`, `event.h`.
- Detected declarations: `function perf_event_open`, `function __event_init_opts`, `function event_init_opts`, `function event_init_named`, `function event_init`, `function event_init_sampling`, `function event_open_with_options`, `function event_open_with_group`, `function event_open_with_pid`, `function event_open_with_cpu`.
- 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.