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

Multi_channel: allow more than one instance per program with different configurations #50

Merged
merged 21 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
31e8594
Multi_channel: assert that id is valid before reusing it
edwintorok Oct 10, 2021
b8cf627
Multi_channel: use per-channel key instead of global
edwintorok Oct 10, 2021
9348e59
Utilise effect handlers
kayceesrk Oct 12, 2021
2755c84
Prevent tasks blocking on await from hopping pools. Optimisations.
kayceesrk Oct 14, 2021
d023dc2
Backtraces from await
kayceesrk Oct 14, 2021
a9ce266
Use a random number as the cache prefix to disable cache in CI
smorimoto Oct 14, 2021
db22e17
Make await non-recursive
kayceesrk Oct 15, 2021
b34a56b
Fix throughput test
kayceesrk Oct 15, 2021
49895f0
Merge pull request #52 from smorimoto/disable-setup-ocaml-cache
abbysmal Oct 27, 2021
82cc93c
use last 4.12+domains+effects hash as the cache-key
abbysmal Oct 27, 2021
5104ae9
Merge pull request #54 from Engil/use_last_commit_from_4.12+domains+e…
bikallem Oct 27, 2021
28957cd
make domainslib build/run with OCaml 5.00 after PR #704
bikallem Oct 27, 2021
0931282
Merge pull request #53 from bikallem/ocaml-5.00
Sudha247 Oct 28, 2021
390c489
Merge branch 'master' into effect_handlers
avsm Nov 1, 2021
6024887
use Domain.cpu_relax instead of deprecated Domain.Sync.cpu_relax
avsm Nov 1, 2021
0d7fd11
Fix typo in task ocamldoc
avsm Nov 1, 2021
0c0f8fa
Fix clarity in Task ocamldoc
avsm Nov 1, 2021
df30722
Merge pull request #51 from ocaml-multicore/effect_handlers
kayceesrk Nov 27, 2021
7df1165
merge unique-key PR into updated master
jmid Dec 20, 2021
e1c0019
add crash test
jmid Dec 20, 2021
75ace2c
Fix backtrace unit test
edwintorok Dec 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lib/multi_channel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ type waiting_status =
| Waiting
| Released

type dls_state = {
mutable id: int;
mutable steal_offsets: int array;
rng_state: Random.State.t;
mc: mutex_condvar;
}

type 'a t = {
mask: int;
channels: 'a Ws_deque.t array;
waiters: (waiting_status ref * mutex_condvar ) Chan.t;
next_domain_id: int Atomic.t;
recv_block_spins: int;
dls_key: dls_state Domain.DLS.key;
}

type dls_state = {
mutable id: int;
mutable steal_offsets: int array;
rng_state: Random.State.t;
mc: mutex_condvar;
}

let dls_key =
let dls_make_key () =
Domain.DLS.new_key (fun () ->
{
id = -1;
Expand All @@ -61,6 +62,7 @@ let make ?(recv_block_spins = 2048) n =
waiters = Chan.make_unbounded ();
next_domain_id = Atomic.make 0;
recv_block_spins;
dls_key = dls_make_key ()
}

let register_domain mchan =
Expand All @@ -76,13 +78,16 @@ let init_domain_state mchan dls_state =
[@@inline never]

let get_local_state mchan =
let dls_state = Domain.DLS.get dls_key in
if dls_state.id >= 0 then dls_state
let dls_state = Domain.DLS.get mchan.dls_key in
if dls_state.id >= 0 then begin
assert (dls_state.id < Array.length mchan.channels);
Copy link
Contributor

Choose a reason for hiding this comment

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

The assert is going to execute every time which is sad, but I guess it can stay if you are strongly in favour.

dls_state
end
else (init_domain_state mchan dls_state)
[@@inline]

let clear_local_state () =
let dls_state = Domain.DLS.get dls_key in
let clear_local_state mchan =
let dls_state = Domain.DLS.get mchan.dls_key in
dls_state.id <- (-1)

let rec check_waiters mchan =
Expand Down
4 changes: 2 additions & 2 deletions lib/task.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let setup_pool ?name ~num_additional_domains () =
let task_chan = Multi_channel.make (num_additional_domains+1) in
let rec worker () =
match Multi_channel.recv task_chan with
| Quit -> Multi_channel.clear_local_state ();
| Quit -> Multi_channel.clear_local_state task_chan;
| Task (t, p) ->
do_task t p;
worker ()
Expand Down Expand Up @@ -86,7 +86,7 @@ let teardown_pool pool =
for _i=1 to Array.length pd.domains do
Multi_channel.send pd.task_chan Quit
done;
Multi_channel.clear_local_state ();
Multi_channel.clear_local_state pd.task_chan;
Array.iter Domain.join pd.domains;
(* Remove the pool from the table *)
begin match pd.name with
Expand Down