-
Notifications
You must be signed in to change notification settings - Fork 3k
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
platform: fix mem_trace trace level guard #5614
Conversation
2e8c866
to
742f052
Compare
Was this reported anywhere? Can you please amend your commit to add more details how is this fixing the issue and why are we introducing new API - how it should be used? |
Problem was discovered during mbed_drivers-mem_trace test refactoring. mbed_mem_trace.c:
|
Could be change the nomenclature used to lock/unlock? And it can be binary, I don't think we need levels really. |
18b5776
to
5500f5d
Compare
@bulislaw updated |
ping |
I do not fully understand this fix. trave_level (typo there? should be trace_level) was implemented internally to prevent this. Why do we need API to expose locking? It can not be hidden, internally done. Is this expected from a user to use everytime mem_trace API is invoked? I can see that we as a caller, we use |
|
How previously that level variable inside was failing to prevent this ? |
Previously it was protecting |
/morph build |
Build : SUCCESSBuild number : 675 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 319 |
Test : SUCCESSBuild number : 501 |
@@ -91,6 +91,9 @@ extern "C" { | |||
|
|||
extern "C" void * __wrap__malloc_r(struct _reent * r, size_t size) { | |||
void *ptr = NULL; | |||
#ifdef MBED_MEM_TRACING_ENABLED | |||
mbed_mem_trace_lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory trace mutex should be held here, otherwise another thread my have acquired this lock but not the mutex, causing logging on other threads to be dropped. Could mbed_mem_trace_lock()
include mem_trace_mutex->lock()
to simply this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mistakenly assumed that whole __wrap__malloc_r
is protected by __malloc_lock
but actually __real__malloc_r
is protected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we could encapsulate mem_trace_mutex
inside mbed_mem_trace.c
module but since it's C file we have to use raw OS mutex.
Other solution could be changing this module to cpp and use SingletonPtr<PlatformMutex>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which solution will be acceptable?
platform/mbed_mem_trace.c
Outdated
static uint8_t trace_level; | ||
static uint8_t trace_lock_count; | ||
|
||
#define TRACE_IS_LOCKED() (trace_lock_count > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns false even if lock count is 1. Maybe a different name, such as TRACE_FIRST_LOCK would be more appropriate.
updated |
platform/mbed_mem_trace.cpp
Outdated
void mbed_mem_trace_lock() | ||
{ | ||
mem_trace_mutex->lock(); | ||
core_util_atomic_incr_u8(&trace_lock_count, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick - this doesn't need to be atomically incremented since this is protected by the mutex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
923f32d
to
d78d8c0
Compare
/morph build |
Build : SUCCESSBuild number : 719 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 371 |
Test : FAILUREBuild number : 549 |
/morph test |
Test : SUCCESSBuild number : 551 |
d78d8c0
to
1e04d19
Compare
1e04d19
to
5c417d0
Compare
/morph build |
Build : SUCCESSBuild number : 754 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 407 |
Test : FAILUREBuild number : 578 |
5c417d0
to
aa22ef1
Compare
Restarting builds. Results were not reported. /morph build |
Build : SUCCESSBuild number : 765 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 421 |
Restarting uVisor test due to odd failure with K64F. /morph uvisor-test |
Test : SUCCESSBuild number : 595 |
Description
This change fix "trace inside trace" issue in mem_trace module
It prevents from tracing
malloc
/free
calls inside__wrap__realloc_r
/__wrap__calloc_r
/SUB_REALLOC
/SUB_CALLOC
Status
READY
Migrations
Change
mbed_mem_trace
module APIadd functions:
mbed_mem_trace_level_incr
mbed_mem_trace_level_decr
YES