Skip to content

Commit

Permalink
Renaming atomicskiplist to skiplist
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrm committed Oct 24, 2023
1 parent 0efac79 commit ad8782a
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 69 deletions.
8 changes: 4 additions & 4 deletions bench/bench_atomic_skiplist.ml → bench/bench_skiplist.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
open Lockfree

let workload num_elems num_threads add remove =
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let elems = Array.init num_elems (fun _ -> Random.int 10000) in
let push () =
Domain.spawn (fun () ->
let start_time = Unix.gettimeofday () in
for i = 0 to (num_elems - 1) / num_threads do
Domain.cpu_relax ();
let prob = Random.float 1.0 in
if prob < add then Atomicskiplist.add sl (Random.int 10000) |> ignore
if prob < add then Skiplist.add sl (Random.int 10000) |> ignore
else if prob >= add && prob < add +. remove then
Atomicskiplist.remove sl (Random.int 10000) |> ignore
else Atomicskiplist.mem sl elems.(i) |> ignore
Skiplist.remove sl (Random.int 10000) |> ignore
else Skiplist.mem sl elems.(i) |> ignore
done;
start_time)
in
Expand Down
6 changes: 3 additions & 3 deletions bench/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ let benchmark_list =
Mpmc_queue.bench ~use_cas:true ~takers:4 ~pushers:4;
Mpmc_queue.bench ~use_cas:true ~takers:1 ~pushers:8;
Mpmc_queue.bench ~use_cas:true ~takers:8 ~pushers:1;
Bench_atomic_skiplist.bench ~workload_type:"read_heavy" ~num_elems:2000000
Bench_skiplist.bench ~workload_type:"read_heavy" ~num_elems:2000000
~num_threads:2;
Bench_skiplist.bench ~workload_type:"moderate_heavy" ~num_elems:2000000
~num_threads:2;
Bench_atomic_skiplist.bench ~workload_type:"moderate_heavy"
~num_elems:2000000 ~num_threads:2;
]
@ backoff_benchmarks

Expand Down
2 changes: 1 addition & 1 deletion src/atomicskiplist.ml → src/skiplist.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let get_random_level sl =
count_level 1

