pktgen.c (2845b63b504b051a9cb4d78bed8b3594451a1f6f) | pktgen.c (b4099fab75d5e3eae8d207c0d7159e2f3348686e) |
---|---|
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> --- 61 unchanged lines hidden (view full) --- 70 * also the thread checks the thread->control which is used for inter-process 71 * communication. controlling process "posts" operations to the threads this 72 * way. The if_lock should be possible to remove when add/rem_device is merged 73 * into this too. 74 * 75 * By design there should only be *one* "controlling" process. In practice 76 * multiple write accesses gives unpredictable result. Understood by "write" 77 * to /proc gives result code thats should be read be the "writer". | 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> --- 61 unchanged lines hidden (view full) --- 70 * also the thread checks the thread->control which is used for inter-process 71 * communication. controlling process "posts" operations to the threads this 72 * way. The if_lock should be possible to remove when add/rem_device is merged 73 * into this too. 74 * 75 * By design there should only be *one* "controlling" process. In practice 76 * multiple write accesses gives unpredictable result. Understood by "write" 77 * to /proc gives result code thats should be read be the "writer". |
78 * For pratical use this should be no problem. | 78 * For practical use this should be no problem. |
79 * 80 * Note when adding devices to a specific CPU there good idea to also assign 81 * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU. 82 * --ro 83 * 84 * Fix refcount off by one if first packet fails, potential null deref, 85 * memleak 030710- KJP 86 * --- 4 unchanged lines hidden (view full) --- 91 * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org> 92 * 93 * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419 94 * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604 95 * 96 * New xmit() return, do_div and misc clean up by Stephen Hemminger 97 * <shemminger@osdl.org> 040923 98 * | 79 * 80 * Note when adding devices to a specific CPU there good idea to also assign 81 * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU. 82 * --ro 83 * 84 * Fix refcount off by one if first packet fails, potential null deref, 85 * memleak 030710- KJP 86 * --- 4 unchanged lines hidden (view full) --- 91 * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org> 92 * 93 * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419 94 * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604 95 * 96 * New xmit() return, do_div and misc clean up by Stephen Hemminger 97 * <shemminger@osdl.org> 040923 98 * |
99 * Rany Dunlap fixed u64 printk compiler waring | 99 * Randy Dunlap fixed u64 printk compiler waring |
100 * 101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org> 102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213 103 * 104 * Corrections from Nikolai Malykh (nmalykh@bilim.com) 105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230 106 * 107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com> --- 131 unchanged lines hidden (view full) --- 239 * sequence numbers in order, for example. 240 */ 241 __u64 started_at; /* micro-seconds */ 242 __u64 stopped_at; /* micro-seconds */ 243 __u64 idle_acc; /* micro-seconds */ 244 __u32 seq_num; 245 246 int clone_skb; /* Use multiple SKBs during packet gen. If this number | 100 * 101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org> 102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213 103 * 104 * Corrections from Nikolai Malykh (nmalykh@bilim.com) 105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230 106 * 107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com> --- 131 unchanged lines hidden (view full) --- 239 * sequence numbers in order, for example. 240 */ 241 __u64 started_at; /* micro-seconds */ 242 __u64 stopped_at; /* micro-seconds */ 243 __u64 idle_acc; /* micro-seconds */ 244 __u32 seq_num; 245 246 int clone_skb; /* Use multiple SKBs during packet gen. If this number |
247 * is greater than 1, then that many coppies of the same | 247 * is greater than 1, then that many copies of the same |
248 * packet will be sent before a new packet is allocated. 249 * For instance, if you want to send 1024 identical packets 250 * before creating a new packet, set clone_skb to 1024. 251 */ 252 253 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 254 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 255 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ --- 135 unchanged lines hidden (view full) --- 391 } 392 else { 393 return ((x & (1ll<<63)) == 0) ? a : -(s64)a; 394 } 395} 396 397/* End of hacks to deal with 64-bit math on x86 */ 398 | 248 * packet will be sent before a new packet is allocated. 249 * For instance, if you want to send 1024 identical packets 250 * before creating a new packet, set clone_skb to 1024. 251 */ 252 253 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 254 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 255 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ --- 135 unchanged lines hidden (view full) --- 391 } 392 else { 393 return ((x & (1ll<<63)) == 0) ? a : -(s64)a; 394 } 395} 396 397/* End of hacks to deal with 64-bit math on x86 */ 398 |
399/** Convert to miliseconds */ | 399/** Convert to milliseconds */ |
400static inline __u64 tv_to_ms(const struct timeval* tv) 401{ 402 __u64 ms = tv->tv_usec / 1000; 403 ms += (__u64)tv->tv_sec * (__u64)1000; 404 return ms; 405} 406 407 --- 12 unchanged lines hidden (view full) --- 420 n, base, tmp); */ 421 return tmp; 422} 423 424static inline __u64 pg_div64(__u64 n, __u64 base) 425{ 426 __u64 tmp = n; 427/* | 400static inline __u64 tv_to_ms(const struct timeval* tv) 401{ 402 __u64 ms = tv->tv_usec / 1000; 403 ms += (__u64)tv->tv_sec * (__u64)1000; 404 return ms; 405} 406 407 --- 12 unchanged lines hidden (view full) --- 420 n, base, tmp); */ 421 return tmp; 422} 423 424static inline __u64 pg_div64(__u64 n, __u64 base) 425{ 426 __u64 tmp = n; 427/* |
428 * How do we know if the architectrure we are running on | 428 * How do we know if the architecture we are running on |
429 * supports division with 64 bit base? 430 * 431 */ 432#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__) 433 434 do_div(tmp, base); 435#else 436 tmp = divremdi3(n, base, PG_DIV); --- 102 unchanged lines hidden (view full) --- 539 goto out; 540 } 541 542 sprintf(data, "%s", VERSION); 543 544 len = strlen(data); 545 546 if(len > count) { | 429 * supports division with 64 bit base? 430 * 431 */ 432#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__) 433 434 do_div(tmp, base); 435#else 436 tmp = divremdi3(n, base, PG_DIV); --- 102 unchanged lines hidden (view full) --- 539 goto out; 540 } 541 542 sprintf(data, "%s", VERSION); 543 544 len = strlen(data); 545 546 if(len > count) { |
547 len =-EFAULT; | 547 len = -EFAULT; |
548 goto out; 549 } 550 551 if (copy_to_user(buf, data, len)) { | 548 goto out; 549 } 550 551 if (copy_to_user(buf, data, len)) { |
552 len =-EFAULT; | 552 len = -EFAULT; |
553 goto out; 554 } 555 556 *ppos += len; 557 proc_pgctrl_read_eof=1; /* EOF next call */ 558 559 out: 560 return len; --- 12 unchanged lines hidden (view full) --- 573 574 data = (void*)vmalloc ((unsigned int)count); 575 576 if(!data) { 577 err = -ENOMEM; 578 goto out; 579 } 580 if (copy_from_user(data, buf, count)) { | 553 goto out; 554 } 555 556 *ppos += len; 557 proc_pgctrl_read_eof=1; /* EOF next call */ 558 559 out: 560 return len; --- 12 unchanged lines hidden (view full) --- 573 574 data = (void*)vmalloc ((unsigned int)count); 575 576 if(!data) { 577 err = -ENOMEM; 578 goto out; 579 } 580 if (copy_from_user(data, buf, count)) { |
581 err =-EFAULT; | 581 err = -EFAULT; |
582 goto out_free; 583 } 584 data[count-1] = 0; /* Make string */ 585 586 if (!strcmp(data, "stop")) 587 pktgen_stop_all_threads_ifs(); 588 589 else if (!strcmp(data, "start")) --- 1107 unchanged lines hidden (view full) --- 1697static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us) 1698{ 1699 __u64 start; 1700 __u64 now; 1701 1702 start = now = getCurUs(); 1703 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now)); 1704 while (now < spin_until_us) { | 582 goto out_free; 583 } 584 data[count-1] = 0; /* Make string */ 585 586 if (!strcmp(data, "stop")) 587 pktgen_stop_all_threads_ifs(); 588 589 else if (!strcmp(data, "start")) --- 1107 unchanged lines hidden (view full) --- 1697static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us) 1698{ 1699 __u64 start; 1700 __u64 now; 1701 1702 start = now = getCurUs(); 1703 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now)); 1704 while (now < spin_until_us) { |
1705 /* TODO: optimise sleeping behavior */ | 1705 /* TODO: optimize sleeping behavior */ |
1706 if (spin_until_us - now > jiffies_to_usecs(1)+1) 1707 schedule_timeout_interruptible(1); 1708 else if (spin_until_us - now > 100) { 1709 do_softirq(); 1710 if (!pkt_dev->running) 1711 return; 1712 if (need_resched()) 1713 schedule(); --- 642 unchanged lines hidden (view full) --- 2356 2357 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads.\n")); 2358 2359 thread_lock(); 2360 while(t) { 2361 pktgen_stop(t); 2362 t = t->next; 2363 } | 1706 if (spin_until_us - now > jiffies_to_usecs(1)+1) 1707 schedule_timeout_interruptible(1); 1708 else if (spin_until_us - now > 100) { 1709 do_softirq(); 1710 if (!pkt_dev->running) 1711 return; 1712 if (need_resched()) 1713 schedule(); --- 642 unchanged lines hidden (view full) --- 2356 2357 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads.\n")); 2358 2359 thread_lock(); 2360 while(t) { 2361 pktgen_stop(t); 2362 t = t->next; 2363 } |
2364 thread_unlock(); | 2364 thread_unlock(); |
2365} 2366 2367static int thread_is_running(struct pktgen_thread *t ) 2368{ 2369 struct pktgen_dev *next; 2370 int res = 0; 2371 2372 for(next=t->if_list; next; next=next->next) { --- 177 unchanged lines hidden (view full) --- 2550{ 2551 /* Remove from the thread list */ 2552 2553 struct pktgen_thread *tmp = pktgen_threads; 2554 2555 if (strlen(t->fname)) 2556 remove_proc_entry(t->fname, NULL); 2557 | 2365} 2366 2367static int thread_is_running(struct pktgen_thread *t ) 2368{ 2369 struct pktgen_dev *next; 2370 int res = 0; 2371 2372 for(next=t->if_list; next; next=next->next) { --- 177 unchanged lines hidden (view full) --- 2550{ 2551 /* Remove from the thread list */ 2552 2553 struct pktgen_thread *tmp = pktgen_threads; 2554 2555 if (strlen(t->fname)) 2556 remove_proc_entry(t->fname, NULL); 2557 |
2558 thread_lock(); | 2558 thread_lock(); |
2559 2560 if (tmp == t) 2561 pktgen_threads = tmp->next; 2562 else { 2563 while (tmp) { 2564 if (tmp->next == t) { 2565 tmp->next = t->next; 2566 t->next = NULL; --- 357 unchanged lines hidden (view full) --- 2924 return -EBUSY; 2925 } 2926} 2927 2928static struct pktgen_thread *pktgen_find_thread(const char* name) 2929{ 2930 struct pktgen_thread *t = NULL; 2931 | 2559 2560 if (tmp == t) 2561 pktgen_threads = tmp->next; 2562 else { 2563 while (tmp) { 2564 if (tmp->next == t) { 2565 tmp->next = t->next; 2566 t->next = NULL; --- 357 unchanged lines hidden (view full) --- 2924 return -EBUSY; 2925 } 2926} 2927 2928static struct pktgen_thread *pktgen_find_thread(const char* name) 2929{ 2930 struct pktgen_thread *t = NULL; 2931 |
2932 thread_lock(); | 2932 thread_lock(); |
2933 2934 t = pktgen_threads; 2935 while (t) { 2936 if (strcmp(t->name, name) == 0) 2937 break; 2938 2939 t = t->next; 2940 } --- 168 unchanged lines hidden --- | 2933 2934 t = pktgen_threads; 2935 while (t) { 2936 if (strcmp(t->name, name) == 0) 2937 break; 2938 2939 t = t->next; 2940 } --- 168 unchanged lines hidden --- |