Skip to content

Commit

Permalink
Merge pull request #69 from UnixJunkie/disable_core_pinning
Browse files Browse the repository at this point in the history
Add support for user-level enabling/disabling of core pinning
  • Loading branch information
rdicosmo committed Nov 30, 2017
2 parents f7346fc + 7c3283c commit d23100d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions oasis_test.sh
@@ -1,8 +1,8 @@
#!/bin/bash

set -x
set -x # DEBUG

oasis setup
ocaml setup.ml -configure
ocaml setup.ml -configure -prefix `opam config var prefix`
ocaml setup.ml -build
ocaml setup.ml -install
ocaml setup.ml -reinstall
21 changes: 16 additions & 5 deletions parmap.ml
Expand Up @@ -37,6 +37,14 @@ let get_ncores () = !ncores

(* core mapping *)

let no_core_pinning = ref false

let disable_core_pinning () =
no_core_pinning := true

let enable_core_pinning () =
no_core_pinning := false

let core_mapping = ref None

let set_core_mapping (m: int array) = core_mapping := Some m
Expand Down Expand Up @@ -252,11 +260,14 @@ type msg_to_master = Ready of int | Error of int * string
type msg_to_worker = Finished | Task of int

let setup_children_chans oc pipedown ?fdarr i =
(* map process i to core i, or, if a core_mapping exist, to core_mapping.(i), reusing core_mapping as many times as needed *)
(match !core_mapping with
| None -> Setcore.setcore i
| Some m -> let ml = Array.length m in
Setcore.setcore m.(i mod ml));
(if !no_core_pinning then ()
else match !core_mapping with
(* map process i to core i, or, if a core_mapping exist,
to core_mapping.(i), reusing core_mapping as many times as needed *)
| None -> Setcore.setcore i
| Some m ->
let ml = Array.length m in
Setcore.setcore m.(i mod ml));
(* close the other ends of the pipe and convert my ends to ic/oc *)
Unix.close (snd pipedown.(i));
let pid = Unix.getpid() in
Expand Down
12 changes: 12 additions & 0 deletions parmap.mli
Expand Up @@ -34,6 +34,18 @@ val get_default_ncores : unit -> int

val get_ncores : unit -> int

(** {6 Enabling/disabling processes core pinning } *)

val disable_core_pinning: unit -> unit
(** [disable_core_pinning ()] will prevent forked out processes
from being pinned to a specific core.
WARNING: this may have a negative impact on performance,
but might be necessary on systems where several parmap computations
are running concurrently. *)

val enable_core_pinning: unit -> unit
(** [enable_core_pinning ()] turns on core pinning (it is on by default). *)

(** {6 Setting and getting an explicity mapping from processes to cores } *)

val set_core_mapping: int array -> unit
Expand Down

0 comments on commit d23100d

Please sign in to comment.