2005-08-28 02:03:09 +00:00
|
|
|
/*
|
|
|
|
* net/dccp/ccids/lib/loss_interval.c
|
|
|
|
*
|
2007-05-28 15:23:29 +00:00
|
|
|
* Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
|
|
|
|
* Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
|
2005-08-28 02:03:09 +00:00
|
|
|
* Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2006-08-27 06:40:50 +00:00
|
|
|
#include <net/sock.h>
|
2006-11-20 20:39:23 +00:00
|
|
|
#include "../../dccp.h"
|
2005-08-28 02:03:09 +00:00
|
|
|
#include "loss_interval.h"
|
2007-06-14 20:41:28 +00:00
|
|
|
#include "packet_history.h"
|
|
|
|
#include "tfrc.h"
|
2005-08-28 02:03:09 +00:00
|
|
|
|
2007-05-28 21:56:44 +00:00
|
|
|
#define DCCP_LI_HIST_IVAL_F_LENGTH 8
|
|
|
|
|
|
|
|
struct dccp_li_hist_entry {
|
|
|
|
struct list_head dccplih_node;
|
|
|
|
u64 dccplih_seqno:48,
|
|
|
|
dccplih_win_count:4;
|
|
|
|
u32 dccplih_interval;
|
|
|
|
};
|
|
|
|
|
2007-07-09 20:18:57 +00:00
|
|
|
static struct kmem_cache *dccp_li_cachep __read_mostly;
|
2005-08-28 02:03:09 +00:00
|
|
|
|
2007-05-28 21:53:08 +00:00
|
|
|
static inline struct dccp_li_hist_entry *dccp_li_hist_entry_new(const gfp_t prio)
|
2007-05-28 21:25:12 +00:00
|
|
|
{
|
2007-05-28 21:53:08 +00:00
|
|
|
return kmem_cache_alloc(dccp_li_cachep, prio);
|
2007-05-28 21:25:12 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:53:08 +00:00
|
|
|
static inline void dccp_li_hist_entry_delete(struct dccp_li_hist_entry *entry)
|
2007-05-28 21:25:12 +00:00
|
|
|
{
|
|
|
|
if (entry != NULL)
|
2007-05-28 21:53:08 +00:00
|
|
|
kmem_cache_free(dccp_li_cachep, entry);
|
2007-05-28 21:25:12 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:53:08 +00:00
|
|
|
void dccp_li_hist_purge(struct list_head *list)
|
2005-08-28 02:03:09 +00:00
|
|
|
{
|
|
|
|
struct dccp_li_hist_entry *entry, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, next, list, dccplih_node) {
|
|
|
|
list_del_init(&entry->dccplih_node);
|
2007-05-28 21:53:08 +00:00
|
|
|
kmem_cache_free(dccp_li_cachep, entry);
|
2005-08-28 02:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_li_hist_purge);
|
|
|
|
|
|
|
|
/* Weights used to calculate loss event rate */
|
|
|
|
/*
|
|
|
|
* These are integers as per section 8 of RFC3448. We can then divide by 4 *
|
|
|
|
* when we use it.
|
|
|
|
*/
|
|
|
|
static const int dccp_li_hist_w[DCCP_LI_HIST_IVAL_F_LENGTH] = {
|
|
|
|
4, 4, 4, 4, 3, 2, 1, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 dccp_li_hist_calc_i_mean(struct list_head *list)
|
|
|
|
{
|
|
|
|
struct dccp_li_hist_entry *li_entry, *li_next;
|
|
|
|
int i = 0;
|
|
|
|
u32 i_tot;
|
|
|
|
u32 i_tot0 = 0;
|
|
|
|
u32 i_tot1 = 0;
|
|
|
|
u32 w_tot = 0;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(li_entry, li_next, list, dccplih_node) {
|
2007-03-20 17:46:52 +00:00
|
|
|
if (li_entry->dccplih_interval != ~0U) {
|
2005-08-28 02:03:09 +00:00
|
|
|
i_tot0 += li_entry->dccplih_interval * dccp_li_hist_w[i];
|
|
|
|
w_tot += dccp_li_hist_w[i];
|
2006-08-27 06:40:50 +00:00
|
|
|
if (i != 0)
|
|
|
|
i_tot1 += li_entry->dccplih_interval * dccp_li_hist_w[i - 1];
|
2005-08-28 02:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (++i > DCCP_LI_HIST_IVAL_F_LENGTH)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != DCCP_LI_HIST_IVAL_F_LENGTH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i_tot = max(i_tot0, i_tot1);
|
|
|
|
|
2006-08-27 06:40:50 +00:00
|
|
|
if (!w_tot) {
|
2006-11-20 20:39:23 +00:00
|
|
|
DCCP_WARN("w_tot = 0\n");
|
2006-08-27 06:40:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2005-08-28 02:03:09 +00:00
|
|
|
|
2006-08-27 06:40:50 +00:00
|
|
|
return i_tot / w_tot;
|
2005-08-28 02:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_li_hist_calc_i_mean);
|
|
|
|
|
2007-05-28 21:53:08 +00:00
|
|
|
static int dccp_li_hist_interval_new(struct list_head *list,
|
2007-05-28 21:21:53 +00:00
|
|
|
const u64 seq_loss, const u8 win_loss)
|
2005-08-28 02:03:09 +00:00
|
|
|
{
|
2006-08-27 06:40:50 +00:00
|
|
|
struct dccp_li_hist_entry *entry;
|
2005-08-28 02:03:09 +00:00
|
|
|
int i;
|
|
|
|
|
2006-08-27 06:40:50 +00:00
|
|
|
for (i = 0; i < DCCP_LI_HIST_IVAL_F_LENGTH; i++) {
|
2007-05-28 21:53:08 +00:00
|
|
|
entry = dccp_li_hist_entry_new(GFP_ATOMIC);
|
2005-08-28 02:03:09 +00:00
|
|
|
if (entry == NULL) {
|
2007-05-28 21:53:08 +00:00
|
|
|
dccp_li_hist_purge(list);
|
2006-11-20 20:39:23 +00:00
|
|
|
DCCP_BUG("loss interval list entry is NULL");
|
2006-08-27 06:40:50 +00:00
|
|
|
return 0;
|
2005-08-28 02:03:09 +00:00
|
|
|
}
|
2006-08-27 06:40:50 +00:00
|
|
|
entry->dccplih_interval = ~0;
|
2005-08-28 02:03:09 +00:00
|
|
|
list_add(&entry->dccplih_node, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->dccplih_seqno = seq_loss;
|
|
|
|
entry->dccplih_win_count = win_loss;
|
2006-08-27 06:40:50 +00:00
|
|
|
return 1;
|
2005-08-28 02:03:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 20:41:28 +00:00
|
|
|
/* calculate first loss interval
|
|
|
|
*
|
|
|
|
* returns estimated loss interval in usecs */
|
|
|
|
static u32 dccp_li_calc_first_li(struct sock *sk,
|
|
|
|
struct list_head *hist_list,
|
2007-08-20 00:17:51 +00:00
|
|
|
ktime_t last_feedback,
|
2007-06-14 20:41:28 +00:00
|
|
|
u16 s, u32 bytes_recv,
|
|
|
|
u32 previous_x_recv)
|
|
|
|
{
|
2007-12-06 15:18:11 +00:00
|
|
|
/*
|
|
|
|
* FIXME:
|
|
|
|
* Will be rewritten in the upcoming new loss intervals code.
|
|
|
|
* Has to be commented ou because it relies on the old rx history
|
|
|
|
* data structures
|
|
|
|
*/
|
|
|
|
#if 0
|
2007-12-06 14:28:39 +00:00
|
|
|
struct tfrc_rx_hist_entry *entry, *next, *tail = NULL;
|
2007-06-14 20:41:28 +00:00
|
|
|
u32 x_recv, p;
|
|
|
|
suseconds_t rtt, delta;
|
2007-08-20 00:17:51 +00:00
|
|
|
ktime_t tstamp = ktime_set(0, 0);
|
2007-06-14 20:41:28 +00:00
|
|
|
int interval = 0;
|
|
|
|
int win_count = 0;
|
|
|
|
int step = 0;
|
|
|
|
u64 fval;
|
|
|
|
|
2007-12-06 14:28:39 +00:00
|
|
|
list_for_each_entry_safe(entry, next, hist_list, tfrchrx_node) {
|
|
|
|
if (tfrc_rx_hist_entry_data_packet(entry)) {
|
2007-06-14 20:41:28 +00:00
|
|
|
tail = entry;
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 0:
|
2007-12-06 14:28:39 +00:00
|
|
|
tstamp = entry->tfrchrx_tstamp;
|
|
|
|
win_count = entry->tfrchrx_ccval;
|
2007-06-14 20:41:28 +00:00
|
|
|
step = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2007-12-06 14:28:39 +00:00
|
|
|
interval = win_count - entry->tfrchrx_ccval;
|
2007-06-14 20:41:28 +00:00
|
|
|
if (interval < 0)
|
|
|
|
interval += TFRC_WIN_COUNT_LIMIT;
|
|
|
|
if (interval > 4)
|
|
|
|
goto found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(step == 0)) {
|
|
|
|
DCCP_WARN("%s(%p), packet history has no data packets!\n",
|
|
|
|
dccp_role(sk), sk);
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(interval == 0)) {
|
2007-11-20 07:46:02 +00:00
|
|
|
DCCP_WARN("%s(%p), Could not find a win_count interval > 0. "
|
2007-06-14 20:41:28 +00:00
|
|
|
"Defaulting to 1\n", dccp_role(sk), sk);
|
|
|
|
interval = 1;
|
|
|
|
}
|
|
|
|
found:
|
|
|
|
if (!tail) {
|
|
|
|
DCCP_CRIT("tail is null\n");
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
2007-12-06 14:28:39 +00:00
|
|
|
delta = ktime_us_delta(tstamp, tail->tfrchrx_tstamp);
|
2007-06-14 20:41:28 +00:00
|
|
|
DCCP_BUG_ON(delta < 0);
|
|
|
|
|
|
|
|
rtt = delta * 4 / interval;
|
|
|
|
dccp_pr_debug("%s(%p), approximated RTT to %dus\n",
|
|
|
|
dccp_role(sk), sk, (int)rtt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the length of the first loss interval via inverse lookup.
|
|
|
|
* Assume that X_recv can be computed by the throughput equation
|
|
|
|
* s
|
|
|
|
* X_recv = --------
|
|
|
|
* R * fval
|
|
|
|
* Find some p such that f(p) = fval; return 1/p [RFC 3448, 6.3.1].
|
|
|
|
*/
|
|
|
|
if (rtt == 0) { /* would result in divide-by-zero */
|
|
|
|
DCCP_WARN("RTT==0\n");
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
2007-08-20 00:17:51 +00:00
|
|
|
delta = ktime_us_delta(ktime_get_real(), last_feedback);
|
2007-06-14 20:41:28 +00:00
|
|
|
DCCP_BUG_ON(delta <= 0);
|
|
|
|
|
|
|
|
x_recv = scaled_div32(bytes_recv, delta);
|
|
|
|
if (x_recv == 0) { /* would also trigger divide-by-zero */
|
|
|
|
DCCP_WARN("X_recv==0\n");
|
|
|
|
if (previous_x_recv == 0) {
|
|
|
|
DCCP_BUG("stored value of X_recv is zero");
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
x_recv = previous_x_recv;
|
|
|
|
}
|
|
|
|
|
|
|
|
fval = scaled_div(s, rtt);
|
|
|
|
fval = scaled_div32(fval, x_recv);
|
|
|
|
p = tfrc_calc_x_reverse_lookup(fval);
|
|
|
|
|
|
|
|
dccp_pr_debug("%s(%p), receive rate=%u bytes/s, implied "
|
|
|
|
"loss rate=%u\n", dccp_role(sk), sk, x_recv, p);
|
|
|
|
|
2007-12-06 15:18:11 +00:00
|
|
|
if (p != 0)
|
2007-06-14 20:41:28 +00:00
|
|
|
return 1000000 / p;
|
2007-12-06 15:18:11 +00:00
|
|
|
#endif
|
|
|
|
return ~0;
|
2007-06-14 20:41:28 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:53:08 +00:00
|
|
|
void dccp_li_update_li(struct sock *sk,
|
2007-06-14 20:41:28 +00:00
|
|
|
struct list_head *li_hist_list,
|
|
|
|
struct list_head *hist_list,
|
2007-08-20 00:17:51 +00:00
|
|
|
ktime_t last_feedback, u16 s, u32 bytes_recv,
|
2007-07-19 01:43:28 +00:00
|
|
|
u32 previous_x_recv, u64 seq_loss, u8 win_loss)
|
2007-06-14 20:41:28 +00:00
|
|
|
{
|
|
|
|
struct dccp_li_hist_entry *head;
|
|
|
|
u64 seq_temp;
|
|
|
|
|
|
|
|
if (list_empty(li_hist_list)) {
|
2007-05-28 21:53:08 +00:00
|
|
|
if (!dccp_li_hist_interval_new(li_hist_list, seq_loss,
|
|
|
|
win_loss))
|
2007-06-14 20:41:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
head = list_entry(li_hist_list->next, struct dccp_li_hist_entry,
|
|
|
|
dccplih_node);
|
|
|
|
head->dccplih_interval = dccp_li_calc_first_li(sk, hist_list,
|
|
|
|
last_feedback,
|
|
|
|
s, bytes_recv,
|
|
|
|
previous_x_recv);
|
|
|
|
} else {
|
|
|
|
struct dccp_li_hist_entry *entry;
|
|
|
|
struct list_head *tail;
|
|
|
|
|
|
|
|
head = list_entry(li_hist_list->next, struct dccp_li_hist_entry,
|
|
|
|
dccplih_node);
|
|
|
|
/* FIXME win count check removed as was wrong */
|
|
|
|
/* should make this check with receive history */
|
|
|
|
/* and compare there as per section 10.2 of RFC4342 */
|
|
|
|
|
|
|
|
/* new loss event detected */
|
|
|
|
/* calculate last interval length */
|
|
|
|
seq_temp = dccp_delta_seqno(head->dccplih_seqno, seq_loss);
|
2007-05-28 21:53:08 +00:00
|
|
|
entry = dccp_li_hist_entry_new(GFP_ATOMIC);
|
2007-06-14 20:41:28 +00:00
|
|
|
|
|
|
|
if (entry == NULL) {
|
|
|
|
DCCP_BUG("out of memory - can not allocate entry");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(&entry->dccplih_node, li_hist_list);
|
|
|
|
|
|
|
|
tail = li_hist_list->prev;
|
|
|
|
list_del(tail);
|
2007-05-28 21:53:08 +00:00
|
|
|
kmem_cache_free(dccp_li_cachep, tail);
|
2007-06-14 20:41:28 +00:00
|
|
|
|
|
|
|
/* Create the newest interval */
|
|
|
|
entry->dccplih_seqno = seq_loss;
|
|
|
|
entry->dccplih_interval = seq_temp;
|
|
|
|
entry->dccplih_win_count = win_loss;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_li_update_li);
|
2007-05-28 21:53:08 +00:00
|
|
|
|
2007-11-28 13:15:40 +00:00
|
|
|
int __init dccp_li_init(void)
|
2007-05-28 21:53:08 +00:00
|
|
|
{
|
|
|
|
dccp_li_cachep = kmem_cache_create("dccp_li_hist",
|
|
|
|
sizeof(struct dccp_li_hist_entry),
|
2007-07-20 01:11:58 +00:00
|
|
|
0, SLAB_HWCACHE_ALIGN, NULL);
|
2007-05-28 21:53:08 +00:00
|
|
|
return dccp_li_cachep == NULL ? -ENOBUFS : 0;
|
|
|
|
}
|
|
|
|
|
2007-11-28 13:15:40 +00:00
|
|
|
void dccp_li_exit(void)
|
2007-05-28 21:53:08 +00:00
|
|
|
{
|
2007-11-28 13:15:40 +00:00
|
|
|
if (dccp_li_cachep != NULL) {
|
|
|
|
kmem_cache_destroy(dccp_li_cachep);
|
|
|
|
dccp_li_cachep = NULL;
|
|
|
|
}
|
2007-05-28 21:53:08 +00:00
|
|
|
}
|