From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 3/8] util: add util_exponential_decay
Date: Tue, 19 Nov 2024 06:24:25 -0800 [thread overview]
Message-ID: <20241119142430.323074-3-prestwoj@gmail.com> (raw)
In-Reply-To: <20241119142430.323074-1-prestwoj@gmail.com>
This is copied from network.c that uses a static table to lookup
exponential decay values by index (generated from 1/pow(n, 0.3)).
network.c uses this for network ranking but it can be useful for
BSS ranking as well if you need to apply some exponential backoff
to a value.
---
src/util.c | 28 ++++++++++++++++++++++++++++
src/util.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/src/util.c b/src/util.c
index a6ab9d85..b673b002 100644
--- a/src/util.c
+++ b/src/util.c
@@ -636,3 +636,31 @@ struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set,
return new;
}
+
+/* First 64 entries calculated by 1 / pow(n, 0.3) for n >= 1 */
+static const double rankmod_table[] = {
+ 1.0000000000, 0.8122523964, 0.7192230933, 0.6597539554,
+ 0.6170338627, 0.5841906811, 0.5577898253, 0.5358867313,
+ 0.5172818580, 0.5011872336, 0.4870596972, 0.4745102806,
+ 0.4632516708, 0.4530661223, 0.4437850034, 0.4352752816,
+ 0.4274303178, 0.4201634287, 0.4134032816, 0.4070905315,
+ 0.4011753236, 0.3956154062, 0.3903746872, 0.3854221125,
+ 0.3807307877, 0.3762772797, 0.3720410580, 0.3680040435,
+ 0.3641502401, 0.3604654325, 0.3569369365, 0.3535533906,
+ 0.3503045821, 0.3471812999, 0.3441752105, 0.3412787518,
+ 0.3384850430, 0.3357878061, 0.3331812996, 0.3306602598,
+ 0.3282198502, 0.3258556179, 0.3235634544, 0.3213395618,
+ 0.3191804229, 0.3170827751, 0.3150435863, 0.3130600345,
+ 0.3111294892, 0.3092494947, 0.3074177553, 0.3056321221,
+ 0.3038905808, 0.3021912409, 0.3005323264, 0.2989121662,
+ 0.2973291870, 0.2957819051, 0.2942689208, 0.2927889114,
+ 0.2913406263, 0.2899228820, 0.2885345572, 0.2871745887,
+};
+
+double util_exponential_decay(unsigned int n)
+{
+ if (n > L_ARRAY_SIZE(rankmod_table))
+ return rankmod_table[L_ARRAY_SIZE(rankmod_table) - 1];
+
+ return rankmod_table[n];
+}
diff --git a/src/util.h b/src/util.h
index 9f3f0a57..8aef2985 100644
--- a/src/util.h
+++ b/src/util.h
@@ -141,4 +141,6 @@ struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set,
DEFINE_CLEANUP_FUNC(scan_freq_set_free);
+double util_exponential_decay(unsigned int n);
+
#endif /* __UTIL_H */
--
2.34.1
next prev parent reply other threads:[~2024-11-19 14:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 14:24 [PATCH 1/8] util: add util_linear_map James Prestwood
2024-11-19 14:24 ` [PATCH 2/8] unit: add linear mapping test James Prestwood
2024-11-19 14:24 ` James Prestwood [this message]
2024-11-20 17:52 ` [PATCH 3/8] util: add util_exponential_decay Denis Kenzior
2024-11-19 14:24 ` [PATCH 4/8] network: use util_exponential_decay James Prestwood
2024-11-19 14:24 ` [PATCH 5/8] scan: parse station count from BSS load IE James Prestwood
2024-11-19 14:24 ` [PATCH 6/8] scan: add ranking modifiers for utilization/station count James Prestwood
2024-11-19 14:24 ` [PATCH 7/8] doc: document [Rank].HighUtilization/StationCount thresholds James Prestwood
2024-11-19 14:24 ` [PATCH 8/8] station: print client count in scan results James Prestwood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241119142430.323074-3-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox