Release 4.11 net/core/gen_estimator.c
/*
* net/sched/gen_estimator.c Simple rate estimator.
*
* 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.
*
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
* Eric Dumazet <edumazet@google.com>
*
* Changes:
* Jamal Hadi Salim - moved it to net/core and reshulfed
* names to make it usable in general net subsystem.
*/
#include <linux/uaccess.h>
#include <linux/bitops.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/in.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/rtnetlink.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/seqlock.h>
#include <net/sock.h>
#include <net/gen_stats.h>
/* This code is NOT intended to be used for statistics collection,
* its purpose is to provide a base for statistical multiplexing
* for controlled load service.
* If you need only statistics, run a user level daemon which
* periodically reads byte counters.
*/
struct net_rate_estimator {
struct gnet_stats_basic_packed *bstats;
spinlock_t *stats_lock;
seqcount_t *running;
struct gnet_stats_basic_cpu __percpu *cpu_bstats;
u8 ewma_log;
u8 intvl_log; /* period : (250ms << intvl_log) */
seqcount_t seq;
u32 last_packets;
u64 last_bytes;
u64 avpps;
u64 avbps;
unsigned long next_jiffies;
struct timer_list timer;
struct rcu_head rcu;
};
static void est_fetch_counters(struct net_rate_estimator *e,
struct gnet_stats_basic_packed *b)
{
if (e->stats_lock)
spin_lock(e->stats_lock);
__gnet_stats_copy_basic(e->running, b, e->cpu_bstats, e->bstats);
if (e->stats_lock)
spin_unlock(e->stats_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 29 | 49.15% | 2 | 50.00% |
David S. Miller | 19 | 32.20% | 1 | 25.00% |
John Fastabend | 11 | 18.64% | 1 | 25.00% |
Total | 59 | 100.00% | 4 | 100.00% |
static void est_timer(unsigned long arg)
{
struct net_rate_estimator *est = (struct net_rate_estimator *)arg;
struct gnet_stats_basic_packed b;
u64 rate, brate;
est_fetch_counters(est, &b);
brate = (b.bytes - est->last_bytes) << (8 - est->ewma_log);
brate -= (est->avbps >> est->ewma_log);
rate = (u64)(b.packets - est->last_packets) << (8 - est->ewma_log);
rate -= (est->avpps >> est->ewma_log);
write_seqcount_begin(&est->seq);
est->avbps += brate;
est->avpps += rate;
write_seqcount_end(&est->seq);
est->last_bytes = b.bytes;
est->last_packets = b.packets;
est->next_jiffies += ((HZ/4) << est->intvl_log);
if (unlikely(time_after_eq(jiffies, est->next_jiffies))) {
/* Ouch... timer was delayed. */
est->next_jiffies = jiffies + 1;
}
mod_timer(&est->timer, est->next_jiffies);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 135 | 66.50% | 4 | 44.44% |
David S. Miller | 42 | 20.69% | 1 | 11.11% |
Jarek Poplawski | 17 | 8.37% | 2 | 22.22% |
John Fastabend | 6 | 2.96% | 1 | 11.11% |
Ranko Zivojnovic | 3 | 1.48% | 1 | 11.11% |
Total | 203 | 100.00% | 9 | 100.00% |
/**
* gen_new_estimator - create a new rate estimator
* @bstats: basic statistics
* @cpu_bstats: bstats per cpu
* @rate_est: rate estimator statistics
* @stats_lock: statistics lock
* @running: qdisc running seqcount
* @opt: rate estimator configuration TLV
*
* Creates a new rate estimator with &bstats as source and &rate_est
* as destination. A new timer with the interval specified in the
* configuration TLV is created. Upon each interval, the latest statistics
* will be read from &bstats and the estimated rate will be stored in
* &rate_est with the statistics lock grabbed during this period.
*
* Returns 0 on success or a negative error code.
*
*/
int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **rate_est,
spinlock_t *stats_lock,
seqcount_t *running,
struct nlattr *opt)
{
struct gnet_estimator *parm = nla_data(opt);
struct net_rate_estimator *old, *est;
struct gnet_stats_basic_packed b;
int intvl_log;
if (nla_len(opt) < sizeof(*parm))
return -EINVAL;
/* allowed timer periods are :
* -2 : 250ms, -1 : 500ms, 0 : 1 sec
* 1 : 2 sec, 2 : 4 sec, 3 : 8 sec
*/
if (parm->interval < -2 || parm->interval > 3)
return -EINVAL;
est = kzalloc(sizeof(*est), GFP_KERNEL);
if (!est)
return -ENOBUFS;
seqcount_init(&est->seq);
intvl_log = parm->interval + 2;
est->bstats = bstats;
est->stats_lock = stats_lock;
est->running = running;
est->ewma_log = parm->ewma_log;
est->intvl_log = intvl_log;
est->cpu_bstats = cpu_bstats;
est_fetch_counters(est, &b);
est->last_bytes = b.bytes;
est->last_packets = b.packets;
old = rcu_dereference_protected(*rate_est, 1);
if (old) {
del_timer_sync(&old->timer);
est->avbps = old->avbps;
est->avpps = old->avpps;
}
est->next_jiffies = jiffies + ((HZ/4) << intvl_log);
setup_timer(&est->timer, est_timer, (unsigned long)est);
mod_timer(&est->timer, est->next_jiffies);
rcu_assign_pointer(*rate_est, est);
if (old)
kfree_rcu(old, rcu);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David S. Miller | 148 | 48.68% | 1 | 8.33% |
Eric Dumazet | 121 | 39.80% | 6 | 50.00% |
John Fastabend | 19 | 6.25% | 1 | 8.33% |
Ranko Zivojnovic | 8 | 2.63% | 1 | 8.33% |
Jarek Poplawski | 4 | 1.32% | 1 | 8.33% |
Patrick McHardy | 3 | 0.99% | 1 | 8.33% |
Andrew Morton | 1 | 0.33% | 1 | 8.33% |
Total | 304 | 100.00% | 12 | 100.00% |
EXPORT_SYMBOL(gen_new_estimator);
/**
* gen_kill_estimator - remove a rate estimator
* @rate_est: rate estimator
*
* Removes the rate estimator.
*
*/
void gen_kill_estimator(struct net_rate_estimator __rcu **rate_est)
{
struct net_rate_estimator *est;
est = xchg((__force struct net_rate_estimator **)rate_est, NULL);
if (est) {
del_timer_sync(&est->timer);
kfree_rcu(est, rcu);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 23 | 42.59% | 1 | 16.67% |
David S. Miller | 22 | 40.74% | 2 | 33.33% |
Ranko Zivojnovic | 5 | 9.26% | 1 | 16.67% |
Jarek Poplawski | 3 | 5.56% | 1 | 16.67% |
Lai Jiangshan | 1 | 1.85% | 1 | 16.67% |
Total | 54 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(gen_kill_estimator);
/**
* gen_replace_estimator - replace rate estimator configuration
* @bstats: basic statistics
* @cpu_bstats: bstats per cpu
* @rate_est: rate estimator statistics
* @stats_lock: statistics lock
* @running: qdisc running seqcount (might be NULL)
* @opt: rate estimator configuration TLV
*
* Replaces the configuration of a rate estimator by calling
* gen_kill_estimator() and gen_new_estimator().
*
* Returns 0 on success or a negative error code.
*/
int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **rate_est,
spinlock_t *stats_lock,
seqcount_t *running, struct nlattr *opt)
{
return gen_new_estimator(bstats, cpu_bstats, rate_est,
stats_lock, running, opt);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Thomas Graf | 32 | 61.54% | 1 | 14.29% |
Eric Dumazet | 10 | 19.23% | 3 | 42.86% |
John Fastabend | 8 | 15.38% | 1 | 14.29% |
Patrick McHardy | 1 | 1.92% | 1 | 14.29% |
Jarek Poplawski | 1 | 1.92% | 1 | 14.29% |
Total | 52 | 100.00% | 7 | 100.00% |
EXPORT_SYMBOL(gen_replace_estimator);
/**
* gen_estimator_active - test if estimator is currently in use
* @rate_est: rate estimator
*
* Returns true if estimator is active, and false if not.
*/
bool gen_estimator_active(struct net_rate_estimator __rcu **rate_est)
{
return !!rcu_access_pointer(*rate_est);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 16 | 76.19% | 1 | 33.33% |
Stephen Hemminger | 3 | 14.29% | 1 | 33.33% |
Jarek Poplawski | 2 | 9.52% | 1 | 33.33% |
Total | 21 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(gen_estimator_active);
bool gen_estimator_read(struct net_rate_estimator __rcu **rate_est,
struct gnet_stats_rate_est64 *sample)
{
struct net_rate_estimator *est;
unsigned seq;
rcu_read_lock();
est = rcu_dereference(*rate_est);
if (!est) {
rcu_read_unlock();
return false;
}
do {
seq = read_seqcount_begin(&est->seq);
sample->bps = est->avbps >> 8;
sample->pps = est->avpps >> 8;
} while (read_seqcount_retry(&est->seq, seq));
rcu_read_unlock();
return true;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 90 | 89.11% | 3 | 50.00% |
Stephen Hemminger | 7 | 6.93% | 1 | 16.67% |
Jarek Poplawski | 3 | 2.97% | 1 | 16.67% |
David S. Miller | 1 | 0.99% | 1 | 16.67% |
Total | 101 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(gen_estimator_read);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 473 | 50.00% | 9 | 36.00% |
David S. Miller | 314 | 33.19% | 2 | 8.00% |
John Fastabend | 44 | 4.65% | 1 | 4.00% |
Thomas Graf | 36 | 3.81% | 1 | 4.00% |
Jarek Poplawski | 32 | 3.38% | 4 | 16.00% |
Stephen Hemminger | 21 | 2.22% | 1 | 4.00% |
Ranko Zivojnovic | 16 | 1.69% | 1 | 4.00% |
Patrick McHardy | 4 | 0.42% | 1 | 4.00% |
Tejun Heo | 2 | 0.21% | 1 | 4.00% |
Lai Jiangshan | 1 | 0.11% | 1 | 4.00% |
Linus Torvalds | 1 | 0.11% | 1 | 4.00% |
Andrew Morton | 1 | 0.11% | 1 | 4.00% |
Jiri Slaby | 1 | 0.11% | 1 | 4.00% |
Total | 946 | 100.00% | 25 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.