Skip to content

Introduce backwards compatible infrastructure for parallelism #1708

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

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

Conversation

arkocal
Copy link
Contributor

@arkocal arkocal commented Mar 11, 2025

This contains the rather harmless parts. As discussed, all variations of modules have been implemented using domain_shims and the select stanza in dune. ppx_optcomp is not involved anymore.

The PR is rather large, but can be reviewed commit-by-commit.

arkocal and others added 7 commits March 11, 2025 10:16
In order to maintain backwards compatibility, we need to provide
stubs for functionality needed for parallelism when no libraries
provide this. Also, to keep possibly diverging parts to a minimum,
the utilities for parallelism are kept in a separate module.
This works async in Ocaml4 and truly parallel in OCaml5
fix printing issue by using BatFormat in messages.ml
This is a high level abstraction AND a backward compat. wrapper
Possibly, this could be needed elsewhere, where state is involved
Make stack DLS and initialize for each domain
Actually implemented by Felix Krayer
@arkocal arkocal force-pushed the parallelism_backwards_compat_1 branch from 522315f to 80cac2a Compare March 11, 2025 09:36
@arkocal arkocal force-pushed the parallelism_backwards_compat_1 branch from 80cac2a to 3f7d226 Compare March 11, 2025 09:38
@arkocal arkocal added the parallel Parallel Goblint label Mar 11, 2025
@arkocal
Copy link
Contributor Author

arkocal commented Mar 11, 2025

Turns out introducing domain_shims breaks GobView. The application than outputs

Uncaught TypeError: runtime.caml_thread_self is not a function

on the console and hangs indefinitely.

@sim642 sim642 self-requested a review March 11, 2025 12:52
@michael-schwarz
Copy link
Member

Turns out introducing domain_shims breaks GobView. The application than outputs

Do you know where this call happens? Is it something we can safely stub to just return unit or somehow avoid these calls when in Gobview mode?

@michael-schwarz
Copy link
Member

I guess we either need to turn the gobview job into an unlocked one, or provide a different lockfile for the gobview job somehow?

Comment on lines +200 to +203
let pp_print_option ?(none = fun _ () -> ()) pp_v ppf = function
| None -> none ppf ()
| Some v -> pp_v ppf v
in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about? Isn't it just a copy of what's in Stdlib.Format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module now uses BatFormat, which does not define the method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why BatFormat? The standard library version from OCaml 5 should be safe: it's been reimplemented to use DLS properly. Batteries as no domains-specific fixes.

Comment on lines 18 to 19
let enabled_dls = Domain.DLS.new_key (fun () -> false)
let options_dls = Domain.DLS.new_key (fun () -> dummy_options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary for these to be domain-local? These are more like global options than state.
#1550 mentions that maybe only current needs to be domain-local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Felix himself has introduced all of them in 62422e9

As far as can see enabled_dls is rather tracking if it is active in a given moment (set via start and stop), and making it a reference makes the solver crash at the end. Options however are global options and can be made into refs.

9e1614d reflects this now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as can see enabled_dls is rather tracking if it is active in a given moment (set via start and stop), and making it a reference makes the solver crash at the end.

But we only ever call start at the very beginning of Goblint and never even call stop. So I don't understand why there would be any issue. start also modifies options and that's fine.

@sim642 sim642 added the setup Dependencies, CI, releasing label Mar 26, 2025
@michael-schwarz michael-schwarz requested a review from Copilot April 8, 2025 22:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 8 out of 25 changed files in this pull request and generated 1 comment.

Files not reviewed (17)
  • dune-project: Language not supported
  • goblint.opam: Language not supported
  • goblint.opam.locked: Language not supported
  • src/cdomain/value/cdomains/mutexAttrDomain.ml: Language not supported
  • src/cdomain/value/dune: Language not supported
  • src/common/util/messages.ml: Language not supported
  • src/config/options.schema.json: Language not supported
  • src/dune: Language not supported
  • src/goblint_lib.ml: Language not supported
  • src/lifters/wideningTokenLifter.ml: Language not supported
  • src/solver/dune: Language not supported
  • src/util/parallel/domainsafeLazy.ml: Language not supported
  • src/util/parallel/domainsafeLazy.mli: Language not supported
  • src/util/parallel/dune: Language not supported
  • src/util/parallel/gobMutex.domainslib.ml: Language not supported
  • src/util/parallel/gobMutex.no-domainslib.ml: Language not supported
  • src/util/parallel/threadpool.domainslib.ml: Language not supported
Comments suppressed due to low confidence (1)

.github/workflows/unlocked.yml:255

  • [nitpick] Consider using consistent capitalization for 'GobView' across workflow configurations to align with the documentation.
gobview:

@sim642
Copy link
Member

sim642 commented Apr 9, 2025

Looks like the Copilot reviews won't be too useful for us right now since it doesn't want to review .ml files.

@sim642 sim642 self-requested a review April 9, 2025 06:50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a non-parallel implementation here?

(name goblint_parallel)
(public_name goblint.parallel)
(libraries
batteries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is batteries used here?

(select threadpool.ml from
(domainslib -> threadpool.domainslib.ml)
(-> threadpool.no-domainslib.ml)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
)

@@ -0,0 +1,6 @@
(** Lazy type which protects against concurrent calls of 'force'. *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(** Lazy type which protects against concurrent calls of 'force'. *)
(** Lazy type which protects against concurrent calls of {!force}. *)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're taking the mutex implementation from domain-local-await, why not the lazy? https://github.com/ocaml-multicore/domain-local-await?tab=readme-ov-file#example-concurrency-safe-lazy (pending the licence question below)

In particular, that one seems to properly handle exceptions, whereas the one here would royally break: the mutex wouldn't be unlocked even and any future attempts to lock it will block forever.

Comment on lines +1 to +10
(* Simple Mutex Implementation using Domain-Local Await (https://github.com/ocaml-multicore/domain-local-await)
Copyright © 2023 Vesa Karvonen

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The big question with this is whether this licence just allows us to swallow the code into MIT-licenced Goblint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ther ISC license is compatible in spirit with the MIT license. Maybe we just leave the license notice in this file as is and add at the top in the LICENSE.md that the MIT license applies to all files unless specified otherwise?

I think polluting the opam repo with a package containing only this file for trivial license stuff may be excessive.

Comment on lines +8 to +14
(select gobMutex.ml from
(domainslib -> gobMutex.domainslib.ml)
( -> gobMutex.no-domainslib.ml)
)
(select threadpool.ml from
(domainslib -> threadpool.domainslib.ml)
(-> threadpool.no-domainslib.ml)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to have .mli files for these as well (not dependent on domainlib presence).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parallel Parallel Goblint setup Dependencies, CI, releasing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants