8000 aarch64: select the cycle counter by class, not by id by Martin-Lndbl · Pull Request #44 · miniosv/miniosv · GitHub
[go: up one dir, main page]

Skip to content

aarch64: select the cycle counter by class, not by id - #44

Merged
Meandres merged 2 commits into
miniosv:masterfrom
Martin-Lndbl:feature/aarch64-counter-ids
Oct 22, 2026
Merged

Meandres merged 2 commits into
miniosv:masterfrom
Martin-Lndbl:feature/aarch64-counter-ids

Conversation

@Martin-Lndbl
Copy link
Copy Markdown
Collaborator

Previously, the cycle couter id has been hardcoded in the arm arch-perf.hh. Basing it on the class ensures the cycle counter is whatever PMCSelect defines it to be. This however required some internal interfaces to change

Two conflations of a counter id with the bitmask that selects it.

pmc_stop wrote its argument into pmcntenclr_el0 as a mask, but every caller
passes an id. Ids are 0..5, so id 0 cleared nothing and id 1 cleared counter
0. Harmless while counting; while sampling it leaves a counter overflowing
after its handler is gone, which on a level-triggered PPI is a storm with
nothing to service it.

The cycle counter went the other way: it was identified by the mask 1u<<31,
written as a literal in seven places, so the arch back-end recognised it by
value. It does not have to. PMCSelect already knows which counter is the
cycle counter -- it is the one with PMClass::CYCLES -- and that class now
travels with the call, so the back-end asks what a counter *is* instead of
inferring it from a magic id.

The primitives therefore take a PMClass. On aarch64 it picks PMCCNTR_EL0
over PMEVCNTR<n>_EL0 and bit 31 over bit n; on x86 there is no separate
cycle register, so it is accepted and ignored, and callers need no #ifdef.
31 survives once, as the documented PMCNTENSET_EL0 bit position, reached
through the class rather than through an id.

The cycle counter's id is now unused, so make_default_core_pmcs registers it
as 0 rather than a value that means "not an id".

Builds for x86-64 and aarch64.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUfbSaGMKakCM4PxALA3vE
@Martin-Lndbl Martin-Lndbl self-assigned this Sep 9, 2026
@Martin-Lndbl Martin-Lndbl added the enhancement New feature or request label Sep 9, 2026
@seb711
seb711 commented Oct 9, 2026
Copy link
Copy Markdown
Collaborator

Why do we have PerfEvtSel and PerfCtr if that value is always the same? What does this enable us to do?

@Martin-Lndbl
Copy link
Copy Markdown
Collaborator Author

Its only the same for arm as they don't give you the hardware address of the counter but an designated assembly instruction per counter. For x86 these 2 fields hold the actual address and are therefore different.

Or did I misunderstand the question?

Master's PMU work still identified the cycle counter by the 1u<<31 id; it is
ported onto this branch's PMClass-carrying primitives:

- pmc_start_with_conf returns bool (master) and takes the class (this branch).
  The PMCCFILTR_EL0 filter write moves from the 1u<<31 evt_sel case into the
  CYCLES branch, and the "refuse event counters >= 6" check exempts the cycle
  counter by class instead of by id.
- pmc_read keeps master's zero default for unwired counters.
- pmc_overflow_width uses pmu_event_counter_width() for event counters and
  picks the cycle counter by class.
- The new wrap-counting and sampler call sites, and the x86
  pmc_overflow_bit stub, pass the class.
- PMC::probe() is now PMC::read(), as on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Meandres
Meandres merged commit 07f52da into miniosv:master Oct 22, 2026
2 checks passed
@Martin-Lndbl
Martin-Lndbl deleted the feature/aarch64-counter-ids branch November 6, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0