Skip to content

Commit

Permalink
Merge pull request #9 from johnelse/cache-gnttab-interface
Browse files Browse the repository at this point in the history
Cache a single interface to gnttab
  • Loading branch information
johnelse committed Feb 7, 2014
2 parents 09bc418 + 1377da8 commit b24d856
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/rrd_reader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,39 @@ type interdomain_id = {
shared_page_refs: int list;
}

module Mutex = struct
include Mutex

let execute lock f =
Mutex.lock lock;
let result = begin
try f ()
with e ->
Mutex.unlock lock;
raise e
end in
Mutex.unlock lock;
result
end

module Page = struct
open Gnt

let interface_ref : Gnttab.interface option ref = ref None
let interface_m = Mutex.create ()

let with_interface f =
Mutex.execute interface_m
(fun () ->
let interface = match !interface_ref with
| Some interface -> interface
| None ->
let interface = Gnttab.interface_open () in
interface_ref := Some interface;
interface
in
f interface)

(** Remote domid * list of grant references. *)
type id_t = interdomain_id
type state_t = Gnttab.Local_mapping.t
Expand All @@ -66,15 +96,15 @@ module Page = struct
shared_page_refs
in
let mapping_opt =
Gnttab.with_gnttab
with_interface
(fun gnttab -> Gnttab.mapv gnttab grants false)
in
match mapping_opt with
| Some mapping -> mapping
| None -> failwith "failed to map shared page(s)"

let cleanup _ mapping =
Gnttab.with_gnttab
with_interface
(fun gnttab -> Gnttab.unmap_exn gnttab mapping)

let expose mapping =
Expand Down

0 comments on commit b24d856

Please sign in to comment.