tools/testing/selftests/powerpc/pmu/ebb/ebb.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/pmu/ebb/ebb.c- Extension
.c- Size
- 9529 bytes
- Lines
- 486
- 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
sched.hsys/wait.hsetjmp.hsignal.hstdio.hstdlib.hstring.hsys/ioctl.htrace.hebb.h
Detected Declarations
struct opdfunction ebb_hookfunction reset_ebb_with_clear_maskfunction reset_ebbfunction ebb_check_mmcr0function ebb_check_countfunction standard_ebb_calleefunction setup_ebb_handlerfunction clear_ebb_statsfunction dump_summary_ebb_statefunction dump_ebb_hw_statefunction dump_ebb_statefunction count_pmcfunction ebb_event_enablefunction ebb_freeze_pmcsfunction ebb_unfreeze_pmcsfunction ebb_global_enablefunction ebb_global_disablefunction ebb_is_supportedfunction event_ebb_initfunction event_bhrb_initfunction event_leader_ebb_initfunction ebb_childfunction sigill_handlerfunction catch_sigillfunction write_pmc1function write_pmcfunction read_pmcfunction term_handlerfunction __attribute__
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2014, Michael Ellerman, IBM Corp.
*/
#define _GNU_SOURCE /* For CPU_ZERO etc. */
#include <sched.h>
#include <sys/wait.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include "trace.h"
#include "ebb.h"
void (*ebb_user_func)(void);
void ebb_hook(void)
{
if (ebb_user_func)
ebb_user_func();
}
struct ebb_state ebb_state;
u64 sample_period = 0x40000000ull;
void reset_ebb_with_clear_mask(unsigned long mmcr0_clear_mask)
{
u64 val;
/* 2) clear MMCR0[PMAO] - docs say BESCR[PMEO] should do this */
/* 3) set MMCR0[PMAE] - docs say BESCR[PME] should do this */
val = mfspr(SPRN_MMCR0);
mtspr(SPRN_MMCR0, (val & ~mmcr0_clear_mask) | MMCR0_PMAE);
/* 4) clear BESCR[PMEO] */
mtspr(SPRN_BESCRR, BESCR_PMEO);
/* 5) set BESCR[PME] */
mtspr(SPRN_BESCRS, BESCR_PME);
/* 6) rfebb 1 - done in our caller */
}
void reset_ebb(void)
{
reset_ebb_with_clear_mask(MMCR0_PMAO | MMCR0_FC);
}
/* Called outside of the EBB handler to check MMCR0 is sane */
int ebb_check_mmcr0(void)
{
u64 val;
val = mfspr(SPRN_MMCR0);
if ((val & (MMCR0_FC | MMCR0_PMAO)) == MMCR0_FC) {
/* It's OK if we see FC & PMAO, but not FC by itself */
printf("Outside of loop, only FC set 0x%llx\n", val);
return 1;
}
return 0;
}
bool ebb_check_count(int pmc, u64 sample_period, int fudge)
{
u64 count, upper, lower;
count = ebb_state.stats.pmc_count[PMC_INDEX(pmc)];
lower = ebb_state.stats.ebb_count * (sample_period - fudge);
if (count < lower) {
printf("PMC%d count (0x%llx) below lower limit 0x%llx (-0x%llx)\n",
pmc, count, lower, lower - count);
return false;
}
upper = ebb_state.stats.ebb_count * (sample_period + fudge);
if (count > upper) {
printf("PMC%d count (0x%llx) above upper limit 0x%llx (+0x%llx)\n",
pmc, count, upper, count - upper);
return false;
Annotation
- Immediate include surface: `sched.h`, `sys/wait.h`, `setjmp.h`, `signal.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/ioctl.h`.
- Detected declarations: `struct opd`, `function ebb_hook`, `function reset_ebb_with_clear_mask`, `function reset_ebb`, `function ebb_check_mmcr0`, `function ebb_check_count`, `function standard_ebb_callee`, `function setup_ebb_handler`, `function clear_ebb_stats`, `function dump_summary_ebb_state`.
- 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.