[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd2] 12/12: get_all_net_updates_by_epoll(): reduced the size
From: |
Admin |
Subject: |
[libmicrohttpd2] 12/12: get_all_net_updates_by_epoll(): reduced the size of the data passed to the kernel |
Date: |
Fri, 06 Jun 2025 16:01:20 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd2.
commit cdd4c1f9cc9686fc57ce9e5894c77fb70b3529c6
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
AuthorDate: Fri Jun 6 15:59:25 2025 +0200
get_all_net_updates_by_epoll(): reduced the size of the data passed to the
kernel
Fixed possible wait for the second batch of epoll data
---
src/mhd2/events_process.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/mhd2/events_process.c b/src/mhd2/events_process.c
index 6008c0e..1f67a00 100644
--- a/src/mhd2/events_process.c
+++ b/src/mhd2/events_process.c
@@ -1578,6 +1578,7 @@ update_statuses_from_eevents (struct MHD_Daemon *restrict
d,
static MHD_FN_PAR_NONNULL_ (1) bool
get_all_net_updates_by_epoll (struct MHD_Daemon *restrict d)
{
+ int max_events;
int num_events;
unsigned int events_processed;
int max_wait;
@@ -1591,6 +1592,21 @@ get_all_net_updates_by_epoll (struct MHD_Daemon
*restrict d)
// TODO: add listen socket enable/disable
+ /* Minimise amount of data passed from userspace to kernel and back */
+ max_events = d->conns.cfg.count_limit;
+#ifdef MHD_SUPPORT_THREADS
+ ++max_events;
+#endif /* MHD_SUPPORT_THREADS */
+ if (MHD_INVALID_SOCKET != d->net.listen.fd)
+ ++max_events;
+ /* Make sure that one extra slot used to clearly detect that all events
+ * were gotten. */
+ ++max_events;
+ if (0 > max_events)
+ max_events = (int) (((unsigned int)~((unsigned int) 0)) >> 1);
+ if (max_events > (int) d->events.data.epoll.num_elements)
+ max_events = (int) d->events.data.epoll.num_elements;
+
events_processed = 0;
max_wait = get_max_wait (d); // TODO: use correct timeout value
do
@@ -1604,13 +1620,13 @@ get_all_net_updates_by_epoll (struct MHD_Daemon
*restrict d)
#endif /* mhd_DEBUG_POLLING_FDS */
num_events = epoll_wait (d->events.data.epoll.e_fd,
d->events.data.epoll.events,
- (int) d->events.data.epoll.num_elements,
+ max_events,
max_wait);
#ifdef mhd_DEBUG_POLLING_FDS
fprintf (stderr,
"### (Finished) epoll_wait(%d, events, %d, %d) -> %d\n",
d->events.data.epoll.e_fd,
- (int) d->events.data.epoll.num_elements,
+ max_events,
max_wait,
num_events);
#endif /* mhd_DEBUG_POLLING_FDS */
@@ -1628,11 +1644,16 @@ get_all_net_updates_by_epoll (struct MHD_Daemon
*restrict d)
}
if (! update_statuses_from_eevents (d, (unsigned int) num_events))
return false;
+ if (max_events > num_events)
+ return true; /* All events have been read */
+
+ /* Use all buffer for the next getting events round(s) */
+ max_events = d->events.data.epoll.num_elements;
+ max_wait = 0; /* Do not block on the next getting events rounds */
events_processed += (unsigned int) num_events; /* Avoid reading too many
events */
- } while ((((unsigned int) num_events) == d->events.data.epoll.num_elements)
&&
- ((events_processed < d->conns.cfg.count_limit)
- || (events_processed < d->conns.cfg.count_limit + 2)));
+ } while ((events_processed < d->conns.cfg.count_limit)
+ || (events_processed < d->conns.cfg.count_limit + 2));
return true;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd2] 03/12: mhd_response_check_frozen_freeze(): fixed assert, (continued)
- [libmicrohttpd2] 03/12: mhd_response_check_frozen_freeze(): fixed assert, Admin, 2025/06/06
- [libmicrohttpd2] 01/12: Added missing includes for "mhd_assert.h", sorted some includes, Admin, 2025/06/06
- [libmicrohttpd2] 04/12: Improved error reporting for the listen socket creation, Admin, 2025/06/06
- [libmicrohttpd2] 06/12: mhd_stream_finish_req_serving(): minor simplification, Admin, 2025/06/06
- [libmicrohttpd2] 05/12: perf_replies: muted compiler warning, Admin, 2025/06/06
- [libmicrohttpd2] 02/12: Unified debug macro checks, Admin, 2025/06/06
- [libmicrohttpd2] 09/12: Added detection and used "externally_visible" function attribute, Admin, 2025/06/06
- [libmicrohttpd2] 07/12: mhd_atomic_counter: fixed formatting, fixed single thread version build, Admin, 2025/06/06
- [libmicrohttpd2] 08/12: configure: improved test for alignof() detection, Admin, 2025/06/06
- [libmicrohttpd2] 10/12: Implemented and used counters based on atomic variables, Admin, 2025/06/06
- [libmicrohttpd2] 12/12: get_all_net_updates_by_epoll(): reduced the size of the data passed to the kernel,
Admin <=
- [libmicrohttpd2] 11/12: Made zeroing of memory pool optional, other memory pool improvements, Admin, 2025/06/06