tfrc.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _TFRC_H_
  3. #define _TFRC_H_
  4. /*
  5. * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
  6. * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
  7. * Copyright (c) 2005-6 Ian McDonald <ian.mcdonald@jandi.co.nz>
  8. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  9. * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
  10. */
  11. #include <linux/types.h>
  12. #include <linux/math64.h>
  13. #include "../../dccp.h"
  14. /* internal includes that this library exports: */
  15. #include "loss_interval.h"
  16. #include "packet_history.h"
  17. #ifdef CONFIG_IP_DCCP_TFRC_DEBUG
  18. extern bool tfrc_debug;
  19. #define tfrc_pr_debug(format, a...) DCCP_PR_DEBUG(tfrc_debug, format, ##a)
  20. #else
  21. #define tfrc_pr_debug(format, a...)
  22. #endif
  23. /* integer-arithmetic divisions of type (a * 1000000)/b */
  24. static inline u64 scaled_div(u64 a, u64 b)
  25. {
  26. BUG_ON(b == 0);
  27. return div64_u64(a * 1000000, b);
  28. }
  29. static inline u32 scaled_div32(u64 a, u64 b)
  30. {
  31. u64 result = scaled_div(a, b);
  32. if (result > UINT_MAX) {
  33. DCCP_CRIT("Overflow: %llu/%llu > UINT_MAX",
  34. (unsigned long long)a, (unsigned long long)b);
  35. return UINT_MAX;
  36. }
  37. return result;
  38. }
  39. /**
  40. * tfrc_ewma - Exponentially weighted moving average
  41. * @weight: Weight to be used as damping factor, in units of 1/10
  42. */
  43. static inline u32 tfrc_ewma(const u32 avg, const u32 newval, const u8 weight)
  44. {
  45. return avg ? (weight * avg + (10 - weight) * newval) / 10 : newval;
  46. }
  47. u32 tfrc_calc_x(u16 s, u32 R, u32 p);
  48. u32 tfrc_calc_x_reverse_lookup(u32 fvalue);
  49. u32 tfrc_invert_loss_event_rate(u32 loss_event_rate);
  50. int tfrc_tx_packet_history_init(void);
  51. void tfrc_tx_packet_history_exit(void);
  52. int tfrc_rx_packet_history_init(void);
  53. void tfrc_rx_packet_history_exit(void);
  54. int tfrc_li_init(void);
  55. void tfrc_li_exit(void);
  56. #ifdef CONFIG_IP_DCCP_TFRC_LIB
  57. int tfrc_lib_init(void);
  58. void tfrc_lib_exit(void);
  59. #else
  60. #define tfrc_lib_init() (0)
  61. #define tfrc_lib_exit()
  62. #endif
  63. #endif /* _TFRC_H_ */