1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
Commit Graph

60 Commits

Author SHA1 Message Date
Stefan Metzmacher
6740718e0e tevent: split out tevent_common_invoke_immediate_handler()
We'll undo the 0.9.36 ABI change on the 0.9.37 release
at the end of this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:20 +02:00
Stefan Metzmacher
a85ee852ac tevent: split out tevent_common_invoke_timer_handler()
As side effect this avoids tricks with an extra
tevent_common_timed_deny_destructor().

We'll undo the 0.9.36 ABI change on the 0.9.37 release
at the end of this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:20 +02:00
Stefan Metzmacher
ddab21987d tevent: split out tevent_common_invoke_signal_handler()
As side effect this avoids tricks with tevent_se_exists_destructor() to
figure out if the event handler removed itself.

We'll undo the 0.9.36 ABI change on the 0.9.37 release
at the end of this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:20 +02:00
Stefan Metzmacher
58fa08c805 tevent: add tevent_common_check_double_free() helper function
This will be used to generically support TALLOC_FREE() on
event which are currently running.

It aborts on every explicit talloc_free(), but ignores implicit
cleanup when the talloc parent is about to go.

We'll undo the 0.9.36 ABI change on the 0.9.37 release
at the end of this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:19 +02:00
Stefan Metzmacher
add485e47c tevent: make tevent_abort() available for backends
We'll undo the 0.9.36 ABI change on the 0.9.37 release
at the end of this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:18 +02:00
Stefan Metzmacher
f69bca61d5 tevent: rewrite/simplify tevent_poll and maintain ev->fd_events correctly
The following patches will rely on having all valid fd events in
ev->fd_events, even if they are temporary disabled with
tevent_set_fd_flags(fde, 0);

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-11 23:04:17 +02:00
Jeremy Allison
993fa5793f lib: tevent: Minor cleanup. wakeup_fd can always be gotten from the event context.
We don't need to store it. I prefer this as it shows that we must always
get wakeup_fd from the event context at time of use, rather than possibly
storing an out-of-date variable.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Fri Nov 17 12:43:01 CET 2017 on sn-devel-144
2017-11-17 12:43:01 +01:00
Jeremy Allison
2a003b1a57 lib: tevent: Remove select backend.
select() is no longer useful on modern systems.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Sat Sep 16 08:35:39 CEST 2017 on sn-devel-144
2017-09-16 08:35:39 +02:00
Volker Lendecke
d5cc7be959 tevent: Make talloc_free safe when threaded_contexts exist
I did not find a way to do this safely without a mutex per threaded_context.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-10-05 00:06:21 +02:00
Volker Lendecke
5b3019cb91 tevent: Add tevent_common_wakeup_fd()
This prepares tevent run-down with active threads.

It has the advantage to not depend on talloc'ed structs. It is needed to make
talloc_free(tevent_context) safe when tevent_threaded_contexts are still
around.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-10-05 00:06:21 +02:00
Volker Lendecke
d90f325878 tevent: Rename wakeup fds
This makes the reading end of the signalling pipe special: If we have eventfd,
this is the same as the write fd. Without eventfd, it will have to be a
separate fd. This moves the requirement to #ifdef from the writing end to the
reading end. Why? We'll use the writing end somewhere else too soon, and this
patch avoids an #ifdef in that new place.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-10-05 00:06:21 +02:00
Volker Lendecke
c7e2cb839d tevent: Use eventfd for signal/thread wakeup
According to the manpage, eventfd is cheaper than a pipe. At least, we can save
a file descriptor and space for it in struct tevent_context :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-08-24 01:33:48 +02:00
Volker Lendecke
80cd6b7528 tevent: reorder tevent_context for cache locality
No functionality change. This just looks better in objdump --disassemble :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-08-24 01:33:48 +02:00
Volker Lendecke
f6aaece578 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>
2016-08-24 01:33:48 +02:00
Volker Lendecke
8a9b8ac724 tevent: Move the async wakeup pipe to common
Signalling the main event loop will also happen from threads soon, and
that will use the same mechanism. This also keeps the pipe open after the last
signal handler is removed. Threaded jobs will come and go very frequently, and
always setting up and tearing down the pipe for each job will be expensive.
Also, this is "just" two file descriptors, and with eventfd just one.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2016-08-24 01:33:48 +02:00
Jeremy Allison
88c1eb4ae1 Add Solaris ports as a tevent backend.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>

