Attention is currently required from: laforge, pespin, fixeria, daniel.
osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/31903 )
Change subject: select.c: osmo_fd_unregister(): Avoid assert hit with old buggy users of the API
......................................................................
Patch Set 2:
(1 comment)
File src/core/select.c:
https://gerrit.osmocom.org/c/libosmocore/+/31903/comment/a7ce13d0_a4a68bb1
PS2, Line 234: fprintf(stderr, "osmo_fd_unregister(fd=%u) out of expected range (0..%u), fix your code!!!\n",
why printf and not an osmocom error log message?
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/31903
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
Gerrit-Change-Number: 31903
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 14 Mar 2023 11:23:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/31811 )
Change subject: bscc_sccp: Small optimiztion in bsc_sccp_inst_next_conn_id()
......................................................................
bscc_sccp: Small optimiztion in bsc_sccp_inst_next_conn_id()
Refactor the double loop to check a code path matching the sccp_instance
once instead of doing so for every subscr_conn.
If for instance let's say we have 1000 concurrent calls in progress,
which means we have 1000 subscr_conn, which means we at least do the
extra check regarding SMLC vs MSC 1000 times (at least, xN times if N
conn_id already used are already found).
That overhead happens every time a new subscr_conn is created (which in
a BSC with already 1000 concurrent calls can potentially happen quite
frequently).
Change-Id: Ic32b1eeb201fc51110e1ee130110824845f81e82
---
M src/osmo-bsc/bsc_sccp.c
1 file changed, 51 insertions(+), 13 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/src/osmo-bsc/bsc_sccp.c b/src/osmo-bsc/bsc_sccp.c
index 431e194..e0cce39 100644
--- a/src/osmo-bsc/bsc_sccp.c
+++ b/src/osmo-bsc/bsc_sccp.c
@@ -47,6 +47,33 @@
/* This looks really suboptimal, but in most cases the static next_id should indicate exactly the next unused
* conn_id, and we only iterate all conns once to make super sure that it is not already in use. */
+ /* SCCP towards SMLC: */
+ if (bsc_gsmnet->smlc->sccp == sccp) {
+ for (i = 0; i < SCCP_CONN_ID_MAX; i++) {
+ struct gsm_subscriber_connection *conn;
+ uint32_t conn_id = next_id;
+ bool conn_id_already_used = false;
+
+ /* Optimized modulo operation (% SCCP_CONN_ID_MAX) using bitwise AND plus CMP: */
+ next_id = (next_id + 1) & 0x00FFFFFF;
+ if (OSMO_UNLIKELY(next_id == 0x00FFFFFF))
+ next_id = 0;
+
+ llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
+ if (conn->lcs.lb.state != SUBSCR_SCCP_ST_NONE &&
+ conn->lcs.lb.conn_id == conn_id) {
+ conn_id_already_used = true;
+ break;
+ }
+ }
+
+ if (!conn_id_already_used)
+ return conn_id;
+ }
+ return 0xFFFFFFFF;
+ }
+
+ /* SCCP towards MSC: */
for (i = 0; i < SCCP_CONN_ID_MAX; i++) {
struct gsm_subscriber_connection *conn;
uint32_t conn_id = next_id;
@@ -58,19 +85,10 @@
next_id = 0;
llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
- if (conn->sccp.msc && conn->sccp.msc->a.sccp == sccp) {
- if (conn_id == conn->sccp.conn_id) {
- conn_id_already_used = true;
- break;
- }
- }
-
- if (bsc_gsmnet->smlc->sccp == sccp
- && conn->lcs.lb.state != SUBSCR_SCCP_ST_NONE) {
- if (conn_id == conn->lcs.lb.conn_id) {
- conn_id_already_used = true;
- break;
- }
+ if (conn->sccp.msc && conn->sccp.msc->a.sccp == sccp &&
+ conn->sccp.conn_id == conn_id) {
+ conn_id_already_used = true;
+ break;
}
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/31811
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ic32b1eeb201fc51110e1ee130110824845f81e82
Gerrit-Change-Number: 31811
Gerrit-PatchSet: 3
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: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
pespin has uploaded a new patch set (#2). ( https://gerrit.osmocom.org/c/libosmocore/+/31903 )
Change subject: select.c: osmo_fd_unregister(): Avoid assert hit with old buggy users of the API
......................................................................
select.c: osmo_fd_unregister(): Avoid assert hit with old buggy users of the API
Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
---
M src/core/select.c
1 file changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/03/31903/2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/31903
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
Gerrit-Change-Number: 31903
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-MessageType: newpatchset
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/31903 )
Change subject: select.c: osmo-fd_unregister(): Avoid assert hit with old buggy users of the API
......................................................................
select.c: osmo-fd_unregister(): Avoid assert hit with old buggy users of the API
Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
---
M src/core/select.c
1 file changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/03/31903/1
diff --git a/src/core/select.c b/src/core/select.c
index ea8c654..924356a 100644
--- a/src/core/select.c
+++ b/src/core/select.c
@@ -223,13 +223,20 @@
* osmo_fd_is_registered() */
unregistered_count++;
llist_del(&fd->list);
- OSMO_ASSERT(fd->fd >= 0);
- OSMO_ASSERT(fd->fd <= maxfd);
- osmo_fd_lookup.table[fd->fd] = NULL;
#ifndef FORCE_IO_SELECT
g_poll.num_registered--;
#endif /* FORCE_IO_SELECT */
+ if (OSMO_UNLIKELY(fd->fd < 0 || fd->fd > maxfd)) {
+ /* Some old users used to incorrectly set fd = -1 *before* calling osmo_unregister().
+ * Hence, in order to keep backward compatibility it's not possible to assert() here.
+ * Instead, print an error message since this is actually a bug in the API user. */
+ fprintf(stderr, "osmo_fd_unregister(fd=%u) out of expected range (0..%u), fix your code!!!\n",
+ fd->fd, maxfd);
+ return;
+ }
+
+ osmo_fd_lookup.table[fd->fd] = NULL;
/* If existent, free any statistical data */
osmo_stats_tcp_osmo_fd_unregister(fd);
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/31903
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
Gerrit-Change-Number: 31903
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/31902 )
Change subject: select.c: Clarify osmo_fd_unregister() can only be called on registered osmo_fds
......................................................................
select.c: Clarify osmo_fd_unregister() can only be called on registered osmo_fds
Change-Id: I5e397e121f2fe2254c7f4b474e6eefd7aebe7a83
---
M src/core/select.c
1 file changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/02/31902/1
diff --git a/src/core/select.c b/src/core/select.c
index 584de24..ea8c654 100644
--- a/src/core/select.c
+++ b/src/core/select.c
@@ -212,6 +212,7 @@
/*! Unregister a file descriptor from select loop abstraction
* \param[in] fd osmocom file descriptor to be unregistered
*
+ * Caller is responsible from ensuring the fd is really registered before calling this API.
* This function must be called before changing the value of the fd field in
* the struct osmo_fd.
*/
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/31902
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5e397e121f2fe2254c7f4b474e6eefd7aebe7a83
Gerrit-Change-Number: 31902
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange