summaryrefslogtreecommitdiff
path: root/lib/tevent/tevent_port.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2016-08-08 11:26:37 +0200
committerJeremy Allison <jra@samba.org>2016-08-24 01:33:48 +0200
commitf6aaece578a53a539a3fe8bf3aeb800967615e2d (patch)
tree8c7d1c0c784c8691d0ad2dbf9d3093a7a3ce62ff /lib/tevent/tevent_port.c
parent8a9b8ac72461657a3a5de2fd5232eaa9861bf696 (diff)
downloadsamba-f6aaece578a53a539a3fe8bf3aeb800967615e2d.tar.gz
tevent: Add threaded immediate activation
This is infrastructure to improve our async r/w result handling and latency. The pthreadpool signalling goes through a pipe. This has downsides: The main event loop has to go through a read on the pipe before it can ship the result. Also, it is not guaranteed by poll/epoll that the pthreadpool signal pipe is handled with top priority. When an async pread/pwrite has finished, we should immediately ship the result to the client, not waiting for anything else. This patch enables tevent_immediate structs as job signalling. This means a busy main tevent loop will handle the threaded job completion before any timed or file descriptor events. Opposite to Jeremy's tevent_thread_proxy this is done by a modification of the main event loop by looking at a linked list under a central mutex. Regarding performance: In a later commit I've created a test that does nothing but fire one immediate over and over again. If you add a phread_mutex_lock and unlock pair in the immediate handler, you lose roughly 25% of rounds per second, so it is measurable. It is questionable that will be measurable in the real world, but to counter concerns activation of immediates needs to go through a new struct tevent_threaded_context. Only if such a tevent_threaded_context exists for a tevent context, the main loop takes the hit to look at the mutex'ed list of finished jobs. This patch by design does not care about talloc hierarchies. The idea is that the main thread owning the tevent context creates a chunk of memory and prepares the tevent_immediate indication job completion. The main thread hands the memory chunk together with the immediate as a job description over to a helper thread. The helper thread does its job and upon completion calls tevent_threaded_schedule_immediate with the already-prepared immediate. From that point on memory ownership is again transferred to the main thread. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/tevent/tevent_port.c')
-rw-r--r--lib/tevent/tevent_port.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/tevent/tevent_port.c b/lib/tevent/tevent_port.c
index 4b524dff291..8cf9fd1a0de 100644
--- a/lib/tevent/tevent_port.c
+++ b/lib/tevent/tevent_port.c
@@ -760,6 +760,10 @@ static int port_event_loop_once(struct tevent_context *ev, const char *location)
return 0;
}
+ if (ev->threaded_contexts != NULL) {
+ tevent_common_threaded_activate_immediate(ev);
+ }
+
if (ev->immediate_events &&
tevent_common_loop_immediate(ev)) {
return 0;