diff mbox series

[3/9] wmediumd: sync with external scheduler on API socket

Message ID 20200625150754.c7dd5cb194aa.Icb95242975e6e6952a14e5ae1337245496489a6b@changeid (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series [1/9] wmediumd: add -lstdc++ for SANITIZE=1 | expand

Commit Message

Johannes Berg June 25, 2020, 1:08 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

If there's a non-control message on the API socket, sync time
from the external scheduler to update the internal time and
handle updates correctly.

Also synchronize time to the external scheduler when we send
anything to the API socket, in case we were free-running for
a while.

---
 wmediumd/wmediumd.c | 9 +++++++++
 wmediumd/wmediumd.h | 2 ++
 2 files changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c
index 8a9d97b6a427..0f45c75be9c9 100644
--- a/wmediumd/wmediumd.c
+++ b/wmediumd/wmediumd.c
@@ -508,6 +508,8 @@  static void send_tx_info_frame_nl(struct wmediumd *ctx, struct frame *frame)
 		goto out;
 	}
 
+	if (ctx->ctrl)
+		usfstl_sched_ctrl_sync_to(ctx->ctrl);
 	wmediumd_send_to_client(ctx, frame->src, msg);
 
 out:
@@ -549,6 +551,9 @@  static void send_cloned_frame_msg(struct wmediumd *ctx, struct station *dst,
 	w_logf(ctx, LOG_DEBUG, "cloned msg dest " MAC_FMT " (radio: " MAC_FMT ") len %d\n",
 		   MAC_ARGS(dst->addr), MAC_ARGS(dst->hwaddr), data_len);
 
+	if (ctx->ctrl)
+		usfstl_sched_ctrl_sync_to(ctx->ctrl);
+
 	if (dst->client) {
 		wmediumd_send_to_client(ctx, dst->client, msg);
 	} else {
@@ -904,6 +909,9 @@  static void wmediumd_api_handler(struct usfstl_loop_entry *entry)
 		list_del_init(&client->list);
 		break;
 	case WMEDIUMD_MSG_NETLINK:
+		if (ctx->ctrl)
+			usfstl_sched_ctrl_sync_from(ctx->ctrl);
+
 		if (!nlmsg_ok((const struct nlmsghdr *)data, len)) {
 			response = WMEDIUMD_MSG_INVALID;
 			break;
@@ -1180,6 +1188,7 @@  int main(int argc, char *argv[])
 				      &scheduler);
 		vusrv.scheduler = &scheduler;
 		vusrv.ctrl = &ctrl;
+		ctx.ctrl = &ctrl;
 	} else {
 		usfstl_sched_wallclock_init(&scheduler, 1000);
 	}
diff --git a/wmediumd/wmediumd.h b/wmediumd/wmediumd.h
index fb7b47a43574..2360da75cdb2 100644
--- a/wmediumd/wmediumd.h
+++ b/wmediumd/wmediumd.h
@@ -192,6 +192,8 @@  struct wmediumd {
 	struct nl_sock *sock;
 	struct usfstl_loop_entry nl_loop;
 
+	struct usfstl_sched_ctrl *ctrl;
+
 	struct list_head clients;
 	struct client nl_client;