pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39169?usp=email )
Change subject: pcap-client: Split wrapped ctr generic calculation to helper function
......................................................................
pcap-client: Split wrapped ctr generic calculation to helper function
This gives more freedom later on (follow-up patch) to rework how the
osmocom rate_ctrs are incremented.
Change-Id: I06722bcadf1e0b81fd11787153b0c1007c08a47b
---
M src/osmo_client_core.c
1 file changed, 21 insertions(+), 14 deletions(-)
Approvals:
fixeria: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index e6e5a38..41f4dfc 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -179,24 +179,31 @@
return ~val;
}
+static uint64_t get_psbl_wrapped_ctr(u_int old_val, u_int new_val)
+{
+ uint64_t ret;
+ /*
+ * Wrapped..
+ * So let's at from N to XYZ_MAX
+ * and then from 0 to new_val
+ * Only issue is we don't know sizeof(u_int)
+ */
+ if (old_val > new_val) {
+ ret = P_CAP_UINT_MAX() - old_val;
+ ret += new_val;
+ return ret;
+ }
+ /* old_val <= new_val, Just increment it */
+ return new_val - old_val;
+}
+
static void add_psbl_wrapped_ctr(struct osmo_pcap_client *client,
u_int *old_val, u_int new_val, int ctr)
{
- /*
- * Wrapped..
- * So let's at from N to XYZ_MAX
- * and then from 0 to new_val
- * Only issue is we don't know sizeof(u_int)
- */
- if (*old_val > new_val) {
- rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), P_CAP_UINT_MAX() -
*old_val);
- rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), new_val);
- *old_val = new_val;
- return;
- }
+ uint64_t inc;
- /* Just increment it */
- rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), new_val - *old_val);
+ inc = get_psbl_wrapped_ctr(*old_val, new_val);
+ rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), inc);
*old_val = new_val;
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39169?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I06722bcadf1e0b81fd11787153b0c1007c08a47b
Gerrit-Change-Number: 39169
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>