tools/perf/tests/bp_account.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/bp_account.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/bp_account.c- Extension
.c- Size
- 5056 bytes
- Lines
- 226
- 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
stdlib.hstdio.hunistd.hstring.hsys/ioctl.hfcntl.hlinux/hw_breakpoint.htests.hdebug.hevent.hparse-events.h../perf-sys.hcloexec.h
Detected Declarations
function test_functionfunction __eventfunction wp_eventfunction bp_eventfunction bp_accountingfunction detect_cntfunction detect_ioctlfunction detect_sharefunction test__bp_accounting
Annotated Snippet
if (cnt == 100) {
pr_debug("way too many debug registers, fix the test\n");
return 0;
}
fd[cnt] = __event(is_x, addr, &attr);
if (fd[cnt] < 0)
break;
cnt++;
}
for (i = 0; i < cnt; i++)
close(fd[i]);
return cnt;
}
static int detect_ioctl(void)
{
struct perf_event_attr attr;
int fd, ret = 1;
fd = wp_event((void *) &the_var, &attr);
if (fd > 0) {
ret = ioctl(fd, PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &attr);
close(fd);
}
return ret ? 0 : 1;
}
static int detect_share(int wp_cnt, int bp_cnt)
{
struct perf_event_attr attr;
int i, *fd = NULL, ret = -1;
if (wp_cnt + bp_cnt == 0)
return 0;
fd = malloc(sizeof(int) * (wp_cnt + bp_cnt));
if (!fd)
return -1;
for (i = 0; i < wp_cnt; i++) {
fd[i] = wp_event((void *)&the_var, &attr);
if (fd[i] == -1) {
pr_err("failed to create wp\n");
goto out;
}
}
for (; i < (bp_cnt + wp_cnt); i++) {
fd[i] = bp_event((void *)test_function, &attr);
if (fd[i] == -1)
break;
}
ret = i != (bp_cnt + wp_cnt);
out:
while (i--)
close(fd[i]);
free(fd);
return ret;
}
/*
* This test does following:
* - detects the number of watch/break-points,
* skip test if any is missing
* - detects PERF_EVENT_IOC_MODIFY_ATTRIBUTES ioctl,
* skip test if it's missing
* - detects if watchpoints and breakpoints share
* same slots
* - create all possible watchpoints on cpu 0
* - change one of it to breakpoint
* - in case wp and bp do not share slots,
* we create another watchpoint to ensure
* the slot accounting is correct
*/
static int test__bp_accounting(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
int has_ioctl = detect_ioctl();
int wp_cnt = detect_cnt(false);
int bp_cnt = detect_cnt(true);
int share = detect_share(wp_cnt, bp_cnt);
if (!BP_ACCOUNT_IS_SUPPORTED) {
pr_debug("Test not supported on this architecture");
Annotation
- Immediate include surface: `stdlib.h`, `stdio.h`, `unistd.h`, `string.h`, `sys/ioctl.h`, `fcntl.h`, `linux/hw_breakpoint.h`, `tests.h`.
- Detected declarations: `function test_function`, `function __event`, `function wp_event`, `function bp_event`, `function bp_accounting`, `function detect_cnt`, `function detect_ioctl`, `function detect_share`, `function test__bp_accounting`.
- 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.