diff options
author | Luiz Capitulino <lcapitulino@mandriva.com.br> | 2006-03-21 01:18:16 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-03-21 01:18:16 -0500 |
commit | c26a80168f2d44f525a5adb0c95cddffb4a5aaa4 (patch) | |
tree | 78795c5986ab1a05bcf259f028d59ec719458036 | |
parent | 8024bb245408060bec8393469e945b541a9b0865 (diff) |
[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: Luiz Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/pktgen.c | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index fda403419ff2..74194afb9540 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
@@ -210,7 +210,7 @@ struct pktgen_dev { | |||
210 | char result[512]; | 210 | char result[512]; |
211 | 211 | ||
212 | struct pktgen_thread *pg_thread; /* the owner */ | 212 | struct pktgen_thread *pg_thread; /* the owner */ |
213 | struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */ | 213 | struct list_head list; /* Used for chaining in the thread's run-queue */ |
214 | 214 | ||
215 | int running; /* if this changes to false, the test will stop */ | 215 | int running; /* if this changes to false, the test will stop */ |
216 | 216 | ||
@@ -330,7 +330,7 @@ struct pktgen_hdr { | |||
330 | 330 | ||
331 | struct pktgen_thread { | 331 | struct pktgen_thread { |
332 | spinlock_t if_lock; | 332 | spinlock_t if_lock; |
333 | struct pktgen_dev *if_list; /* All device here */ | 333 | struct list_head if_list; /* All device here */ |
334 | struct list_head th_list; | 334 | struct list_head th_list; |
335 | int removed; | 335 | int removed; |
336 | char name[32]; | 336 | char name[32]; |
@@ -1378,7 +1378,7 @@ static struct file_operations pktgen_if_fops = { | |||
1378 | static int pktgen_thread_show(struct seq_file *seq, void *v) | 1378 | static int pktgen_thread_show(struct seq_file *seq, void *v) |
1379 | { | 1379 | { |
1380 | struct pktgen_thread *t = seq->private; | 1380 | struct pktgen_thread *t = seq->private; |
1381 | struct pktgen_dev *pkt_dev = NULL; | 1381 | struct pktgen_dev *pkt_dev; |
1382 | 1382 | ||
1383 | BUG_ON(!t); | 1383 | BUG_ON(!t); |
1384 | 1384 | ||
@@ -1388,13 +1388,13 @@ static int pktgen_thread_show(struct seq_file *seq, void *v) | |||
1388 | seq_printf(seq, "Running: "); | 1388 | seq_printf(seq, "Running: "); |
1389 | 1389 | ||
1390 | if_lock(t); | 1390 | if_lock(t); |
1391 | for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) | 1391 | list_for_each_entry(pkt_dev, &t->if_list, list) |
1392 | if (pkt_dev->running) | 1392 | if (pkt_dev->running) |
1393 | seq_printf(seq, "%s ", pkt_dev->ifname); | 1393 | seq_printf(seq, "%s ", pkt_dev->ifname); |
1394 | 1394 | ||
1395 | seq_printf(seq, "\nStopped: "); | 1395 | seq_printf(seq, "\nStopped: "); |
1396 | 1396 | ||
1397 | for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) | 1397 | list_for_each_entry(pkt_dev, &t->if_list, list) |
1398 | if (!pkt_dev->running) | 1398 | if (!pkt_dev->running) |
1399 | seq_printf(seq, "%s ", pkt_dev->ifname); | 1399 | seq_printf(seq, "%s ", pkt_dev->ifname); |
1400 | 1400 | ||
@@ -2421,13 +2421,13 @@ static void pktgen_clear_counters(struct pktgen_dev *pkt_dev) | |||
2421 | 2421 | ||
2422 | static void pktgen_run(struct pktgen_thread *t) | 2422 | static void pktgen_run(struct pktgen_thread *t) |
2423 | { | 2423 | { |
2424 | struct pktgen_dev *pkt_dev = NULL; | 2424 | struct pktgen_dev *pkt_dev; |
2425 | int started = 0; | 2425 | int started = 0; |
2426 | 2426 | ||
2427 | PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t)); | 2427 | PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t)); |
2428 | 2428 | ||
2429 | if_lock(t); | 2429 | if_lock(t); |
2430 | for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) { | 2430 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
2431 | 2431 | ||
2432 | /* | 2432 | /* |
2433 | * setup odev and create initial packet. | 2433 | * setup odev and create initial packet. |
@@ -2468,15 +2468,14 @@ static void pktgen_stop_all_threads_ifs(void) | |||
2468 | 2468 | ||
2469 | static int thread_is_running(struct pktgen_thread *t) | 2469 | static int thread_is_running(struct pktgen_thread *t) |
2470 | { | 2470 | { |
2471 | struct pktgen_dev *next; | 2471 | struct pktgen_dev *pkt_dev; |
2472 | int res = 0; | 2472 | int res = 0; |
2473 | 2473 | ||
2474 | for (next = t->if_list; next; next = next->next) { | 2474 | list_for_each_entry(pkt_dev, &t->if_list, list) |
2475 | if (next->running) { | 2475 | if (pkt_dev->running) { |
2476 | res = 1; | 2476 | res = 1; |
2477 | break; | 2477 | break; |
2478 | } | 2478 | } |
2479 | } | ||
2480 | return res; | 2479 | return res; |
2481 | } | 2480 | } |
2482 | 2481 | ||
@@ -2597,17 +2596,17 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev) | |||
2597 | 2596 | ||
2598 | static struct pktgen_dev *next_to_run(struct pktgen_thread *t) | 2597 | static struct pktgen_dev *next_to_run(struct pktgen_thread *t) |
2599 | { | 2598 | { |
2600 | struct pktgen_dev *next, *best = NULL; | 2599 | struct pktgen_dev *pkt_dev, *best = NULL; |
2601 | 2600 | ||
2602 | if_lock(t); | 2601 | if_lock(t); |
2603 | 2602 | ||
2604 | for (next = t->if_list; next; next = next->next) { | 2603 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
2605 | if (!next->running) | 2604 | if (!pkt_dev->running) |
2606 | continue; | 2605 | continue; |
2607 | if (best == NULL) | 2606 | if (best == NULL) |
2608 | best = next; | 2607 | best = pkt_dev; |
2609 | else if (next->next_tx_us < best->next_tx_us) | 2608 | else if (pkt_dev->next_tx_us < best->next_tx_us) |
2610 | best = next; | 2609 | best = pkt_dev; |
2611 | } | 2610 | } |
2612 | if_unlock(t); | 2611 | if_unlock(t); |
2613 | return best; | 2612 | return best; |
@@ -2615,18 +2614,18 @@ static struct pktgen_dev *next_to_run(struct pktgen_thread *t) | |||
2615 | 2614 | ||
2616 | static void pktgen_stop(struct pktgen_thread *t) | 2615 | static void pktgen_stop(struct pktgen_thread *t) |
2617 | { | 2616 | { |
2618 | struct pktgen_dev *next = NULL; | 2617 | struct pktgen_dev *pkt_dev; |
2619 | 2618 | ||
2620 | PG_DEBUG(printk("pktgen: entering pktgen_stop\n")); | 2619 | PG_DEBUG(printk("pktgen: entering pktgen_stop\n")); |
2621 | 2620 | ||
2622 | if_lock(t); | 2621 | if_lock(t); |
2623 | 2622 | ||
2624 | for (next = t->if_list; next; next = next->next) { | 2623 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
2625 | pktgen_stop_device(next); | 2624 | pktgen_stop_device(pkt_dev); |
2626 | if (next->skb) | 2625 | if (pkt_dev->skb) |
2627 | kfree_skb(next->skb); | 2626 | kfree_skb(pkt_dev->skb); |
2628 | 2627 | ||
2629 | next->skb = NULL; | 2628 | pkt_dev->skb = NULL; |
2630 | } | 2629 | } |
2631 | 2630 | ||
2632 | if_unlock(t); | 2631 | if_unlock(t); |
@@ -2638,14 +2637,15 @@ static void pktgen_stop(struct pktgen_thread *t) | |||
2638 | */ | 2637 | */ |
2639 | static void pktgen_rem_one_if(struct pktgen_thread *t) | 2638 | static void pktgen_rem_one_if(struct pktgen_thread *t) |
2640 | { | 2639 | { |
2641 | struct pktgen_dev *cur, *next = NULL; | 2640 | struct list_head *q, *n; |
2641 | struct pktgen_dev *cur; | ||
2642 | 2642 | ||
2643 | PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n")); | 2643 | PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n")); |
2644 | 2644 | ||
2645 | if_lock(t); | 2645 | if_lock(t); |
2646 | 2646 | ||
2647 | for (cur = t->if_list; cur; cur = next) { | 2647 | list_for_each_safe(q, n, &t->if_list) { |
2648 | next = cur->next; | 2648 | cur = list_entry(q, struct pktgen_dev, list); |
2649 | 2649 | ||
2650 | if (!cur->removal_mark) | 2650 | if (!cur->removal_mark) |
2651 | continue; | 2651 | continue; |
@@ -2664,15 +2664,16 @@ static void pktgen_rem_one_if(struct pktgen_thread *t) | |||
2664 | 2664 | ||
2665 | static void pktgen_rem_all_ifs(struct pktgen_thread *t) | 2665 | static void pktgen_rem_all_ifs(struct pktgen_thread *t) |
2666 | { | 2666 | { |
2667 | struct pktgen_dev *cur, *next = NULL; | 2667 | struct list_head *q, *n; |
2668 | struct pktgen_dev *cur; | ||
2668 | 2669 | ||
2669 | /* Remove all devices, free mem */ | 2670 | /* Remove all devices, free mem */ |
2670 | 2671 | ||
2671 | PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n")); | 2672 | PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n")); |
2672 | if_lock(t); | 2673 | if_lock(t); |
2673 | 2674 | ||
2674 | for (cur = t->if_list; cur; cur = next) { | 2675 | list_for_each_safe(q, n, &t->if_list) { |
2675 | next = cur->next; | 2676 | cur = list_entry(q, struct pktgen_dev, list); |
2676 | 2677 | ||
2677 | if (cur->skb) | 2678 | if (cur->skb) |
2678 | kfree_skb(cur->skb); | 2679 | kfree_skb(cur->skb); |
@@ -2959,14 +2960,14 @@ static void pktgen_thread_worker(struct pktgen_thread *t) | |||
2959 | static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, | 2960 | static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, |
2960 | const char *ifname) | 2961 | const char *ifname) |
2961 | { | 2962 | { |
2962 | struct pktgen_dev *pkt_dev = NULL; | 2963 | struct pktgen_dev *p, *pkt_dev = NULL; |
2963 | if_lock(t); | 2964 | if_lock(t); |
2964 | 2965 | ||
2965 | for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) { | 2966 | list_for_each_entry(p, &t->if_list, list) |
2966 | if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) { | 2967 | if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) { |
2968 | pkt_dev = p; | ||
2967 | break; | 2969 | break; |
2968 | } | 2970 | } |
2969 | } | ||
2970 | 2971 | ||
2971 | if_unlock(t); | 2972 | if_unlock(t); |
2972 | PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev)); | 2973 | 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 | rv = -EBUSY; | 2990 | rv = -EBUSY; |
2990 | goto out; | 2991 | goto out; |
2991 | } | 2992 | } |
2992 | pkt_dev->next = t->if_list; | 2993 | |
2993 | t->if_list = pkt_dev; | 2994 | list_add(&pkt_dev->list, &t->if_list); |
2994 | pkt_dev->pg_thread = t; | 2995 | pkt_dev->pg_thread = t; |
2995 | pkt_dev->running = 0; | 2996 | pkt_dev->running = 0; |
2996 | 2997 | ||
@@ -3117,6 +3118,8 @@ static int __init pktgen_create_thread(const char *name, int cpu) | |||
3117 | pe->proc_fops = &pktgen_thread_fops; | 3118 | pe->proc_fops = &pktgen_thread_fops; |
3118 | pe->data = t; | 3119 | pe->data = t; |
3119 | 3120 | ||
3121 | INIT_LIST_HEAD(&t->if_list); | ||
3122 | |||
3120 | list_add_tail(&t->th_list, &pktgen_threads); | 3123 | list_add_tail(&t->th_list, &pktgen_threads); |
3121 | 3124 | ||
3122 | t->removed = 0; | 3125 | t->removed = 0; |
@@ -3140,20 +3143,13 @@ static int __init pktgen_create_thread(const char *name, int cpu) | |||
3140 | static void _rem_dev_from_if_list(struct pktgen_thread *t, | 3143 | static void _rem_dev_from_if_list(struct pktgen_thread *t, |
3141 | struct pktgen_dev *pkt_dev) | 3144 | struct pktgen_dev *pkt_dev) |
3142 | { | 3145 | { |
3143 | struct pktgen_dev *i, *prev = NULL; | 3146 | struct list_head *q, *n; |
3144 | 3147 | struct pktgen_dev *p; | |
3145 | i = t->if_list; | ||
3146 | 3148 | ||
3147 | while (i) { | 3149 | list_for_each_safe(q, n, &t->if_list) { |
3148 | if (i == pkt_dev) { | 3150 | p = list_entry(q, struct pktgen_dev, list); |
3149 | if (prev) | 3151 | if (p == pkt_dev) |
3150 | prev->next = i->next; | 3152 | list_del(&p->list); |
3151 | else | ||
3152 | t->if_list = NULL; | ||
3153 | break; | ||
3154 | } | ||
3155 | prev = i; | ||
3156 | i = i->next; | ||
3157 | } | 3153 | } |
3158 | } | 3154 | } |
3159 | 3155 | ||