Skip to content
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

Closed
wants to merge 11 commits into from
Closed

Conversation

Josar
Copy link
Contributor

@Josar Josar commented Apr 25, 2018

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.

32bit 125000 < 1MHz : 239307 ticks = 1914456 us
32bit 125000 < 1MHz : 10000 us = 1250 ticks

@Josar Josar force-pushed the pr/tick_conversion branch from 84cda38 to 7635781 Compare April 26, 2018 00:25
@Josar Josar force-pushed the pr/tick_conversion branch from 7635781 to b8dc65f Compare April 26, 2018 00:29
Copy link
Member

@jnohlgard jnohlgard left a 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

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", \
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 ;-).

#include <stdio.h>
#include <string.h>
#include "fmt.h"
#define DEBUG_PRINT_TICKS_32( CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) ({\
Copy link
Member

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.

})
#else
#define DEBUG_PRINT_TICKS_32(CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) {}
#define DEBUG_PRINT_TICKS_64(CLOCK_HZ, EQUAL, VALUE1, VALUE2, BASE2) {}
Copy link
Member

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.

@@ -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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000MHz -> 1 MHz?

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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000MHz -> 1 MHz

@Josar
Copy link
Contributor Author

Josar commented Apr 26, 2018

@gebart not sure if i understand you correctly. Could you have a look at the changes!

Copy link
Member

@jnohlgard jnohlgard left a 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.


#if ENABLE_DEBUG_PRINT_TICK_CONVERSION
#ifndef MODULE_FMT
#error "Module fmt is necessary to ENABLE_DEBUG_TICKS set 'USEMODULE += fmt' \
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Josar Josar force-pushed the pr/tick_conversion branch from 66e5634 to 2c0a48b Compare April 26, 2018 10:52
#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
Copy link
Contributor Author

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.

Copy link
Member

@smlng smlng left a 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?

#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"
Copy link
Member

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

*
* USEMODULE += fmt
* CFLAGS += -DENABLE_DEBUG_PRINT_TICK_CONVERSION=1
* */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dup *

#endif

inline void debug_print_ticks32(uint32_t clock_hz, char *sign, uint32_t from,
char *base_from, uint32_t to,char *base_to) {
Copy link
Member

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

}

inline void debug_print_ticks64(uint32_t clock_hz, char *sign, uint64_t from,
char *base_from, uint64_t to,char *base_to) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito, see above

Copy link
Member

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.

Copy link
Contributor Author

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.

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");
Copy link
Member

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?

@Josar
Copy link
Contributor Author

Josar commented May 8, 2018

@smlng changed it to use one print function as the overhead from fmt64 does not matter if this debug prints are used.

@Josar
Copy link
Contributor Author

Josar commented May 8, 2018

@gebart @smlng squash and rebase?

@Josar
Copy link
Contributor Author

Josar commented May 14, 2018

@gebart @smlng still waiting for requests or ACK.

Copy link
Member

@smlng smlng left a 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).
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie aabadie changed the title Pr/tick conversion sys/xtimer: tick conversion May 15, 2018
@aabadie aabadie added the Area: timers Area: timer subsystems label May 15, 2018
@Josar
Copy link
Contributor Author

Josar commented May 23, 2018

@gebart @smlng can you find some time for this?

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 24, 2018
@Josar
Copy link
Contributor Author

Josar commented May 29, 2018

@gebart @smlng any further objectives?

@smlng
Copy link
Member

smlng commented May 29, 2018

I get the following error when building RIOT native on macOS:

Undefined symbols for architecture i386:
  "_debug_print_ticks", referenced from:
      __xtimer_ticks_from_usec in application_tests_xtimer_drift.a(main.o)
      __xtimer_usec_from_ticks in application_tests_xtimer_drift.a(main.o)
      __xtimer_usec_from_ticks64 in xtimer.a(xtimer.o)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
make: *** [link] Error 1

@smlng
Copy link
Member

smlng commented May 29, 2018

btw. tried to use it with tests/xtimer_drift

@Josar Josar force-pushed the pr/tick_conversion branch from 5e26b0e to ae8c7ab Compare May 29, 2018 13:47
@Josar
Copy link
Contributor Author

Josar commented May 29, 2018

force inlining solved that for me.

@smlng
Copy link
Member

smlng commented May 29, 2018

works now

@Josar
Copy link
Contributor Author

Josar commented Jun 4, 2018

@gebart any further remarks?

@Josar
Copy link
Contributor Author

Josar commented Jul 3, 2018

@smlng @gebart squash and rebase?

@smlng
Copy link
Member

smlng commented Jul 4, 2018

I've nothing to add, @gebart anything?

@Josar
Copy link
Contributor Author

Josar commented Sep 11, 2018

any news here?

@PeterKietzmann
Copy link
Member

@gebart?!

@stale
Copy link

stale bot commented Aug 10, 2019

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.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants