[ovs-dev] [PATCH] stopwatch: Fix qsort comparison function.
Mark Michelson
mmichels at redhat.com
Tue Dec 18 19:19:32 UTC 2018
Thanks for the fix Ilya.
Acked-by: Mark Michelson <mmichels at redhat.com>
On 12/18/18 11:38 AM, Ilya Maximets wrote:
> Current version is broken because it converts first argument to
> integer and after that substracts the duoble value. At the end
> the result converted to integer again.
> This does not cause unit test failures because qsort on linux
> accidentially makes right order. On FreeBSD this leads to the
> test failure:
>
> TEST '10-intervals-linear-growth'
> Assertion \
> '|(&stats)->pctl_95 - (&d->expected_stats)->pctl_95| < 1e-1' failed:
> |9 - 10| < 0.1
>
> CC: Mark Michelson <mmichels at redhat.com>
> Fixes: aed45befeff2 ("Add stopwatch timing API")
> Signed-off-by: Ilya Maximets <i.maximets at samsung.com>
> ---
> lib/stopwatch.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/lib/stopwatch.c b/lib/stopwatch.c
> index 2e69d8189..b8b31da67 100644
> --- a/lib/stopwatch.c
> +++ b/lib/stopwatch.c
> @@ -104,7 +104,13 @@ comp_samples(const void *left, const void *right)
> const double *left_d = left;
> const double *right_d = right;
>
> - return (int) *right_d - *left_d;
> + if (*right_d > *left_d) {
> + return -1;
> + }
> + if (*right_d < *left_d) {
> + return 1;
> + }
> + return 0;
> }
>
> /* Calculate the percentile using the P-square algorithm. For more
>
More information about the dev
mailing list