summaryrefslogtreecommitdiffstats
path: root/src/tests/cbc_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/cbc_test.c')
-rw-r--r--src/tests/cbc_test.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/tests/cbc_test.c b/src/tests/cbc_test.c
index ada991b21..cb0f7bdea 100644
--- a/src/tests/cbc_test.c
+++ b/src/tests/cbc_test.c
@@ -36,6 +36,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/profile.h>
#include "cbc_test.h"
+/** Number of sample iterations for profiling */
+#define PROFILE_COUNT 16
+
/**
* Test CBC encryption
*
@@ -115,8 +118,7 @@ static unsigned long cbc_cost ( struct cipher_algorithm *cipher,
uint8_t key[key_len];
uint8_t iv[cipher->blocksize];
uint8_t ctx[cipher->ctxsize];
- union profiler profiler;
- unsigned long long elapsed;
+ struct profiler profiler;
unsigned long cost;
unsigned int i;
int rc;
@@ -135,13 +137,17 @@ static unsigned long cbc_cost ( struct cipher_algorithm *cipher,
assert ( rc == 0 );
cipher_setiv ( cipher, ctx, iv );
- /* Time operation */
- profile ( &profiler );
- op ( cipher, ctx, random, random, sizeof ( random ) );
- elapsed = profile ( &profiler );
+ /* Profile cipher operation */
+ memset ( &profiler, 0, sizeof ( profiler ) );
+ for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
+ profile_start ( &profiler );
+ op ( cipher, ctx, random, random, sizeof ( random ) );
+ profile_stop ( &profiler );
+ }
/* Round to nearest whole number of cycles per byte */
- cost = ( ( elapsed + ( sizeof ( random ) / 2 ) ) / sizeof ( random ) );
+ cost = ( ( profile_mean ( &profiler ) + ( sizeof ( random ) / 2 ) ) /
+ sizeof ( random ) );
return cost;
}