Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libflux: refactor reactor/watcher implementation #6494

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

garlick
Copy link
Member

@garlick garlick commented Dec 9, 2024

This was split off of an (aborted for now) effort to convert flux to libuv, mentioned in #6492.

This isolates the reactor and watcher implementations from each other somewhat, and also localizes libev calls to two source files.

Full disclosure: several watchers including the ones for zmq sockets, flux_t handles, and subprocess buffers are reimplemented in terms of the Flux API, which might introduce a few extra small mallocs per instance. This is because libev watchers are just structs that you initialize instead of opaque objects that you allocate, and each of these high level "composite watchers" contains three or four internal watchers that are now flux_watcher_t's. I can't imagine this is a big deal.

src/common/libflux/watcher.c Dismissed Show dismissed Hide dismissed
Problem: some older code violates RFC 7 whitespace guidelines.

Break long parameter lists to one per line.
Problem: watcher implementations are derefencing w->fn() but
otherwise use accessors for struct watcher internals.

Add watcher_call() to replace direct access to structure member.
Problem: the zmq watcher is implemented in an ambigously named
source file.

Use zwatcher.[ch] instead of reactor.[ch]
Rename unit test too.
Update include directives.
Problem: the zmq watcher is implemeted directly on libev
which complicates changing the Flux reactor implementation
to something else.

Reimplement watcher using the Flux API.
Problem: the flux_t handle watcher is implemeted directly on libev
which complicates changing the Flux reactor implementation
to something else.

Reimplement watcher using the Flux API.
Move it to a new source file since it is now fairly standalone.
Problem: the subprocess internal "buffer watchers" are implemeted
directly on libev which complicates changing the Flux reactor
implementation to something else.

Reimplement watcher using the Flux API.
Problem: the internal sdbus watcher is_active() callback calls
ev_is_active() on a flux_watcher_t, which is accepted because
ev_is_active() is a macro that casts its pointer argument.

Although flux_watcher_is_active() is not currently used in the
sdbus module (the only user of the watcher), fix the code in
case it ever is.
Problem: the reactor and watcher implementations are unnecessarily
exposed and co-mingled.

Split up reactor.c, reactor.h (public), reactor_private.h into:

reactor.c, reactor_private.h
  Only the reactor struct and implementation.
  Add an accessor for the ev_loop, to be used only in watcher_wrap.c

watcher.c, watcher_private.h
  Only the watcher struct and generic "class" implementation.
  Add accessors to avoid exposing watcher struct details to watcher
  implementations.

watcher_wrap.c
  Wrapped libev watcher implementations.
  These now use watcher accessors rather than directly accessing
  the watcher struct.

A public watcher.h header is added to split out the public watcher
interfaces from reactor.h.  This was not strictly necessary, but
reactor.h was a little busy.  Users are still expected to just include
<flux/core.h>.

Update the zmq watcher, flux_t handle watcher, fbuf watchers, and sdbus
watcher to include watcher_private.h and use watcher accessors.

Replacing the inlines in reactor_private.h with actual functions
in watcher.c necessitated linking some executables with
src/common/libflux/watcher.lo.

libev use is now localized to reactor.c and watcher_wrap.c, which should
make transitioning to a new implementation somewhat easier than before.
The code should also be easier to read and navigate.
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 92.80959% with 54 lines in your changes missing coverage. Please review.

Project coverage is 83.62%. Comparing base (8ee6a97) to head (f7d3cec).

Files with missing lines Patch % Lines
src/common/libzmqutil/zwatcher.c 82.00% 18 Missing ⚠️
src/common/libsubprocess/fbuf_watcher.c 93.06% 14 Missing ⚠️
src/common/libflux/hwatcher.c 82.85% 12 Missing ⚠️
src/common/libflux/watcher_wrap.c 97.21% 9 Missing ⚠️
src/modules/sdbus/watcher.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6494      +/-   ##
==========================================
- Coverage   83.63%   83.62%   -0.02%     
==========================================
  Files         525      522       -3     
  Lines       87682    87669      -13     
==========================================
- Hits        73334    73309      -25     
- Misses      14348    14360      +12     
Files with missing lines Coverage Δ
src/broker/overlay.c 83.51% <ø> (ø)
src/common/libflux/reactor.c 95.83% <100.00%> (-0.89%) ⬇️
src/common/libflux/watcher.c 100.00% <100.00%> (ø)
src/common/libzmqutil/monitor.c 83.16% <ø> (ø)
src/common/libzmqutil/zap.c 87.15% <ø> (ø)
src/modules/sdbus/watcher.c 86.95% <0.00%> (ø)
src/common/libflux/watcher_wrap.c 97.21% <97.21%> (ø)
src/common/libflux/hwatcher.c 82.85% <82.85%> (ø)
src/common/libsubprocess/fbuf_watcher.c 92.51% <93.06%> (+7.12%) ⬆️
src/common/libzmqutil/zwatcher.c 82.00% <82.00%> (ø)

... and 10 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant