Skip to content

Commit fd0b14d

Browse files
committed
Add support for benchmarking on mps3
1 parent 6264ae0 commit fd0b14d

File tree

6 files changed

+98
-8
lines changed

6 files changed

+98
-8
lines changed

nix/m55-an547-arm-none-eabi/default.nix

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
stdenvNoCC.mkDerivation {
1010
pname = "mldsa-native-m55-an547";
11-
version = "main-2025-10-02";
12-
11+
version = "main-2025-10-13";
1312

1413
# Fetch platform files from pqmx (envs/m55-an547)
1514
src = fetchFromGitHub {
16-
owner = "slothy-optimizer";
15+
owner = "bremoran";
1716
repo = "pqmx";
18-
rev = "4ed493d3cf2af62a08fd9fe36c3472a0dc50ad9f";
19-
hash = "sha256-jLIqwknjRwcoDeEAETlMhRqZQ5a3QGCDZX9DENelGeQ=";
17+
rev = "3b4177cb76a614ed1887bcc2f90e571469d6fe2f";
18+
hash = "sha256-27ur5JYtZbwQ0fnrp/0Cj/R60TaZwouimFgOJGPjpMk=";
2019
};
2120

2221
dontBuild = true;

scripts/tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ def cli():
961961
"-c",
962962
"--cycles",
963963
help="Method for counting clock cycles. PMU requires (user-space) access to the Arm Performance Monitor Unit (PMU). PERF requires a kernel with perf support. MAC works on some Apple platforms, at least Apple M1.",
964-
choices=["NO", "PMU", "PERF", "MAC"],
964+
choices=["NO", "PMU", "PERF", "MAC", "SYSTICK"],
965965
type=str.upper,
966966
required=True,
967967
)

