Page MenuHomeFreeBSD

LinuxKPI: add Exponentially Weighted Moving Average implementation
ClosedPublic

Authored by bz on May 24 2021, 5:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 14 2024, 4:57 AM
Unknown Object (File)
Dec 22 2023, 11:46 PM
Unknown Object (File)
Dec 17 2023, 12:28 PM
Unknown Object (File)
Dec 14 2023, 10:26 PM
Unknown Object (File)
Oct 19 2023, 7:42 PM
Unknown Object (File)
Oct 18 2023, 10:10 AM
Unknown Object (File)
Oct 13 2023, 11:15 PM
Unknown Object (File)
Aug 25 2023, 11:09 PM
Subscribers

Details

Summary

Add DECLARE_EWMA() which expands to a per-name EWMA implementation
as used by multiple wireless drivers.

Sposnored by: The FreeBSD Foundation
MFC After: 2 weeks
Reviewed by:
Differential Revision:

Test Plan

Someone with maths/stats clue please verify that I got it right.
It's been a while.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested review of this revision.May 24 2021, 5:59 PM

Adding Colin and David as reviewers as I think both know maths/stats very well.

LGTM. I can certainly confirm that it computes *a* exponential weighted average; whether it's the one you want (in particular, with _p fractional bits being stored but not returned), I can't say.

This revision is now accepted and ready to land.May 24 2021, 10:46 PM

Also looks good to me. Slightly pedantic suggestions:

  1. If you wanted, you could probably change the "((x << (_p)) >> d) + (((ztm1 << d) - ztm1) >> d)" to "((x << (_p)) + ((ztm1 << d) - ztm1)) >> d", which (I think) would have similar risk of overflow but might keep an extra couple of bits of precision.
  1. As Colin says, the interface truncates the _p fractional bits, rather than returning them. We could round instead, but if the Linux interface doesn't do that, we can live without it.
  1. If you really wanted to be pedantic, you could check the x value that is passed in will not overflow when shifted.

Also looks good to me. Slightly pedantic suggestions:

I decided I'll get it in as-is and then any follow-ups will be a lot easier to deal with.

  1. If you wanted, you could probably change the "((x << (_p)) >> d) + (((ztm1 << d) - ztm1) >> d)" to "((x << (_p)) + ((ztm1 << d) - ztm1)) >> d", which (I think) would have similar risk of overflow but might keep an extra couple of bits of precision.
  1. As Colin says, the interface truncates the _p fractional bits, rather than returning them. We could round instead, but if the Linux interface doesn't do that, we can live without it.

I don't know what they do internally.

  1. If you really wanted to be pedantic, you could check the x value that is passed in will not overflow when shifted.

I was thinking about checking for overflows; maybe we should address these three things?