add benchmark to app. TODO: test benchmark.

This commit is contained in:
TXuian 2022-12-07 20:51:01 +08:00
parent 02ff38a344
commit 222fc55b08
1 changed files with 4 additions and 1 deletions

View File

@ -68,7 +68,6 @@ extern benchmark_handle *get_benchmark_list();
extern void add_benchmark_handle(benchmark_handle *head, benchmark_handle *); extern void add_benchmark_handle(benchmark_handle *head, benchmark_handle *);
float tmp_diff = 0.0; float tmp_diff = 0.0;
float global_diff = 0.0; float global_diff = 0.0;
void start_trigger(clock_t *start_time) { *start_time = PrivGetTickTime(); } void start_trigger(clock_t *start_time) { *start_time = PrivGetTickTime(); }
void stop_trigger(clock_t *end_time) { *end_time = PrivGetTickTime(); } void stop_trigger(clock_t *end_time) { *end_time = PrivGetTickTime(); }
@ -103,6 +102,7 @@ void print_result() {
} }
}; };
pthread_mutex_t case_mu;
sem_t syn_sem; sem_t syn_sem;
void *run_one_example(void *arg) { void *run_one_example(void *arg) {
const benchmark_handle *handle = arg; const benchmark_handle *handle = arg;
@ -118,7 +118,9 @@ void *run_one_example(void *arg) {
if (!correct) { if (!correct) {
printf("[EmBench] Wrong result!.\n"); printf("[EmBench] Wrong result!.\n");
} }
PrivMutexObtain(&case_mu);
organize_result(handle, start_time, end_time); organize_result(handle, start_time, end_time);
PrivMutexAbandon(&case_mu);
PrivSemaphoreAbandon(&syn_sem); PrivSemaphoreAbandon(&syn_sem);
} }
@ -138,6 +140,7 @@ void *run_benchmark(void *args) {
case_attr.schedparam.sched_priority = 30; case_attr.schedparam.sched_priority = 30;
case_attr.stacksize = 16384; case_attr.stacksize = 16384;
PrivSemaphoreCreate(&syn_sem, 0, -21); PrivSemaphoreCreate(&syn_sem, 0, -21);
PrivMutexCreate(&case_mu, 0);
benchmark_handle *cur_handle = head.next; benchmark_handle *cur_handle = head.next;
while (NULL != cur_handle) { while (NULL != cur_handle) {