Skip to content

mbedmicro-rtos-mbed tests : reduce memory consumption #4890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions TESTS/mbedmicro-rtos-mbed/malloc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#error [NOT_SUPPORTED] test not supported
#endif

#define NUM_THREADS 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The large number of threads was specifically chosen to help this test catch race conditions faster and more reliably. When I was testing this with only 2 threads, race conditions wouldn't reliably get caught in the 15 seconds the test ran for. If you want to reduce the number of threads then you'll probably need to increase the test time.

You can verify this test is working by temporarily removing the malloc locks (__malloc_lock and __malloc_unlock) in platform/mbed_retarget.cpp and running this test and waiting for a failure. You should be able to run this test a couple of times with two threads to get the mean time to failure. From that you could then adjust the test time accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi
I'm back...
Temp test done (removing malloc locks): either test is failing before first LED blink, either test is OK whatever the duration...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep us updated (as we understand the test is failing?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New commit done.
Test report added.

Copy link
Contributor

@maciejbocianski maciejbocianski Oct 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be fix in other way than thread number reduction, by removing extraneous heap allocations (by statically allocation of threads stack). PR #5338

...
uint8_t stack[THREAD_STACK_SIZE * NUM_THREADS];
...
// Allocate threads for the test
for (int i = 0; i < NUM_THREADS; i++) {
    thread_list[i] = new Thread(osPriorityNormal, THREAD_STACK_SIZE, stack + i * THREAD_STACK_SIZE);

#define NUM_THREADS 3

#if defined(__CORTEX_A9)
#define THREAD_STACK_SIZE DEFAULT_STACK_SIZE
Expand Down Expand Up @@ -55,8 +55,8 @@ void task_using_malloc(void)
int main()
{
Thread *thread_list[NUM_THREADS];
int test_time = 15;
GREENTEA_SETUP(20, "default_auto");
int test_time = 30;
GREENTEA_SETUP(40, "default_auto");

// Allocate threads for the test
for (int i = 0; i < NUM_THREADS; i++) {
Expand Down
36 changes: 20 additions & 16 deletions TESTS/mbedmicro-rtos-mbed/threads/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#error [NOT_SUPPORTED] test not supported
#endif

#if defined(TARGET_NUCLEO_F070RB) || defined(TARGET_NUCLEO_F072RB)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of changes are fine. I am not certain about this. Are we expecting to have here ifdef for varios targets .

There is not 2x768bytes available for these 2 targets?

#define THREAD_STACK_SIZE 512
#else
#define THREAD_STACK_SIZE 768
#endif

using namespace utest::v1;

Expand Down Expand Up @@ -272,7 +276,7 @@ void signal_wait_multibit_tout()
template <int S, void (*F)()>
void test_thread_signal()
{
Thread t_wait;
Thread t_wait(osPriorityNormal, THREAD_STACK_SIZE);

t_wait.start(callback(F));

Expand Down Expand Up @@ -308,7 +312,7 @@ void signal_clr()
*/
void test_thread_signal_clr()
{
Thread t_wait;
Thread t_wait(osPriorityNormal, THREAD_STACK_SIZE);

t_wait.start(callback(signal_clr));

Expand Down Expand Up @@ -412,7 +416,7 @@ void test_deleted_thread()
*/
void test_deleted()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);

TEST_ASSERT_EQUAL(Thread::Deleted, t.get_state());

Expand All @@ -435,7 +439,7 @@ void test_delay_thread()
*/
void test_delay()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);

t.start(callback(test_delay_thread));

Expand All @@ -460,7 +464,7 @@ void test_signal_thread()
*/
void test_signal()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);

t.start(callback(test_signal_thread));

Expand All @@ -484,7 +488,7 @@ void test_evt_flag_thread(osEventFlagsId_t evtflg)
*/
void test_evt_flag()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
mbed_rtos_storage_event_flags_t evtflg_mem;
osEventFlagsAttr_t evtflg_attr;
osEventFlagsId_t evtflg;
Expand Down Expand Up @@ -516,7 +520,7 @@ void test_mutex_thread(Mutex *mutex)
*/
void test_mutex()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
Mutex mutex;

mutex.lock();
Expand All @@ -543,7 +547,7 @@ void test_semaphore_thread(Semaphore *sem)
*/
void test_semaphore()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
Semaphore sem;

t.start(callback(test_semaphore_thread, &sem));
Expand All @@ -568,7 +572,7 @@ void test_msg_get_thread(Queue<int32_t, 1> *queue)
*/
void test_msg_get()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
Queue<int32_t, 1> queue;

t.start(callback(test_msg_get_thread, &queue));
Expand All @@ -594,7 +598,7 @@ void test_msg_put_thread(Queue<int32_t, 1> *queue)
*/
void test_msg_put()
{
Thread t;
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
Queue<int32_t, 1> queue;

queue.put((int32_t *)0xE1EE7);
Expand Down Expand Up @@ -642,7 +646,7 @@ void test_thread_ext_stack() {
then priority is changed and can be retrieved using @a get_priority
*/
void test_thread_prio() {
Thread t(osPriorityNormal);
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
t.start(callback(thread_wait_signal));

TEST_ASSERT_EQUAL(osPriorityNormal, t.get_priority());
Expand All @@ -666,23 +670,23 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
// macros don't play nicely with the templates (extra comma).
static const case_t cases[] = {
{"Testing single thread", test_single_thread<increment>, DEFAULT_HANDLERS},
{"Testing parallel threads", test_parallel_threads<3, increment> , DEFAULT_HANDLERS},
{"Testing parallel threads", test_parallel_threads<2, increment> , DEFAULT_HANDLERS},
{"Testing serial threads", test_serial_threads<10, increment> , DEFAULT_HANDLERS},

{"Testing single thread with yield", test_single_thread<increment_with_yield>, DEFAULT_HANDLERS},
{"Testing parallel threads with yield", test_parallel_threads<3, increment_with_yield>, DEFAULT_HANDLERS},
{"Testing parallel threads with yield", test_parallel_threads<2, increment_with_yield>, DEFAULT_HANDLERS},
{"Testing serial threads with yield", test_serial_threads<10, increment_with_yield>, DEFAULT_HANDLERS},

{"Testing single thread with wait", test_single_thread<increment_with_wait>, DEFAULT_HANDLERS},
{"Testing parallel threads with wait", test_parallel_threads<3, increment_with_wait>, DEFAULT_HANDLERS},
{"Testing parallel threads with wait", test_parallel_threads<2, increment_with_wait>, DEFAULT_HANDLERS},
{"Testing serial threads with wait", test_serial_threads<10, increment_with_wait>, DEFAULT_HANDLERS},

{"Testing single thread with child", test_single_thread<increment_with_child>, DEFAULT_HANDLERS},
{"Testing parallel threads with child", test_parallel_threads<3, increment_with_child>, DEFAULT_HANDLERS},
{"Testing parallel threads with child", test_parallel_threads<1, increment_with_child>, DEFAULT_HANDLERS},
{"Testing serial threads with child", test_serial_threads<10, increment_with_child>, DEFAULT_HANDLERS},

{"Testing single thread with murder", test_single_thread<increment_with_murder>, DEFAULT_HANDLERS},
{"Testing parallel threads with murder", test_parallel_threads<3, increment_with_murder>, DEFAULT_HANDLERS},
{"Testing parallel threads with murder", test_parallel_threads<1, increment_with_murder>, DEFAULT_HANDLERS},
{"Testing serial threads with murder", test_serial_threads<10, increment_with_murder>, DEFAULT_HANDLERS},

{"Testing thread self terminate", test_self_terminate, DEFAULT_HANDLERS},
Expand Down