Skip to content

Commit 0b1e53c

Browse files
committed
use a monotonic counter for the RX id (similar to TX id)
wrap RX counter to 16 bit
1 parent c974a67 commit 0b1e53c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/frontend.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module Make(C: S.CONFIGURATION with type 'a io = 'a Lwt.t) = struct
8282
rx_client: (RX.Response.t,int) Lwt_ring.Front.t;
8383
rx_map: (int, Gnt.gntref * Io_page.t) Hashtbl.t;
8484
rx_gnt: Gnt.gntref;
85+
mutable rx_id: Cstruct.uint16;
8586

8687
evtchn: Eventchn.t;
8788
features: Features.t;
@@ -145,7 +146,7 @@ module Make(C: S.CONFIGURATION with type 'a io = 'a Lwt.t) = struct
145146
(* Register callback activation *)
146147
let backend = backend_conf.S.backend in
147148
return { vif_id; backend_id; tx_client; tx_gnt; tx_mutex; tx_pool;
148-
rx_gnt; rx_fring; rx_client; rx_map; stats;
149+
rx_gnt; rx_fring; rx_client; rx_map; rx_id = 0 ; stats;
149150
evtchn; mac; backend; features;
150151
}
151152

@@ -163,7 +164,12 @@ module Make(C: S.CONFIGURATION with type 'a io = 'a Lwt.t) = struct
163164
let pages = Io_page.pages num in
164165
List.iter
165166
(fun (gref, page) ->
166-
let id = gref mod (1 lsl 16) in
167+
let rec next () =
168+
let id = nf.rx_id in
169+
nf.rx_id <- (succ nf.rx_id) mod (1 lsl 16) ;
170+
if Hashtbl.mem nf.rx_map id then next () else id
171+
in
172+
let id = next () in
167173
Gnt.Gntshr.grant_access ~domid:nf.backend_id ~writable:true gref page;
168174
Hashtbl.add nf.rx_map id (gref, page);
169175
let slot_id = Ring.Rpc.Front.next_req_id nf.rx_fring in

0 commit comments

Comments
 (0)