-
Notifications
You must be signed in to change notification settings - Fork 2k
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
debug_irq_disable: add module to debug time spent in irq_disable #18795
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (C) 2022 Benjamin Valentin | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
# | ||
|
||
menuconfig MODULE_DEBUG_IRQ_DISABLE | ||
bool "Measure IRQ disable durations" | ||
depends on TEST_KCONFIG | ||
depends on CPU_CORE_CORTEX_M | ||
help | ||
Print time spent with IRQs disabled | ||
|
||
config DEBUG_IRQ_DISABLE_THRESHOLD | ||
int "Suppress Threshold" | ||
default 1 | ||
depends on MODULE_DEBUG_IRQ_DISABLE | ||
help | ||
Threshold (in CPU ticks) below which periods with IRQs disabled are not printed. | ||
Use this to prevent *a lot* of output when debugging. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup debug_irq_disable | ||
* @{ | ||
* | ||
* @file | ||
* @brief Helper for debug_irq_disable | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
* @} | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include "fmt.h" | ||
#include "debug_irq_disable.h" | ||
|
||
void debug_irq_disable_print(const char *file, unsigned line, uint32_t ticks) | ||
{ | ||
static unsigned is_printing; | ||
static unsigned init_skip = 10; | ||
|
||
/* if we try to print before libc is initialized, we will hard fault */ | ||
if (init_skip && --init_skip) { | ||
return; | ||
} | ||
|
||
if (is_printing) { | ||
return; | ||
} | ||
|
||
if (ticks < CONFIG_DEBUG_IRQ_DISABLE_THRESHOLD) { | ||
return; | ||
} | ||
|
||
/* prevent infinite recursion if stdio driver uses irq_disable() */ | ||
++is_printing; | ||
|
||
print_str("irq disabled for "); | ||
print_u32_dec(ticks); | ||
print_str(" ticks in "); | ||
print_str(file); | ||
print_str(":"); | ||
print_u32_dec(line); | ||
print_str("\n"); | ||
|
||
--is_printing; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup debug_irq_disable IRQ Disable Debug helper | ||
* @ingroup sys | ||
* @brief Debug time spent with IRQ disabled | ||
* @{ | ||
* | ||
* @file | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
*/ | ||
|
||
#ifndef DEBUG_IRQ_DISABLE_H | ||
#define DEBUG_IRQ_DISABLE_H | ||
|
||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Threshold (in CPU ticks) below which periods with IRQs | ||
* disabled are not printed. | ||
* | ||
* Use this to prevent *a lot* of output when debugging. | ||
*/ | ||
#ifndef CONFIG_DEBUG_IRQ_DISABLE_THRESHOLD | ||
#define CONFIG_DEBUG_IRQ_DISABLE_THRESHOLD (1) | ||
jue89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
|
||
/** | ||
* @brief Print time spent with IRQ disabled | ||
* @internal | ||
* | ||
* @param[in] file file where irq_restore() was called | ||
* @param[in] line line where irq_restore() was called | ||
* @param[in] ticks CPU ticks spent with IRQ disabled | ||
*/ | ||
void debug_irq_disable_print(const char *file, unsigned line, uint32_t ticks); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
/** @} */ | ||
#endif /* DEBUG_IRQ_DISABLE_H */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
wouldn't this work better if we keep the systick running and store the lock time
and than
return reload_mask & ( unlock_time -locktime)
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 you think that's better? We'd need an extra variable and start / stop would no longer by symmetric, we'd need an extra function to start the SysTick.
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 way this PR does it is: ether use systick for this xor for something else (e.g.: your countdowntimer)
The way would allow you to have any Initialisation on that systick (counting down or systicking around) and do this and all that needs is
static uint32_t
i am not sure if it also would be quicker since these are 3 memory write accesses and mine has 1 read and 1 write for start and this has 1 read and 1 write for stop vs mine has 2 reads.
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 Countdown timer wouldn't run the SysTick continuously either, only when there is a countdown scheduled.
It would be incompatible with this either way, if merged.
And I'm not that concerned about a few instructions here - the UART printouts will ensure that this is purely a debug feature and can't be used for anything performance critical 😉