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

Add tools and atomic datastructures to upstream-extra #699

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

edwintorok
Copy link
Contributor

Add some useful tools (that I had pinned in my local opam switch for a while):

  • ocaml-print-intf: is useful for creating .mli files in a dune project (or at least a starting point for one)
  • opam-dune-lint: can find some missing dependencies in opam files that are present in dune files (not all ... yet)

Also add some parallelism-safe data structures that work on both OCaml 4 and OCaml 5:

  • saturn and saturn-lockfree contains very efficient, domain and thread-safe imperative data structures. It is well tested, and the algorithms are quite well known and used in other languages (property testing and fuzzing with qcheck, and qcheck-stm; model checking with dscheck, and some in-progress formal proofs)

  • kcas and kcas_data which provide composable lock-free data structures. Where composability is not needed saturn is likely faster and uses less memory, but where composability or transactions are needed this is more flexible. This could be useful for XAPI's main database (if we thread through the 'Xt' transaction log). The algorithms are similar to optimistic concurrency control: try to perform all operations assuming you'd succeed, and keep track of which values you've read inside a transaction, and then commit or rollback and restart depending on whether any of those values have changed; and is quite similar to how the transactions work in oxenstored. This allows for transactions that don't interfere with each-other to proceed in parallel. Some attention to detail is still needed, as this doesn't eliminate all concurrency bugs (read skew and write skew are still possible, but there are mechanisms for avoiding them, see the tutorial in the https://github.com/ocaml-multicore/kcas?tab=readme-ov-file#beware-of-torn-reads)

Adding these tools and libraries should be safe, as nothing in the product would use them yet. And we can gradually introduce them into XAPI behind a feature flag, only switching to them when we are confident that they work well for our use case.

We also gain some testing tools that are generally useful for XAPI (I've used some of these in various branches already):

  • qcheck-stm: for checking that a module matches a reference implementation (this is what found some of those security bugs in oxenstored)

Some other useful libraries that get brought in as dependencies:

  • thread-table: this is a magic-free thread-local-storage implementation for OCaml 4, and can be used to optimize our named mutex handling in XAPI (one of my branches will depend on something similar that was hand-written, but probably better to use this one instead). Not Domain-safe for OCaml 5, so we'll have to figure another solution for that, maybe by that time the standard library will have something (there is a 'thread-local-storage' on opam, but it relies on Obj.magic)

These libraries also bring in multicore-magic, which sounds .. dangerous ... although from its description perhaps most of this will get integrated into future OCaml 5 releases. With careful use of kcas and saturn we might be able to avoid most of the unsafe operations though (they are mostly meant as internal performance optimizations), although I'm still somewhat worried about its presence in the dependencies. We'll need to reevaluate this when we have some actual code that uses kcas/ saturn though.

It was missing a dependency on rrd-transport.

Signed-off-by: Edwin Török <[email protected]>
This can be used to create a `.mli` file (or at least a starting point for one)
when `dune` is used and you have a lot of dependencies (so that invoking `ocamlc` by hand would be too tedious).

It is recommended by the dune docs:
https://dune.readthedocs.io/en/latest/faq.html#how-can-i-generate-an-mli-file-from-an-ml-file

I had this pinned in my local opam switch for a long time.

Signed-off-by: Edwin Török <[email protected]>
This can be used to keep `dune-project` and `*.opam.template` files up-to-date
by finding dependencies that are declared in `dune` files, but not in the `opam` package.
It doesn't yet find all such bugs (ocurrent/opam-dune-lint#71),
but it is a starting point.

It also adds its dependencies for parsing opam files:
* ocamlgraph.2.1.0 (I'm surprised we didn't already have this)
* opam-core, opam-file-format, opam-format, opam-repository-opam-state 2.2.1
* spdx_licenses.1.2.0, swhid_core.0.1

I had this pinned in my local opam repo for a while too, this is the latest version.

Signed-off-by: Edwin Török <[email protected]>
And dependencies:
* backoff.0.1.0
* containers.3.9
* domain-local-await.1.0.1
* domain-local-timeout.1.0.1
* domain_shims.0.1.0
* dscheck.0.5.0
* kcas.0.7.0
* mdx.2.4.1
* multicore-bench.0.1.5
* multicore-magic-dscheck.2.3.0
* multicore-magic.2.3.0
* oseq.0.5.1
* qcheck-multicoretest-util.0.4
* qcheck-stm-0.4
* saturn_lockfree.0.5.0
* thread-table.1.0.0
* tsort.2.1.0

This isn't used in the product yet, but having it in xs-opam allows us to start experimenting,
and perhaps add some feature flagged code to XAPI that uses these.

Signed-off-by: Edwin Török <[email protected]>
@lindig
Copy link
Collaborator

lindig commented Sep 20, 2024

Have we moved to collect the libraries that we package into an RPM based on dependencies? Previously packaging was based on the tree hierarchy. @psafont

@edwintorok edwintorok marked this pull request as ready for review September 20, 2024 10:31
@psafont
Copy link
Member

psafont commented Sep 20, 2024

We can't move to a dependency-bases system yet until all the issues surrounding tarball generation andpackage retrieval from it are fixed in opam. They are fixed in master, and should be available in the next major version (2.3.0, 2025.2, ???)
The branch with the dependency-based system is present at master...psafont:xs-opam:reorg

@psafont
Copy link
Member

psafont commented Sep 20, 2024

I'm not too happy with the amount of dependencies being added here, we should do some trimming beforehand. For example goblint pulls a lot of dependencies. And while it's packages, it's still unused

@edwintorok
Copy link
Contributor Author

edwintorok commented Sep 23, 2024

And while it's packages, it's still unused

I'll try to find some time on the next OIL day to update the analyzer so we can start using it with XAPI. You are right it has now been more than a year since I originally wrote the analyzer and I haven't been able to find the time to finish the CI integration.
Unfortunately dune doesn't support pattern rules (like Makefiles) do, and I started writing a dune generator https://github.com/edwintorok/lintcstubs/tree/genrules2, edwintorok/lintcstubs@main...genrules2maybe, but I'm not happy with the outcome.

I think it'll be easier to do the parallelisation of the analysis inside the tool itself rather than generating dune (and relying on its caching).

Lets keep this PR open meanwhile (I'll likely need to update goblint to a newer version too).

@edwintorok edwintorok marked this pull request as draft September 23, 2024 08:28
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.

3 participants