From e216dc2392283cb702c2ef95a79086679c063e4d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 31 Mar 2020 11:22:35 +0200 Subject: [PATCH] Allow setting the UTCP clock granularity. This sets the granularity to 10 ms by default, and adds the function meshlink_set_scheduling_granularity() to be able to change it. --- src/meshlink++.h | 12 ++++++++++++ src/meshlink.c | 10 ++++++++++ src/meshlink.h | 12 ++++++++++++ src/meshlink.sym | 2 ++ 4 files changed, 36 insertions(+) diff --git a/src/meshlink++.h b/src/meshlink++.h index 93020661..98ccf5b3 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -619,6 +619,18 @@ public: meshlink_set_invitation_timeout(handle, timeout); } + /// Set the scheduling granularity of the application + /** This should be set to the effective scheduling granularity for the application. + * This depends on the scheduling granularity of the operating system, the application's + * process priority and whether it is running as realtime or not. + * The default value is 10000 (10 milliseconds). + * + * @param granularity The scheduling granularity of the application in microseconds. + */ + void set_granularity(long granularity) { + meshlink_set_scheduling_granularity(handle, granularity); + } + /// Invite another node into the mesh. /** This function generates an invitation that can be used by another node to join the same mesh as the local node. * The generated invitation is a string containing a URL. diff --git a/src/meshlink.c b/src/meshlink.c index 3242bc26..ef46a952 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -4162,6 +4162,15 @@ void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, c pthread_mutex_unlock(&mesh->mutex); } +void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity) { + if(!mesh || granularity < 0) { + meshlink_errno = EINVAL; + return; + } + + utcp_set_clock_granularity(granularity); +} + void handle_network_change(meshlink_handle_t *mesh, bool online) { (void)online; @@ -4189,6 +4198,7 @@ void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno) { static void __attribute__((constructor)) meshlink_init(void) { crypto_init(); + utcp_set_clock_granularity(10000); } static void __attribute__((destructor)) meshlink_exit(void) { diff --git a/src/meshlink.h b/src/meshlink.h index 5390c4e8..6a50eb66 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -1608,6 +1608,18 @@ extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, boo */ extern void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url); +/// Set the scheduling granularity of the application +/** This should be set to the effective scheduling granularity for the application. + * This depends on the scheduling granularity of the operating system, the application's + * process priority and whether it is running as realtime or not. + * The default value is 10000 (10 milliseconds). + * + * \memberof meshlink_handle + * @param mesh A handle which represents an instance of MeshLink. + * @param granularity The scheduling granularity of the application in microseconds. + */ +extern void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity); + #ifdef __cplusplus } #endif diff --git a/src/meshlink.sym b/src/meshlink.sym index 57eea5e5..16a659ee 100644 --- a/src/meshlink.sym +++ b/src/meshlink.sym @@ -18,6 +18,7 @@ meshlink_channel_aio_receive meshlink_channel_aio_send meshlink_channel_close meshlink_channel_get_flags +meshlink_channel_get_mss meshlink_channel_get_recvq meshlink_channel_get_sendq meshlink_channel_open @@ -82,6 +83,7 @@ meshlink_set_node_pmtu_cb meshlink_set_node_status_cb meshlink_set_port meshlink_set_receive_cb +meshlink_set_scheduling_granularity meshlink_sign meshlink_start meshlink_stop -- 2.39.5