Skip to content

No singletons, core: cvc::net, the volren cache, cvc-cli and core's counters per app [4.0, breaking] - #1183

Closed
transfix wants to merge 1 commit into
p0a/no-singletons-ariadne-4from
p0a/no-singletons-core
Closed

transfix wants to merge 1 commit into
p0a/no-singletons-ariadne-4from
p0a/no-singletons-core

Conversation

@transfix

Copy link
Copy Markdown
Owner

No singletons, core: cvc::net, the volren cache, cvc-cli and core's counters per app. Stacked on #1176 (Ariadne part 3); a sibling of #1182. Breaking (4.0).

What moved onto the app, and the bugs it fixes

  • cvc::net's HTTP client:
    • send, start, http_starts_async and set_http_client take the app first.
    • New http_client(app) and send(HttpClient&, req[, policy]). Data's download thread takes the app's client while it holds the app, and sends without the app after that.
  • cvc::net's browser: browser_available, set_browser_disabled, open_url, set_url_opener, set_url_notice, url_notice and every page:: function take the app first.
  • Bug fixed: a test's fake HTTP client or URL opener, and OIDC's --no-browser, were process-wide, so one app setting or clearing them changed every app. This also ends the leftover that No singletons, Ariadne part 3: URIs, HTTP, and the net and OIDC hosts per app [4.0, breaking] #1176 noted (enabling OIDC set the browser flag for the whole process).
  • volren:
    • The CUDA raycaster's resident-volume cache is the app's: the new raycast_cuda_cache, one per app through raycast_cuda_cache_of(app), and raycast_cuda(cache, req). The six free cache functions are removed.
    • The volume_cache::instance() singleton and the raycaster's generation counter are gone.
  • cvc-cli: main makes the command's app and passes it to each cmd_*; the cvc_app() static is gone.
  • Core's counters: the lane and pool task sequences, exec_pool's call serial, pool serial and pump total, and sliced_task's chunk sequence are per app or per pool.
    • Lane reply channels are <prefix>#<name>.<tag>-<n>.
    • exec_pool's failed-groups list is keyed by a per-pool life token.
    • exec_pool_worker_pumps_total() is replaced by a pool's stats().worker_pumps.
  • Constants built at first use:
    • dataType<T>() is decided at compile time;
    • data_type_strings is inline constexpr;
    • spider's error strings, lsys's recipe table and tf's preset names are constants;
    • archive builds its fixed Huffman codes per decoder;
    • rawivHeader was a stray global that every reader shadowed; it is gone.
  • Scratch: the EDT scratch is per call; se2_train and media_rungs lend theirs from per-call or per-shaper pools.
  • Names and settings:
    • lod's HDF5 names and assimp's temp-file names use a per-app random tag and count;
    • CVC_EXEC_THREADS and CVC_SLICED_THREADING are read when a pool or task is built.
  • tf: the mesh overlay_job takes the app, and overlay_job::instances(app).
  • Ariadne callers: host_get / host_get_start / oidc_flows / detail::send_http take the app.

