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.

- 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.
pull/6377/head
Steven Cartmell 2018-03-15 15:49:42 +00:00
parent 5523d53f83
commit bd63f93984
4 changed files with 27 additions and 38 deletions

View File

@ -42,23 +42,6 @@ typedef struct sleep_statistic {
static sleep_statistic_t sleep_stats[STATISTIC_COUNT]; static sleep_statistic_t sleep_stats[STATISTIC_COUNT];
static const char* strip_path(const char* const filename)
{
char *output = strrchr(filename, '/');
if (output != NULL) {
return output + 1;
}
output = strrchr(filename, '\\');
if (output != NULL) {
return output + 1;
}
return filename;
}
static sleep_statistic_t* sleep_tracker_find(const char *const filename) static sleep_statistic_t* sleep_tracker_find(const char *const filename)
{ {
char temp[IDENTIFIER_WIDTH]; char temp[IDENTIFIER_WIDTH];
@ -115,34 +98,31 @@ static void sleep_tracker_print_stats(void)
void sleep_tracker_lock(const char* const filename, int line) void sleep_tracker_lock(const char* const filename, int line)
{ {
const char* const stripped_path = strip_path(filename); sleep_statistic_t *stat = sleep_tracker_find(filename);
sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
// Entry for this driver does not exist, create one. // Entry for this driver does not exist, create one.
if (stat == NULL) { if (stat == NULL) {
stat = sleep_tracker_add(stripped_path); stat = sleep_tracker_add(filename);
} }
core_util_atomic_incr_u8(&stat->count, 1); 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);
} }
void sleep_tracker_unlock(const char* const filename, int line) void sleep_tracker_unlock(const char* const filename, int line)
{ {
const char* const stripped_path = strip_path(filename); sleep_statistic_t *stat = sleep_tracker_find(filename);
sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
// Entry for this driver does not exist, something went wrong. // Entry for this driver does not exist, something went wrong.
if (stat == NULL) { if (stat == NULL) {
debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", stripped_path, line); debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", filename, line);
return; return;
} }
core_util_atomic_decr_u8(&stat->count, 1); core_util_atomic_decr_u8(&stat->count, 1);
debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock); debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
} }
#endif // MBED_SLEEP_TRACING_ENABLED #endif // MBED_SLEEP_TRACING_ENABLED

View File

@ -68,18 +68,26 @@ extern "C" {
void sleep_tracker_lock(const char *const filename, int line); void sleep_tracker_lock(const char *const filename, int line);
void sleep_tracker_unlock(const char *const filename, int line); void sleep_tracker_unlock(const char *const filename, int line);
#define sleep_manager_lock_deep_sleep() \ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
do \ #define __FILENAME__ __MODULE__
{ \ #elif defined(__GNUC__)
sleep_manager_lock_deep_sleep_internal(); \ #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__)
sleep_tracker_lock(__FILE__, __LINE__); \ #else
} while (0); #define __FILENAME__ __FILE__
#endif
#define sleep_manager_unlock_deep_sleep() \ #define sleep_manager_lock_deep_sleep() \
do \ do \
{ \ { \
sleep_manager_unlock_deep_sleep_internal(); \ sleep_manager_lock_deep_sleep_internal(); \
sleep_tracker_unlock(__FILE__, __LINE__); \ sleep_tracker_lock(__FILENAME__, __LINE__); \
} while (0);
#define sleep_manager_unlock_deep_sleep() \
do \
{ \
sleep_manager_unlock_deep_sleep_internal(); \
sleep_tracker_unlock(__FILENAME__, __LINE__); \
} while (0); } while (0);
#else #else
@ -121,7 +129,6 @@ void sleep_manager_unlock_deep_sleep_internal(void);
*/ */
bool sleep_manager_can_deep_sleep(void); bool sleep_manager_can_deep_sleep(void);
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based /** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
* on the deepsleep locking counter * on the deepsleep locking counter
* *

View File

@ -51,7 +51,8 @@
"common": [ "common": [
"--no_wrap_diagnostics", "-e", "--no_wrap_diagnostics", "-e",
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-On", "-r", "-DMBED_DEBUG", "--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-On", "-r", "-DMBED_DEBUG",
"-DMBED_TRAP_ERRORS_ENABLED=1", "--enable_restrict"], "-DMBED_TRAP_ERRORS_ENABLED=1", "--enable_restrict",
"--no_path_in_file_macros"],
"asm": [], "asm": [],
"c": ["--vla"], "c": ["--vla"],
"cxx": ["--guard_calls", "--no_static_destruction"], "cxx": ["--guard_calls", "--no_static_destruction"],

View File

@ -46,7 +46,8 @@
"IAR": { "IAR": {
"common": [ "common": [
"--no_wrap_diagnostics", "-e", "--no_wrap_diagnostics", "-e",
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-Oh", "--enable_restrict"], "--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-Oh", "--enable_restrict",
"--no_path_in_file_macros"],
"asm": [], "asm": [],
"c": ["--vla"], "c": ["--vla"],
"cxx": ["--guard_calls", "--no_static_destruction"], "cxx": ["--guard_calls", "--no_static_destruction"],