Skip to content

Conversation

robots
Copy link

@robots robots commented Mar 19, 2024

This PR fixes yield test with FreeRTOS.

  • Pthread emulations do not have this problem as thread resources are collected automatically.
  • With FreeRTOS buffer overflow occurs in function "bench_thread_exit" as there are no limit checks on threads_to_remove_idx variable.

This PR also does some cleaning:

  • removes compiler warning - unused argument
  • adds newline at the end of file (src/common/bench_malloc_free_test.c)


for (i = 1; i <= ITERATIONS; i++) {
gather_set1_stats(MAIN_PRIORITY, i);
bench_collect_resources();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this right? The ancillary thread should never run, so it never adds itself to the "remove list".

Copy link
Collaborator

Choose a reason for hiding this comment

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

As @edersondisouza pointed out, the ancillary thread should never run. If it is actually running then the test is not working as intended and further investigation would be needed. The presence of bench_collect_resources() would then be hiding a problem.


/**
* @brief Special ISR used to measure irq latency
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the commit message: you give a more detailed description of the issue on the PR message - could you please add that info to the commit message? It's better to have more information in it.


for (i = 1; i < ITERATIONS; i++) {
gather_set2_stats(MAIN_PRIORITY, i);
bench_collect_resources();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even here, IIUIC, the ancillary thread (bench_set2_helper) doesn't ever get to the bench_thread_exit(), it's aborted before - am I missing something?

Copy link
Author

Choose a reason for hiding this comment

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

My debugging shows that bench_thread_exit is called 1000times (or ITERATIONS times). Which effectively leads to buffer overflow. (I used different FreeRTOS_config.h than the one provided)

I have followed how other tests were organized - gather_xx_stats, bench_collect_resources. When this same template was applied on the failing test, it started to work. I have not analyzed how gather_set[12]_stats works for the yield test.

The test framework should not assume what bench does on the inside.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You indicated that a different configuration file was used. Can you identify the key differences?

Copy link
Contributor

@maiomai maiomai May 24, 2024

Choose a reason for hiding this comment

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

The issue occurs when configUSE_TIME_SLICING is defined 1 in FreeRTOSConfig.h . The bench_set2_helper() will run into bench_thread_exit() after the time slice of bench_thread_yield() is used up.

Copy link
Author

Choose a reason for hiding this comment

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

Nice catch, I didn't notice this option, as it was not in my config file and defaults to being enabled by default. I didnt have enough time to get back to testing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants