@@ -1189,14 +1189,15 @@ static void rx_session_del(rx_session_t* const self,
11891189 mem_free (self -> owner -> memory .session , sizeof (rx_session_t ), self );
11901190}
11911191
1192- /// Checks which slots can be ejected or interned in the reordering window.
1193- /// Should be invoked whenever a slot MAY or MUST be ejected.
1192+ /// In the ORDERED mode, checks which slots can be ejected or interned in the reordering window.
1193+ /// This is only useful for the ORDERED mode.
1194+ /// Should be invoked whenever a slot MAY or MUST be ejected (i.e., on completion or when an empty slot is required).
11941195/// If the force flag is set, at least one DONE slot will be ejected even if its reordering window is still open;
11951196/// this is used to forcibly free up at least one slot when all slots are busy and a new transfer arrives.
1196- static void rx_session_scan_slots (rx_session_t * const self ,
1197- udpard_rx_t * const rx ,
1198- const udpard_us_t ts ,
1199- const bool force_one )
1197+ static void rx_session_ordered_scan_slots (rx_session_t * const self ,
1198+ udpard_rx_t * const rx ,
1199+ const udpard_us_t ts ,
1200+ const bool force_one )
12001201{
12011202 // Reset the reordering window timer because we will either eject everything or arm it again later.
12021203 if (cavl2_is_inserted (rx -> index_session_by_reordering , & self -> index_reordering_window )) {
@@ -1214,12 +1215,15 @@ static void rx_session_scan_slots(rx_session_t* const self,
12141215 if ((self -> slots [i ].state == rx_slot_done ) && (dist < min_tid_dist )) {
12151216 min_tid_dist = dist ;
12161217 slot = & self -> slots [i ];
1218+ if (dist == 0 ) {
1219+ break ; // Fast path for a common case.
1220+ }
12171221 }
12181222 }
12191223
12201224 // The slot needs to be ejected if it's in-sequence, if it's reordering window is closed, or if we're
12211225 // asked to force an ejection and we haven't done so yet.
1222- // The reordering window timeout implies that we will not be receiving earlier transfers anymore .
1226+ // The reordering window timeout implies that earlier transfers will be dropped if ORDERED mode is used .
12231227 const bool eject =
12241228 (slot != NULL ) && ((slot -> transfer_id == tid_expected ) ||
12251229 (ts >= (slot -> ts_min + self -> owner -> reordering_window )) || (force_one && (iter == 0 )));
@@ -1284,9 +1288,9 @@ static void rx_session_scan_slots(rx_session_t* const self,
12841288
12851289typedef enum
12861290{
1287- rx_session_transfer_new ,
1288- rx_session_transfer_acknowledged ,
1289- rx_session_transfer_lost ,
1291+ rx_session_transfer_new , ///< Should be accepted --- part of a transfer not yet received.
1292+ rx_session_transfer_acknowledged , ///< Send ACK back if requested by the sender; already received and processed.
1293+ rx_session_transfer_late , ///< Not received but ORDERED acceptance is no longer possible.
12901294} rx_session_transfer_status_t ;
12911295
12921296static rx_session_transfer_status_t rx_session_check_transfer_status (const rx_session_t * const self ,
@@ -1303,7 +1307,7 @@ static rx_session_transfer_status_t rx_session_check_transfer_status(const rx_se
13031307 }
13041308 }
13051309 // The transfer is not received; check if it's within the dup transfer-ID window.
1306- return rx_transfer_id_window_contains (& self -> received , transfer_id ) ? rx_session_transfer_lost
1310+ return rx_transfer_id_window_contains (& self -> received , transfer_id ) ? rx_session_transfer_late
13071311 : rx_session_transfer_new ;
13081312}
13091313
@@ -1386,7 +1390,7 @@ static void rx_session_update(rx_session_t* const self,
13861390 // If it's done, we have to force the reordering window to close early to free up a slot without transfer loss.
13871391 UDPARD_ASSERT ((slot != NULL ) && ((slot -> state == rx_slot_busy ) || (slot -> state == rx_slot_done )));
13881392 if (slot -> state == rx_slot_done ) {
1389- rx_session_scan_slots (self , rx , ts , true); // A slot will be ejected (maybe another one).
1393+ rx_session_ordered_scan_slots (self , rx , ts , true); // A slot will be ejected (maybe another one).
13901394 slot = NULL ; // Repeat the search. It is certain that now we have at least one idle slot.
13911395 for (size_t i = 0 ; i < RX_SLOT_COUNT ; i ++ ) {
13921396 if (self -> slots [i ].state == rx_slot_idle ) {
@@ -1427,7 +1431,7 @@ static void rx_session_update(rx_session_t* const self,
14271431 }
14281432 // The final ejection procedure is a little complicated because we need to manage the reordering window
14291433 // and possible obsolescence of other in-progress slots.
1430- rx_session_scan_slots (self , rx , ts , false);
1434+ rx_session_ordered_scan_slots (self , rx , ts , false);
14311435 }
14321436}
14331437
@@ -1488,6 +1492,6 @@ void udpard_rx_poll(udpard_rx_t* const self, const udpard_us_t now)
14881492 if ((ses == NULL ) || (now < ses -> reordering_window_deadline )) {
14891493 break ;
14901494 }
1491- rx_session_scan_slots (ses , self , now , false);
1495+ rx_session_ordered_scan_slots (ses , self , now , false);
14921496 }
14931497}
0 commit comments