cregit-Linux how code gets into the kernel

Release 4.11 net/sched/sch_prio.c

Directory: net/sched
/*
 * net/sched/sch_prio.c Simple 3-band priority "scheduler".
 *
 *              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>
 * Fixes:       19990609: J Hadi Salim <hadi@nortelnetworks.com>:
 *              Init --  EINVAL when opt undefined
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <net/netlink.h>
#include <net/pkt_sched.h>
#include <net/pkt_cls.h>


struct prio_sched_data {
	
int bands;
	
struct tcf_proto __rcu *filter_list;
	
u8  prio2band[TC_PRIO_MAX+1];
	
struct Qdisc *queues[TCQ_PRIO_BANDS];
};



static struct Qdisc * prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) { struct prio_sched_data *q = qdisc_priv(sch); u32 band = skb->priority; struct tcf_result res; struct tcf_proto *fl; int err; *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; if (TC_H_MAJ(skb->priority) != sch->handle) { fl = rcu_dereference_bh(q->filter_list); err = tc_classify(skb, fl, &res, false); #ifdef CONFIG_NET_CLS_ACT switch (err) { case TC_ACT_STOLEN: case TC_ACT_QUEUED: *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN; case TC_ACT_SHOT: return NULL; } #endif if (!fl || err < 0) { if (TC_H_MAJ(band)) band = 0; return q->queues[q->prio2band[band & TC_PRIO_MAX]]; } band = res.classid; } band = TC_H_MIN(band) - 1; if (band >= q->bands) return q->queues[q->prio2band[0]]; return q->queues[band]; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9143.96%318.75%
Jamal Hadi Salim4421.26%318.75%
Patrick McHardy3014.49%212.50%
John Fastabend167.73%16.25%
David S. Miller146.76%16.25%
Jarek Poplawski52.42%212.50%
Stephen Hemminger31.45%16.25%
Daniel Borkmann20.97%16.25%
Adrian Bunk10.48%16.25%
Lucas Nussbaum10.48%16.25%
Total207100.00%16100.00%


static int prio_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { struct Qdisc *qdisc; int ret; qdisc = prio_classify(skb, sch, &ret); #ifdef CONFIG_NET_CLS_ACT if (qdisc == NULL) { if (ret & __NET_XMIT_BYPASS) qdisc_qstats_drop(sch); kfree_skb(skb); return ret; } #endif ret = qdisc_enqueue(skb, qdisc, to_free); if (ret == NET_XMIT_SUCCESS) { qdisc_qstats_backlog_inc(sch, skb); sch->q.qlen++; return NET_XMIT_SUCCESS; } if (net_xmit_drop_count(ret)) qdisc_qstats_drop(sch); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5040.00%325.00%
Patrick McHardy2318.40%18.33%
Jamal Hadi Salim1713.60%216.67%
Jarek Poplawski97.20%216.67%
Eric Dumazet86.40%18.33%
Américo Wang75.60%18.33%
John Fastabend64.80%18.33%
Jussi Kivilinna54.00%18.33%
Total125100.00%12100.00%


static struct sk_buff *prio_peek(struct Qdisc *sch) { struct prio_sched_data *q = qdisc_priv(sch); int prio; for (prio = 0; prio < q->bands; prio++) { struct Qdisc *qdisc = q->queues[prio]; struct sk_buff *skb = qdisc->ops->peek(qdisc); if (skb) return skb; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy79100.00%1100.00%
Total79100.00%1100.00%


static struct sk_buff *prio_dequeue(struct Qdisc *sch) { struct prio_sched_data *q = qdisc_priv(sch); int prio; for (prio = 0; prio < q->bands; prio++) { struct Qdisc *qdisc = q->queues[prio]; struct sk_buff *skb = qdisc_dequeue_peeked(qdisc); if (skb) { qdisc_bstats_update(sch, skb); qdisc_qstats_backlog_dec(sch, skb); sch->q.qlen--; return skb; } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4950.00%114.29%
Peter P. Waskiewicz Jr2525.51%114.29%
Eric Dumazet77.14%114.29%
Américo Wang77.14%114.29%
David S. Miller66.12%114.29%
Stephen Hemminger33.06%114.29%
Florian Westphal11.02%114.29%
Total98100.00%7100.00%


static void prio_reset(struct Qdisc *sch) { int prio; struct prio_sched_data *q = qdisc_priv(sch); for (prio = 0; prio < q->bands; prio++) qdisc_reset(q->queues[prio]); sch->qstats.backlog = 0; sch->q.qlen = 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5483.08%250.00%
Américo Wang812.31%125.00%
Stephen Hemminger34.62%125.00%
Total65100.00%4100.00%


static void prio_destroy(struct Qdisc *sch) { int prio; struct prio_sched_data *q = qdisc_priv(sch); tcf_destroy_chain(&q->filter_list); for (prio = 0; prio < q->bands; prio++) qdisc_destroy(q->queues[prio]); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4680.70%120.00%
David S. Miller58.77%120.00%
Stephen Hemminger35.26%120.00%
Patrick McHardy35.26%240.00%
Total57100.00%5100.00%


static int prio_tune(struct Qdisc *sch, struct nlattr *opt) { struct prio_sched_data *q = qdisc_priv(sch); struct Qdisc *queues[TCQ_PRIO_BANDS]; int oldbands = q->bands, i; struct tc_prio_qopt *qopt; if (nla_len(opt) < sizeof(*qopt)) return -EINVAL; qopt = nla_data(opt); if (qopt->bands > TCQ_PRIO_BANDS || qopt->bands < 2) return -EINVAL; for (i = 0; i <= TC_PRIO_MAX; i++) { if (qopt->priomap[i] >= qopt->bands) return -EINVAL; } /* Before commit, make sure we can allocate all new qdiscs */ for (i = oldbands; i < qopt->bands; i++) { queues[i] = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, TC_H_MAKE(sch->handle, i + 1)); if (!queues[i]) { while (i > oldbands) qdisc_destroy(queues[--i]); return -ENOMEM; } } sch_tree_lock(sch); q->bands = qopt->bands; memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1); for (i = q->bands; i < oldbands; i++) { struct Qdisc *child = q->queues[i]; qdisc_tree_reduce_backlog(child, child->q.qlen, child->qstats.backlog); qdisc_destroy(child); } for (i = oldbands; i < q->bands; i++) q->queues[i] = queues[i]; sch_tree_unlock(sch); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)15650.49%426.67%
Eric Dumazet9129.45%16.67%
David S. Miller216.80%213.33%
Patrick McHardy144.53%426.67%
Peter P. Waskiewicz Jr113.56%16.67%
Américo Wang72.27%16.67%
Amnon Aaronsohn61.94%16.67%
Stephen Hemminger30.97%16.67%
Total309100.00%15100.00%


static int prio_init(struct Qdisc *sch, struct nlattr *opt) { if (!opt) return -EINVAL; return prio_tune(sch, opt); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3090.91%466.67%
Eric Dumazet26.06%116.67%
Patrick McHardy13.03%116.67%
Total33100.00%6100.00%


static int prio_dump(struct Qdisc *sch, struct sk_buff *skb) { struct prio_sched_data *q = qdisc_priv(sch); unsigned char *b = skb_tail_pointer(skb); struct tc_prio_qopt opt; opt.bands = q->bands; memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX + 1); if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt)) goto nla_put_failure; return skb->len; nla_put_failure: nlmsg_trim(skb, b); return -1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8785.29%116.67%
David S. Miller76.86%116.67%
Arnaldo Carvalho de Melo43.92%233.33%
Stephen Hemminger32.94%116.67%
Patrick McHardy10.98%116.67%
Total102100.00%6100.00%


static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, struct Qdisc **old) { struct prio_sched_data *q = qdisc_priv(sch); unsigned long band = arg - 1; if (new == NULL) new = &noop_qdisc; *old = qdisc_replace(sch, new, &q->queues[band]); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)6686.84%133.33%
Américo Wang79.21%133.33%
Stephen Hemminger33.95%133.33%
Total76100.00%3100.00%


static struct Qdisc * prio_leaf(struct Qdisc *sch, unsigned long arg) { struct prio_sched_data *q = qdisc_priv(sch); unsigned long band = arg - 1; return q->queues[band]; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4093.02%150.00%
Stephen Hemminger36.98%150.00%
Total43100.00%2100.00%


static unsigned long prio_get(struct Qdisc *sch, u32 classid) { struct prio_sched_data *q = qdisc_priv(sch); unsigned long band = TC_H_MIN(classid); if (band - 1 >= q->bands) return 0; return band; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4794.00%150.00%
Stephen Hemminger36.00%150.00%
Total50100.00%2100.00%


static unsigned long prio_bind(struct Qdisc *sch, unsigned long parent, u32 classid) { return prio_get(sch, classid); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)27100.00%1100.00%
Total27100.00%1100.00%


static void prio_put(struct Qdisc *q, unsigned long cl) { }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1392.86%150.00%
Joe Perches17.14%150.00%
Total14100.00%2100.00%


static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb, struct tcmsg *tcm) { struct prio_sched_data *q = qdisc_priv(sch); tcm->tcm_handle |= TC_H_MIN(cl); tcm->tcm_info = q->queues[cl-1]->handle; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5080.65%250.00%
Alexey Kuznetsov914.52%125.00%
Stephen Hemminger34.84%125.00%
Total62100.00%4100.00%


static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl, struct gnet_dump *d) { struct prio_sched_data *q = qdisc_priv(sch); struct Qdisc *cl_q; cl_q = q->queues[cl - 1]; if (gnet_stats_copy_basic(qdisc_root_sleeping_running(sch), d, NULL, &cl_q->bstats) < 0 || gnet_stats_copy_queue(d, NULL, &cl_q->qstats, cl_q->q.qlen) < 0) return -1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jarek Poplawski7984.04%120.00%
John Fastabend1010.64%360.00%
Eric Dumazet55.32%120.00%
Total94100.00%5100.00%


static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg) { struct prio_sched_data *q = qdisc_priv(sch); int prio; if (arg->stop) return; for (prio = 0; prio < q->bands; prio++) { if (arg->count < arg->skip) { arg->count++; continue; } if (arg->fn(sch, prio + 1, arg) < 0) { arg->stop = 1; break; } arg->count++; } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9997.06%266.67%
Stephen Hemminger32.94%133.33%
Total102100.00%3100.00%


static struct tcf_proto __rcu **prio_find_tcf(struct Qdisc *sch, unsigned long cl) { struct prio_sched_data *q = qdisc_priv(sch); if (cl) return NULL; return &q->filter_list; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3890.48%133.33%
Stephen Hemminger37.14%133.33%
John Fastabend12.38%133.33%
Total42100.00%3100.00%

static const struct Qdisc_class_ops prio_class_ops = { .graft = prio_graft, .leaf = prio_leaf, .get = prio_get, .put = prio_put, .walk = prio_walk, .tcf_chain = prio_find_tcf, .bind_tcf = prio_bind, .unbind_tcf = prio_put, .dump = prio_dump_class, .dump_stats = prio_dump_class_stats, }; static struct Qdisc_ops prio_qdisc_ops __read_mostly = { .next = NULL, .cl_ops = &prio_class_ops, .id = "prio", .priv_size = sizeof(struct prio_sched_data), .enqueue = prio_enqueue, .dequeue = prio_dequeue, .peek = prio_peek, .init = prio_init, .reset = prio_reset, .destroy = prio_destroy, .change = prio_tune, .dump = prio_dump, .owner = THIS_MODULE, };
static int __init prio_module_init(void) { return register_qdisc(&prio_qdisc_ops); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1381.25%266.67%
Al Viro318.75%133.33%
Total16100.00%3100.00%


static void __exit prio_module_exit(void) { unregister_qdisc(&prio_qdisc_ops); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1280.00%266.67%
Al Viro320.00%133.33%
Total15100.00%3100.00%

module_init(prio_module_init) module_exit(prio_module_exit) MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)107458.82%610.17%
Patrick McHardy1568.54%915.25%
Eric Dumazet1156.30%58.47%
Jarek Poplawski985.37%35.08%
Jamal Hadi Salim613.34%35.08%
David S. Miller583.18%58.47%
Dave Jones382.08%11.69%
Peter P. Waskiewicz Jr361.97%11.69%
Américo Wang361.97%35.08%
Stephen Hemminger361.97%11.69%
John Fastabend341.86%58.47%
Art Haas221.20%11.69%
Al Viro150.82%11.69%
Alexey Kuznetsov90.49%11.69%
Linus Torvalds70.38%23.39%
Arnaldo Carvalho de Melo70.38%23.39%
Amnon Aaronsohn60.33%11.69%
Jussi Kivilinna50.27%11.69%
Tejun Heo30.16%11.69%
Jiri Pirko30.16%11.69%
Daniel Borkmann20.11%11.69%
Lucas Nussbaum10.05%11.69%
Hideaki Yoshifuji / 吉藤英明10.05%11.69%
Joe Perches10.05%11.69%
Adrian Bunk10.05%11.69%
Florian Westphal10.05%11.69%
Total1826100.00%59100.00%
Directory: net/sched
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.