Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use PMU for benchmarking on ARM #1147

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ else()
set(OQS_DEBUG_BUILD OFF)
endif()

option(OQS_SPEED_USE_ARM_PMU "Use ARM Performance Monitor Unit during benchmarking" OFF)

if(WIN32)
set(CMAKE_GENERATOR_CC cl)
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/oqsconfig.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#cmakedefine OQS_USE_ARM_SHA3_INSTRUCTIONS 1
#cmakedefine OQS_USE_ARM_NEON_INSTRUCTIONS 1

#cmakedefine OQS_SPEED_USE_ARM_PMU 1

#cmakedefine OQS_ENABLE_TEST_CONSTANT_TIME 1

#cmakedefine OQS_ENABLE_SHA3_xkcp_low_avx2 1
Expand Down
29 changes: 29 additions & 0 deletions tests/ds_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ static uint64_t _bench_rdtsc(void) {
__asm__ volatile("mrc p15, 0, %0, c9, c13, 0\t\n"
: "=r"(value));
return value;
#elif defined(SPEED_USE_ARM_PMU)
/* Use the Performance Monitoring Unit */
uint64_t value;
/* Read the PMU register */
__asm__ volatile("mrs %0, PMCCNTR_EL0" : "=r" (value));
return value;
#elif defined(__s390x__)
#define USING_TIME_RATHER_THAN_CYCLES
uint64_t tod;
Expand Down Expand Up @@ -174,6 +180,20 @@ static void _bench_init_perfcounters(int32_t do_reset, int32_t enable_divider) {
/* Clear overflows */
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3\t\n" ::"r"(0x8000000f));
}
#elif defined(SPEED_USE_ARM_PMU)

/* Enabling access to ARMv8's Performance Monitoring Unit
* cannot be done from user mode. A kernel module to
* enable access must be loaded. This generally will
* require superuser permissions. A module that has
* been found to work on some platforms can be found at
* https://github.com/mupq/pqax#enable-access-to-performance-counters
*/

static void _bench_init_perfcounters(void) {
__asm__ volatile("MSR PMCR_EL0, %0" ::"r"(1));
__asm__ volatile("MSR PMCNTENSET_EL0, %0" ::"r"(0x80000000));
}
#endif

#define DEFINE_TIMER_VARIABLES \
Expand All @@ -194,6 +214,15 @@ static void _bench_init_perfcounters(int32_t do_reset, int32_t enable_divider) {
_bench_time_cumulative = 0; \
_bench_time_mean = 0.0; \
_bench_time_M2 = 0.0;
#elif defined(SPEED_USE_ARM_PMU)
#define INITIALIZE_TIMER \
_bench_init_perfcounters(); \
_bench_iterations = 0; \
_bench_cycles_mean = 0.0; \
_bench_cycles_M2 = 0.0; \
_bench_time_cumulative = 0; \
_bench_time_mean = 0.0; \
_bench_time_M2 = 0.0;
#else
#define INITIALIZE_TIMER \
_bench_iterations = 0; \
Expand Down
3 changes: 3 additions & 0 deletions tests/speed_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#if defined(USE_RASPBERRY_PI)
#define _RASPBERRY_PI
#endif
#if defined(OQS_SPEED_USE_ARM_PMU)
#define SPEED_USE_ARM_PMU
#endif
#include "ds_benchmark.h"
#include "system_info.c"

Expand Down
3 changes: 3 additions & 0 deletions tests/speed_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#if defined(USE_RASPBERRY_PI)
#define _RASPBERRY_PI
#endif
#if defined(OQS_SPEED_USE_ARM_PMU)
#define SPEED_USE_ARM_PMU
#endif
#include "ds_benchmark.h"
#include "system_info.c"

Expand Down
3 changes: 3 additions & 0 deletions tests/test_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#if defined(USE_RASPBERRY_PI)
#define _RASPBERRY_PI
#endif
#if defined(OQS_SPEED_USE_ARM_PMU)
#define SPEED_USE_ARM_PMU
#endif
#include "ds_benchmark.h"
#include "system_info.c"

Expand Down