(** Create a new skiplist *)
let create ?(max_height=10) () =
let create ?(max_height = 10) () =
let tail = create_new_node Int.max_int max_height in
let next =
Array.init (max_height + 1) (fun _ ->
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src_lockfree/saturn_lockfree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ module Single_prod_single_cons_queue = Spsc_queue
module Single_consumer_queue = Mpsc_queue
module Relaxed_queue = Mpmc_relaxed_queue
module Backoff = Backoff
module Atomicskiplist = Atomicskiplist
module Skiplist = Skiplist
2 changes: 1 addition & 1 deletion src_lockfree/saturn_lockfree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ module Relaxed_queue = Mpmc_relaxed_queue
(** {2 Other} *)

module Backoff = Backoff
module Atomicskiplist = Atomicskiplist
module Skiplist = Skiplist
22 changes: 0 additions & 22 deletions test/atomicskiplist/dune

This file was deleted.

22 changes: 22 additions & 0 deletions test/skiplist/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(rule
(copy ../../src/backoff.ml backoff.ml))

(rule
(copy ../../src/skiplist.ml skiplist.ml))

(test
(name skiplist_dscheck)
(libraries atomic dscheck alcotest)
(modules skiplist skiplist_dscheck))

(test
(name qcheck_skiplist)
(libraries lockfree qcheck qcheck-alcotest)
(modules qcheck_skiplist))

(test
(name stm_skiplist)
(modules stm_skiplist)
(libraries lockfree qcheck-stm.sequential qcheck-stm.domain)
(action
(run %{test} --verbose)))
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
module Atomicskiplist = Lockfree.Atomicskiplist
module Skiplist = Lockfree.Skiplist

let tests_sequential =
QCheck.
[
(* TEST 1: add*)
Test.make ~name:"add" (list int) (fun lpush ->
assume (lpush <> []);
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let rec add_all_elems l =
match l with
| h :: t ->
if Atomicskiplist.add sl h then add_all_elems t else false
| h :: t -> if Skiplist.add sl h then add_all_elems t else false
| [] -> true
in
add_all_elems lpush);
(*TEST 2: add_remove*)
Test.make ~name:"add_remove" (list int) (fun lpush ->
let lpush = List.sort_uniq Int.compare lpush in
let sl = Atomicskiplist.create () in
List.iter (fun key -> ignore (Atomicskiplist.add sl key)) lpush;
let sl = Skiplist.create () in
List.iter (fun key -> ignore (Skiplist.add sl key)) lpush;
let rec remove_all_elems l =
match l with
| h :: t ->
if Atomicskiplist.remove sl h then remove_all_elems t else false
if Skiplist.remove sl h then remove_all_elems t else false
| [] -> true
in
remove_all_elems lpush);
(*TEST 3: add_find*)
Test.make ~name:"add_find" (list int) (fun lpush ->
let lpush = List.sort_uniq Int.compare lpush in
let lpush = Array.of_list lpush in
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let len = Array.length lpush in
let pos = Array.sub lpush 0 (len / 2) in
let neg = Array.sub lpush (len / 2) (len / 2) in
Array.iter (fun key -> ignore @@ Atomicskiplist.add sl key) pos;
Array.iter (fun key -> ignore @@ Skiplist.add sl key) pos;
let rec check_pos index =
if index < len / 2 then
if Atomicskiplist.mem sl pos.(index) then check_pos (index + 1)
if Skiplist.mem sl pos.(index) then check_pos (index + 1)
else false
else true
in
let rec check_neg index =
if index < len / 2 then
if not @@ Atomicskiplist.mem sl neg.(index) then
check_neg (index + 1)
if not @@ Skiplist.mem sl neg.(index) then check_neg (index + 1)
else false
else true
in
check_pos 0 && check_neg 0);
(* TEST 4: add_remove_find *)
Test.make ~name:"add_remove_find" (list int) (fun lpush ->
let lpush = List.sort_uniq Int.compare lpush in
let sl = Atomicskiplist.create () in
List.iter (fun key -> ignore @@ Atomicskiplist.add sl key) lpush;
List.iter (fun key -> ignore @@ Atomicskiplist.remove sl key) lpush;
let sl = Skiplist.create () in
List.iter (fun key -> ignore @@ Skiplist.add sl key) lpush;
List.iter (fun key -> ignore @@ Skiplist.remove sl key) lpush;
let rec not_find_all_elems l =
match l with
| h :: t ->
if not @@ Atomicskiplist.mem sl h then not_find_all_elems t
else false
if not @@ Skiplist.mem sl h then not_find_all_elems t else false
| [] -> true
in

Expand All @@ -72,14 +69,14 @@ let tests_two_domains =
(* TEST 1: Two domains doing multiple adds *)
Test.make ~name:"parallel_add" (pair small_nat small_nat)
(fun (npush1, npush2) ->
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let sema = Semaphore.Binary.make false in
let lpush1 = List.init npush1 (fun i -> i) in
let lpush2 = List.init npush2 (fun i -> i + npush1) in
let work lpush =
List.map
(fun elt ->
let completed = Atomicskiplist.add sl elt in
let completed = Skiplist.add sl elt in
Domain.cpu_relax ();
completed)
lpush
Expand Down Expand Up @@ -107,7 +104,7 @@ let tests_two_domains =
(* TEST 2: Two domains doing multiple one push and one pop in parallel *)
Test.make ~count:10000 ~name:"parallel_add_remove"
(pair small_nat small_nat) (fun (npush1, npush2) ->
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let sema = Semaphore.Binary.make false in

let lpush1 = List.init npush1 (fun i -> i) in
Expand All @@ -116,9 +113,9 @@ let tests_two_domains =
let work lpush =
List.map
(fun elt ->
ignore @@ Atomicskiplist.add sl elt;
ignore @@ Skiplist.add sl elt;
Domain.cpu_relax ();
Atomicskiplist.remove sl elt)
Skiplist.remove sl elt)
lpush
in

Expand All @@ -138,17 +135,17 @@ let tests_two_domains =
let rec check_none_present l =
match l with
| h :: t ->
if Atomicskiplist.mem sl h then false else check_none_present t
if Skiplist.mem sl h then false else check_none_present t
| [] -> true
in
check_none_present lpush1 && check_none_present lpush2);
(* TEST 3: Parallel push and pop using the same elements in two domains
*)
Test.make ~name:"parallel_add_remove_same_list" (list int) (fun lpush ->
let sl = Atomicskiplist.create () in
let sl = Skiplist.create () in
let sema = Semaphore.Binary.make false in
let add_all_elems l = List.map (Atomicskiplist.add sl) l in
let remove_all_elems l = List.map (Atomicskiplist.remove sl) l in
let add_all_elems l = List.map (Skiplist.add sl) l in
let remove_all_elems l = List.map (Skiplist.remove sl) l in

let domain1 =
Domain.spawn (fun () ->
Expand All @@ -170,15 +167,15 @@ let tests_two_domains =
let rec check_none_present l =
match l with
| h :: t ->
if Atomicskiplist.mem sl h then false else check_none_present t
if Skiplist.mem sl h then false else check_none_present t
| [] -> true
in
check_none_present lpush);
]

let () =
let to_alcotest = List.map QCheck_alcotest.to_alcotest in
Alcotest.run "Atomic Skip List"
Alcotest.run "Skip List"
[
("test_sequential", to_alcotest tests_sequential);
("tests_two_domains", to_alcotest tests_two_domains);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Atomicskiplist
open Skiplist

let _two_mem () =
Atomic.trace (fun () ->
Expand Down Expand Up @@ -80,7 +80,7 @@ let _two_remove () =
Atomic.final (fun () ->
Atomic.check (fun () ->
let found1 = mem sl 1 in
!added1 && !removed1 && not !removed2 && not found1)))
!added1 && !removed1 && (not !removed2) && not found1)))

let () =
let open Alcotest in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

open QCheck
open STM
module Skiplist = Lockfree.Atomicskiplist
module Skiplist = Lockfree.Skiplist

module WSDConf = struct
type cmd = Mem of int | Add of int | Remove of int
Expand All @@ -13,11 +13,11 @@ module WSDConf = struct
| Add i -> "Add " ^ string_of_int i
| Remove i -> "Remove " ^ string_of_int i

module Sint = Set.Make (
struct
type t = int
let compare = compare
end)
module Sint = Set.Make (struct
type t = int

let compare = compare
end)

type state = Sint.t
type sut = Skiplist.t
Expand Down Expand Up @@ -67,4 +67,4 @@ let () =
[
WSDT_seq.agree_test ~count ~name:"STM Lockfree.Skiplist test sequential";
WSDT_dom.agree_test_par ~count ~name:"STM Lockfree.Skiplist test parallel";
]
]

0 comments on commit ad8782a

Please sign in to comment.