The default slack caused there to be a delay before timers fired. Solve it
by setting timers that should trigger immediately to trigger far in the past.
This brings down the ideal-case dhcp lease acquisition time from about 500ms to
about 50ms (over a veth pair, so no network latency involved).
All the rest of the time (except for ~0.5ms) is spent in the bind() call in,
dhcp_network_bind_raw_socket(). I don't know if there is anything to be done
about that though...
void *userdata) {
sd_dhcp_client *client = userdata;
usec_t next_timeout = 0;
void *userdata) {
sd_dhcp_client *client = userdata;
usec_t next_timeout = 0;
assert(s);
assert(client);
assert(client->event);
assert(s);
assert(client);
assert(client->event);
+ r = sd_event_get_now_monotonic(client->event, &time_now);
+ if (r < 0)
+ goto error;
+
switch (client->state) {
case DHCP_STATE_RENEWING:
switch (client->state) {
case DHCP_STATE_RENEWING:
if (time_left < 60)
time_left = 60;
if (time_left < 60)
time_left = 60;
- next_timeout = usec + time_left * USEC_PER_SEC;
+ next_timeout = time_now + time_left * USEC_PER_SEC;
if (time_left < 60)
time_left = 60;
if (time_left < 60)
time_left = 60;
- next_timeout = usec + time_left * USEC_PER_SEC;
+ next_timeout = time_now + time_left * USEC_PER_SEC;
break;
case DHCP_STATE_INIT:
break;
case DHCP_STATE_INIT:
if (client->attempt < 64)
client->attempt *= 2;
if (client->attempt < 64)
client->attempt *= 2;
- next_timeout = usec + (client->attempt - 1) * USEC_PER_SEC;
+ next_timeout = time_now + (client->attempt - 1) * USEC_PER_SEC;
switch (client->state) {
case DHCP_STATE_INIT:
switch (client->state) {
case DHCP_STATE_INIT:
- client_update_secs(client, usec);
+ client_update_secs(client, time_now);
r = client_send_discover(client, client->secs);
if (r >= 0) {
r = client_send_discover(client, client->secs);
if (r >= 0) {
break;
case DHCP_STATE_SELECTING:
break;
case DHCP_STATE_SELECTING:
- client_update_secs(client, usec);
+ client_update_secs(client, time_now);
r = client_send_discover(client, client->secs);
if (r < 0 && client->attempt >= 64)
r = client_send_discover(client, client->secs);
if (r < 0 && client->attempt >= 64)
if (r < 0 && client->attempt >= 64)
goto error;
if (r < 0 && client->attempt >= 64)
goto error;
- client->request_sent = usec;
+ client->request_sent = time_now;
}
static int client_initialize_events(sd_dhcp_client *client,
}
static int client_initialize_events(sd_dhcp_client *client,
- sd_event_io_handler_t io_callback,
- usec_t usec) {
+ sd_event_io_handler_t io_callback) {
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
r = sd_event_add_monotonic(client->event,
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
r = sd_event_add_monotonic(client->event,
- &client->timeout_resend,
- usec, 0,
+ &client->timeout_resend, 0, 0,
client_timeout_resend, client);
if (r < 0)
goto error;
client_timeout_resend, client);
if (r < 0)
goto error;
log_dhcp_client(client, "TIMEOUT T2");
log_dhcp_client(client, "TIMEOUT T2");
- return client_initialize_events(client, client_receive_message_raw,
- usec);
+ return client_initialize_events(client, client_receive_message_raw);
}
static int client_timeout_t1(sd_event_source *s, uint64_t usec,
}
static int client_timeout_t1(sd_event_source *s, uint64_t usec,
log_dhcp_client(client, "TIMEOUT T1");
log_dhcp_client(client, "TIMEOUT T1");
- return client_initialize_events(client, client_receive_message_udp, usec);
+ return client_initialize_events(client, client_receive_message_udp);
}
static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
}
static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
return -EINVAL;
r = sd_event_add_monotonic(client->event,
return -EINVAL;
r = sd_event_add_monotonic(client->event,
- &client->timeout_t1,
- next_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_t1, client);
+ &client->timeout_t1,
+ next_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_t1, client);
return -EINVAL;
r = sd_event_add_monotonic(client->event,
return -EINVAL;
r = sd_event_add_monotonic(client->event,
- &client->timeout_t2,
- next_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_t2, client);
+ &client->timeout_t2,
+ next_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_t2, client);
return -EINVAL;
r = sd_event_add_monotonic(client->event,
return -EINVAL;
r = sd_event_add_monotonic(client->event,
- &client->timeout_expire, next_timeout,
- 10 * USEC_PER_MSEC,
- client_timeout_expire, client);
+ &client->timeout_expire, next_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_expire, client);
client->attempt = 1;
r = sd_event_add_monotonic(client->event,
client->attempt = 1;
r = sd_event_add_monotonic(client->event,
- &client->timeout_resend,
- time_now, 0,
- client_timeout_resend,
+ &client->timeout_resend, 0,
+ 0, client_timeout_resend,
client);
if (r < 0)
goto error;
client);
if (r < 0)
goto error;
log_dhcp_client(client, "STARTED");
log_dhcp_client(client, "STARTED");
- return client_initialize_events(client, client_receive_message_raw,
- client->start_time);
+ return client_initialize_events(client, client_receive_message_raw);
}
int sd_dhcp_client_stop(sd_dhcp_client *client) {
}
int sd_dhcp_client_stop(sd_dhcp_client *client) {