cregit-Linux how code gets into the kernel

Release 4.8 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>



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
pre-gitpre-git9143.96%318.75%
jamal hadi salimjamal hadi salim4421.26%318.75%
patrick mchardypatrick mchardy3014.49%212.50%
john fastabendjohn fastabend167.73%16.25%
david s. millerdavid s. miller146.76%16.25%
jarek poplawskijarek poplawski52.42%212.50%
stephen hemmingerstephen hemminger31.45%16.25%
daniel borkmanndaniel borkmann20.97%16.25%
lucas nussbaumlucas nussbaum10.48%16.25%
adrian bunkadrian bunk10.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
pre-gitpre-git5040.00%325.00%
patrick mchardypatrick mchardy2318.40%18.33%
jamal hadi salimjamal hadi salim1713.60%216.67%
jarek poplawskijarek poplawski97.20%216.67%
eric dumazeteric dumazet86.40%18.33%
americo wangamerico wang75.60%18.33%
john fastabendjohn fastabend64.80%18.33%
jussi kivilinnajussi 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 mchardypatrick 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
pre-gitpre-git4950.00%114.29%
peter p waskiewiczpeter p waskiewicz2525.51%114.29%
americo wangamerico wang77.14%114.29%
eric dumazeteric dumazet77.14%114.29%
david s. millerdavid s. miller66.12%114.29%
stephen hemmingerstephen hemminger33.06%114.29%
florian westphalflorian 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
pre-gitpre-git5483.08%250.00%
americo wangamerico wang812.31%125.00%
stephen hemmingerstephen 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
pre-gitpre-git4680.70%120.00%
david s. millerdavid s. miller58.77%120.00%
patrick mchardypatrick mchardy35.26%240.00%
stephen hemmingerstephen hemminger35.26%120.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
pre-gitpre-git15650.49%426.67%
eric dumazeteric dumazet9129.45%16.67%
david s. millerdavid s. miller216.80%213.33%
patrick mchardypatrick mchardy144.53%426.67%
peter p waskiewiczpeter p waskiewicz113.56%16.67%
americo wangamerico wang72.27%16.67%
amnon aaronsohnamnon aaronsohn61.94%16.67%
stephen hemmingerstephen 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
pre-gitpre-git3090.91%466.67%
eric dumazeteric dumazet26.06%116.67%
patrick mchardypatrick 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
pre-gitpre-git8785.29%116.67%
david s. millerdavid s. miller76.86%116.67%
arnaldo carvalho de meloarnaldo carvalho de melo43.92%233.33%
stephen hemmingerstephen hemminger32.94%116.67%
patrick mchardypatrick 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
pre-gitpre-git6686.84%133.33%
americo wangamerico wang79.21%133.33%
stephen hemmingerstephen 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
pre-gitpre-git4093.02%150.00%
stephen hemmingerstephen 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
pre-gitpre-git4794.00%150.00%
stephen hemmingerstephen 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
pre-gitpre-git27100.00%1100.00%
Total27100.00%1100.00%


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

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1392.86%150.00%
joe perchesjoe 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
pre-gitpre-git5080.65%250.00%
alexey kuznetsovalexey kuznetsov914.52%125.00%
stephen hemmingerstephen 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 poplawskijarek poplawski7984.04%120.00%
john fastabendjohn fastabend1010.64%360.00%
eric dumazeteric 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
pre-gitpre-git9997.06%266.67%
stephen hemmingerstephen 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
pre-gitpre-git3890.48%133.33%
stephen hemmingerstephen hemminger37.14%133.33%
john fastabendjohn 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
pre-gitpre-git1381.25%266.67%
al viroal viro318.75%133.33%
Total16100.00%3100.00%


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

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1280.00%266.67%
al viroal viro320.00%133.33%
Total15100.00%3100.00%

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

Overall Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git107458.91%610.34%
patrick mchardypatrick mchardy1568.56%915.52%
eric dumazeteric dumazet1156.31%58.62%
jarek poplawskijarek poplawski985.38%35.17%
jamal hadi salimjamal hadi salim613.35%35.17%
david s. millerdavid s. miller583.18%58.62%
dave jonesdave jones382.08%11.72%
stephen hemmingerstephen hemminger361.97%11.72%
peter p waskiewiczpeter p waskiewicz361.97%11.72%
americo wangamerico wang361.97%35.17%
john fastabendjohn fastabend341.87%58.62%
art haasart haas221.21%11.72%
al viroal viro150.82%11.72%
alexey kuznetsovalexey kuznetsov90.49%11.72%
arnaldo carvalho de meloarnaldo carvalho de melo70.38%23.45%
linus torvaldslinus torvalds70.38%23.45%
amnon aaronsohnamnon aaronsohn60.33%11.72%
jussi kivilinnajussi kivilinna50.27%11.72%
tejun heotejun heo30.16%11.72%
daniel borkmanndaniel borkmann20.11%11.72%
joe perchesjoe perches10.05%11.72%
adrian bunkadrian bunk10.05%11.72%
lucas nussbaumlucas nussbaum10.05%11.72%
hideaki yoshifujihideaki yoshifuji10.05%11.72%
florian westphalflorian westphal10.05%11.72%
Total1823100.00%58100.00%
Directory: net/sched
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.