Skip to content

Commit f683146

Browse files
authored
Merge pull request #46 from dinosaure/re-mono
Monomorphize some min/max functions
2 parents f151e8e + 3c23171 commit f683146

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

src/input.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ let deliver_in_2 m stats now id conn seg ack =
171171
rcv_nxt ;
172172
rcv_wnd ;
173173
tf_rxwin0sent = (rcv_wnd = 0) ;
174-
rcv_adv = Sequence.addi rcv_nxt ((min (rcv_wnd lsr rcv_scale) Params.tcp_maxwin) lsl rcv_scale) ;
174+
rcv_adv = Sequence.addi rcv_nxt ((Int.min (rcv_wnd lsr rcv_scale) Params.tcp_maxwin) lsl rcv_scale) ;
175175
t_maxseg ;
176176
last_ack_sent = rcv_nxt ;
177177
t_softerror ;
@@ -573,7 +573,7 @@ let di3_ackstuff now id conn seg ourfinisacked fin ack =
573573
let snd_ssthresh =
574574
(*: Set to half the current flight size as per RFC2581/2582 :*)
575575
(* TODO hannes still true in respect of ABC? *)
576-
max 2 ((min cb.snd_wnd cb.snd_cwnd) / 2 / cb.t_maxseg) * cb.t_maxseg
576+
Int.max 2 ((Int.min cb.snd_wnd cb.snd_cwnd) / 2 / cb.t_maxseg) * cb.t_maxseg
577577
in
578578
let control_block = {
579579
cb with t_dupacks = t_dupacks' ;
@@ -636,7 +636,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
636636
urgent data in the segment. :*)
637637
let trim_amt_left =
638638
if Sequence.greater cb.rcv_nxt seg.Segment.seq then
639-
min (Sequence.window cb.rcv_nxt seg.seq) (Cstruct.length seg.payload)
639+
Int.min (Sequence.window cb.rcv_nxt seg.seq) (Cstruct.length seg.payload)
640640
else
641641
0
642642
in
@@ -650,7 +650,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
650650
here because there is still urgent data to be received, but now in a future
651651
segment. :*)
652652
let data_trimmed_left_right =
653-
Cstruct.sub data_trimmed_left 0 (min cb.rcv_wnd (Cstruct.length data_trimmed_left))
653+
Cstruct.sub data_trimmed_left 0 (Int.min cb.rcv_wnd (Cstruct.length data_trimmed_left))
654654
in
655655
let fin_trimmed =
656656
if Cstruct.equal data_trimmed_left_right data_trimmed_left then

src/segment.ml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ let tcp_output_required now conn =
267267
cb.State.snd_cwnd
268268
in
269269
(*: Calculate the amount of unused send window :*)
270-
let win = min cb.State.snd_wnd snd_cwnd in
270+
let win = Int.min cb.State.snd_wnd snd_cwnd in
271271
let snd_wnd_unused = win - (Sequence.window cb.State.snd_nxt cb.State.snd_una) in
272272
(*: Is it possible that a FIN may need to be sent? :*)
273273
let fin_required =
@@ -287,7 +287,7 @@ let tcp_output_required now conn =
287287
let have_data_or_fin_to_send = Sequence.less cb.snd_nxt last_sndq_data_and_fin_seq in
288288
(*: The amount by which the right edge of the advertised window could be moved :*)
289289
let window_update_delta =
290-
(min (Params.tcp_maxwin lsl cb.State.rcv_scale))
290+
(Int.min (Params.tcp_maxwin lsl cb.State.rcv_scale))
291291
(conn.rcvbufsize - Cstruct.lenv conn.rcvq) -
292292
Sequence.window cb.State.rcv_adv cb.State.rcv_nxt
293293
in
@@ -353,7 +353,7 @@ let tcp_output_really_helper now (src, src_port, dst, dst_port) window_probe con
353353
else
354354
cb.State.snd_cwnd
355355
in
356-
let win0 = min cb.State.snd_wnd snd_cwnd in
356+
let win0 = Int.min cb.State.snd_wnd snd_cwnd in
357357
let win = if window_probe && win0 = 0 then 1 else win0 in
358358
let snd_wnd_unused = win - (Sequence.window cb.State.snd_nxt cb.State.snd_una) in
359359
let fin_required =
@@ -365,15 +365,15 @@ let tcp_output_really_helper now (src, src_port, dst, dst_port) window_probe con
365365
let data_to_send, more_data_could_be_sent =
366366
let data' =
367367
Cstruct.shiftv (List.rev conn.State.sndq)
368-
(max 0
369-
(min (Cstruct.lenv conn.State.sndq)
368+
(Int.max 0
369+
(Int.min (Cstruct.lenv conn.State.sndq)
370370
(Sequence.window cb.State.snd_nxt cb.State.snd_una)))
371371
(* taking the minimum to avoid exceeding the sndq *)
372372
in
373373
let data' = Cstruct.concat data' in
374-
let len_could_be_sent = max 0 snd_wnd_unused in
374+
let len_could_be_sent = Int.max 0 snd_wnd_unused in
375375
let dlen = Cstruct.length data' in
376-
Cstruct.sub data' 0 (min dlen (min len_could_be_sent cb.State.t_maxseg)),
376+
Cstruct.sub data' 0 (Int.min dlen (Int.min len_could_be_sent cb.State.t_maxseg)),
377377
dlen > cb.t_maxseg && len_could_be_sent > cb.t_maxseg
378378
in
379379
let dlen = Cstruct.length data_to_send in
@@ -402,8 +402,8 @@ let tcp_output_really_helper now (src, src_port, dst, dst_port) window_probe con
402402
| Time_wait -> window_size
403403
| _ ->
404404
let rcv_wnd'' = Subr.calculate_bsd_rcv_wnd conn in
405-
max window_size
406-
(min (Params.tcp_maxwin lsl cb.State.rcv_scale)
405+
Int.max window_size
406+
(Int.min (Params.tcp_maxwin lsl cb.State.rcv_scale)
407407
(if rcv_wnd'' < conn.rcvbufsize / 4 && rcv_wnd'' < cb.State.t_maxseg
408408
then 0 (*: Silly window avoidance: shouldn't advertise a tiny window :*)
409409
else rcv_wnd''))
@@ -414,7 +414,7 @@ let tcp_output_really_helper now (src, src_port, dst, dst_port) window_probe con
414414
let seg =
415415
{ src_port ; dst_port ; seq = snd_nxt;
416416
ack = Some cb.State.rcv_nxt ; flag ; push ;
417-
window = min (rcv_wnd' lsr cb.rcv_scale) max_win ;
417+
window = Int.min (rcv_wnd' lsr cb.rcv_scale) max_win ;
418418
options = [] ; payload = data_to_send
419419
}
420420
in
@@ -430,7 +430,7 @@ let tcp_output_really_helper now (src, src_port, dst, dst_port) window_probe con
430430
in
431431
(*: Updated values to store in the control block after the segment is output :*)
432432
let snd_nxt' = Sequence.(addi (addi snd_nxt dlen) (if fin then 1 else 0)) in
433-
let snd_max = max cb.State.snd_max snd_nxt' in
433+
let snd_max = Sequence.max cb.State.snd_max snd_nxt' in
434434
(*: Following a |tcp_output| code walkthrough by SB: :*)
435435
let tt_rexmt =
436436
if (State.mode_of cb.tt_rexmt = None ||
@@ -515,7 +515,7 @@ let tcp_output_perhaps now id conn =
515515

516516
(* auxFns:1384 *)
517517
let make_syn_ack cb (src, src_port, dst, dst_port) =
518-
let window = min cb.State.rcv_wnd max_win in
518+
let window = Int.min cb.State.rcv_wnd max_win in
519519
let options =
520520
MaximumSegmentSize cb.t_advmss ::
521521
(Option.map (fun sc -> WindowScale sc) cb.request_r_scale |> Option.to_list)
@@ -527,7 +527,7 @@ let make_syn_ack cb (src, src_port, dst, dst_port) =
527527

528528
(* auxFns:1333 *)
529529
let make_syn cb (src, src_port, dst, dst_port) =
530-
let window = min cb.State.rcv_wnd max_win in
530+
let window = Int.min cb.State.rcv_wnd max_win in
531531
let options =
532532
MaximumSegmentSize cb.State.t_advmss ::
533533
(Option.map (fun sc -> WindowScale sc) cb.request_r_scale |> Option.to_list)
@@ -539,7 +539,7 @@ let make_syn cb (src, src_port, dst, dst_port) =
539539

540540
(* auxFns:1437 *)
541541
let make_ack cb ~fin (src, src_port, dst, dst_port) =
542-
let window = min (cb.State.rcv_wnd lsr cb.rcv_scale) max_win in
542+
let window = Int.min (cb.State.rcv_wnd lsr cb.rcv_scale) max_win in
543543
(* sack *)
544544
src, dst,
545545
{ src_port ; dst_port ;

src/subr.ml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let calculate_buf_sizes (* conn *) cb_t_maxseg seg_mss bw_delay_product_for_rt r
4949
BSD has the route MTU if avail, or [[MIN MSSDFLT (link MTU)]] otherwise, as the first argument
5050
of the MIN below. That is the same calculation as we did in [[connect_1]]. We don't repeat it,
5151
but use the cached value in [[cb.t_maxseg]]. :*)
52-
min cb_t_maxseg (max 64 (match seg_mss with None -> Params.mssdflt | Some x -> x))
52+
min cb_t_maxseg (Int.max 64 (match seg_mss with None -> Params.mssdflt | Some x -> x))
5353
in
5454
let rcvbufsize' = match bw_delay_product_for_rt with None -> rcvbufsize | Some x -> x in
5555
let rcvbufsize'',t_maxseg'' =
@@ -67,11 +67,11 @@ let calculate_buf_sizes (* conn *) cb_t_maxseg seg_mss bw_delay_product_for_rt r
6767
min Params.sb_max (roundup t_maxseg' sndbufsize')
6868
in
6969
(* compute initial cwnd *)
70-
let snd_cwnd = min (4 * t_maxseg'') (max (2 * t_maxseg'') 4380) in
70+
let snd_cwnd = min (4 * t_maxseg'') (Int.max (2 * t_maxseg'') 4380) in
7171
rcvbufsize'', sndbufsize'', t_maxseg'', snd_cwnd
7272

7373
let calculate_bsd_rcv_wnd conn =
74-
max (Sequence.window conn.control_block.rcv_adv conn.control_block.rcv_nxt)
74+
Int.max (Sequence.window conn.control_block.rcv_adv conn.control_block.rcv_nxt)
7575
(conn.rcvbufsize - Cstruct.lenv conn.rcvq)
7676

7777
let update_rtt rtt ri =
@@ -80,8 +80,8 @@ let update_rtt rtt ri =
8080
if ri.tf_srtt_valid then
8181
let delta = Int64.(sub (sub rtt (Duration.of_ms 1)) ri.t_srtt) in
8282
let vardelta = Int64.(sub (abs delta) ri.t_rttvar) in
83-
let t_srtt' = max (Duration.of_ms 16) Int64.(add ri.t_srtt (shift_right delta 3))
84-
and t_rttvar' = max (Duration.of_ms 32) Int64.(add ri.t_rttvar (shift_right vardelta 2))
83+
let t_srtt' = Int64.max (Duration.of_ms 16) Int64.(add ri.t_srtt (shift_right delta 3))
84+
and t_rttvar' = Int64.max (Duration.of_ms 32) Int64.(add ri.t_rttvar (shift_right vardelta 2))
8585
(* BSD behaviour is never to let these go to zero, but clip at the least
8686
positive value. Since SRTT is measured in 1/32 tick and RTTVAR in
8787
1/16 tick, these are the minimum values. A more natural implementation
@@ -107,26 +107,26 @@ let update_rtt rtt ri =
107107

108108
(* auxFns:864 *)
109109
let expand_cwnd ssthresh maxseg maxwin cwnd =
110-
min maxwin (cwnd + (if cwnd > ssthresh then max 1 ((maxseg * maxseg) / cwnd) else maxseg))
110+
min maxwin (cwnd + (if cwnd > ssthresh then Int.max 1 ((maxseg * maxseg) / cwnd) else maxseg))
111111

112112
(* auxFns:657 *)
113113
let computed_rto backoffs shift ri =
114114
Int64.(mul backoffs.(shift)
115-
(max ri.t_rttmin Int64.(add ri.t_srtt (shift_left ri.t_rttvar 2))))
115+
(Int64.max ri.t_rttmin Int64.(add ri.t_srtt (shift_left ri.t_rttvar 2))))
116116

117117
(* auxFns:663 *)
118118
let computed_rxtcur ri =
119-
max ri.t_rttmin
120-
(min Params.tcptv_rexmtmax
119+
Int64.max ri.t_rttmin
120+
(Int64.min Params.tcptv_rexmtmax
121121
(computed_rto
122122
(if ri.t_wassyn then Params.tcp_syn_backoff else Params.tcp_backoff)
123123
(match ri.t_lastshift with None -> 0 | Some x -> x) ri))
124124

125125
(* auxFns:692 *)
126126
let start_tt_rexmt_gen mode backoffs now shift wantmin ri =
127127
let rxtcur =
128-
max (if wantmin then
129-
max ri.t_rttmin
128+
Int64.max (if wantmin then
129+
Int64.max ri.t_rttmin
130130
(match ri.t_lastrtt with None -> 0L | Some v -> Int64.add v (Duration.of_ms 2))
131131
else ri.t_rttmin)
132132
(min Params.tcptv_rexmtmax (* better not be infinite! *)
@@ -142,8 +142,8 @@ let start_tt_rexmt_syn = start_tt_rexmt_gen RexmtSyn Params.tcp_syn_backoff
142142
let start_tt_rexmt = start_tt_rexmt_gen Rexmt Params.tcp_backoff
143143

144144
let start_tt_persist now shift ri =
145-
let cur = max Params.tcptv_persmin (* better not be infinite! *)
146-
(min Params.tcptv_persmax (* better not be infinite! *)
145+
let cur = Int64.max Params.tcptv_persmin (* better not be infinite! *)
146+
(Int64.min Params.tcptv_persmax (* better not be infinite! *)
147147
(computed_rto Params.tcp_backoff shift ri))
148148
in
149149
Log.debug (fun m -> m "starting persist timer %a (backoff is %a)"

src/tcptimer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let timer_tt_rexmtsyn m now shift id conn =
3131
snd_recover = Sequence.incr cb.iss ;
3232
t_rttseg = None ;
3333
snd_cwnd = maxseg ;
34-
snd_ssthresh = maxseg * max 2 (min cb.snd_wnd cb.snd_cwnd / (2 * maxseg)) ; (* need to adjust with cc_newreno *)
34+
snd_ssthresh = maxseg * Int.max 2 (min cb.snd_wnd cb.snd_cwnd / (2 * maxseg)) ; (* need to adjust with cc_newreno *)
3535
t_dupacks = 0 ;
3636
}
3737
in

0 commit comments

Comments
 (0)