Autobuild-User(master): David Disseldorp <ddiss@samba.org>
Autobuild-Date(master): Sun Feb 15 23:25:07 CET 2015 on sn-devel-104
2015-02-15 23:25:07 +01:00
Stefan Metzmacher
50b9f154d2 tevent: add tevent_req_set_cleanup_fn()
Note that some callers used their own destructor for their
tevent_req instance, they'll just overwrite this,
which is not intended, but works without problems.

The intended way is to specify a cleanup function
and handle the TEVENT_REQ_RECEIVED state as destructor.

Note that the TEVENT_REQ_RECEIVED cleanup event might
be triggered by an explicit tevent_req_received()
in the _recv() function. The TEVENT_REQ_RECEIVED event
is only triggered once as tevent_req_received()
will remove the destructor.

So the difference compared to a custom destructor
is that the struct tevent_req itself can continue
to be there, while tevent_req_received() removed
all internal state.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2014-01-17 12:38:08 +01:00
Stefan Metzmacher
36345d44c8 tevent: tevent_epoll_set_panic_fallback() can be a void function
There's no case where this could return an error.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2013-12-11 22:46:09 +01:00
Stefan Metzmacher
35385a3e28 tevent: optimize adding new zero timer events
Such events were used before we had immediate events.
It's likely that there're a lot of this events
and we need to add new ones in fifo order.

The tricky part is that tevent_common_add_timer()
should not use the optimization as it's used
by broken Samba versions, which don't use
tevent_common_loop_timer_delay() in source3/lib/events.c.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2013-03-01 12:01:54 -08:00
Jeremy Allison
203f85c25e tevent: Add a private function tevent_poll_event_add_fd_internal().
Not yet used, but will be called by the "standard"
fallback from epoll -> poll backends.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-02-14 10:19:38 -08:00
Jeremy Allison
aceeb585cb tevent: Add a utility function tevent_find_ops_byname().
Returns an event ops struct given a string name. Not
yet used, but will be part of the new "standard" fallback
code.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-02-14 10:19:38 -08:00
Jeremy Allison
04ba47e491 tevent: Add an internal function tevent_epoll_set_panic_fallback().
Can be set externally, allows us to fallback if epoll
fails at runtime.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-02-14 10:19:38 -08:00
Volker Lendecke
fa71f32411 lib/tevent: Add a thread-safe tevent backend
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2012-08-16 20:49:11 +02:00
Martin Schwenke
796acbd9ff lib/tevent: Add trace point callback
Set/get a single callback function to be invoked at various trace
points.  Define "before wait" and "after wait" trace points - more
trace points can be added later if required.

CTDB wants this to log long waits and events.

Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Signed-off-by: Martin Schwenke <martin@meltin.net>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2012-06-08 19:00:05 +02:00
Stefan Metzmacher
e5827a4007 tevent: add tevent_req_defer_callback()
metze
2011-07-09 11:02:42 +02:00
Stefan Metzmacher
20284f2a84 tevent: change tevent_fd->additional_flags to uint64_t
metze
2011-03-10 09:37:02 +01:00
Volker Lendecke
3254e39220 tevent: Add a poll backend 2011-02-28 16:40:20 +01:00
Bo Yang
8c8bb51de1 s3: signals are processed twice in child.
Signed-off-by: Bo Yang <boyang@samba.org>
2010-02-09 17:05:58 +08:00
Volker Lendecke
4d8118f145 tevent: Fix a comment 2009-11-26 17:22:56 +01:00
Rusty Russell
be4ac22784 lib/tevent: handle tevent_common_add_signal on different event contexts.
I don't know if this is a problem in real life.

The code assumes there's only one tevent_context; all signals will notify
the first event context.  That's counter-intuitive if you ever use more
than one, and there's nothing else in this code which prevents it AFAICT.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2009-08-28 14:09:09 +10:00
Stefan Metzmacher
45e4be0d96 tevent: add tevent_req_cancel() infrastructure
This offers a generic way for callers to cancel an
async request.

