Change in osmo-pcu[master]: bts: Drop specific functions to add values to counters

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Tue May 12 20:33:54 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/18227 )


Change subject: bts: Drop specific functions to add values to counters
......................................................................

bts: Drop specific functions to add values to counters

It's super annoying seeing lots of functions being called everywhere
only to find out they are only incrementing a counter. Let's drop all
those functions and increment the counter so people looking at code
doesn't see dozens of code paths evyerwhere.

Most of the commit was generated by following sh snippet:
"""
 #!/bin/bash
define_pattern="^CREATE_COUNT_ADD_INLINE"
generic_func="do_rate_ctr_add"
grep -r -l "${define_pattern}" . | xargs cat | grep "${define_pattern}("| tr -d ",;" | tr "()" " " | awk '{ print $2 " " $3 }' >/tmp/hello

while read -r func_name ctr_name
do
 #echo "$func_name -> $ctr_name";
files="$(grep -r -l "${func_name}(" .)"
for f in $files; do
echo "$f: $func_name -> $ctr_name";
sed -i "s#${func_name}(#${generic_func}(${ctr_name}, #g" $f
done;
done < /tmp/hello

grep -r -l "void ${generic_func}" | xargs sed -i "/void ${generic_func}(CTR/d"
grep -r -l "$define_pattern" | xargs sed -i "/$define_pattern/d"
"""

Change-Id: I966221d6f9fb9bb4f6068bf45ca2978008a0efed
---
M src/bts.h
M src/gprs_rlcmac_sched.cpp
M src/pdch.cpp
M src/tbf_dl.cpp
M src/tbf_ul.cpp
5 files changed, 10 insertions(+), 22 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/27/18227/1

diff --git a/src/bts.h b/src/bts.h
index 471ac2e..5090f58 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -320,12 +320,6 @@
 	/*
 	 * Statistics
 	 */
-	void rlc_dl_bytes(int bytes);
-	void rlc_dl_payload_bytes(int bytes);
-	void rlc_ul_bytes(int bytes);
-	void rlc_ul_payload_bytes(int bytes);
-	void llc_dl_bytes(int bytes);
-	void llc_ul_bytes(int bytes);
 
 	void ms_present(int32_t n);
 	int32_t ms_present_get();
@@ -336,6 +330,7 @@
 	struct rate_ctr_group *rate_counters() const;
 	struct osmo_stat_item_group *stat_items() const;
 	void do_rate_ctr_inc(unsigned int ctr_id);
+	void do_rate_ctr_add(unsigned int ctr_id, int inc);
 
 	LListHead<gprs_rlcmac_tbf>& ul_tbfs();
 	LListHead<gprs_rlcmac_tbf>& dl_tbfs();
@@ -409,17 +404,10 @@
 	rate_ctr_inc(&m_ratectrs->ctr[ctr_id]);
 }
 
-#define CREATE_COUNT_ADD_INLINE(func_name, ctr_name) \
-	inline void BTS::func_name(int inc) {\
-		rate_ctr_add(&m_ratectrs->ctr[ctr_name], inc); \
-	}
+inline void BTS::do_rate_ctr_add(unsigned int ctr_id, int inc) {
+	rate_ctr_add(&m_ratectrs->ctr[ctr_id], inc);
+}
 
-CREATE_COUNT_ADD_INLINE(rlc_dl_bytes, CTR_RLC_DL_BYTES);
-CREATE_COUNT_ADD_INLINE(rlc_dl_payload_bytes, CTR_RLC_DL_PAYLOAD_BYTES);
-CREATE_COUNT_ADD_INLINE(rlc_ul_bytes, CTR_RLC_UL_BYTES);
-CREATE_COUNT_ADD_INLINE(rlc_ul_payload_bytes, CTR_RLC_UL_PAYLOAD_BYTES);
-CREATE_COUNT_ADD_INLINE(llc_dl_bytes, CTR_LLC_DL_BYTES);
-CREATE_COUNT_ADD_INLINE(llc_ul_bytes, CTR_LLC_UL_BYTES);
 
 #define CREATE_STAT_INLINE(func_name, func_name_get, stat_name) \
 	inline void BTS::func_name(int32_t val) {\
diff --git a/src/gprs_rlcmac_sched.cpp b/src/gprs_rlcmac_sched.cpp
index 6a53468..3db3365 100644
--- a/src/gprs_rlcmac_sched.cpp
+++ b/src/gprs_rlcmac_sched.cpp
@@ -444,7 +444,7 @@
 	if (!msg)
 		return -ENOMEM;
 	/* msg is now available */
-	bts->bts->rlc_dl_bytes(msg->data_len);
+	bts->bts->do_rate_ctr_add(CTR_RLC_DL_BYTES, msg->data_len);
 
 	/* set USF */
 	OSMO_ASSERT(msgb_length(msg) > 0);
diff --git a/src/pdch.cpp b/src/pdch.cpp
index 202f642..fb02d59 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -759,7 +759,7 @@
 		return -EINVAL;
 	}
 
-	bts()->rlc_ul_bytes(len);
+	bts()->do_rate_ctr_add(CTR_RLC_UL_BYTES, len);
 
 	LOGP(DRLCMACUL, LOGL_DEBUG, "Got RLC block, coding scheme: %s, "
 		"length: %d (%d))\n", mcs_name(cs), len, cs.usedSizeUL());
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 5197717..dab1e29 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -630,14 +630,14 @@
 			&m_llc, &write_offset, &num_chunks, data, is_final, &payload_written);
 
 		if (payload_written > 0)
-			bts->rlc_dl_payload_bytes(payload_written);
+			bts->do_rate_ctr_add(CTR_RLC_DL_PAYLOAD_BYTES, payload_written);
 
 		if (ar == Encoding::AR_NEED_MORE_BLOCKS)
 			break;
 
 		LOGPTBFDL(this, LOGL_DEBUG, "Complete DL frame, len=%d\n", m_llc.frame_length());
 		gprs_rlcmac_dl_bw(this, m_llc.frame_length());
-		bts->llc_dl_bytes(m_llc.frame_length());
+		bts->do_rate_ctr_add(CTR_LLC_DL_BYTES, m_llc.frame_length());
 		m_llc.reset();
 
 		if (is_final) {
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index 90cbf8d..fee9919 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -92,7 +92,7 @@
 		frame = frames + i;
 
 		if (frame->length) {
-			bts->rlc_ul_payload_bytes(frame->length);
+			bts->do_rate_ctr_add(CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
 
 			LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
 				"starts at offset %d, "
@@ -108,7 +108,7 @@
 			/* send frame to SGSN */
 			LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", m_llc.frame_length());
 			snd_ul_ud();
-			bts->llc_ul_bytes(m_llc.frame_length());
+			bts->do_rate_ctr_add(CTR_LLC_UL_BYTES, m_llc.frame_length());
 			m_llc.reset();
 		}
 	}

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-pcu/+/18227
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: I966221d6f9fb9bb4f6068bf45ca2978008a0efed
Gerrit-Change-Number: 18227
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200512/317d9e02/attachment.htm>


More information about the gerrit-log mailing list