tests: benchmarks: sys_kernel: Add mem_slab benchmark

Add mem_slab benchmark. It measures times of allocation
and dealloaction of the slabs.

Signed-off-by: Kamil Lazowski <Kamil.Lazowski@nordicsemi.no>
This commit is contained in:
Kamil Lazowski 2020-10-22 11:41:48 +02:00 committed by Carles Cufí
parent 5cbf2ec1f7
commit a5a3798c6c
4 changed files with 128 additions and 4 deletions

View file

@ -3,7 +3,7 @@ Title: kernel Object Performance
Description:
The SysKernel test measures the performance of semaphore,
lifo, fifo and stack objects.
lifo, fifo, stack and memslab objects.
--------------------------------------------------------------------------------
@ -172,6 +172,21 @@ TEST RESULT: SUCCESSFUL
DETAILS: Average time for 1 iteration: NNNN nSec
END TEST CASE
TEST CASE: Memslab #1
TEST COVERAGE:
k_mem_slab_alloc
Starting test. Please wait...
TEST RESULT: SUCCESSFUL
DETAILS: Average time for 1 iteration: NNNN nSec
END TEST CASE
TEST CASE: Memslab #2
TEST COVERAGE:
k_mem_slab_free
Starting test. Please wait...
TEST RESULT: SUCCESSFUL
DETAILS: Average time for 1 iteration: NNNN nSec
END TEST CASE
PROJECT EXECUTION SUCCESSFUL
QEMU: Terminated

View file

@ -0,0 +1,107 @@
/* memslab.c */
/*
* Copyright (c) 2020, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "syskernel.h"
#define MEM_SLAB_BLOCK_SIZE (8)
#define MEM_SLAB_BLOCK_CNT (NUMBER_OF_LOOPS)
#define MEM_SLAB_BLOCK_ALIGN (4)
static K_MEM_SLAB_DEFINE(my_slab,
MEM_SLAB_BLOCK_SIZE,
MEM_SLAB_BLOCK_CNT,
MEM_SLAB_BLOCK_ALIGN);
/* Array contains pointers to allocated regions. */
static void *slab_array[MEM_SLAB_BLOCK_CNT];
/**
*
* @brief Memslab allocation test function.
* This test allocates available memory space.
*
* @param no_of_loops Amount of loops to run.
* @param test_repeats Amount of test repeats per loop.
*
* @return NUmber of done loops.
*/
static int mem_slab_alloc_test(int no_of_loops)
{
int i;
for (i = 0; i < no_of_loops; i++) {
if (k_mem_slab_alloc(&my_slab, &slab_array[i], K_NO_WAIT)
!= 0) {
return i;
}
}
return i;
}
/**
*
* @brief Memslab free test function.
* This test frees memory previously allocated in
* @ref mem_slab_alloc_test.
*
* @param no_of_loops Amount of loops to run.
* @param test_repeats Amount of test repeats per loop.
*
* @return NUmber of done loops.
*/
static int mem_slab_free_test(int no_of_loops)
{
int i;
for (i = 0; i < no_of_loops; i++) {
k_mem_slab_free(&my_slab, &slab_array[i]);
}
return i;
}
int mem_slab_test(void)
{
uint32_t t;
int i = 0;
int return_value = 0;
/* Test k_mem_slab_alloc. */
fprintf(output_file, sz_test_case_fmt,
"Memslab #1");
fprintf(output_file, sz_description,
"\n\tk_mem_slab_alloc");
printf(sz_test_start_fmt);
t = BENCH_START();
i = mem_slab_alloc_test(number_of_loops);
t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t);
/* Test k_mem_slab_free. */
fprintf(output_file, sz_test_case_fmt,
"Memslab #2");
fprintf(output_file, sz_description,
"\n\tk_mem_slab_free");
printf(sz_test_start_fmt);
t = BENCH_START();
i = mem_slab_free_test(number_of_loops);
t = TIME_STAMP_DELTA_GET(t);
/* Check if all slabs were freed. */
if (k_mem_slab_num_used_get(&my_slab) != 0) {
i = 0;
}
return_value += check_result(i, t);
return return_value;
}

View file

@ -165,10 +165,11 @@ void main(void)
test_result += lifo_test();
test_result += fifo_test();
test_result += stack_test();
test_result += mem_slab_test();
if (test_result) {
/* sema/lifo/fifo/stack account for 12 tests in total */
if (test_result == 12) {
/* sema/lifo/fifo/stack/mem_slab account for 14 tests in total */
if (test_result == 14) {
fprintf(output_file, sz_module_result_fmt,
sz_success);
} else {

View file

@ -51,6 +51,7 @@ int sema_test(void);
int lifo_test(void);
int fifo_test(void);
int stack_test(void);
int mem_slab_test(void);
void begin_test(void);
static inline uint32_t BENCH_START(void)