<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thank you for your review feedback.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 19 May 2021 at 11:38, David Plowman <<a href="mailto:david.plowman@raspberrypi.com">david.plowman@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Naush<br>
<br>
Thank you for this patch.<br>
<br>
On Tue, 18 May 2021 at 11:09, Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>> wrote:<br>
><br>
> A new RPiController::Duration typedef is defined to represent a<br>
> std::chrono::duration type with double precision nanosecond timebase<br>
> that will be used throughout. This minimises the loss of precision when<br>
> converting timebases. A function for returning the duration count in any<br>
> timebase is also provided.<br>
><br>
> An operator << overload is define to help with displaying<br>
> RPiController::Duration value in stream objects.<br>
><br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> ---<br>
> src/ipa/raspberrypi/controller/duration.hpp | 33 +++++++++++++++++++++<br>
> 1 file changed, 33 insertions(+)<br>
> create mode 100644 src/ipa/raspberrypi/controller/duration.hpp<br>
><br>
> diff --git a/src/ipa/raspberrypi/controller/duration.hpp b/src/ipa/raspberrypi/controller/duration.hpp<br>
> new file mode 100644<br>
> index 000000000000..98aa3d78f52f<br>
> --- /dev/null<br>
> +++ b/src/ipa/raspberrypi/controller/duration.hpp<br>
> @@ -0,0 +1,33 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +/*<br>
> + * Copyright (C) 2021, Raspberry Pi (Trading) Limited<br>
> + *<br>
> + * duration.hpp - Helper macros for std::chrono::duration handling.<br>
> + */<br>
> +#pragma once<br>
> +<br>
> +#include <chrono><br>
> +#include <iomanip><br>
> +#include <iostream><br>
> +<br>
> +namespace RPiController {<br>
> +<br>
> +using Duration = std::chrono::duration<double, std::nano>;<br>
> +<br>
> +// Helper to convert and return the count of any std::chrono::duration type to<br>
> +// another timebase. Use a double rep type to try and preserve precision.<br>
> +template <typename P, typename T><br>
> +static constexpr double DurationValue(T const &d)<br>
> +{<br>
> + return std::chrono::duration_cast<std::chrono::duration<double, P>>(d).count();<br>
> +};<br>
> +<br>
> +static inline std::ostream &operator<<(std::ostream &os, const Duration &duration)<br>
> +{<br>
> + std::streamsize ss = os.precision();<br>
> + os << std::fixed << std::setprecision(2) << DurationValue<std::micro>(duration) << " us";<br>
<br>
I suppose I wonder slightly why we change the precision, I assume the<br>
output is just a bit tidier like that? And a space before the "us"? I<br>
guess, why not!<br></blockquote><div><br></div><div>Yes, I did not want more than 2 decimal places of precision in the output. I can remove the space</div><div>before the "us" in the next revision.</div><div><br></div><div>Regards,</div><div>Naush</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Reviewed-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br>
<br>
Thanks<br>
David<br>
<br>
> + os << std::setprecision(ss) << std::defaultfloat;<br>
> + return os;<br>
> +}<br>
> +<br>
> +} // namespace RPiController<br>
> --<br>
> 2.25.1<br>
><br>
</blockquote></div></div>