-
Notifications
You must be signed in to change notification settings - Fork 3k
Add optional tracing to sleep manager lock/unlock #6142
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
It would be nice if the print function was configurable, so that e.g. |
Had the same comment to be added here. @deepikabhavnani is working on tracing lib, but that might take a while. we have some logs in this codebase in some parts (not yet unified), but rather than own config would be easier to align this on something that it's been already used, then the new tracing lib would come and refactor this? @scartmell-arm please chat with @deepikabhavnani |
Yes, the intention was to use the tracing library with this, which as far as I can tell should just require replacing the |
Printing filename and line number was part of the logging implementation and was removed recently for string based implementation, will that be required here? |
The line number isn't important and the filename output isn't required as part of the interface. The FILE macro is used as an identifier to track which drivers have called the lock/unlock functions, so it isn't required as part of the interface as it's already accessible when printing the lock statistics. |
For consistency across mbed-os, the macro could be named
It would be also helpful if
|
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 actually sure why sleep manager lives in HAL, it's a driver. @SenRamakri do you think we could move it to drivers?
hal/mbed_sleep_manager.c
Outdated
// Number of drivers that can be stored in the structure | ||
#define STATISTIC_COUNT 10 | ||
|
||
typedef struct __PACKED sleep_statistic { |
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.
Remove the __PACKED
it doesn't make any difference here and generally I'm sceptical about use of packed structures, it may have negative effects on performance and put pressure on the bus with unaligned accesses.
platform/mbed_sleep.h
Outdated
sleep_tracker_unlock(__FILE__, __LINE__); \ | ||
} while (0); | ||
|
||
void sleep_tracker_lock(const char *const filename, int line); |
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 do we need it here?
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.
It's sort of the other way around, if you use serial then the deep sleep is disabled.
I am thinking of case, when no device/peripheral has locked deep sleep, so device can actually enter deep sleep.
- Last unlock, sleep_manager_unlock_deep_sleep_internal() - Counter goes down to zero.
sleep_tracker_unlock(__FILE__, __LINE__);
- This will enable UART.- So it will lock deep sleep again unlock again.
Will this be recursive? Correct me if I am missing anything or interpreting it wrongly.
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 sounds like it could be an issue, but I've never seen it happen. I've not seen UART lock the deep sleep while running the tracker, perhaps it locks it through some other means.
We currently have a distinction between "tracing" and "stats". "Tracing" utilities continuously log data on relevant events, whereas "stats" utilities allow you to manually grab snapshots about the current state. Looking at this pr, MBED_SLEEP_TRACING_ENABLED would probably be a better config name. Building on @amq comment, it'd be useful to have the MBED_SLEEP_STATS_ENABLED side as well. If you're interested this would require adding a This would be useful for tools that report stats on their own tick and profiling tests in the CI. cc @kegilbert, @c1728p9 |
platform/mbed_sleep.h
Outdated
@@ -64,6 +64,34 @@ extern "C" { | |||
* } | |||
* @endcode | |||
*/ | |||
#ifdef MBED_SLEEP_STATS_ENABLED | |||
|
|||
#define sleep_manager_lock_deep_sleep() \ |
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.
How deep is sleep for peripherals at present? Do we disable clock for UART in any target device?
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.
It's sort of the other way around, if you use serial then the deep sleep is disabled. So this info is theoretical and @scartmell-arm will create a docs how to interpret that data.
hal/mbed_sleep_manager.c
Outdated
|
||
printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock); | ||
sleep_tracker_print_stats(); | ||
printf("\r\n"); |
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.
Please move this printf inside sleep_tracker_print_stats, makes it look cleaner.
platform/mbed_sleep.h
Outdated
do \ | ||
{ \ | ||
sleep_manager_lock_deep_sleep_internal(); \ | ||
sleep_tracker_lock(__FILE__, __LINE__); \ |
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 __MODULE__
for ARM and __BASE_FILE__
for GCC_ARM instead of __FILE__
to get just filename without path details.
--no_path_in_file_macros option in IAR is to exclude path from __BASE_FILE__
, but I have not tested that.
We are dangerously close to the code freeze, lets park this one for now. |
Guys the code freeze is coming please rereview: @deepikabhavnani @SenRamakri @geky |
/morph build |
Build : SUCCESSBuild number : 1295 Triggering tests/morph test |
|
||
static sleep_statistic_t sleep_stats[STATISTIC_COUNT]; | ||
|
||
static const char* strip_path(const char* const 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.
All this runtime processing can be avoided, if we use proper compile time pre-processing macros (__MODULE__
for ARM and __BASE_FILE__
for GCC_ARM). Not blocking the release, but please update this in next PR.
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.
That's fine for ARM and GCC, but the only way to do it for IAR seems to be enabling --no_path_in_file_macros
which seems excessive unless it can be applied selectively to this 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.
--no_path_in_file_macros : I guess we will be adding this anyways in future for unified tracing.
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.
Instead of using filename can we use function name of the caller( the caller will pass __FUNCTION__
), that will avoid all these processing as well, does that work?
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 think using __BASE_FILE__
would work better, it can be added when this is altered to use the tracing.
Using __FUNCTION__
might be problematic. The names of the functions that call lock and unlock are going to be different so tracking which unlock is associated with each lock would be complicated, multiple drivers are also likely to have the same function names that lock/unlock the sleep manager, and it's difficult to identify which driver locked the sleep manager based on the function name alone
Exporter Build : SUCCESSBuild number : 956 |
Test : FAILUREBuild number : 1081 |
Heh, should all be sorted now, as indicated fixing merge conflicts is not my forte. |
/morph build |
Build : SUCCESSBuild number : 1316 Triggering tests/morph test |
@bulislaw Is the intention for this to make it into 5.8-rc1? I'm reading conflicting message from you: @scartmell-arm A friendly reminder that only maintainers should be triggering builds, especially this close to generating a release PR. |
@scartmell-arm Do you run tests or at least do a sanity compilation in between commits? I'm wondering how those merge errors got into the history in the first place, especially since they're so far apart from each other (2 days vs 6 days). |
Exporter Build : SUCCESSBuild number : 976 |
Yes, it's 5.8 the #6142 (comment) was about Chrises comment and adding extra features. |
@bulislaw @sg- @deepikabhavnani @SenRamakri @geky @c1728p9 Any final words on this PR while there's still a chance? |
hal/mbed_sleep_manager.c
Outdated
core_util_atomic_decr_u8(&stat->count, 1); | ||
|
||
printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock); | ||
sleep_tracker_print_stats(); |
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 think its an overkill to print the stats on every unlock call, particularly when we are printing the LOCK/UNLOCK info in the sleep_tracker_lock/unlock calls. But, I'm not going to block this PR for that as its not a major blocker, but you may want to re-think on that.
Test : FAILUREBuild number : 1100 |
hal/mbed_sleep_manager.c
Outdated
|
||
core_util_atomic_incr_u8(&stat->count, 1); | ||
|
||
printf("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, 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.
Why is this printf and not debug? If debug it could be stripped from a release build.
hal/mbed_sleep_manager.c
Outdated
|
||
core_util_atomic_decr_u8(&stat->count, 1); | ||
|
||
printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, 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.
Why is this printf and not debug? If debug it could be stripped from a release build.
/morph build |
Build : SUCCESSBuild number : 1319 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 980 |
Test : SUCCESSBuild number : 1104 |
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.
LGTM
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 like the review comments have been completed and Steve has approved them. Thus approving this PR overall in order to merge.
Exporter Build : FAILUREBuild number : 2363 |
Description
Add tracing output to console to track when drivers lock and unlock deep sleep. Tracing output is enabled by configuring the 'MBED_SLEEP_TRACING_ENABLED ' at compile time.
Status
IN DEVELOPMENT
Todos
Steps to test or reproduce
Define the
SLEEP_PROFILING_ENABLED
macro in an application, eg:cause deep sleep to be locked/unlock by calling a driver that locks it:
output should show: