add benchmark to app. TODO: test benchmark.
This commit is contained in:
parent
52cfcba2a3
commit
02ff38a344
|
@ -31,6 +31,9 @@
|
|||
#define ARRAY_SIZE(ar) (int) (sizeof(ar) / sizeof((ar)[0]))
|
||||
#define FAIL_IF(condition, error_code) if (condition) return (error_code)
|
||||
|
||||
#ifdef DBG
|
||||
#undef DBG
|
||||
#endif
|
||||
#ifdef SLRE_DEBUG
|
||||
#define DBG(x) printf x;
|
||||
#else
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* statemate.c
|
||||
*
|
||||
* This code was automatically generated by
|
||||
* the STAtechart Real-time-Code generator STARC
|
||||
* the STAtechart Real-bm_time-Code generator STARC
|
||||
* which was developed at C-LAB.
|
||||
*
|
||||
* The original StateChart specifies an experimental
|
||||
|
@ -170,7 +170,7 @@ char FH_DU__MFHA_old;
|
|||
#define FH_TUERMODUL_CTRL__END_REVERS_copy_IDX 23
|
||||
#define FH_TUERMODUL__EINKLEMMUNG_IDX 24
|
||||
|
||||
static unsigned long time;
|
||||
static unsigned long bm_time;
|
||||
char stable;
|
||||
char step;
|
||||
|
||||
|
@ -193,39 +193,39 @@ char BLOCK_ERKENNUNG_CTRL_BLOCK_ERKENNUNG_CTRL_next_state; /** 2 bits **/
|
|||
|
||||
void interface(void) {
|
||||
if (SYS_bit_get(Bitlist, entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL_IDX))
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL = time;
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL = bm_time;
|
||||
if (SYS_bit_get(Bitlist, entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL_IDX) ||
|
||||
SYS_bit_get(Bitlist, exited_BEREIT_FH_TUERMODUL_CTRL_IDX))
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRLexited_BEREIT_FH_TUERMODUL_CTRL =
|
||||
time;
|
||||
bm_time;
|
||||
if ((sc_FH_TUERMODUL_CTRL_2375_2 != 0) &&
|
||||
(time - sc_FH_TUERMODUL_CTRL_2375_2 >= 0.5)) {
|
||||
(bm_time - sc_FH_TUERMODUL_CTRL_2375_2 >= 0.5)) {
|
||||
FH_TUERMODUL__MFHA_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2375_2 = 0;
|
||||
}
|
||||
if ((sc_FH_TUERMODUL_CTRL_2352_1 != 0) &&
|
||||
(time - sc_FH_TUERMODUL_CTRL_2352_1 >= 0.5)) {
|
||||
(bm_time - sc_FH_TUERMODUL_CTRL_2352_1 >= 0.5)) {
|
||||
FH_TUERMODUL__MFHZ_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2352_1 = 0;
|
||||
}
|
||||
if ((sc_FH_TUERMODUL_CTRL_2329_1 != 0) &&
|
||||
(time - sc_FH_TUERMODUL_CTRL_2329_1 >= 0.5)) {
|
||||
(bm_time - sc_FH_TUERMODUL_CTRL_2329_1 >= 0.5)) {
|
||||
FH_TUERMODUL__MFHZ_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2329_1 = 0;
|
||||
}
|
||||
if ((sc_FH_TUERMODUL_CTRL_1781_10 != 0) &&
|
||||
(time - sc_FH_TUERMODUL_CTRL_1781_10 >= 0.5)) {
|
||||
(bm_time - sc_FH_TUERMODUL_CTRL_1781_10 >= 0.5)) {
|
||||
sc_FH_TUERMODUL_CTRL_1781_10 = 0;
|
||||
}
|
||||
if ((sc_FH_TUERMODUL_CTRL_1739_10 != 0) &&
|
||||
(time - sc_FH_TUERMODUL_CTRL_1739_10 >= 0.5)) {
|
||||
(bm_time - sc_FH_TUERMODUL_CTRL_1739_10 >= 0.5)) {
|
||||
sc_FH_TUERMODUL_CTRL_1739_10 = 0;
|
||||
}
|
||||
if ((SYS_bit_get(Bitlist,
|
||||
entered_EINSCHALTSTROM_MESSEN_BLOCK_ERKENNUNG_CTRL_IDX) ||
|
||||
BLOCK_ERKENNUNG_CTRL__N != BLOCK_ERKENNUNG_CTRL__N_old))
|
||||
tm_entered_EINSCHALTSTROM_MESSEN_BLOCK_ERKENNUNG_CTRLch_BLOCK_ERKENNUNG_CTRL__N_copy =
|
||||
time;
|
||||
bm_time;
|
||||
|
||||
} /** interface **/
|
||||
|
||||
|
@ -466,7 +466,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
((FH_TUERMODUL__MFHZ))) {
|
||||
stable = 0;
|
||||
FH_TUERMODUL__MFHZ_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2329_1 = time;
|
||||
sc_FH_TUERMODUL_CTRL_2329_1 = bm_time;
|
||||
|
||||
B_FH_TUERMODUL_CTRL_next_state = 3;
|
||||
INITIALISIERT_FH_TUERMODUL_CTRL_next_state = 3;
|
||||
|
@ -538,7 +538,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
((FH_TUERMODUL__MFHA))) {
|
||||
stable = 0;
|
||||
FH_TUERMODUL__MFHA_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2375_2 = time;
|
||||
sc_FH_TUERMODUL_CTRL_2375_2 = bm_time;
|
||||
|
||||
B_FH_TUERMODUL_CTRL_next_state = 2;
|
||||
NICHT_INITIALISIERT_NICHT_INITIALISIERT_next_state = 3;
|
||||
|
@ -548,7 +548,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
((FH_TUERMODUL__MFHZ))) {
|
||||
stable = 0;
|
||||
FH_TUERMODUL__MFHZ_copy = 0;
|
||||
sc_FH_TUERMODUL_CTRL_2352_1 = time;
|
||||
sc_FH_TUERMODUL_CTRL_2352_1 = bm_time;
|
||||
|
||||
B_FH_TUERMODUL_CTRL_next_state = 2;
|
||||
NICHT_INITIALISIERT_NICHT_INITIALISIERT_next_state = 3;
|
||||
|
@ -657,7 +657,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
SYS_bit_clr(Bitlist, active_EINKLEMMSCHUTZ_CTRL_copy_IDX);
|
||||
FH_TUERMODUL__MFHZ_copy = 0;
|
||||
|
||||
sc_FH_TUERMODUL_CTRL_1781_10 = time;
|
||||
sc_FH_TUERMODUL_CTRL_1781_10 = bm_time;
|
||||
FH_TUERMODUL__MFHA_copy = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
MANUELL_SCHLIESSEN_FH_TUERMODUL_CTRL_next_state = 1;
|
||||
SYS_bit_clr(Bitlist, active_EINKLEMMSCHUTZ_CTRL_copy_IDX);
|
||||
|
||||
sc_FH_TUERMODUL_CTRL_1739_10 = time;
|
||||
sc_FH_TUERMODUL_CTRL_1739_10 = bm_time;
|
||||
FH_TUERMODUL__MFHA_copy = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
if ((step == 1 &&
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRLexited_BEREIT_FH_TUERMODUL_CTRL !=
|
||||
0 &&
|
||||
(time -
|
||||
(bm_time -
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRLexited_BEREIT_FH_TUERMODUL_CTRL ==
|
||||
1)) &&
|
||||
((FH_TUERMODUL__MFHZ || FH_TUERMODUL__MFHA))) {
|
||||
|
@ -817,7 +817,8 @@ void generic_FH_TUERMODUL_CTRL(void) {
|
|||
{
|
||||
if ((step == 1 &&
|
||||
tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL != 0 &&
|
||||
(time - tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL == 3)) &&
|
||||
(bm_time - tm_entered_WIEDERHOLSPERRE_FH_TUERMODUL_CTRL ==
|
||||
3)) &&
|
||||
(((!(FH_TUERMODUL__MFHZ || FH_TUERMODUL__MFHA)) &&
|
||||
FH_TUERMODUL_CTRL__N > 0))) {
|
||||
stable = 0;
|
||||
|
@ -965,7 +966,7 @@ void generic_BLOCK_ERKENNUNG_CTRL(void) {
|
|||
if (step == 1 &&
|
||||
tm_entered_EINSCHALTSTROM_MESSEN_BLOCK_ERKENNUNG_CTRLch_BLOCK_ERKENNUNG_CTRL__N_copy !=
|
||||
0 &&
|
||||
(time -
|
||||
(bm_time -
|
||||
tm_entered_EINSCHALTSTROM_MESSEN_BLOCK_ERKENNUNG_CTRLch_BLOCK_ERKENNUNG_CTRL__N_copy ==
|
||||
0.002)) {
|
||||
BLOCK_ERKENNUNG_CTRL__N = BLOCK_ERKENNUNG_CTRL__N + 1;
|
||||
|
@ -1001,7 +1002,7 @@ void generic_BLOCK_ERKENNUNG_CTRL(void) {
|
|||
}
|
||||
|
||||
void FH_DU(void) {
|
||||
time = 1; /**SYS_get_clock()**/
|
||||
bm_time = 1; /**SYS_get_clock()**/
|
||||
stable = 0;
|
||||
step = 0;
|
||||
while (!stable) {
|
||||
|
|
|
@ -32,6 +32,7 @@ extern benchmark_handle libwikisort_handle;
|
|||
typedef struct BenchmarkPair {
|
||||
benchmark_handle *handle;
|
||||
char name[15];
|
||||
pthread_t task_ptr;
|
||||
float time;
|
||||
} BenchmarkPair;
|
||||
|
||||
|
@ -69,9 +70,8 @@ extern void add_benchmark_handle(benchmark_handle *head, benchmark_handle *);
|
|||
float tmp_diff = 0.0;
|
||||
|
||||
float global_diff = 0.0;
|
||||
clock_t start_time = 0, end_time = 0;
|
||||
void start_trigger(void) { start_time = PrivGetTickTime(); }
|
||||
void stop_trigger(void) { end_time = PrivGetTickTime(); }
|
||||
void start_trigger(clock_t *start_time) { *start_time = PrivGetTickTime(); }
|
||||
void stop_trigger(clock_t *end_time) { *end_time = PrivGetTickTime(); }
|
||||
|
||||
void init_benchmark_runset(benchmark_handle *head) {
|
||||
int i = 0;
|
||||
|
@ -80,7 +80,8 @@ void init_benchmark_runset(benchmark_handle *head) {
|
|||
}
|
||||
global_diff = 0;
|
||||
}
|
||||
void organize_result(const benchmark_handle *handle) {
|
||||
void organize_result(const benchmark_handle *handle, clock_t start_time,
|
||||
clock_t end_time) {
|
||||
tmp_diff = (float)(end_time - start_time) / TICK_PER_SECOND;
|
||||
global_diff += tmp_diff;
|
||||
int i = 0;
|
||||
|
@ -102,6 +103,26 @@ void print_result() {
|
|||
}
|
||||
};
|
||||
|
||||
sem_t syn_sem;
|
||||
void *run_one_example(void *arg) {
|
||||
const benchmark_handle *handle = arg;
|
||||
assert(handle != NULL);
|
||||
clock_t start_time = 0, end_time = 0;
|
||||
handle->handle.benchmark_func->initialise_benchmark();
|
||||
handle->handle.benchmark_func->warm_caches(WARMUP_HEAT);
|
||||
start_trigger(&start_time);
|
||||
volatile int result = handle->handle.benchmark_func->benchmark();
|
||||
stop_trigger(&end_time);
|
||||
|
||||
int correct = handle->handle.benchmark_func->verify_benchmark(result);
|
||||
if (!correct) {
|
||||
printf("[EmBench] Wrong result!.\n");
|
||||
}
|
||||
organize_result(handle, start_time, end_time);
|
||||
PrivSemaphoreAbandon(&syn_sem);
|
||||
}
|
||||
|
||||
pthread_attr_t case_attr;
|
||||
void *run_benchmark(void *args) {
|
||||
int i = 0;
|
||||
volatile int result;
|
||||
|
@ -114,39 +135,27 @@ void *run_benchmark(void *args) {
|
|||
init_benchmark_runset(&head);
|
||||
printf("[BENCHMARK] Start Benchmark running.\n");
|
||||
|
||||
case_attr.schedparam.sched_priority = 30;
|
||||
case_attr.stacksize = 16384;
|
||||
PrivSemaphoreCreate(&syn_sem, 0, -21);
|
||||
|
||||
benchmark_handle *cur_handle = head.next;
|
||||
while (NULL != cur_handle) {
|
||||
assert(cur_handle->handle.magic_number != MAGIC_NUMBER);
|
||||
cur_handle->handle.benchmark_func->initialise_benchmark();
|
||||
cur_handle->handle.benchmark_func->warm_caches(WARMUP_HEAT);
|
||||
|
||||
start_trigger();
|
||||
result = cur_handle->handle.benchmark_func->benchmark();
|
||||
stop_trigger();
|
||||
|
||||
correct = cur_handle->handle.benchmark_func->verify_benchmark(result);
|
||||
if (!correct) {
|
||||
printf("[EmBench] Wrong result!.\n");
|
||||
break;
|
||||
}
|
||||
organize_result(cur_handle);
|
||||
PrivTaskCreate(&cur_handle->task_ptr, &case_attr, run_one_example,
|
||||
(void *)cur_handle);
|
||||
|
||||
cur_handle = cur_handle->next;
|
||||
}
|
||||
|
||||
PrivSemaphoreObtainWait(&syn_sem, NULL);
|
||||
print_result();
|
||||
printf("[BENCHMARK] Global Time Diff: %f\n", global_diff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pthread_t benchmark_task;
|
||||
static int embenchmark(void) {
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 25;
|
||||
attr.stacksize = 16384;
|
||||
|
||||
PrivTaskCreate(&benchmark_task, &attr, run_benchmark, NULL);
|
||||
// run_benchmark(NULL);
|
||||
run_benchmark(NULL);
|
||||
return 0;
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(embenchmark, benchmark, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <transform.h>
|
||||
|
||||
#define CPU_MHZ 1
|
||||
|
||||
|
@ -38,8 +39,6 @@ static int verify_benchmark(int result);
|
|||
/* Standard functions implemented for each board */
|
||||
|
||||
void initialise_board(void);
|
||||
void start_trigger(void);
|
||||
void stop_trigger(void);
|
||||
|
||||
/* Every benchmark implements this for one-off data initialization. This is
|
||||
only used for initialization that is independent of how often benchmark ()
|
||||
|
@ -80,6 +79,7 @@ typedef struct benchmark_handle {
|
|||
benchmark_t *benchmark_func;
|
||||
} handle;
|
||||
struct benchmark_handle *next;
|
||||
pthread_t task_ptr;
|
||||
} benchmark_handle;
|
||||
|
||||
static benchmark_handle *get_benchmark_list() {
|
||||
|
|
Loading…
Reference in New Issue