-
Notifications
You must be signed in to change notification settings - Fork 3k
Replace runtime strip_path function with compiler intrinsic equivalents #6377
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
Conversation
Sleep manager tracing strips the path from filenames and uses the result as an identifier to track drivers that unlock/lock sleep tracing. Replace the function that strips the path from the string, replace this function with a new macro, __FILENAME__ which performs the same action in a compiler specific manner. - GCC_ARM, use __builtin_strrchr which is optimized out at compile time. - ARM, use __MODULE__ which returns the filename without path. - IAR, specifiy the --no_path_in_file_macros compiler flag.
platform/mbed_power_mgmt.h
Outdated
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) | ||
#define __FILENAME__ __MODULE__ | ||
#elif defined(__GNUC__) | ||
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__) |
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.
Doesn't GCC map strchr to __builtin_strrchr automatically?
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.
Apparently yes, I just hadn't turned on optimizations when checking, it doesn't for -O0.
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.
You can use __BASE_FILE__
for GNU. https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
__BASE_FILE__
This macro expands to the name of the main input file, in the form of a C string constant. This is the source file that was specified on the command line of the preprocessor or C compiler.
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 tried it, but it doesn't work in this situation, it expands to the full path of the module that is passed into make/compiler so the output is the same as __FILE__
in this scenario, and something completely different in others.
…filepath. The use of __FILE__ macro to get a usable identifier from the driver path causes the path of the file to be stored in the .text region of the binary. Given that this remains for the entire duration of the program, storing a pointer to this string as an identifier is more efficient than copying the contents of the string during lookup/insertion.
platform/mbed_power_mgmt.h
Outdated
sleep_manager_lock_deep_sleep_internal(); \ | ||
sleep_tracker_lock(__FILE__, __LINE__); \ | ||
} while (0); | ||
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) |
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 guess we don't have to check version of ARM compiler here. __CC_ARM should be sufficient
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.
Looks good to me
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.
Looks fine, but the change --no_path_in_file_macros
in the compiler flags for IAR - is this required for this patch to land?
Changing the compiler flags sets the minor version label for this
I wouldn't say it's necessary, but removing it does change the behaviour between GCC/ARM and IAR.
|
Good snippet to see how it changes. If compiler flag change can be send separately, this bugfix can go into patch release. Otherwise this will be labeled for the next minor release due to changing compiler flags. |
That's fine, I've removed it so it can be added elsewhere. |
platform/mbed_power_mgmt.h
Outdated
sleep_tracker_lock(__FILE__, __LINE__); \ | ||
} while (0); | ||
#if defined(__CC_ARM) | ||
#define __FILENAME__ __MODULE__ |
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.
Why is this starting with __
? This resembles C lib macro but it is not ? As this is in platform header, I expect this goes to the user space (not internal use only).
If it is our own macro, should not use reserved characters (prefix ___
). Similar to what we define in mbed toolchain (shouldn't this be there rather?)
platform/mbed_toolchain.h
Outdated
// string literal. | ||
#ifndef FILENAME | ||
#if defined(__CC_ARM) | ||
#define FILENAME __MODULE__ |
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.
should it follow the same prefix MBED_FILENAME
?
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.
yep, fixed
- Move macro definition to mbed_toolchain.h - Remove double underscores from macro which are reserved. - Fix macro for IAR until compiler flags to disable path are added again.
} | ||
|
||
core_util_atomic_incr_u8(&stat->count, 1); | ||
|
||
debug("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock); | ||
debug("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_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.
Do we really need the lock/unlock calls? I would say they just repeat the same info we get out of the who's holding sleep lock prints.
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.
Those changes are in a different PR: #6349
/morph build |
Build : SUCCESSBuild number : 1523 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 1163 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 1166 |
Hmm, looks like a UBLOX_EVK_ODIN_W2 timeouts. /morph test |
Description
Replace runtime strip_path function with compiler intrinsic equivalents
Sleep manager tracing strips the path from filenames and uses the result as an identifier to track drivers that unlock/lock sleep tracing. Replace the function that strips the path from the string, replace this function with a new macro,
__FILENAME__
which performs the same action in a compiler specific manner.__MODULE__
which returns the filename without a path.Change the driver identifier in the sleep tracing manager to a pointer of the stored file path.
Currently, the identifier is 15-byte character array that is copied from the
__FILE__
of the driver being profiled. Given that the content of__FILE__
is stored inside the binary for the duration of the application it would be more efficient to store a pointer to this character string. This saves space in the statistics struct and saves time during lookup and insertion.Pull request type
@deepikabhavnani @SenRamakri @bulislaw