linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: me@bcopeland.com
Cc: linux-wireless@vger.kernel.org, Johannes Berg <johannes.berg@intel.com>
Subject: [PATCH 9/9] wmediumd: lib: wallclock: fix timerfd handling
Date: Thu, 25 Jun 2020 15:08:44 +0200	[thread overview]
Message-ID: <20200625150754.61ba963a8ccf.I2aa70a3d80eba03d766b354a4ba05e8fb15e8287@changeid> (raw)
In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net>

From: Johannes Berg <johannes.berg@intel.com>

When we have a timerfd for wallclock integration, it is possible
that the following scenario happens:
 * we insert an event in to the scheduler at time T
 * some job handling handles the event loop and the fd
   becomes readable and the read is handled
 * we go back to the scheduler, now waiting for time T,
   but the fd doesn't become readable because it already
   had

This causes the scheduler to lose synchronization and nothing
really works - this manifested for example when having virtual
ethernet with a low latency, where the real processing time
may be more than the latency.

Fix this by keeping the loop entry only active when we need it,
so that the fd becomes readable we don't handle it until we're
in a situation where we actually want to.

---
 wmediumd/lib/wallclock.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/wmediumd/lib/wallclock.c b/wmediumd/lib/wallclock.c
index 4f62a5894329..3fb09accba61 100644
--- a/wmediumd/lib/wallclock.c
+++ b/wmediumd/lib/wallclock.c
@@ -56,9 +56,13 @@ void usfstl_sched_wallclock_wait(struct usfstl_scheduler *sched)
 {
 	sched->wallclock.timer_triggered = 0;
 
+	usfstl_loop_register(&sched->wallclock.entry);
+
 	while (!sched->wallclock.timer_triggered)
 		usfstl_loop_wait_and_handle();
 
+	usfstl_loop_unregister(&sched->wallclock.entry);
+
 	usfstl_sched_set_time(sched, sched->prev_external_sync);
 }
 
@@ -76,8 +80,6 @@ void usfstl_sched_wallclock_init(struct usfstl_scheduler *sched,
 	sched->wallclock.entry.handler = usfstl_sched_wallclock_handle_fd;
 
 	sched->wallclock.nsec_per_tick = ns_per_tick;
-
-	usfstl_loop_register(&sched->wallclock.entry);
 }
 
 void usfstl_sched_wallclock_exit(struct usfstl_scheduler *sched)
@@ -87,8 +89,6 @@ void usfstl_sched_wallclock_exit(struct usfstl_scheduler *sched)
 
 	sched->external_request = NULL;
 	sched->external_wait = NULL;
-
-	usfstl_loop_unregister(&sched->wallclock.entry);
 	close(sched->wallclock.entry.fd);
 }
 
-- 
2.26.2


  parent reply	other threads:[~2020-06-25 13:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 13:08 wmediumd: further updates Johannes Berg
2020-06-25 13:08 ` [PATCH 1/9] wmediumd: add -lstdc++ for SANITIZE=1 Johannes Berg
2020-06-25 13:08 ` [PATCH 2/9] wmediumd: properly wait for control socket ACK Johannes Berg
2020-06-25 13:08 ` [PATCH 3/9] wmediumd: sync with external scheduler on API socket Johannes Berg
2020-06-25 13:08 ` [PATCH 4/9] wmediumd: init time controller connection later Johannes Berg
2020-06-25 13:08 ` [PATCH 5/9] wmediumd: add a control message to the API socket Johannes Berg
2020-06-25 13:08 ` [PATCH 6/9] wmediumd: fix RX message with cookie Johannes Berg
2020-06-25 13:08 ` [PATCH 7/9] wmediumd: add the ability to write a pcapng file Johannes Berg
2020-06-26  3:10   ` Bob Copeland
2020-06-26  8:10     ` Johannes Berg
2020-06-25 13:08 ` [PATCH 8/9] wmediumd: lib: minor code cleanups Johannes Berg
2020-06-25 13:08 ` Johannes Berg [this message]
2020-06-26  3:10 ` wmediumd: further updates Bob Copeland

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=20200625150754.61ba963a8ccf.I2aa70a3d80eba03d766b354a4ba05e8fb15e8287@changeid \
    --to=johannes@sipsolutions.net \
    --cc=johannes.berg@intel.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=me@bcopeland.com \
    /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;
as well as URLs for NNTP newsgroup(s).