Allowlist: -53 lines (cvc 51, cvc-cli 2)

  • algo (EDT);
  • app.cpp (the exec-threads knob, the data-type table);
  • core's counters;
  • sliced_task;
  • lod;
  • lsys;
  • media_rungs (two TurboJPEG thread-locals);
  • assimp;
  • net (browser.cpp's 8, http_client.cpp's 3, oidc's kOwn);
  • ph (se2_train);
  • tf;
  • archive (both Huffman tables);
  • volren (the generation counter, and the <header> volume_cache::instance() and its guard);
  • volume (data_type_strings, rawivHeader, spider's strings);
  • cvc-cli (cvc_app() and its guard).

Not removed, and why (please review)

  • Process resources:

    • curl's once-per-process curl_global_init (two once-flags);
    • ImageMagick's once-per-process init;
    • HDF5's library lock (one HDF5 per process, not thread-safe);
    • CUDA's device manager and raycast.cu's __constant__ marching-cubes tables (per-device state);
    • the process's scheduling class (g_process_nice);
    • cvc-cli serve's signal-handler flag. Signal state stays, as agreed.
  • Third-party code compiled into stb_io.cpp: stb_image's statics. These could go in scan.py's THIRD_PARTY. Note that stb's invalid_chunk is a mutable static buffer, a real race between threads decoding PNGs.

  • Per-thread role markers:

    • exec_pool's t_worker, t_caller, t_defer, t_callback, t_failed;
    • thread_pool's t_active_pool and t_fanout_context;
    • async_lane's t_running_top;
    • app.cpp's t_poolDropReason.

    Each records what the calling thread is doing right now, set and restored around a call; none holds an app's data.

  • exec_pool's g_membership mutex: its home is group_pool_link in state_exec's exec_group.h, left to the state_exec PR.

Tests

  • New and extended:
    • net_http_client_test (two apps in both orders, threads, a later app gets the default client, a taken client outlives its replacement);
    • net_oidc_test's browser cases (each app's opener, notice, page hooks and no-browser flag are its own);
    • three multi-app cases in volren_render_test;
    • volren_cuda_test (each app's own cache; skipped without CUDA);
    • tf_overlays_test;
    • app_test (pool-task channels per app, data types are constants);
    • lod_store_test;
    • async_lane_test (two lanes of one name never repeat a key).
  • multi_app_integration_test gains three parts:
    • net: each app's fake client answers with its index, and its opener and page are its own;
    • volren: each app renders its own volume;
    • core_counters.
  • Updated: the tests that set the global client, opener or hooks now set their app's (ariadne_runtime, ariadne_data, uri_http_cache, net_policy, the stub OIDC provider, cvcgl_tf_binding).

Locally (Windows, MSVC Release):

  • net_http_client_test 13, net_policy_test 25, net_oidc_test 13, uri_http_cache_test 13;
  • multi_app_integration_test 2, app_test 123, async_lane_test 21, exec_pool_test 33;
  • volren_render_test 53, tf_overlays_test 19, tf_model_test 54, lod_store_test 27;
  • the image, model, volume, voxels and ph tests;
  • ariadne_runtime_test 262, ariadne_media_test 56, ariadne_data_test 14;
  • cvc_cli_test 160 (without the slow integration ones);
  • cvcgl_tf_binding.

raycast.cu (CUDA) was not compiled here; CI's CUDA lanes build it. pycvc and the examples were not rebuilt locally; nothing in them uses the changed API (grep).

CI

Full run: the push to ci/full/no-singletons-core, https://github.com/transfix/libcvc/actions/runs/43209799275.

…ounters per app

libcvc keeps no process-wide state. This moves the core libraries' share of it onto cvc::app
(slots) or into the objects that do the work, and deletes 53 allowlist lines (cvc 51, cvc-cli 2).

cvc::net, per app:
- The HTTP client (set_http_client) is the app's: send, start, http_starts_async and
  set_http_client take the app. http_client(app) hands out the app's client, and
  send(HttpClient &, req[, policy]) sends through it, for work on a thread that may outlive the
  app (ariadne/data.cpp's download takes it with the app and sends holding none).
- The URL opener and notice, the page hooks and --no-browser (browser.cpp) are the app's:
  browser_available, set_browser_disabled, open_url, set_url_opener, set_url_notice, url_notice
  and every page:: call take the app.
- Their users follow: ariadne's net_intrinsics (host_get and host_get_start take the app),
  net_host, oidc_host (oidc_flows(app); a session uses its app), uri_http, uri_http_cache,
  media, data; ari and arigl set their own app's notice.
- Bug fixed: enable_oidc's --no-browser and a test's opener or fake client were process-wide, so
  one app's set or reset changed every other app's.

volren: the resident device cache (raycast.cu's volume_cache::instance()) is the app's:
raycast_cuda_cache_of(app), shared by the app's raycasters and freed with the app;
raycast_cuda(cache, req); the cache controls are its methods. The content-generation counter it
validates against is the app's too.

cvc-cli: main makes the command's app (cvc_app()'s static is gone); each command takes it.

core and the rest:
- Counters: launch_pool_task's and the sliced chunks' reply channels count per app;
  launch_lane_task's per lane, with a random tag per lane (async_lane::next_task_key);
  exec_pool's call stamps per pool; the process-wide worker-pump total is gone (a pool's
  stats().worker_pumps remain), and the pool serial t_failed was keyed by is a per-pool life
  token (owner-equal weak_ptr), so a reused thread id or pool address still reads nothing stale.
- CVC_EXEC_THREADS and CVC_SLICED_THREADING are read where they are used (once per pool or task),
  not cached in statics. dataType<T>() is decided at compile time (no typeid table).
- lod's in-memory HDF5 names: each app has its own nonce and count. model's embedded-texture
  temp names: an app tag and count. tf::overlay_job counts each app's jobs (instances(app); a
  mesh job takes its app).
- Constant tables are constexpr: lsys recipes, tf preset names (preset_names() returns a new
  vector), oidc's own parameters, spider_io's error strings, cvc::data_type_strings.
- archive's fixed Huffman codes are built per decoder at its first fixed block. The EDT scratch
  is the call's own; se2_train's no-gradient scratch is lent from a per-call pool; media_rungs'
  TurboJPEG handles are a call's own, or lent from the shaper's pool.
- rawiv_io's stray global header (every reader shadowed it) is gone.

Left, as real process resources or another area's: curl_global_init's once flags (libcurl's
global state is one per process), ImageMagick's init once, the HDF5 library lock, the CUDA device
manager and raycast.cu's __constant__ tables and their upload flag, the process nice value
(set_process_class), cvc-cli's serve signal flag, the stb_image statics (third-party code
compiled into stb_io.cpp), and the per-thread role markers of exec_pool, thread_pool, async_lane
and app::poolDropReason (each says what the calling thread is doing now) with exec_pool's group
membership mutex (its home is exec_group's pool_link, in state_exec).

Tests: two apps in both orders, apps on threads at once, and a later app starting clean, for the
HTTP client (net_http_client_test), the browser hooks (net_oidc_test), the volren cache
(volren_render_test; volren_cuda_test on CUDA), overlay job counts (tf_overlays_test), pool-task
channels and data types (app_test), lod names (lod_store_test) and lane keys (async_lane_test);
multi_app_integration_test's workload adds net (each app's fake client answers with its index,
its opener records its own URLs, its page and --no-browser are its own), volren (each app
renders its own volume; its cache holds only that) and core counters. Tests that set the
process-wide client or opener now set their app's.
@transfix

Copy link
Copy Markdown
Owner Author

Replaced by #1203, which lands the whole no-singletons stack as one PR. This branch's head is an ancestor of #1203's branch, so its commits are all there; the branch is kept.

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