提交 c26a8016 编写于 作者: L Luiz Capitulino 提交者: David S. Miller

[PKTGEN]: Ports if_list to the in-kernel implementation.

This patch ports the per-thread interface list list to the in-kernel
linked list implementation. In the general, the resulting code is a
bit simpler.
Signed-off-by: NLuiz Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 8024bb24
...@@ -210,7 +210,7 @@ struct pktgen_dev { ...@@ -210,7 +210,7 @@ struct pktgen_dev {
char result[512]; char result[512];
struct pktgen_thread *pg_thread; /* the owner */ struct pktgen_thread *pg_thread; /* the owner */
struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */ struct list_head list; /* Used for chaining in the thread's run-queue */
int running; /* if this changes to false, the test will stop */ int running; /* if this changes to false, the test will stop */
...@@ -330,7 +330,7 @@ struct pktgen_hdr { ...@@ -330,7 +330,7 @@ struct pktgen_hdr {
struct pktgen_thread { struct pktgen_thread {
spinlock_t if_lock; spinlock_t if_lock;
struct pktgen_dev *if_list; /* All device here */ struct list_head if_list; /* All device here */
struct list_head th_list; struct list_head th_list;
int removed; int removed;
char name[32]; char name[32];
...@@ -1378,7 +1378,7 @@ static struct file_operations pktgen_if_fops = { ...@@ -1378,7 +1378,7 @@ static struct file_operations pktgen_if_fops = {
static int pktgen_thread_show(struct seq_file *seq, void *v) static int pktgen_thread_show(struct seq_file *seq, void *v)
{ {
struct pktgen_thread *t = seq->private; struct pktgen_thread *t = seq->private;
struct pktgen_dev *pkt_dev = NULL; struct pktgen_dev *pkt_dev;
BUG_ON(!t); BUG_ON(!t);
...@@ -1388,13 +1388,13 @@ static int pktgen_thread_show(struct seq_file *seq, void *v) ...@@ -1388,13 +1388,13 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)
seq_printf(seq, "Running: "); seq_printf(seq, "Running: ");
if_lock(t); if_lock(t);
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) list_for_each_entry(pkt_dev, &t->if_list, list)
if (pkt_dev->running) if (pkt_dev->running)
seq_printf(seq, "%s ", pkt_dev->ifname); seq_printf(seq, "%s ", pkt_dev->ifname);
seq_printf(seq, "\nStopped: "); seq_printf(seq, "\nStopped: ");
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) list_for_each_entry(pkt_dev, &t->if_list, list)
if (!pkt_dev->running) if (!pkt_dev->running)
seq_printf(seq, "%s ", pkt_dev->ifname); seq_printf(seq, "%s ", pkt_dev->ifname);
...@@ -2421,13 +2421,13 @@ static void pktgen_clear_counters(struct pktgen_dev *pkt_dev) ...@@ -2421,13 +2421,13 @@ static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
static void pktgen_run(struct pktgen_thread *t) static void pktgen_run(struct pktgen_thread *t)
{ {
struct pktgen_dev *pkt_dev = NULL; struct pktgen_dev *pkt_dev;
int started = 0; int started = 0;
PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t)); PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t));
if_lock(t); if_lock(t);
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) { list_for_each_entry(pkt_dev, &t->if_list, list) {
/* /*
* setup odev and create initial packet. * setup odev and create initial packet.
...@@ -2468,15 +2468,14 @@ static void pktgen_stop_all_threads_ifs(void) ...@@ -2468,15 +2468,14 @@ static void pktgen_stop_all_threads_ifs(void)
static int thread_is_running(struct pktgen_thread *t) static int thread_is_running(struct pktgen_thread *t)
{ {
struct pktgen_dev *next; struct pktgen_dev *pkt_dev;
int res = 0; int res = 0;
for (next = t->if_list; next; next = next->next) { list_for_each_entry(pkt_dev, &t->if_list, list)
if (next->running) { if (pkt_dev->running) {
res = 1; res = 1;
break; break;
} }
}
return res; return res;
} }
...@@ -2597,17 +2596,17 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev) ...@@ -2597,17 +2596,17 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
static struct pktgen_dev *next_to_run(struct pktgen_thread *t) static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
{ {
struct pktgen_dev *next, *best = NULL; struct pktgen_dev *pkt_dev, *best = NULL;
if_lock(t); if_lock(t);
for (next = t->if_list; next; next = next->next) { list_for_each_entry(pkt_dev, &t->if_list, list) {
if (!next->running) if (!pkt_dev->running)
continue; continue;
if (best == NULL) if (best == NULL)
best = next; best = pkt_dev;
else if (next->next_tx_us < best->next_tx_us) else if (pkt_dev->next_tx_us < best->next_tx_us)
best = next; best = pkt_dev;
} }
if_unlock(t); if_unlock(t);
return best; return best;
...@@ -2615,18 +2614,18 @@ static struct pktgen_dev *next_to_run(struct pktgen_thread *t) ...@@ -2615,18 +2614,18 @@ static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
static void pktgen_stop(struct pktgen_thread *t) static void pktgen_stop(struct pktgen_thread *t)
{ {
struct pktgen_dev *next = NULL; struct pktgen_dev *pkt_dev;
PG_DEBUG(printk("pktgen: entering pktgen_stop\n")); PG_DEBUG(printk("pktgen: entering pktgen_stop\n"));
if_lock(t); if_lock(t);
for (next = t->if_list; next; next = next->next) { list_for_each_entry(pkt_dev, &t->if_list, list) {
pktgen_stop_device(next); pktgen_stop_device(pkt_dev);
if (next->skb) if (pkt_dev->skb)
kfree_skb(next->skb); kfree_skb(pkt_dev->skb);
next->skb = NULL; pkt_dev->skb = NULL;
} }
if_unlock(t); if_unlock(t);
...@@ -2638,14 +2637,15 @@ static void pktgen_stop(struct pktgen_thread *t) ...@@ -2638,14 +2637,15 @@ static void pktgen_stop(struct pktgen_thread *t)
*/ */
static void pktgen_rem_one_if(struct pktgen_thread *t) static void pktgen_rem_one_if(struct pktgen_thread *t)
{ {
struct pktgen_dev *cur, *next = NULL; struct list_head *q, *n;
struct pktgen_dev *cur;
PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n")); PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n"));
if_lock(t); if_lock(t);
for (cur = t->if_list; cur; cur = next) { list_for_each_safe(q, n, &t->if_list) {
next = cur->next; cur = list_entry(q, struct pktgen_dev, list);
if (!cur->removal_mark) if (!cur->removal_mark)
continue; continue;
...@@ -2664,15 +2664,16 @@ static void pktgen_rem_one_if(struct pktgen_thread *t) ...@@ -2664,15 +2664,16 @@ static void pktgen_rem_one_if(struct pktgen_thread *t)
static void pktgen_rem_all_ifs(struct pktgen_thread *t) static void pktgen_rem_all_ifs(struct pktgen_thread *t)
{ {
struct pktgen_dev *cur, *next = NULL; struct list_head *q, *n;
struct pktgen_dev *cur;
/* Remove all devices, free mem */ /* Remove all devices, free mem */
PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n")); PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n"));
if_lock(t); if_lock(t);
for (cur = t->if_list; cur; cur = next) { list_for_each_safe(q, n, &t->if_list) {
next = cur->next; cur = list_entry(q, struct pktgen_dev, list);
if (cur->skb) if (cur->skb)
kfree_skb(cur->skb); kfree_skb(cur->skb);
...@@ -2959,14 +2960,14 @@ static void pktgen_thread_worker(struct pktgen_thread *t) ...@@ -2959,14 +2960,14 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
const char *ifname) const char *ifname)
{ {
struct pktgen_dev *pkt_dev = NULL; struct pktgen_dev *p, *pkt_dev = NULL;
if_lock(t); if_lock(t);
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) { list_for_each_entry(p, &t->if_list, list)
if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) { if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) {
pkt_dev = p;
break; break;
} }
}
if_unlock(t); if_unlock(t);
PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev)); PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev));
...@@ -2989,8 +2990,8 @@ static int add_dev_to_thread(struct pktgen_thread *t, ...@@ -2989,8 +2990,8 @@ static int add_dev_to_thread(struct pktgen_thread *t,
rv = -EBUSY; rv = -EBUSY;
goto out; goto out;
} }
pkt_dev->next = t->if_list;
t->if_list = pkt_dev; list_add(&pkt_dev->list, &t->if_list);
pkt_dev->pg_thread = t; pkt_dev->pg_thread = t;
pkt_dev->running = 0; pkt_dev->running = 0;
...@@ -3117,6 +3118,8 @@ static int __init pktgen_create_thread(const char *name, int cpu) ...@@ -3117,6 +3118,8 @@ static int __init pktgen_create_thread(const char *name, int cpu)
pe->proc_fops = &pktgen_thread_fops; pe->proc_fops = &pktgen_thread_fops;
pe->data = t; pe->data = t;
INIT_LIST_HEAD(&t->if_list);
list_add_tail(&t->th_list, &pktgen_threads); list_add_tail(&t->th_list, &pktgen_threads);
t->removed = 0; t->removed = 0;
...@@ -3140,20 +3143,13 @@ static int __init pktgen_create_thread(const char *name, int cpu) ...@@ -3140,20 +3143,13 @@ static int __init pktgen_create_thread(const char *name, int cpu)
static void _rem_dev_from_if_list(struct pktgen_thread *t, static void _rem_dev_from_if_list(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev) struct pktgen_dev *pkt_dev)
{ {
struct pktgen_dev *i, *prev = NULL; struct list_head *q, *n;
struct pktgen_dev *p;
i = t->if_list;
while (i) { list_for_each_safe(q, n, &t->if_list) {
if (i == pkt_dev) { p = list_entry(q, struct pktgen_dev, list);
if (prev) if (p == pkt_dev)
prev->next = i->next; list_del(&p->list);
else
t->if_list = NULL;
break;
}
prev = i;
i = i->next;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册