2008-06-26 13:36:25 +00:00
|
|
|
/*
|
2010-02-21 07:24:53 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio.
|
2008-06-26 13:36:25 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-08 17:37:49 +00:00
|
|
|
#include "ch.h"
|
2008-06-26 13:36:25 +00:00
|
|
|
#include "test.h"
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks Kernel Benchmarks
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* This module implements a series of system benchmarks. The benchmarks are
|
|
|
|
* useful as a stress test and as a reference when comparing ChibiOS/RT
|
|
|
|
* with similar systems.
|
|
|
|
*
|
|
|
|
* <h2>Objective</h2>
|
|
|
|
* Objective of the test module is to provide a performance index for the
|
|
|
|
* most critical system subsystems. The performance numbers allow to
|
|
|
|
* discover performance regressions between successive ChibiOS/RT releases.
|
|
|
|
*
|
|
|
|
* <h2>Preconditions</h2>
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* <h2>Test Cases</h2>
|
|
|
|
* - @subpage test_benchmarks_001
|
|
|
|
* - @subpage test_benchmarks_002
|
|
|
|
* - @subpage test_benchmarks_003
|
|
|
|
* - @subpage test_benchmarks_004
|
|
|
|
* - @subpage test_benchmarks_005
|
|
|
|
* - @subpage test_benchmarks_006
|
|
|
|
* - @subpage test_benchmarks_007
|
|
|
|
* - @subpage test_benchmarks_008
|
|
|
|
* - @subpage test_benchmarks_009
|
|
|
|
* - @subpage test_benchmarks_010
|
|
|
|
* - @subpage test_benchmarks_011
|
2009-09-06 10:11:12 +00:00
|
|
|
* - @subpage test_benchmarks_012
|
2009-09-13 08:21:02 +00:00
|
|
|
* - @subpage test_benchmarks_013
|
2009-05-07 20:36:26 +00:00
|
|
|
* .
|
|
|
|
* @file testbmk.c Kernel Benchmarks
|
|
|
|
* @brief Kernel Benchmarks source file
|
|
|
|
* @file testbmk.h
|
|
|
|
* @brief Kernel Benchmarks header file
|
|
|
|
*/
|
|
|
|
|
2008-07-30 11:01:56 +00:00
|
|
|
static Semaphore sem1;
|
2009-04-04 10:50:21 +00:00
|
|
|
#if CH_USE_MUTEXES
|
2009-02-28 09:39:02 +00:00
|
|
|
static Mutex mtx1;
|
2009-04-04 10:50:21 +00:00
|
|
|
#endif
|
2008-07-30 11:01:56 +00:00
|
|
|
|
2008-07-03 15:18:59 +00:00
|
|
|
static msg_t thread1(void *p) {
|
|
|
|
msg_t msg;
|
|
|
|
|
2009-10-17 10:33:37 +00:00
|
|
|
(void)p;
|
2008-07-03 15:18:59 +00:00
|
|
|
do {
|
|
|
|
chMsgRelease(msg = chMsgWait());
|
|
|
|
} while (msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-05 18:55:46 +00:00
|
|
|
#ifdef __GNUC__
|
2008-06-26 13:36:25 +00:00
|
|
|
__attribute__((noinline))
|
2010-03-05 18:55:46 +00:00
|
|
|
#endif
|
2008-06-26 13:36:25 +00:00
|
|
|
static unsigned int msg_loop_test(Thread *tp) {
|
|
|
|
|
|
|
|
uint32_t n = 0;
|
2008-07-02 12:32:13 +00:00
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
2008-07-02 14:01:18 +00:00
|
|
|
do {
|
2008-07-03 15:18:59 +00:00
|
|
|
(void)chMsgSend(tp, 1);
|
2008-06-26 13:36:25 +00:00
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-06-26 13:36:25 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
2008-07-02 14:01:18 +00:00
|
|
|
} while (!test_timer_done);
|
2008-07-03 15:18:59 +00:00
|
|
|
(void)chMsgSend(tp, 0);
|
2008-06-26 13:36:25 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_001 Messages performance #1
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A message server thread is created with a lower priority than the client
|
|
|
|
* thread, the messages throughput per second is measured and the result
|
|
|
|
* printed in the output log.
|
|
|
|
*/
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
static char *bmk1_gettest(void) {
|
|
|
|
|
2009-05-09 20:06:52 +00:00
|
|
|
return "Benchmark, messages #1";
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk1_execute(void) {
|
|
|
|
uint32_t n;
|
|
|
|
|
2008-12-28 10:07:46 +00:00
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread1, NULL);
|
2008-06-26 13:36:25 +00:00
|
|
|
n = msg_loop_test(threads[0]);
|
|
|
|
test_wait_threads();
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_print(" msgs/S, ");
|
|
|
|
test_printn(n << 1);
|
|
|
|
test_println(" ctxswc/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk1 = {
|
|
|
|
bmk1_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2008-06-26 13:36:25 +00:00
|
|
|
bmk1_execute
|
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_002 Messages performance #2
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A message server thread is created with an higher priority than the client
|
|
|
|
* thread, the messages throughput per second is measured and the result
|
|
|
|
* printed in the output log.
|
|
|
|
*/
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
static char *bmk2_gettest(void) {
|
|
|
|
|
2009-05-09 20:06:52 +00:00
|
|
|
return "Benchmark, messages #2";
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk2_execute(void) {
|
|
|
|
uint32_t n;
|
|
|
|
|
2008-12-28 10:07:46 +00:00
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread1, NULL);
|
2008-06-26 13:36:25 +00:00
|
|
|
n = msg_loop_test(threads[0]);
|
|
|
|
test_wait_threads();
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_print(" msgs/S, ");
|
|
|
|
test_printn(n << 1);
|
|
|
|
test_println(" ctxswc/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk2 = {
|
|
|
|
bmk2_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2008-06-26 13:36:25 +00:00
|
|
|
bmk2_execute
|
|
|
|
};
|
|
|
|
|
2008-07-03 15:18:59 +00:00
|
|
|
static msg_t thread2(void *p) {
|
|
|
|
|
|
|
|
return (msg_t)p;
|
|
|
|
}
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_003 Messages performance #3
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A message server thread is created with an higher priority than the client
|
|
|
|
* thread, four lower priority threads crowd the ready list, the messages
|
|
|
|
* throughput per second is measured while the ready list and the result
|
|
|
|
* printed in the output log.
|
|
|
|
*/
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
static char *bmk3_gettest(void) {
|
|
|
|
|
2009-05-09 20:06:52 +00:00
|
|
|
return "Benchmark, messages #3";
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk3_execute(void) {
|
|
|
|
uint32_t n;
|
|
|
|
|
2008-12-28 10:07:46 +00:00
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread1, NULL);
|
|
|
|
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-2, thread2, NULL);
|
|
|
|
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread2, NULL);
|
|
|
|
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-4, thread2, NULL);
|
|
|
|
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-5, thread2, NULL);
|
2008-06-26 13:36:25 +00:00
|
|
|
n = msg_loop_test(threads[0]);
|
|
|
|
test_wait_threads();
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_print(" msgs/S, ");
|
|
|
|
test_printn(n << 1);
|
|
|
|
test_println(" ctxswc/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk3 = {
|
|
|
|
bmk3_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2008-06-26 13:36:25 +00:00
|
|
|
bmk3_execute
|
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_004 Context Switch performance
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A thread is created that just performs a @p chSchGoSleepS() into a loop,
|
|
|
|
* the thread is awakened as fast is possible by the tester thread.<br>
|
|
|
|
* The Context Switch performance is calculated by measuring the number of
|
2009-05-26 13:08:40 +00:00
|
|
|
* iterations after a second of continuous operations.
|
2009-05-07 20:36:26 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
static char *bmk4_gettest(void) {
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
return "Benchmark, context switch";
|
2009-04-13 09:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg_t thread4(void *p) {
|
|
|
|
msg_t msg;
|
|
|
|
Thread *self = chThdSelf();
|
|
|
|
|
2009-10-17 10:33:37 +00:00
|
|
|
(void)p;
|
2009-04-13 09:56:03 +00:00
|
|
|
chSysLock();
|
|
|
|
do {
|
2010-01-20 14:39:34 +00:00
|
|
|
chSchGoSleepS(THD_STATE_SUSPENDED);
|
|
|
|
msg = self->p_u.rdymsg;
|
2009-04-13 09:56:03 +00:00
|
|
|
} while (msg == RDY_OK);
|
|
|
|
chSysUnlock();
|
|
|
|
return 0;
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk4_execute(void) {
|
2009-04-13 09:56:03 +00:00
|
|
|
Thread *tp;
|
2010-03-05 18:55:46 +00:00
|
|
|
uint32_t n;
|
2008-06-26 13:36:25 +00:00
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
tp = threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread4, NULL);
|
2010-03-05 18:55:46 +00:00
|
|
|
n = 0;
|
2008-07-02 12:32:13 +00:00
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
2008-07-02 14:01:18 +00:00
|
|
|
do {
|
2009-04-13 09:56:03 +00:00
|
|
|
chSysLock();
|
|
|
|
chSchWakeupS(tp, RDY_OK);
|
|
|
|
chSchWakeupS(tp, RDY_OK);
|
|
|
|
chSchWakeupS(tp, RDY_OK);
|
|
|
|
chSchWakeupS(tp, RDY_OK);
|
|
|
|
chSysUnlock();
|
|
|
|
n += 4;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-06-26 13:36:25 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
2008-07-02 14:01:18 +00:00
|
|
|
} while (!test_timer_done);
|
2009-04-13 09:56:03 +00:00
|
|
|
chSysLock();
|
|
|
|
chSchWakeupS(tp, RDY_TIMEOUT);
|
|
|
|
chSysUnlock();
|
|
|
|
|
|
|
|
test_wait_threads();
|
2008-06-26 13:36:25 +00:00
|
|
|
test_print("--- Score : ");
|
2009-05-09 20:03:19 +00:00
|
|
|
test_printn(n * 2);
|
2009-04-13 09:56:03 +00:00
|
|
|
test_println(" ctxswc/S");
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk4 = {
|
|
|
|
bmk4_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2008-06-26 13:36:25 +00:00
|
|
|
bmk4_execute
|
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_005 Threads performance, full cycle
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* Threads are continuously created and terminated into a loop. A full
|
|
|
|
* @p chThdCreateStatic() / @p chThdExit() / @p chThdWait() cycle is performed
|
2009-05-26 13:08:40 +00:00
|
|
|
* in each iteration.<br>
|
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
static char *bmk5_gettest(void) {
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
return "Benchmark, threads, full cycle";
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk5_execute(void) {
|
2008-07-06 08:45:08 +00:00
|
|
|
|
|
|
|
uint32_t n = 0;
|
|
|
|
void *wap = wa[0];
|
2009-04-13 09:56:03 +00:00
|
|
|
tprio_t prio = chThdGetPriority() - 1;
|
2008-07-06 08:45:08 +00:00
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
2009-04-13 09:56:03 +00:00
|
|
|
chThdWait(chThdCreateStatic(wap, WA_SIZE, prio, thread2, NULL));
|
2008-07-06 08:45:08 +00:00
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-07-06 08:45:08 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_println(" threads/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk5 = {
|
|
|
|
bmk5_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2008-07-06 08:45:08 +00:00
|
|
|
bmk5_execute
|
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_006 Threads performance, create/exit only
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* Threads are continuously created and terminated into a loop. A partial
|
|
|
|
* @p chThdCreateStatic() / @p chThdExit() cycle is performed in each
|
2009-05-26 13:08:40 +00:00
|
|
|
* iteration, the @p chThdWait() is not necessary because the thread is
|
2009-05-07 20:36:26 +00:00
|
|
|
* created at an higher priority so there is no need to wait for it to
|
|
|
|
* terminate.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
static char *bmk6_gettest(void) {
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
return "Benchmark, threads, create only";
|
2009-04-13 09:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk6_execute(void) {
|
|
|
|
|
|
|
|
uint32_t n = 0;
|
|
|
|
void *wap = wa[0];
|
|
|
|
tprio_t prio = chThdGetPriority() + 1;
|
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
|
|
|
chThdCreateStatic(wap, WA_SIZE, prio, thread2, NULL);
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2009-04-13 09:56:03 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_println(" threads/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk6 = {
|
|
|
|
bmk6_gettest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bmk6_execute
|
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
2010-03-18 16:01:11 +00:00
|
|
|
* @page test_benchmarks_007 Mass reschedule performance
|
2009-05-07 20:36:26 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
2010-03-18 21:00:25 +00:00
|
|
|
* Five threads are created and atomically rescheduled by resetting the
|
2009-05-07 20:36:26 +00:00
|
|
|
* semaphore where they are waiting on. The operation is performed into a
|
|
|
|
* continuous loop.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2008-07-30 11:01:56 +00:00
|
|
|
static msg_t thread3(void *p) {
|
|
|
|
|
2009-10-17 10:33:37 +00:00
|
|
|
(void)p;
|
2008-07-30 11:01:56 +00:00
|
|
|
while (!chThdShouldTerminate())
|
|
|
|
chSemWait(&sem1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
static char *bmk7_gettest(void) {
|
2008-07-06 08:45:08 +00:00
|
|
|
|
2010-03-18 16:01:11 +00:00
|
|
|
return "Benchmark, mass reschedule, 5 threads";
|
2008-07-06 08:45:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
static void bmk7_setup(void) {
|
2008-07-06 08:45:08 +00:00
|
|
|
|
2008-07-30 11:01:56 +00:00
|
|
|
chSemInit(&sem1, 0);
|
2008-07-06 08:45:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
static void bmk7_execute(void) {
|
2008-07-30 11:01:56 +00:00
|
|
|
uint32_t n;
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+5, thread3, NULL);
|
|
|
|
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()+4, thread3, NULL);
|
2008-12-28 10:07:46 +00:00
|
|
|
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()+3, thread3, NULL);
|
2009-05-07 20:36:26 +00:00
|
|
|
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()+2, thread3, NULL);
|
|
|
|
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()+1, thread3, NULL);
|
2008-07-30 11:01:56 +00:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
|
|
|
chSemReset(&sem1, 0);
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-07-30 11:01:56 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
2008-07-30 14:56:35 +00:00
|
|
|
test_terminate_threads();
|
2008-07-30 11:01:56 +00:00
|
|
|
chSemReset(&sem1, 0);
|
|
|
|
test_wait_threads();
|
|
|
|
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
2010-03-18 16:01:11 +00:00
|
|
|
test_print(" reschedules/S, ");
|
2008-07-30 11:01:56 +00:00
|
|
|
test_printn(n * 6);
|
|
|
|
test_println(" ctxswc/S");
|
|
|
|
}
|
|
|
|
|
2009-04-13 09:56:03 +00:00
|
|
|
const struct testcase testbmk7 = {
|
|
|
|
bmk7_gettest,
|
|
|
|
bmk7_setup,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
2009-04-13 09:56:03 +00:00
|
|
|
bmk7_execute
|
2008-07-30 11:01:56 +00:00
|
|
|
};
|
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
2010-03-18 16:01:11 +00:00
|
|
|
* @page test_benchmarks_008 I/O Round-Robin voluntary reschedule.
|
2009-09-05 15:31:27 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* Five threads are created at equal priority, each thread just increases a
|
|
|
|
* variable and yields.<br>
|
|
|
|
* The performance is calculated by measuring the number of iterations after
|
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static msg_t thread8(void *p) {
|
|
|
|
|
|
|
|
do {
|
|
|
|
chThdYield();
|
|
|
|
chThdYield();
|
|
|
|
chThdYield();
|
|
|
|
chThdYield();
|
|
|
|
(*(uint32_t *)p) += 4;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2009-09-19 09:20:22 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
2009-09-05 15:31:27 +00:00
|
|
|
} while(!chThdShouldTerminate());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *bmk8_gettest(void) {
|
|
|
|
|
|
|
|
return "Benchmark, round robin context switching";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk8_execute(void) {
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
test_wait_tick();
|
|
|
|
|
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread8, (void *)&n);
|
|
|
|
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-1, thread8, (void *)&n);
|
|
|
|
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-1, thread8, (void *)&n);
|
|
|
|
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-1, thread8, (void *)&n);
|
|
|
|
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread8, (void *)&n);
|
|
|
|
|
|
|
|
chThdSleepSeconds(1);
|
|
|
|
test_terminate_threads();
|
|
|
|
test_wait_threads();
|
|
|
|
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n);
|
|
|
|
test_println(" ctxswc/S");
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk8 = {
|
|
|
|
bmk8_gettest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bmk8_execute
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @page test_benchmarks_009 I/O Queues throughput
|
2009-05-07 20:36:26 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* Four bytes are written and then read from an @p InputQueue into a continuous
|
|
|
|
* loop.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static char *bmk9_gettest(void) {
|
2008-07-30 11:01:56 +00:00
|
|
|
|
|
|
|
return "Benchmark, I/O Queues throughput";
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk9_execute(void) {
|
2010-03-05 18:55:46 +00:00
|
|
|
uint32_t n;
|
2008-06-26 13:36:25 +00:00
|
|
|
static uint8_t ib[16];
|
2009-05-01 12:58:05 +00:00
|
|
|
static InputQueue iq;
|
2008-06-26 13:36:25 +00:00
|
|
|
|
|
|
|
chIQInit(&iq, ib, sizeof(ib), NULL);
|
2010-03-05 18:55:46 +00:00
|
|
|
n = 0;
|
2008-07-02 12:32:13 +00:00
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
2008-07-02 14:01:18 +00:00
|
|
|
do {
|
2008-06-26 13:36:25 +00:00
|
|
|
chIQPutI(&iq, 0);
|
|
|
|
chIQPutI(&iq, 1);
|
|
|
|
chIQPutI(&iq, 2);
|
|
|
|
chIQPutI(&iq, 3);
|
|
|
|
(void)chIQGet(&iq);
|
|
|
|
(void)chIQGet(&iq);
|
|
|
|
(void)chIQGet(&iq);
|
|
|
|
(void)chIQGet(&iq);
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-06-26 13:36:25 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
2008-07-02 14:01:18 +00:00
|
|
|
} while (!test_timer_done);
|
2008-06-26 13:36:25 +00:00
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n * 4);
|
|
|
|
test_println(" bytes/S");
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
const struct testcase testbmk9 = {
|
|
|
|
bmk9_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-09-05 15:31:27 +00:00
|
|
|
bmk9_execute
|
2008-06-26 13:36:25 +00:00
|
|
|
};
|
2008-11-02 12:43:53 +00:00
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
2009-09-05 15:31:27 +00:00
|
|
|
* @page test_benchmarks_010 Virtual Timers set/reset performance
|
2009-05-07 20:36:26 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A virtual timer is set and immediately reset into a continuous loop.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static char *bmk10_gettest(void) {
|
2008-11-02 12:43:53 +00:00
|
|
|
|
|
|
|
return "Benchmark, virtual timers set/reset";
|
|
|
|
}
|
|
|
|
|
2009-10-17 10:33:37 +00:00
|
|
|
static void tmo(void *param) {(void)param;}
|
2008-11-02 12:43:53 +00:00
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk10_execute(void) {
|
2008-11-02 12:43:53 +00:00
|
|
|
static VirtualTimer vt1, vt2;
|
|
|
|
uint32_t n = 0;
|
|
|
|
|
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
|
|
|
chSysLock();
|
|
|
|
chVTSetI(&vt1, 1, tmo, NULL);
|
|
|
|
chVTSetI(&vt2, 10000, tmo, NULL);
|
|
|
|
chVTResetI(&vt1);
|
|
|
|
chVTResetI(&vt2);
|
|
|
|
chSysUnlock();
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2008-11-02 12:43:53 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n * 2);
|
|
|
|
test_println(" timers/S");
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
const struct testcase testbmk10 = {
|
|
|
|
bmk10_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-09-05 15:31:27 +00:00
|
|
|
bmk10_execute
|
2008-11-02 12:43:53 +00:00
|
|
|
};
|
2009-02-16 18:22:49 +00:00
|
|
|
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
2009-09-05 15:31:27 +00:00
|
|
|
* @page test_benchmarks_011 Semaphores wait/signal performance
|
2009-05-07 20:36:26 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A counting semaphore is taken/released into a continuous loop, no Context
|
|
|
|
* Switch happens because the counter is always non negative.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static char *bmk11_gettest(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
|
|
|
|
return "Benchmark, semaphores wait/signal";
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk11_setup(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
|
|
|
|
chSemInit(&sem1, 1);
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk11_execute(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
uint32_t n = 0;
|
|
|
|
|
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
|
|
|
chSemWait(&sem1);
|
|
|
|
chSemSignal(&sem1);
|
|
|
|
chSemWait(&sem1);
|
|
|
|
chSemSignal(&sem1);
|
|
|
|
chSemWait(&sem1);
|
|
|
|
chSemSignal(&sem1);
|
|
|
|
chSemWait(&sem1);
|
|
|
|
chSemSignal(&sem1);
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2009-02-28 09:39:02 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n * 4);
|
|
|
|
test_println(" wait+signal/S");
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
const struct testcase testbmk11 = {
|
|
|
|
bmk11_gettest,
|
|
|
|
bmk11_setup,
|
2009-02-28 09:39:02 +00:00
|
|
|
NULL,
|
2009-09-05 15:31:27 +00:00
|
|
|
bmk11_execute
|
2009-02-28 09:39:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if CH_USE_MUTEXES
|
2009-05-07 20:36:26 +00:00
|
|
|
/**
|
2009-09-05 15:31:27 +00:00
|
|
|
* @page test_benchmarks_012 Mutexes lock/unlock performance
|
2009-05-07 20:36:26 +00:00
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* A mutex is locked/unlocked into a continuous loop, no Context Switch happens
|
|
|
|
* because there are no other threads asking for the mutex.<br>
|
2009-05-26 13:08:40 +00:00
|
|
|
* The performance is calculated by measuring the number of iterations after
|
2009-05-07 20:36:26 +00:00
|
|
|
* a second of continuous operations.
|
|
|
|
*/
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static char *bmk12_gettest(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
|
|
|
|
return "Benchmark, mutexes lock/unlock";
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk12_setup(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
|
|
|
|
chMtxInit(&mtx1);
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
static void bmk12_execute(void) {
|
2009-02-28 09:39:02 +00:00
|
|
|
uint32_t n = 0;
|
|
|
|
|
|
|
|
test_wait_tick();
|
|
|
|
test_start_timer(1000);
|
|
|
|
do {
|
|
|
|
chMtxLock(&mtx1);
|
|
|
|
chMtxUnlock();
|
|
|
|
chMtxLock(&mtx1);
|
|
|
|
chMtxUnlock();
|
|
|
|
chMtxLock(&mtx1);
|
|
|
|
chMtxUnlock();
|
|
|
|
chMtxLock(&mtx1);
|
|
|
|
chMtxUnlock();
|
|
|
|
n++;
|
2009-12-24 09:38:50 +00:00
|
|
|
#if defined(SIMULATOR)
|
2009-02-28 09:39:02 +00:00
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
} while (!test_timer_done);
|
|
|
|
test_print("--- Score : ");
|
|
|
|
test_printn(n * 4);
|
|
|
|
test_println(" lock+unlock/S");
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:31:27 +00:00
|
|
|
const struct testcase testbmk12 = {
|
|
|
|
bmk12_gettest,
|
|
|
|
bmk12_setup,
|
2009-02-28 09:39:02 +00:00
|
|
|
NULL,
|
2009-09-05 15:31:27 +00:00
|
|
|
bmk12_execute
|
2009-02-28 09:39:02 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-09-13 08:21:02 +00:00
|
|
|
/**
|
|
|
|
* @page test_benchmarks_013 RAM Footprint
|
|
|
|
*
|
|
|
|
* <h2>Description</h2>
|
|
|
|
* The memory size of the various kernel objects is printed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *bmk13_gettest(void) {
|
|
|
|
|
|
|
|
return "Benchmark, RAM footprint";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bmk13_execute(void) {
|
|
|
|
|
|
|
|
test_print("--- System: ");
|
|
|
|
test_printn(sizeof(ReadyList) + sizeof(VTList) + IDLE_THREAD_STACK_SIZE +
|
|
|
|
(sizeof(Thread) + sizeof(struct intctx) + sizeof(struct extctx) +
|
|
|
|
INT_REQUIRED_STACK) * 2);
|
|
|
|
test_println(" bytes");
|
|
|
|
test_print("--- Thread: ");
|
|
|
|
test_printn(sizeof(Thread));
|
|
|
|
test_println(" bytes");
|
|
|
|
test_print("--- Timer : ");
|
|
|
|
test_printn(sizeof(VirtualTimer));
|
|
|
|
test_println(" bytes");
|
|
|
|
test_print("--- Semaph: ");
|
|
|
|
test_printn(sizeof(Semaphore));
|
|
|
|
test_println(" bytes");
|
|
|
|
#if CH_USE_EVENTS
|
|
|
|
test_print("--- EventS: ");
|
|
|
|
test_printn(sizeof(EventSource));
|
|
|
|
test_println(" bytes");
|
|
|
|
test_print("--- EventL: ");
|
|
|
|
test_printn(sizeof(EventListener));
|
|
|
|
test_println(" bytes");
|
|
|
|
#endif
|
|
|
|
#if CH_USE_MUTEXES
|
|
|
|
test_print("--- Mutex : ");
|
|
|
|
test_printn(sizeof(Mutex));
|
|
|
|
test_println(" bytes");
|
|
|
|
#endif
|
|
|
|
#if CH_USE_CONDVARS
|
|
|
|
test_print("--- CondV.: ");
|
|
|
|
test_printn(sizeof(CondVar));
|
|
|
|
test_println(" bytes");
|
|
|
|
#endif
|
|
|
|
#if CH_USE_QUEUES
|
|
|
|
test_print("--- Queue : ");
|
|
|
|
test_printn(sizeof(GenericQueue));
|
|
|
|
test_println(" bytes");
|
|
|
|
#endif
|
|
|
|
#if CH_USE_MAILBOXES
|
|
|
|
test_print("--- MailB.: ");
|
|
|
|
test_printn(sizeof(Mailbox));
|
|
|
|
test_println(" bytes");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testbmk13 = {
|
|
|
|
bmk13_gettest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bmk13_execute
|
|
|
|
};
|
|
|
|
|
2009-02-16 18:22:49 +00:00
|
|
|
/*
|
|
|
|
* Test sequence for benchmarks pattern.
|
|
|
|
*/
|
2009-02-28 10:38:32 +00:00
|
|
|
const struct testcase * const patternbmk[] = {
|
2009-02-16 20:38:05 +00:00
|
|
|
#if !TEST_NO_BENCHMARKS
|
2009-02-16 18:22:49 +00:00
|
|
|
&testbmk1,
|
|
|
|
&testbmk2,
|
|
|
|
&testbmk3,
|
|
|
|
&testbmk4,
|
|
|
|
&testbmk5,
|
|
|
|
&testbmk6,
|
|
|
|
&testbmk7,
|
|
|
|
&testbmk8,
|
2009-02-28 09:39:02 +00:00
|
|
|
&testbmk9,
|
|
|
|
&testbmk10,
|
2009-04-13 09:56:03 +00:00
|
|
|
&testbmk11,
|
2009-09-05 15:31:27 +00:00
|
|
|
#if CH_USE_MUTEXES
|
|
|
|
&testbmk12,
|
2009-02-28 09:39:02 +00:00
|
|
|
#endif
|
2009-09-13 08:21:02 +00:00
|
|
|
&testbmk13,
|
2009-02-16 18:22:49 +00:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|