mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			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
							parent
							
								
									5523d53f83
								
							
						
					
					
						commit
						bd63f93984
					
				| 
						 | 
				
			
			@ -42,23 +42,6 @@ typedef struct sleep_statistic {
 | 
			
		|||
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
    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)
 | 
			
		||||
{
 | 
			
		||||
    const char* const stripped_path = strip_path(filename);
 | 
			
		||||
 | 
			
		||||
    sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
 | 
			
		||||
    sleep_statistic_t *stat = sleep_tracker_find(filename);
 | 
			
		||||
 | 
			
		||||
    // Entry for this driver does not exist, create one.
 | 
			
		||||
    if (stat == NULL) {
 | 
			
		||||
        stat = sleep_tracker_add(stripped_path);
 | 
			
		||||
        stat = sleep_tracker_add(filename);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
{
 | 
			
		||||
    const char* const stripped_path = strip_path(filename);
 | 
			
		||||
    sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
 | 
			
		||||
    sleep_statistic_t *stat = sleep_tracker_find(filename);
 | 
			
		||||
 | 
			
		||||
    // Entry for this driver does not exist, something went wrong.
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,18 +68,26 @@ extern "C" {
 | 
			
		|||
void sleep_tracker_lock(const char *const filename, int line);
 | 
			
		||||
void sleep_tracker_unlock(const char *const filename, int line);
 | 
			
		||||
 | 
			
		||||
#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__)
 | 
			
		||||
#else
 | 
			
		||||
#define __FILENAME__ __FILE__
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define sleep_manager_lock_deep_sleep()             \
 | 
			
		||||
    do                                              \
 | 
			
		||||
    {                                               \
 | 
			
		||||
        sleep_manager_lock_deep_sleep_internal();   \
 | 
			
		||||
        sleep_tracker_lock(__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(__FILE__, __LINE__);   \
 | 
			
		||||
        sleep_tracker_unlock(__FILENAME__, __LINE__); \
 | 
			
		||||
    } while (0);
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +129,6 @@ void sleep_manager_unlock_deep_sleep_internal(void);
 | 
			
		|||
 */
 | 
			
		||||
bool sleep_manager_can_deep_sleep(void);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
 | 
			
		||||
 *  on the deepsleep locking counter
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,7 +51,8 @@
 | 
			
		|||
        "common": [
 | 
			
		||||
            "--no_wrap_diagnostics",  "-e",
 | 
			
		||||
            "--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": [],
 | 
			
		||||
        "c": ["--vla"],
 | 
			
		||||
        "cxx": ["--guard_calls", "--no_static_destruction"],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,7 +46,8 @@
 | 
			
		|||
    "IAR": {
 | 
			
		||||
        "common": [
 | 
			
		||||
            "--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": [],
 | 
			
		||||
        "c": ["--vla"],
 | 
			
		||||
        "cxx": ["--guard_calls", "--no_static_destruction"],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue