2 * net/dccp/ccids/lib/loss_interval.c
4 * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
5 * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
6 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/config.h>
15 #include <linux/module.h>
17 #include "loss_interval.h"
19 struct dccp_li_hist *dccp_li_hist_new(const char *name)
21 struct dccp_li_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
22 static const char dccp_li_hist_mask[] = "li_hist_%s";
28 slab_name = kmalloc(strlen(name) + sizeof(dccp_li_hist_mask) - 1,
30 if (slab_name == NULL)
33 sprintf(slab_name, dccp_li_hist_mask, name);
34 hist->dccplih_slab = kmem_cache_create(slab_name,
35 sizeof(struct dccp_li_hist_entry),
36 0, SLAB_HWCACHE_ALIGN,
38 if (hist->dccplih_slab == NULL)
39 goto out_free_slab_name;
50 EXPORT_SYMBOL_GPL(dccp_li_hist_new);
52 void dccp_li_hist_delete(struct dccp_li_hist *hist)
54 const char* name = kmem_cache_name(hist->dccplih_slab);
56 kmem_cache_destroy(hist->dccplih_slab);
61 EXPORT_SYMBOL_GPL(dccp_li_hist_delete);
63 void dccp_li_hist_purge(struct dccp_li_hist *hist, struct list_head *list)
65 struct dccp_li_hist_entry *entry, *next;
67 list_for_each_entry_safe(entry, next, list, dccplih_node) {
68 list_del_init(&entry->dccplih_node);
69 kmem_cache_free(hist->dccplih_slab, entry);
73 EXPORT_SYMBOL_GPL(dccp_li_hist_purge);
75 /* Weights used to calculate loss event rate */
77 * These are integers as per section 8 of RFC3448. We can then divide by 4 *
80 static const int dccp_li_hist_w[DCCP_LI_HIST_IVAL_F_LENGTH] = {
81 4, 4, 4, 4, 3, 2, 1, 1,
84 u32 dccp_li_hist_calc_i_mean(struct list_head *list)
86 struct dccp_li_hist_entry *li_entry, *li_next;
93 list_for_each_entry_safe(li_entry, li_next, list, dccplih_node) {
94 if (i < DCCP_LI_HIST_IVAL_F_LENGTH) {
95 i_tot0 += li_entry->dccplih_interval * dccp_li_hist_w[i];
96 w_tot += dccp_li_hist_w[i];
100 i_tot1 += li_entry->dccplih_interval * dccp_li_hist_w[i - 1];
102 if (++i > DCCP_LI_HIST_IVAL_F_LENGTH)
106 if (i != DCCP_LI_HIST_IVAL_F_LENGTH)
109 i_tot = max(i_tot0, i_tot1);
111 /* FIXME: Why do we do this? -Ian McDonald */
112 if (i_tot * 4 < w_tot)
115 return i_tot * 4 / w_tot;
118 EXPORT_SYMBOL_GPL(dccp_li_hist_calc_i_mean);
120 struct dccp_li_hist_entry *dccp_li_hist_interval_new(struct dccp_li_hist *hist,
121 struct list_head *list,
125 struct dccp_li_hist_entry *tail = NULL, *entry;
128 for (i = 0; i <= DCCP_LI_HIST_IVAL_F_LENGTH; ++i) {
129 entry = dccp_li_hist_entry_new(hist, SLAB_ATOMIC);
131 dccp_li_hist_purge(hist, list);
136 list_add(&entry->dccplih_node, list);
139 entry->dccplih_seqno = seq_loss;
140 entry->dccplih_win_count = win_loss;
144 EXPORT_SYMBOL_GPL(dccp_li_hist_interval_new);