test/baremetal/platform/m55-an547/platform.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ LDFLAGS += \
5959
# Extra sources to be included in test binaries
6060
EXTRA_SOURCES = $(wildcard $(M55_AN547_PATH)/*.c)
6161
EXEC_WRAPPER := $(realpath $(PLATFORM_PATH)/exec_wrapper.py)
62+
63+
CYCLES ?= SYSTICK

test/bench_mldsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void print_percentile_legend(void)
5656
printf("%21s", "percentile");
5757
for (i = 0; i < sizeof(percentiles) / sizeof(percentiles[0]); i++)
5858
{
59-
printf("%7d", percentiles[i]);
59+
printf("%9d", percentiles[i]);
6060
}
6161
printf("\n");
6262
}
@@ -67,7 +67,7 @@ static void print_percentiles(const char *txt, uint64_t cyc[NTESTS])
6767
printf("%10s percentiles:", txt);
6868
for (i = 0; i < sizeof(percentiles) / sizeof(percentiles[0]); i++)
6969
{
70-
printf("%7" PRIu64, (cyc)[NTESTS * percentiles[i] / 100] / NITERATIONS);
70+
printf("%9" PRIu64, (cyc)[NTESTS * percentiles[i] / 100] / NITERATIONS);
7171
}
7272
printf("\n");
7373
}

test/hal/hal.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,41 @@ uint64_t get_cyclecounter(void)
9494
__asm __volatile("mrs %[retval], pmccntr_el0\n" : [retval] "=r"(retval));
9595
return retval;
9696
}
97+
#elif defined(__ARM_ARCH_8_1M_MAIN__) || defined(__ARM_FEATURE_MVE)
98+
#include <ARMCM55.h>
99+
#include <system_ARMCM55.h>
100+
#include <uart.h>
101+
#include "pmu_armv8.h"
102+
103+
volatile uint64_t v8m_pmu_cycles;
104+
void DebugMon_Handler(void) {
105+
uint32_t ovsclr;
106+
ARM_PMU_CNTR_Disable(PMU_CNTENSET_CCNTR_ENABLE_Msk);
107+
v8m_pmu_cycles += ARM_PMU_Get_CCNTR();
108+
ovsclr = ARM_PMU_Get_CNTR_OVS();
109+
ARM_PMU_Set_CNTR_OVS(ovsclr);
110+
ARM_PMU_CYCCNT_Reset();
111+
ARM_PMU_CNTR_Enable(PMU_CNTENSET_CCNTR_ENABLE_Msk);
112+
}
113+
void enable_cyclecounter(void)
114+
{
115+
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk | CoreDebug_DEMCR_MON_EN_Msk;
116+
ARM_PMU_Enable();
117+
118+
v8m_pmu_cycles = 0;
119+
ARM_PMU_CYCCNT_Reset();
120+
}
121+
void disable_cyclecounter(void)
122+
{
123+
ARM_PMU_Disable();
124+
CoreDebug->DEMCR &= (~CoreDebug_DEMCR_TRCENA_Msk) & (~CoreDebug_DEMCR_MON_EN_Msk);
125+
}
126+
uint64_t get_cyclecounter(void)
127+
{
128+
v8m_pmu_cycles += ARM_PMU_Get_CCNTR();
129+
ARM_PMU_CYCCNT_Reset();
130+
return v8m_pmu_cycles;
131+
}
97132

98133
#else
99134
#error PMU_CYCLES option only supported on x86_64 and AArch64
@@ -305,6 +340,56 @@ uint64_t get_cyclecounter(void)
305340
return g_counters[2];
306341
}
307342

343+
#elif defined(SYSTICK_CYCLES)
344+
#include <ARMCM55.h>
345+
#include <system_ARMCM55.h>
346+
static volatile uint32_t systick_overflows;
347+
void SysTick_Handler(void)
348+
{
349+
uint32_t cnt;
350+
uint32_t fail;
351+
do {
352+
__asm__ volatile (
353+
"ldrex %[val], [%[guard]]\n"
354+
"addw %[val], %[val], #1\n"
355+
"strex %[fail], %[val], [%[guard]]\n"
356+
:[fail] "=r" (fail), [val] "=&r" (cnt)
357+
:[guard] "r" (&systick_overflows) : "memory");
358+
} while (fail);
359+
}
360+
361+
void enable_cyclecounter(void) {
362+
uint32_t cnt;
363+
uint32_t fail;
364+
do {
365+
__asm__ volatile ("ldrex.w %[val], [%[guard]]"
366+
:[val] "=&r" (cnt)
367+
:[guard] "r" (&systick_overflows));
368+
cnt = 0;
369+
__asm__ volatile ("strex.w %[fail], %[val], [%[guard]]"
370+
:[fail] "=r" (fail), [val] "=&r" (cnt)
371+
:[guard] "r" (&systick_overflows) : "memory");
372+
} while (fail);
373+
SysTick_Config(0xFFFFFFu);
374+
}
375+
376+
void disable_cyclecounter(void) { return; }
377+
378+
uint64_t get_cyclecounter(void) {
379+
uint32_t val;
380+
uint32_t cnt;
381+
uint32_t fail;
382+
do {
383+
__asm__ volatile (
384+
"ldrex %[cnt], [%[guard]]\n"
385+
"ldr %[val], [%[systv]]\n"
386+
"strex %[fail], %[cnt], [%[guard]]\n"
387+
:[fail] "=r" (fail), [cnt] "=&r" (cnt), [val] "=r" (val)
388+
:[guard] "r" (&systick_overflows), [systv] "r" (&(SysTick->VAL)): "memory");
389+
} while (fail);
390+
return ((uint64_t)cnt + 1) * 16777216llu - val;
391+
}
392+
308393
#else
309394

310395
void enable_cyclecounter(void) { return; }

test/mk/config.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ ifeq ($(CYCLES),MAC)
7474
CFLAGS += -DMAC_CYCLES
7575
endif
7676

77+
ifeq ($(CYCLES),SYSTICK)
78+
CFLAGS += -DSYSTICK_CYCLES
79+
endif
80+
7781
##############################
7882
# Include retained variables #
7983
##############################

0 commit comments

Comments
 (0)