diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2023-06-04 23:42:12 +0200 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2023-06-05 01:22:33 +0200 |
commit | b7316c5cc1a6b272bbba84c9f93aa49a1e7efb0e (patch) | |
tree | a99f3b09591785c0fbf0fa6b36b4d2167e0ebd71 | |
parent | 53ce949578446360c4b636a46eadfdb7aed2779d (diff) | |
download | klibc-b7316c5cc1a6b272bbba84c9f93aa49a1e7efb0e.tar.gz |
[klibc] ipconfig: Do not poll sockets we don't intend to read from
When a device is in state DEVST_COMPLETE or DEVST_ERROR, we never read
packets from its socket, but we still poll it. If the socket is
readable or in an error state, this results in busy-polling until a
timeout is reached.
Only add a device's socket to the fds array when the device is in some
other state.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/kinit/ipconfig/main.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c index 5472d0f015adbd..32e3dd1f3bfc86 100644 --- a/usr/kinit/ipconfig/main.c +++ b/usr/kinit/ipconfig/main.c @@ -417,11 +417,14 @@ static int do_pkt_recv(int nr, struct pollfd *fds, time_t now) int i, ret = 0; struct state *s; - for (i = 0, s = slist; s && nr; s = s->next, i++) { + for (i = 0, s = slist; s && nr; s = s->next) { + if (s->dev->pkt_fd != fds[i].fd) + continue; if (fds[i].revents & POLLRDNORM) { ret |= process_receive_event(s, now); nr--; } + i++; } return ret; } @@ -452,12 +455,9 @@ static int loop(void) int timeout_ms; int x; - for (i = 0, s = slist; s; s = s->next, i++) { + for (i = 0, s = slist; s; s = s->next) { dprintf("%s: state = %d\n", s->dev->name, s->state); - fds[i].fd = s->dev->pkt_fd; - fds[i].events = POLLRDNORM; - if (s->state == DEVST_COMPLETE) { done++; continue; @@ -470,6 +470,12 @@ static int loop(void) process_timeout_event(s, now.tv_sec); } + if (s->state != DEVST_ERROR) { + fds[i].fd = s->dev->pkt_fd; + fds[i].events = POLLRDNORM; + i++; + } + if (timeout > s->expire - now.tv_sec) timeout = s->expire - now.tv_sec; } @@ -485,7 +491,7 @@ static int loop(void) if (timeout_ms <= 0) timeout_ms = 100; - nr = poll(fds, n_devices, timeout_ms); + nr = poll(fds, i, timeout_ms); prev = now; gettimeofday(&now, NULL); |