pktgen.c (2918cd81f58aa9748acf961240c006394f474047) pktgen.c (25c4e53a4c9bfe45be52821f54ec5ce957519db2)
1/*
2 * Authors:
3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
6 *
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>

--- 150 unchanged lines hidden (view full) ---

159#include <asm/io.h>
160#include <asm/dma.h>
161#include <asm/uaccess.h>
162#include <asm/div64.h> /* do_div */
163#include <asm/timex.h>
164
165#define VERSION "pktgen v2.68: Packet Generator for packet performance testing.\n"
166
1/*
2 * Authors:
3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
6 *
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>

--- 150 unchanged lines hidden (view full) ---

159#include <asm/io.h>
160#include <asm/dma.h>
161#include <asm/uaccess.h>
162#include <asm/div64.h> /* do_div */
163#include <asm/timex.h>
164
165#define VERSION "pktgen v2.68: Packet Generator for packet performance testing.\n"
166
167/* #define PG_DEBUG(a) a */
168#define PG_DEBUG(a)
169
170/* The buckets are exponential in 'width' */
171#define LAT_BUCKETS_MAX 32
172#define IP_NAME_SZ 32
173#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
174#define MPLS_STACK_BOTTOM __constant_htonl(0x00000100)
175
176/* Device flag bits */
177#define F_IPSRC_RND (1<<0) /* IP-Src Random */

--- 1674 unchanged lines hidden (view full) ---

1852static int pktgen_mark_device(const char *ifname)
1853{
1854 struct pktgen_dev *pkt_dev = NULL;
1855 const int max_tries = 10, msec_per_try = 125;
1856 int i = 0;
1857 int ret = 0;
1858
1859 mutex_lock(&pktgen_thread_lock);
167/* The buckets are exponential in 'width' */
168#define LAT_BUCKETS_MAX 32
169#define IP_NAME_SZ 32
170#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
171#define MPLS_STACK_BOTTOM __constant_htonl(0x00000100)
172
173/* Device flag bits */
174#define F_IPSRC_RND (1<<0) /* IP-Src Random */

--- 1674 unchanged lines hidden (view full) ---

1849static int pktgen_mark_device(const char *ifname)
1850{
1851 struct pktgen_dev *pkt_dev = NULL;
1852 const int max_tries = 10, msec_per_try = 125;
1853 int i = 0;
1854 int ret = 0;
1855
1856 mutex_lock(&pktgen_thread_lock);
1860 PG_DEBUG(printk("pktgen: pktgen_mark_device marking %s for removal\n",
1861 ifname));
1857 pr_debug("pktgen: pktgen_mark_device marking %s for removal\n", ifname);
1862
1863 while (1) {
1864
1865 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
1866 if (pkt_dev == NULL)
1867 break; /* success */
1868
1869 mutex_unlock(&pktgen_thread_lock);
1858
1859 while (1) {
1860
1861 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
1862 if (pkt_dev == NULL)
1863 break; /* success */
1864
1865 mutex_unlock(&pktgen_thread_lock);
1870 PG_DEBUG(printk("pktgen: pktgen_mark_device waiting for %s "
1871 "to disappear....\n", ifname));
1866 pr_debug("pktgen: pktgen_mark_device waiting for %s "
1867 "to disappear....\n", ifname);
1872 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
1873 mutex_lock(&pktgen_thread_lock);
1874
1875 if (++i >= max_tries) {
1876 printk("pktgen_mark_device: timed out after waiting "
1877 "%d msec for device %s to be removed\n",
1878 msec_per_try * i, ifname);
1879 ret = 1;

--- 963 unchanged lines hidden (view full) ---

2843
2844/* Set up structure for sending pkts, clear counters */
2845
2846static void pktgen_run(struct pktgen_thread *t)
2847{
2848 struct pktgen_dev *pkt_dev;
2849 int started = 0;
2850
1868 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
1869 mutex_lock(&pktgen_thread_lock);
1870
1871 if (++i >= max_tries) {
1872 printk("pktgen_mark_device: timed out after waiting "
1873 "%d msec for device %s to be removed\n",
1874 msec_per_try * i, ifname);
1875 ret = 1;

--- 963 unchanged lines hidden (view full) ---

2839
2840/* Set up structure for sending pkts, clear counters */
2841
2842static void pktgen_run(struct pktgen_thread *t)
2843{
2844 struct pktgen_dev *pkt_dev;
2845 int started = 0;
2846
2851 PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t));
2847 pr_debug("pktgen: entering pktgen_run. %p\n", t);
2852
2853 if_lock(t);
2854 list_for_each_entry(pkt_dev, &t->if_list, list) {
2855
2856 /*
2857 * setup odev and create initial packet.
2858 */
2859 pktgen_setup_inject(pkt_dev);

--- 15 unchanged lines hidden (view full) ---

2875 if (started)
2876 t->control &= ~(T_STOP);
2877}
2878
2879static void pktgen_stop_all_threads_ifs(void)
2880{
2881 struct pktgen_thread *t;
2882
2848
2849 if_lock(t);
2850 list_for_each_entry(pkt_dev, &t->if_list, list) {
2851
2852 /*
2853 * setup odev and create initial packet.
2854 */
2855 pktgen_setup_inject(pkt_dev);

--- 15 unchanged lines hidden (view full) ---

2871 if (started)
2872 t->control &= ~(T_STOP);
2873}
2874
2875static void pktgen_stop_all_threads_ifs(void)
2876{
2877 struct pktgen_thread *t;
2878
2883 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads_ifs.\n"));
2879 pr_debug("pktgen: entering pktgen_stop_all_threads_ifs.\n");
2884
2885 mutex_lock(&pktgen_thread_lock);
2886
2887 list_for_each_entry(t, &pktgen_threads, th_list)
2888 t->control |= T_STOP;
2889
2890 mutex_unlock(&pktgen_thread_lock);
2891}

--- 51 unchanged lines hidden (view full) ---

2943 mutex_unlock(&pktgen_thread_lock);
2944 return sig;
2945}
2946
2947static void pktgen_run_all_threads(void)
2948{
2949 struct pktgen_thread *t;
2950
2880
2881 mutex_lock(&pktgen_thread_lock);
2882
2883 list_for_each_entry(t, &pktgen_threads, th_list)
2884 t->control |= T_STOP;
2885
2886 mutex_unlock(&pktgen_thread_lock);
2887}

--- 51 unchanged lines hidden (view full) ---

2939 mutex_unlock(&pktgen_thread_lock);
2940 return sig;
2941}
2942
2943static void pktgen_run_all_threads(void)
2944{
2945 struct pktgen_thread *t;
2946
2951 PG_DEBUG(printk("pktgen: entering pktgen_run_all_threads.\n"));
2947 pr_debug("pktgen: entering pktgen_run_all_threads.\n");
2952
2953 mutex_lock(&pktgen_thread_lock);
2954
2955 list_for_each_entry(t, &pktgen_threads, th_list)
2956 t->control |= (T_RUN);
2957
2958 mutex_unlock(&pktgen_thread_lock);
2959

--- 75 unchanged lines hidden (view full) ---

3035 if_unlock(t);
3036 return best;
3037}
3038
3039static void pktgen_stop(struct pktgen_thread *t)
3040{
3041 struct pktgen_dev *pkt_dev;
3042
2948
2949 mutex_lock(&pktgen_thread_lock);
2950
2951 list_for_each_entry(t, &pktgen_threads, th_list)
2952 t->control |= (T_RUN);
2953
2954 mutex_unlock(&pktgen_thread_lock);
2955

--- 75 unchanged lines hidden (view full) ---

3031 if_unlock(t);
3032 return best;
3033}
3034
3035static void pktgen_stop(struct pktgen_thread *t)
3036{
3037 struct pktgen_dev *pkt_dev;
3038
3043 PG_DEBUG(printk("pktgen: entering pktgen_stop\n"));
3039 pr_debug("pktgen: entering pktgen_stop\n");
3044
3045 if_lock(t);
3046
3047 list_for_each_entry(pkt_dev, &t->if_list, list) {
3048 pktgen_stop_device(pkt_dev);
3049 if (pkt_dev->skb)
3050 kfree_skb(pkt_dev->skb);
3051

--- 7 unchanged lines hidden (view full) ---

3059 * one of our devices needs to be removed - find it
3060 * and remove it
3061 */
3062static void pktgen_rem_one_if(struct pktgen_thread *t)
3063{
3064 struct list_head *q, *n;
3065 struct pktgen_dev *cur;
3066
3040
3041 if_lock(t);
3042
3043 list_for_each_entry(pkt_dev, &t->if_list, list) {
3044 pktgen_stop_device(pkt_dev);
3045 if (pkt_dev->skb)
3046 kfree_skb(pkt_dev->skb);
3047

--- 7 unchanged lines hidden (view full) ---

3055 * one of our devices needs to be removed - find it
3056 * and remove it
3057 */
3058static void pktgen_rem_one_if(struct pktgen_thread *t)
3059{
3060 struct list_head *q, *n;
3061 struct pktgen_dev *cur;
3062
3067 PG_DEBUG(printk("pktgen: entering pktgen_rem_one_if\n"));
3063 pr_debug("pktgen: entering pktgen_rem_one_if\n");
3068
3069 if_lock(t);
3070
3071 list_for_each_safe(q, n, &t->if_list) {
3072 cur = list_entry(q, struct pktgen_dev, list);
3073
3074 if (!cur->removal_mark)
3075 continue;

--- 12 unchanged lines hidden (view full) ---

3088
3089static void pktgen_rem_all_ifs(struct pktgen_thread *t)
3090{
3091 struct list_head *q, *n;
3092 struct pktgen_dev *cur;
3093
3094 /* Remove all devices, free mem */
3095
3064
3065 if_lock(t);
3066
3067 list_for_each_safe(q, n, &t->if_list) {
3068 cur = list_entry(q, struct pktgen_dev, list);
3069
3070 if (!cur->removal_mark)
3071 continue;

--- 12 unchanged lines hidden (view full) ---

3084
3085static void pktgen_rem_all_ifs(struct pktgen_thread *t)
3086{
3087 struct list_head *q, *n;
3088 struct pktgen_dev *cur;
3089
3090 /* Remove all devices, free mem */
3091
3096 PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n"));
3092 pr_debug("pktgen: entering pktgen_rem_all_ifs\n");
3097 if_lock(t);
3098
3099 list_for_each_safe(q, n, &t->if_list) {
3100 cur = list_entry(q, struct pktgen_dev, list);
3101
3102 if (cur->skb)
3103 kfree_skb(cur->skb);
3104 cur->skb = NULL;

--- 166 unchanged lines hidden (view full) ---

3271 u32 tx_since_softirq = 0;
3272
3273 BUG_ON(smp_processor_id() != cpu);
3274
3275 init_waitqueue_head(&t->queue);
3276
3277 t->pid = current->pid;
3278
3093 if_lock(t);
3094
3095 list_for_each_safe(q, n, &t->if_list) {
3096 cur = list_entry(q, struct pktgen_dev, list);
3097
3098 if (cur->skb)
3099 kfree_skb(cur->skb);
3100 cur->skb = NULL;

--- 166 unchanged lines hidden (view full) ---

3267 u32 tx_since_softirq = 0;
3268
3269 BUG_ON(smp_processor_id() != cpu);
3270
3271 init_waitqueue_head(&t->queue);
3272
3273 t->pid = current->pid;
3274
3279 PG_DEBUG(printk("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid));
3275 pr_debug("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid);
3280
3281 max_before_softirq = t->max_before_softirq;
3282
3283 set_current_state(TASK_INTERRUPTIBLE);
3284
3285 while (!kthread_should_stop()) {
3286 pkt_dev = next_to_run(t);
3287

--- 46 unchanged lines hidden (view full) ---

3334 t->control &= ~(T_REMDEV);
3335 }
3336
3337 try_to_freeze();
3338
3339 set_current_state(TASK_INTERRUPTIBLE);
3340 }
3341
3276
3277 max_before_softirq = t->max_before_softirq;
3278
3279 set_current_state(TASK_INTERRUPTIBLE);
3280
3281 while (!kthread_should_stop()) {
3282 pkt_dev = next_to_run(t);
3283

--- 46 unchanged lines hidden (view full) ---

3330 t->control &= ~(T_REMDEV);
3331 }
3332
3333 try_to_freeze();
3334
3335 set_current_state(TASK_INTERRUPTIBLE);
3336 }
3337
3342 PG_DEBUG(printk("pktgen: %s stopping all device\n", t->tsk->comm));
3338 pr_debug("pktgen: %s stopping all device\n", t->tsk->comm);
3343 pktgen_stop(t);
3344
3339 pktgen_stop(t);
3340
3345 PG_DEBUG(printk("pktgen: %s removing all device\n", t->tsk->comm));
3341 pr_debug("pktgen: %s removing all device\n", t->tsk->comm);
3346 pktgen_rem_all_ifs(t);
3347
3342 pktgen_rem_all_ifs(t);
3343
3348 PG_DEBUG(printk("pktgen: %s removing thread.\n", t->tsk->comm));
3344 pr_debug("pktgen: %s removing thread.\n", t->tsk->comm);
3349 pktgen_rem_thread(t);
3350
3351 return 0;
3352}
3353
3354static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
3355 const char *ifname)
3356{
3357 struct pktgen_dev *p, *pkt_dev = NULL;
3358 if_lock(t);
3359
3360 list_for_each_entry(p, &t->if_list, list)
3361 if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) {
3362 pkt_dev = p;
3363 break;
3364 }
3365
3366 if_unlock(t);
3345 pktgen_rem_thread(t);
3346
3347 return 0;
3348}
3349
3350static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
3351 const char *ifname)
3352{
3353 struct pktgen_dev *p, *pkt_dev = NULL;
3354 if_lock(t);
3355
3356 list_for_each_entry(p, &t->if_list, list)
3357 if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) {
3358 pkt_dev = p;
3359 break;
3360 }
3361
3362 if_unlock(t);
3367 PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev));
3363 pr_debug("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev);
3368 return pkt_dev;
3369}
3370
3371/*
3372 * Adds a dev at front of if_list.
3373 */
3374
3375static int add_dev_to_thread(struct pktgen_thread *t,

--- 152 unchanged lines hidden (view full) ---

3528 list_del(&p->list);
3529 }
3530}
3531
3532static int pktgen_remove_device(struct pktgen_thread *t,
3533 struct pktgen_dev *pkt_dev)
3534{
3535
3364 return pkt_dev;
3365}
3366
3367/*
3368 * Adds a dev at front of if_list.
3369 */
3370
3371static int add_dev_to_thread(struct pktgen_thread *t,

--- 152 unchanged lines hidden (view full) ---

3524 list_del(&p->list);
3525 }
3526}
3527
3528static int pktgen_remove_device(struct pktgen_thread *t,
3529 struct pktgen_dev *pkt_dev)
3530{
3531
3536 PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev));
3532 pr_debug("pktgen: remove_device pkt_dev=%p\n", pkt_dev);
3537
3538 if (pkt_dev->running) {
3539 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
3540 pktgen_stop_device(pkt_dev);
3541 }
3542
3543 /* Dis-associate from the interface */
3544

--- 98 unchanged lines hidden ---
3533
3534 if (pkt_dev->running) {
3535 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
3536 pktgen_stop_device(pkt_dev);
3537 }
3538
3539 /* Dis-associate from the interface */
3540

--- 98 unchanged lines hidden ---