dccp ccid-3: Remove ugly RTT-sampling history lookup
[pandora-kernel.git] / net / dccp / ccids / lib / packet_history.c
index 7129305..5c44508 100644 (file)
 #include "packet_history.h"
 #include "../../dccp.h"
 
-/**
- *  tfrc_tx_hist_entry  -  Simple singly-linked TX history list
- *  @next:  next oldest entry (LIFO order)
- *  @seqno: sequence number of this entry
- *  @stamp: send time of packet with sequence number @seqno
- */
-struct tfrc_tx_hist_entry {
-       struct tfrc_tx_hist_entry *next;
-       u64                       seqno;
-       ktime_t                   stamp;
-};
-
 /*
  * Transmitter History Routines
  */
@@ -73,15 +61,6 @@ void tfrc_tx_packet_history_exit(void)
        }
 }
 
-static struct tfrc_tx_hist_entry *
-       tfrc_tx_hist_find_entry(struct tfrc_tx_hist_entry *head, u64 seqno)
-{
-       while (head != NULL && head->seqno != seqno)
-               head = head->next;
-
-       return head;
-}
-
 int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno)
 {
        struct tfrc_tx_hist_entry *entry = kmem_cache_alloc(tfrc_tx_hist_slab, gfp_any());
@@ -111,25 +90,6 @@ void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp)
 }
 EXPORT_SYMBOL_GPL(tfrc_tx_hist_purge);
 
-u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head, const u64 seqno,
-                    const ktime_t now)
-{
-       u32 rtt = 0;
-       struct tfrc_tx_hist_entry *packet = tfrc_tx_hist_find_entry(head, seqno);
-
-       if (packet != NULL) {
-               rtt = ktime_us_delta(now, packet->stamp);
-               /*
-                * Garbage-collect older (irrelevant) entries:
-                */
-               tfrc_tx_hist_purge(&packet->next);
-       }
-
-       return rtt;
-}
-EXPORT_SYMBOL_GPL(tfrc_tx_hist_rtt);
-
-
 /*
  *     Receiver History Routines
  */
@@ -206,10 +166,21 @@ static void tfrc_rx_hist_swap(struct tfrc_rx_hist *h, const u8 a, const u8 b)
  *
  * In the descriptions, `Si' refers to the sequence number of entry number i,
  * whose NDP count is `Ni' (lower case is used for variables).
- * Note: All __after_loss functions expect that a test against duplicates has
- *       been performed already: the seqno of the skb must not be less than the
- *       seqno of loss_prev; and it must not equal that of any valid hist_entry.
+ * Note: All __xxx_loss functions expect that a test against duplicates has been
+ *       performed already: the seqno of the skb must not be less than the seqno
+ *       of loss_prev; and it must not equal that of any valid history entry.
  */
+static void __do_track_loss(struct tfrc_rx_hist *h, struct sk_buff *skb, u64 n1)
+{
+       u64 s0 = tfrc_rx_hist_loss_prev(h)->tfrchrx_seqno,
+           s1 = DCCP_SKB_CB(skb)->dccpd_seq;
+
+       if (!dccp_loss_free(s0, s1, n1)) {      /* gap between S0 and S1 */
+               h->loss_count = 1;
+               tfrc_rx_hist_entry_from_skb(tfrc_rx_hist_entry(h, 1), skb, n1);
+       }
+}
+
 static void __one_after_loss(struct tfrc_rx_hist *h, struct sk_buff *skb, u32 n2)
 {
        u64 s0 = tfrc_rx_hist_loss_prev(h)->tfrchrx_seqno,
@@ -353,6 +324,9 @@ static void __three_after_loss(struct tfrc_rx_hist *h)
  *  Chooses action according to pending loss, updates LI database when a new
  *  loss was detected, and does required post-processing. Returns 1 when caller
  *  should send feedback, 0 otherwise.
+ *  Since it also takes care of reordering during loss detection and updates the
+ *  records accordingly, the caller should not perform any more RX history
+ *  operations when loss_count is greater than 0 after calling this function.
  */
 int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,
                        struct tfrc_loss_hist *lh,
@@ -361,7 +335,9 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,
 {
        int is_new_loss = 0;
 
-       if (h->loss_count == 1) {
+       if (h->loss_count == 0) {
+               __do_track_loss(h, skb, ndp);
+       } else if (h->loss_count == 1) {
                __one_after_loss(h, skb, ndp);
        } else if (h->loss_count != 2) {
                DCCP_BUG("invalid loss_count %d", h->loss_count);