introduced search_fblock_n to remove duplicate code
[ana-net.git] / src / sd_rr.c
blob75043b7ca444000a891da12231164cbdb0e47c82
1 /*
2 * Lightweight Autonomic Network Architecture
4 * Round robin scheduler.
6 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
7 * Swiss federal institute of technology (ETH Zurich)
8 * Subject to the GPL.
9 */
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/cache.h>
14 #include <linux/cpumask.h>
15 #include <linux/spinlock.h>
17 #include "xt_sched.h"
18 #include "xt_engine.h"
20 static unsigned long cpu;
21 static unsigned long cpu_max;
22 static spinlock_t lock;
23 static int initialized = 0;
25 static int ppe_rr_init(void)
27 if (likely(initialized))
28 return 0;
29 cpu = 0;
30 cpu_max = num_online_cpus();
31 spin_lock_init(&lock);
32 initialized = 1;
33 return 0;
36 static int ppe_rr_sched(struct sk_buff *skb, enum path_type dir)
38 unsigned long __cpu, flags;
40 spin_lock_irqsave(&lock, flags);
41 __cpu = cpu++;
42 if (cpu == cpu_max)
43 cpu = 0;
44 spin_unlock_irqrestore(&lock, flags);
46 switch (dir) {
47 case TYPE_EGRESS:
48 enqueue_egress_on_engine(skb, __cpu);
49 break;
50 case TYPE_INGRESS:
51 enqueue_ingress_on_engine(skb, __cpu);
52 break;
53 default:
54 return PPE_ERROR;
56 return PPE_SUCCESS;
59 static void ppe_rr_cleanup(void)
61 initialized = 0;
64 static struct ppesched_discipline_ops ppe_rr_ops __read_mostly = {
65 .discipline_init = ppe_rr_init,
66 .discipline_sched = ppe_rr_sched,
67 .discipline_cleanup = ppe_rr_cleanup,
70 static struct ppesched_discipline ppe_rr __read_mostly = {
71 .name = "roundrobin",
72 .ops = &ppe_rr_ops,
73 .owner = THIS_MODULE,
76 static int __init init_ppe_rr_module(void)
78 return ppesched_discipline_register(&ppe_rr);
81 static void __exit cleanup_ppe_rr_module(void)
83 return ppesched_discipline_unregister(&ppe_rr);
86 module_init(init_ppe_rr_module);
87 module_exit(cleanup_ppe_rr_module);
89 MODULE_LICENSE("GPL");
90 MODULE_AUTHOR("Daniel Borkmann <dborkma@tik.ee.ethz.ch>");
91 MODULE_DESCRIPTION("LANA round robin scheduler");