metze
2009-08-17 09:25:44 +02:00
Simo Sorce
30b2014a01 Expose functions need by backend writers
move publicly needed structures and functions in the public header.
Stop installing internal headers.
Update the signature and exports files with the new exposed
function.
2009-07-03 08:45:30 -04:00
Jelmer Vernooij
857c3f8322 tevent: Install tevent_internal.h in the standalone build.
This is not ideal, but at least it fixes the build of samba-gtk for now.
I've also added a warning about API guarantees at the top of the header.
2009-05-16 04:14:21 +02:00
Stefan Metzmacher
9eaf53d98e tevent: store the location where a request was finished
This is very useful to find bugs.
You can use 'p *req' in gdb to show where
tevent_req_done(), tevent_req_error() or tevent_req_nomem()
was called.

metze
2009-03-17 20:17:01 +01:00
Stefan Metzmacher
4bdf299385 tevent: use an immediate event fot tevent_req_post()
Now tevent_req_post() never fails

metze
2009-03-17 19:59:08 +01:00
Stefan Metzmacher
66886f8966 tevent: add support for immediate events
They're like directly triggered timed events,
but you can preallocated them and scheduling them
will not fail.

metze
2009-03-17 19:59:00 +01:00
Stefan Metzmacher
940e61846e tevent: add tevent_common_loop_wait() helper function and use it
tevent_loop_wait should do the same for all backends.
It should loop as long as we have pending events.

metze
2009-03-17 19:58:57 +01:00
Stefan Metzmacher
7142ef49bd tevent: add tevent_loop_set_nesting_hook()
This is an ugly hack to let the s4 server work arround
some bugs related to nested events and uid changing.

metze
2009-03-12 14:21:26 +01:00
Stefan Metzmacher
06f88fe7a2 tevent: don't allow nested tevent_loop_once() anymore
Incompatible caller should use tevent_loop_allow_nesting()
function.

metze
2009-03-12 12:14:18 +01:00
Stefan Metzmacher
9932fd2d9a tevent: pass __location__ to tevent_loop_once/wait()
metze
2009-03-12 12:12:34 +01:00
Stefan Metzmacher
09d1b2324c tevent: add tevent_req_received() function
This function can be called as last action of a _recv()
function, it destroys the data attached to the tevent_req.

metze
2009-03-10 16:44:44 +01:00
Simo Sorce
67d41d0fc7 Make struct tevent_req opaque
Move struct tevent_req in tevent_internal, and ad getters and setters
for private data and the callback function.
This patch also renames 'private_state' into 'data'. What is held in this
pointer is in fact data and not a state like enum tevent_req_state.
Calling it 'state' is confusing.

The functions addedd are:
tevent_req_set_callback() - sets req->async.fn and req->async.private_data
tevent_req_set_print_fn() - sets req->private_print
tevent_req_callback_data() - gets req->async.private_data
tevent_req_data() - gets rea->data

This way it is much simpler to keep API/ABI compatibility in the future.
2009-03-02 11:02:09 -05:00
Kai Blin
48b874e376 tevent: Rename ev_timeval* functions to tevent_timeval, export them.
Also add tevent_timeval_add() and tevent_timeval_current_ofs()
to help not depending on lub/util/time.c for things that just need tevent
2009-02-17 09:19:31 +01:00
Stefan Metzmacher
6211162d3e lib/tevent: change to LGPLv3+
metze
2009-02-16 08:53:25 +01:00
Stefan Metzmacher
113651c517 lib/tevent: add tevent_req infrastructure
This is almost a copy of the async_req code,
which will be removed later.

metze
2009-02-13 18:37:01 +01:00
Stefan Metzmacher
fa2461ae73 lib/tevent: expose ev_timeval_zero() for internal usage
metze
2009-02-13 16:02:14 +01:00
Stefan Metzmacher
1d949fe742 lib/tevent: remove broken tevent_aio support
It makes no sense to support aio events because,
the current implementation was based on IOCB_CMD_EPOLL_WAIT
which never made it into the main kernel tree.

The native linux aio can be used with select/epoll
using eventfd(), which means we can implement aio
with fd events and implement aio outside of tevent.

metze
2009-02-13 16:02:13 +01:00
Stefan Metzmacher
b09718fef2 tevent: add tevent_context destructor that unlinks the events from the context
metze
2009-01-05 22:44:54 +01:00
Stefan Metzmacher
ceac26008c tevent: keep a linked list of fd_events
metze
2009-01-05 22:44:53 +01:00
Stefan Metzmacher
b24924d6a6 tevent: keep a linked list of signal events
metze
2009-01-05 22:44:53 +01:00