[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 3: (2 comments) Patchset: PS1: > Rounding up is perfectly fine because scheduling granularity can be expected > to be much higher anywa […] Done File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/17b92c91_517005cf PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; > Just hacked some test code with one random timer. […] Done -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 3 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Comment-Date: Wed, 31 Jan 2024 10:46:46 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: Hoernchen Comment-In-Reply-To: jolly Comment-In-Reply-To: pespin Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
jolly has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Prevent poll() in select.c to timeout too early Adjust osmo_timers_nearest_ms() to round up the remaining time. Note that poll() has a granularity of 1 millisecond. Previously, when rounding down the remaining time, osmo_select_main() would return too early, before the nearest timer timed out. Consequently, the main loop repeatedly called osmo_select_main() until the timer actually timed out, resulting in excessive CPU usage. By modifying osmo_timers_nearest_ms() to round up the remaining time, we ensure accurate timeout calculations, preventing unnecessary CPU consumption during the main loop. The patch only applies to non-embedded version of libosmocore, because the impact on embedded systems is not verified tested. Related: OS#6339 Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 --- M src/core/timer.c 1 file changed, 34 insertions(+), 0 deletions(-) Approvals: Hoernchen: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve diff --git a/src/core/timer.c b/src/core/timer.c index 20d87a0..067bd87 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -191,7 +191,16 @@ return -1; nearest_ms = nearest_p->tv_sec * 1000; +#ifndef EMBEDDED + /* By adding 999 milliseconds, we ensure rounding up to the nearest +* whole millisecond. This approach prevents the return of 0 when the +* timer is still active, and it guarantees that the calling process +* does not wait for a duration shorter than the time remaining on the +* timer. */ + nearest_ms += (nearest_p->tv_usec + 999) / 1000; +#else nearest_ms += nearest_p->tv_usec / 1000; +#endif return nearest_ms; } -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 3 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-MessageType: merged
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, jolly, pespin. Hoernchen has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 2 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Tue, 30 Jan 2024 11:56:08 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, jolly, pespin. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 2 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: jolly Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Tue, 30 Jan 2024 11:54:32 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, jolly, laforge, pespin. Hello Hoernchen, Jenkins Builder, laforge, pespin, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review+1 by pespin, Code-Review+2 by Hoernchen, Verified+1 by Jenkins Builder The change is no longer submittable: Code-Review and Verified are unsatisfied now. Change subject: Prevent poll() in select.c to timeout too early .. Prevent poll() in select.c to timeout too early Adjust osmo_timers_nearest_ms() to round up the remaining time. Note that poll() has a granularity of 1 millisecond. Previously, when rounding down the remaining time, osmo_select_main() would return too early, before the nearest timer timed out. Consequently, the main loop repeatedly called osmo_select_main() until the timer actually timed out, resulting in excessive CPU usage. By modifying osmo_timers_nearest_ms() to round up the remaining time, we ensure accurate timeout calculations, preventing unnecessary CPU consumption during the main loop. The patch only applies to non-embedded version of libosmocore, because the impact on embedded systems is not verified tested. Related: OS#6339 Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 --- M src/core/timer.c 1 file changed, 34 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/35672/2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 2 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-MessageType: newpatchset
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, jolly, laforge, pespin. Hoernchen has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) Patchset: PS1: > It is still unresolved, whether we should round up always or only if the > remaining time is < 1 ms. […] Rounding up is perfectly fine because scheduling granularity can be expected to be much higher anyway unless you apply sched_rr or other use other schedulers, but even in that case lower latencies imply a select loop that has nothing else to do, so the expected delay is "in general" not accurate anyway. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Tue, 30 Jan 2024 09:23:25 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: Hoernchen Comment-In-Reply-To: jolly Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, laforge, pespin. jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) Patchset: PS1: > I have no idea how the scheduler works, but if a process is not running > (during poll()), I guess the […] It is still unresolved, whether we should round up always or only if the remaining time is < 1 ms. Both solutions are fine for me. The first solution is a bit faster,especially if the application does other things (like processing queues) in the main loop. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Fri, 26 Jan 2024 08:58:19 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: Hoernchen Comment-In-Reply-To: jolly Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, jolly, laforge, pespin. Hoernchen has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 18:59:15 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, laforge, pespin. jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) Patchset: PS1: > rounding up should be fine, but tbh, I can't quite see the actual real world > issue here - it would r […] I have no idea how the scheduler works, but if a process is not running (during poll()), I guess the CPU thread will be directly switched to another process that is running (due to an event). I have an application that uses timer to schedule RTP stream at a rate of 50 frames per second. This is 20 ms delay between frames. Without this patch, the CPU usage at "top" command shows around 5% CPU usage, with a patch (round up or change from 0 to 1) it shows below 1% CPU usage. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 18:31:19 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: Hoernchen Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, jolly, laforge, pespin. Hoernchen has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) Patchset: PS1: rounding up should be fine, but tbh, I can't quite see the actual real world issue here - it would require 1) < 1ms timout 2) absolutely nothing else to do while repeatedly calling the function which does "nothing" 3) no scheduling of any other task because scheduling granularity is way wy above 1ms anyway... -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 17:09:22 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, laforge, pespin. jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/022bd86c_d6108823 PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; > Mhh yeah. […] Just hacked some test code with one random timer. As I stated above the main loop will call poll() again. On the other hand this is no big performance issue. The early return of poll() will not cause any significant processing, because there is no file descriptor event, nor a timeout to handle. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 16:56:38 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: jolly Comment-In-Reply-To: pespin Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: Hoernchen, fixeria, jolly, laforge. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: Code-Review+1 (1 comment) File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/46f22620_3f60e09c PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; > If we round down values above 1 ms, we still have the problem that timers > that have a remaining time […] Mhh yeah. The main problem here is poll() having a millisecond timeout, but there's not much that we can do there. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: Hoernchen Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 16:18:35 + Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Comment-In-Reply-To: jolly Comment-In-Reply-To: pespin Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, pespin. jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (1 comment) File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/90d9b82a_6bdb986e PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; > Ack, maybe it makes sense to round 0->1 to avoid busy polls, and let the > others X.Y ->X.0. […] If we round down values above 1 ms, we still have the problem that timers that have a remaining time of more than 1 ms will cause poll() to exit too early. The result is that the main loop will call the poll() again, but this time with less than 1 ms, rounded up to 1 ms. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 25 Jan 2024 16:14:36 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: pespin Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: fixeria, jolly. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: -Code-Review (1 comment) File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/af2fde1a_22828c3d PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; > Just curious: in which project did you find timers less than 1 ms? […] Ack, maybe it makes sense to round 0->1 to avoid busy polls, and let the others X.Y ->X.0. Anyway the system will already add some extra time when processing, so let's not add more time ourselves here. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Attention: fixeria Gerrit-Comment-Date: Wed, 24 Jan 2024 19:59:31 + Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: jolly. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: (2 comments) Commit Message: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/3521b26d_5e5f8689 PS1, Line 11: Note that poll() has a granularity of 1 millisecond. ... while `select()` has a granularity of microseconds, according to the man page. File src/core/timer.c: https://gerrit.osmocom.org/c/libosmocore/+/35672/comment/c4d06513_d5da1e09 PS1, Line 199: nearest_ms += (nearest_p->tv_usec + 999) / 1000; Just curious: in which project did you find timers less than 1 ms? BTW, this change has a side effect: * 0.2 ms becomes 1 ms -- fine, as expected; * 1.2 ms becomes 2 ms -- probably not so nice. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-CC: fixeria Gerrit-Attention: jolly Gerrit-Comment-Date: Wed, 24 Jan 2024 18:43:00 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
Attention is currently required from: jolly. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-Attention: jolly Gerrit-Comment-Date: Wed, 24 Jan 2024 16:24:52 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[S] Change in libosmocore[master]: Prevent poll() in select.c to timeout too early
jolly has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email ) Change subject: Prevent poll() in select.c to timeout too early .. Prevent poll() in select.c to timeout too early Adjust osmo_timers_nearest_ms() to round up the remaining time. Note that poll() has a granularity of 1 millisecond. Previously, when rounding down the remaining time, osmo_select_main() would return too early, before the nearest timer timed out. Consequently, the main loop repeatedly called osmo_select_main() until the timer actually timed out, resulting in excessive CPU usage. By modifying osmo_timers_nearest_ms() to round up the remaining time, we ensure accurate timeout calculations, preventing unnecessary CPU consumption during the main loop. Related: OS#6339 Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 --- M src/core/timer.c 1 file changed, 28 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/35672/1 diff --git a/src/core/timer.c b/src/core/timer.c index 20d87a0..4229c5a 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -190,8 +190,13 @@ if (!nearest_p) return -1; + /* By adding 999 milliseconds, we ensure rounding up to the nearest +* whole millisecond. This approach prevents the return of 0 when the +* timer is still active, and it guarantees that the calling process +* does not wait for a duration shorter than the time remaining on the +* timer. */ nearest_ms = nearest_p->tv_sec * 1000; - nearest_ms += nearest_p->tv_usec / 1000; + nearest_ms += (nearest_p->tv_usec + 999) / 1000; return nearest_ms; } -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35672?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I79de77c79af4d50d1eb9ca0c5417123ff760dca3 Gerrit-Change-Number: 35672 Gerrit-PatchSet: 1 Gerrit-Owner: jolly Gerrit-MessageType: newchange