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

use std::chrono::time_point for efitimeus_t #16

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kifir23917
Copy link
Member

@kifir23917 kifir23917 marked this pull request as draft April 26, 2024 01:58
@kifir23917 kifir23917 changed the title use std::chrono::timepoint for efitimeus_t use std::chrono::time_point for efitimeus_t Apr 26, 2024
@@ -54,5 +59,23 @@ efitick_t getTimeNowNt();
#define US_PER_SECOND_F 1000000.0
#define US_PER_SECOND_LL 1000000LL

#define MS2US(MS_TIME) ((MS_TIME) * 1000)
#define US2MS(US_TIME) ((US_TIME) / 1000)
template<typename arithmetic_type> constexpr efitimeus_t USOF(const arithmetic_type& us) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid templating the conversion functions. There are scenarios where we want/need to avoid a 64b->float or 64b divide (both are slow as there's no hardware for it).

Copy link
Member Author

@kifir23917 kifir23917 Apr 26, 2024

Choose a reason for hiding this comment

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

Function USOF is actually used only in mock and unit tests. I'm not sure that we should worry about perfomance there. Maybe this header is not a good place for such stuff. But I'm not sure what place is more appropriate for functions to share between lib-time-mocks.cpp and unit tests. Do you have any suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kifir23917 new header something with obviously test name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've got rid of template functions and moved conversions float -> int64_t to tests

/**
* 64 bit time in microseconds (1/1_000_000 of a second), since boot
*/
using efitimeus_t = int64_t;
using efitimeus_t = std::chrono::time_point<std::chrono::system_clock, efidurus_t>;
Copy link
Contributor

Choose a reason for hiding this comment

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

it probably doesn't matter, but steady_clock is more correct

Copy link
Member Author

Choose a reason for hiding this comment

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

changed to steady_clock

kifir23917 added a commit to kifir23917/libfirmware that referenced this pull request Apr 27, 2024
@kifir23917 kifir23917 force-pushed the chrono branch 2 times, most recently from 4b5e704 to 6455284 Compare April 27, 2024 20:09
@rusefillc
Copy link
Contributor

See alternative approach at FOME-Tech/fome-fw#415

@kifir23917
Copy link
Member Author

Here you can see modifications to rusefi with use of new efitimeus_t

@rusefillc rusefillc force-pushed the master branch 2 times, most recently from 0d5cbb1 to 2481d39 Compare July 23, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants