Skip to content

Commit

Permalink
[AArch64] Apply instruction counter computing overflow rules
Browse files Browse the repository at this point in the history
  • Loading branch information
cyring committed May 12, 2024
1 parent a78e0ae commit 1549ff7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
14 changes: 10 additions & 4 deletions aarch64/corefreqk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2921,6 +2921,8 @@ static void Generic_Core_Counters_Clear(union SAVE_AREA_CORE *Save,
pmevcntr2_el0, Core->Counter[T].C0.UCC, \
pmccntr_el0, Core->Counter[T].C0.URC, \
pmevcntr3_el0, Core->Counter[T].INST ); \
\
Core->Counter[T].INST &= INST_COUNTER_OVERFLOW; \
/* Normalize frequency: */ \
Core->Counter[T].C1 = ( \
Core->Counter[T].TSC \
Expand Down Expand Up @@ -3005,10 +3007,14 @@ static void Generic_Core_Counters_Clear(union SAVE_AREA_CORE *Save,

#define Delta_INST(Core) \
({ /* Delta of Retired Instructions */ \
Core->Delta.INST = ( \
Core->Counter[0].INST > Core->Counter[1].INST \
) ? Core->Counter[0].INST - Core->Counter[1].INST \
: Core->Counter[1].INST - Core->Counter[0].INST; \
if (Core->Counter[1].INST > Core->Counter[0].INST) \
Core->Delta.INST = Core->Counter[1].INST \
- Core->Counter[0].INST; \
else { \
Core->Delta.INST = INST_COUNTER_OVERFLOW \
- Core->Counter[0].INST; \
Core->Delta.INST += Core->Counter[1].INST; \
} \
})

#define PKG_Counters_Generic(Core, T) \
Expand Down
19 changes: 16 additions & 3 deletions aarch64/corefreqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
({ \
unsigned long long overhead = pSlice->Counter[1].INST \
- pSlice->Counter[0].INST; \
pSlice->Delta.INST = pSlice->Counter[2].INST \
- pSlice->Counter[1].INST; \
/* Test and compute if counter has overflowed */ \
if (pSlice->Counter[2].INST > pSlice->Counter[1].INST) \
pSlice->Delta.INST = pSlice->Counter[2].INST \
- pSlice->Counter[1].INST; \
else { \
pSlice->Delta.INST = INST_COUNTER_OVERFLOW \
- pSlice->Counter[1].INST; \
pSlice->Delta.INST += pSlice->Counter[2].INST; \
} \
if (overhead <= pSlice->Delta.INST) \
pSlice->Delta.INST -= overhead; \
pSlice->Delta.INST -= overhead; \
})

void CallWith_RDTSC_RDPMC( RO(SHM_STRUCT) *RO(Shm),
Expand All @@ -47,16 +54,22 @@ void CallWith_RDTSC_RDPMC( RO(SHM_STRUCT) *RO(Shm),
pmevcntr3_el0,
pSlice->Counter[0].INST );

pSlice->Counter[0].INST &= INST_COUNTER_OVERFLOW;

RDTSC_PMCx1( pSlice->Counter[1].TSC,
pmevcntr3_el0,
pSlice->Counter[1].INST );

pSlice->Counter[1].INST &= INST_COUNTER_OVERFLOW;

SliceFunc(RO(Shm), RW(Shm), cpu, arg);

RDTSC_PMCx1( pSlice->Counter[2].TSC,
pmevcntr3_el0,
pSlice->Counter[2].INST );

pSlice->Counter[2].INST &= INST_COUNTER_OVERFLOW;

if (BITVAL(RW(Shm)->Proc.Sync, BURN)) {
DeltaTSC(pSlice);
DeltaINST(pSlice);
Expand Down
2 changes: 2 additions & 0 deletions aarch64/coretypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ enum CSTATES_ENCODING {

#define CSTATES_ENCODING_COUNT 12

#define INST_COUNTER_OVERFLOW 0x7fffffff

enum THM_POINTS {
THM_THRESHOLD_1,
THM_THRESHOLD_2,
Expand Down

0 comments on commit 1549ff7

Please sign in to comment.