-
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
sys/xtimer: tick conversion #9026
Conversation
84cda38
to
7635781
Compare
7635781
to
b8dc65f
Compare
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.
In general, I have no issue with adding more debug outputs as long as they are controlled by a compile time switch. See my comments below regarding the implementation though
sys/include/xtimer/tick_conversion.h
Outdated
buf_1[size] = '\0'; \ | ||
size = fmt_u32_dec(buf_2, VALUE2); \ | ||
buf_2[size] = '\0'; \ | ||
printf("32bit %" PRIu32 " "EQUAL" 1MHz : %s "#VALUE1" = %s "BASE2"\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.
pick either fmt or stdio as output, there is no reason to use PRIu32 for one argument and preformatting with fmt_u32_dec for the other argument.
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.
there are print_xxx
functions in fmt.h which you can use as a convenience instead of managing temporary buffers manually.
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.
But there is no real benefit in print_xxx
as the code then just splits the print in multiple lines.
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.
But there is no real benefit in print_xxx as the code then just splits the print in multiple lines.
Compare the stack usage and you will see the benefit ;-).
sys/include/xtimer/tick_conversion.h
Outdated
#include <stdio.h> | ||
#include <string.h> | ||
#include "fmt.h" | ||
#define DEBUG_PRINT_TICKS_32( CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) ({\ |
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.
change this to a function, it is too long to be readable as a macro.
sys/include/xtimer/tick_conversion.h
Outdated
}) | ||
#else | ||
#define DEBUG_PRINT_TICKS_32(CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) {} | ||
#define DEBUG_PRINT_TICKS_64(CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) {} |
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.
We have reached a consensus regarding ENABLE_DEBUG to use normal if statements and rely on the optimizer to discard the dead code instead of discarding the code in the preprocessor. The benefit is that the debug prints are checked for syntax errors and mistakes by the CI system even without enabling debug.
The same approach should be applicable here too.
sys/include/xtimer/tick_conversion.h
Outdated
@@ -37,97 +85,116 @@ extern "C" { | |||
#if (XTIMER_HZ != (1000000ul << XTIMER_SHIFT)) | |||
#error XTIMER_HZ != (1000000ul << XTIMER_SHIFT) | |||
#endif | |||
/* XTIMER_HZ is a power-of-two multiple of 1 MHz */ | |||
/* XTIMER_HZ is a power-of-two multiple of 1 MHz and is bigger than 1000MHz */ |
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.
1000MHz -> 1 MHz?
sys/include/xtimer/tick_conversion.h
Outdated
return (ticks >> XTIMER_SHIFT); /* divide by power of two */ | ||
} | ||
|
||
#else /* !(XTIMER_HZ > 1000000ul) */ | ||
#if ((XTIMER_HZ << XTIMER_SHIFT) != 1000000ul) | ||
#error (XTIMER_HZ << XTIMER_SHIFT) != 1000000ul | ||
#endif | ||
/* 1 MHz is a power-of-two multiple of XTIMER_HZ */ | ||
/* 1 MHz is a power-of-two multiple of XTIMER_HZ and is smaller than 1000MHz */ |
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.
1000MHz -> 1 MHz
@gebart not sure if i understand you correctly. Could you have a look at the changes! |
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 can't do a proper review now, I'm just looking at it on my phone, but you seem to have the right idea on how to use the fmt print functions.
sys/include/xtimer/tick_conversion.h
Outdated
|
||
#if ENABLE_DEBUG_PRINT_TICK_CONVERSION | ||
#ifndef MODULE_FMT | ||
#error "Module fmt is necessary to ENABLE_DEBUG_TICKS set 'USEMODULE += fmt' \ |
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.
Don't wrap this line, github syntax highlighting gets confused it seems
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.
Also, there's no need to quote the argument to #error
, everything on the line is printed verbatim to stderr by the preprocessor when it encounters the error directive
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.
Qouting is needed to wrap, if there is the no wrap, no need to qoute.
But i just try to understand this, we go ahead with code convention violations as github has a buggy code highlighting?
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.
Or just shorten the message, add more information in a code comment near this line. The error message will have the file name and line number so it's easy to find
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.
66e5634
to
2c0a48b
Compare
sys/include/xtimer/tick_conversion.h
Outdated
#ifndef XTIMER_TICK_CONVERSION_H | ||
#define XTIMER_TICK_CONVERSION_H | ||
|
||
#ifndef XTIMER_H | ||
#error "Do not include this file directly! Use xtimer.h instead" | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include "fmt.h" | ||
#include "div.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif |
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.
Here is also a bad github code highlighting.
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.
general question, do we really need separate debug function for 32 and 64 bit instead of just using the latter only?
sys/include/xtimer/tick_conversion.h
Outdated
#ifndef XTIMER_TICK_CONVERSION_H | ||
#define XTIMER_TICK_CONVERSION_H | ||
|
||
#ifndef XTIMER_H | ||
#error "Do not include this file directly! Use xtimer.h instead" | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include "fmt.h" |
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.
nit picky: please add empty line between system and riot includes
sys/include/xtimer/tick_conversion.h
Outdated
* | ||
* USEMODULE += fmt | ||
* CFLAGS += -DENABLE_DEBUG_PRINT_TICK_CONVERSION=1 | ||
* */ |
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 dup *
sys/include/xtimer/tick_conversion.h
Outdated
#endif | ||
|
||
inline void debug_print_ticks32(uint32_t clock_hz, char *sign, uint32_t from, | ||
char *base_from, uint32_t to,char *base_to) { |
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.
indention looks of, and please apply RIOT coding style see https://github.com/RIOT-OS/RIOT/wiki/Coding-conventions
sys/include/xtimer/tick_conversion.h
Outdated
} | ||
|
||
inline void debug_print_ticks64(uint32_t clock_hz, char *sign, uint64_t from, | ||
char *base_from, uint64_t to,char *base_to) { |
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.
dito, see above
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.
though I see below, that there are some diversion from the coding style here anyway, i.e. parentheses not on a new 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.
i added a seperate uncrustify commit, which also adresses this.
sys/include/xtimer/tick_conversion.h
Outdated
static inline uint32_t _xtimer_ticks_from_usec(uint32_t usec) { | ||
return usec; /* no-op */ | ||
static inline uint32_t _xtimer_usec_from_ticks(uint32_t ticks) { | ||
DEBUG_PRINT_TICKS_32(XTIMER_HZ, "=", ticks, ticks, "us"); |
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 looks like a dup here?
@smlng changed it to use one print function as the overhead from fmt64 does not matter if this debug prints are used. |
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.
still need to test this, too
} | ||
|
||
#else | ||
/* No matching implementation found, try to give meaningful error messages */ | ||
#if ((XTIMER_HZ % 15625) == 0) | ||
#error Unsupported hardware timer frequency (XTIMER_HZ), missing XTIMER_SHIFT in board.h? See xtimer.h documentation for more info | ||
#error Unsupported hardware timer frequency (XTIMER_HZ). |
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 did you changed this error message (here and below). Now the important info is only in the comments instead of showing it to the developer while compiling.
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.
see #9026 (comment)
I get the following error when building RIOT native on macOS:
|
btw. tried to use it with |
force inlining solved that for me. |
works now |
@gebart any further remarks? |
I've nothing to add, @gebart anything? |
any news here? |
@gebart?! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This PR adds a debug print to the xtimer conversion, this enables a better debuging of time conversion related problems.
The messages are as follows.