[klibc] [klibc:master] ipconfig: Do not poll sockets we don't intend to read from
klibc-bot for Ben Hutchings
ben at decadent.org.uk
Sun Jun 4 16:48:08 PDT 2023
Commit-ID: b7316c5cc1a6b272bbba84c9f93aa49a1e7efb0e
Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=b7316c5cc1a6b272bbba84c9f93aa49a1e7efb0e
Author: Ben Hutchings <ben at decadent.org.uk>
AuthorDate: Sun, 4 Jun 2023 23:42:12 +0200
Committer: Ben Hutchings <ben at decadent.org.uk>
CommitDate: Mon, 5 Jun 2023 01:22:33 +0200
[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 at decadent.org.uk>
---
usr/kinit/ipconfig/main.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 5472d0f0..32e3dd1f 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);
More information about the klibc
mailing list