aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/pktgen.c
diff options
context:
space:
mode:
authorDaniel Turull <daniel.turull@gmail.com>2010-06-09 18:49:57 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-11 21:37:09 -0400
commit43d28b6515a6ea580a198df3e253e88236f08978 (patch)
tree97419dbd96cfb236694de00397a619cf5a0bab05 /net/core/pktgen.c
parent0c78a92fbd655ab990e2799f645707f05f548e2f (diff)
pktgen: increasing transmission granularity
This patch increases the granularity of the rate generated by pktgen. The previous version of pktgen uses micro seconds (udelay) resolution when it was delayed causing gaps in the rates. It is changed to nanosecond (ndelay). Now any rate is possible. Also it allows to set, the desired rate in Mb/s or packets per second. The documentation has been updated. Signed-off-by: Daniel Turull <daniel.turull@gmail.com> Signed-off-by: Robert Olsson <robert.olsson@its.uu.se> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/pktgen.c')
-rw-r--r--net/core/pktgen.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 1dacd7ba8dbb..6428653e9498 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -169,7 +169,7 @@
169#include <asm/dma.h> 169#include <asm/dma.h>
170#include <asm/div64.h> /* do_div */ 170#include <asm/div64.h> /* do_div */
171 171
172#define VERSION "2.73" 172#define VERSION "2.74"
173#define IP_NAME_SZ 32 173#define IP_NAME_SZ 32
174#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ 174#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
175#define MPLS_STACK_BOTTOM htonl(0x00000100) 175#define MPLS_STACK_BOTTOM htonl(0x00000100)
@@ -980,6 +980,40 @@ static ssize_t pktgen_if_write(struct file *file,
980 (unsigned long long) pkt_dev->delay); 980 (unsigned long long) pkt_dev->delay);
981 return count; 981 return count;
982 } 982 }
983 if (!strcmp(name, "rate")) {
984 len = num_arg(&user_buffer[i], 10, &value);
985 if (len < 0)
986 return len;
987
988 i += len;
989 if (!value)
990 return len;
991 pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value;
992 if (debug)
993 printk(KERN_INFO
994 "pktgen: Delay set at: %llu ns\n",
995 pkt_dev->delay);
996
997 sprintf(pg_result, "OK: rate=%lu", value);
998 return count;
999 }
1000 if (!strcmp(name, "ratep")) {
1001 len = num_arg(&user_buffer[i], 10, &value);
1002 if (len < 0)
1003 return len;
1004
1005 i += len;
1006 if (!value)
1007 return len;
1008 pkt_dev->delay = NSEC_PER_SEC/value;
1009 if (debug)
1010 printk(KERN_INFO
1011 "pktgen: Delay set at: %llu ns\n",
1012 pkt_dev->delay);
1013
1014 sprintf(pg_result, "OK: rate=%lu", value);
1015 return count;
1016 }
983 if (!strcmp(name, "udp_src_min")) { 1017 if (!strcmp(name, "udp_src_min")) {
984 len = num_arg(&user_buffer[i], 10, &value); 1018 len = num_arg(&user_buffer[i], 10, &value);
985 if (len < 0) 1019 if (len < 0)
@@ -2142,15 +2176,15 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
2142 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 2176 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2143 hrtimer_set_expires(&t.timer, spin_until); 2177 hrtimer_set_expires(&t.timer, spin_until);
2144 2178
2145 remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer)); 2179 remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer));
2146 if (remaining <= 0) { 2180 if (remaining <= 0) {
2147 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay); 2181 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
2148 return; 2182 return;
2149 } 2183 }
2150 2184
2151 start_time = ktime_now(); 2185 start_time = ktime_now();
2152 if (remaining < 100) 2186 if (remaining < 100000)
2153 udelay(remaining); /* really small just spin */ 2187 ndelay(remaining); /* really small just spin */
2154 else { 2188 else {
2155 /* see do_nanosleep */ 2189 /* see do_nanosleep */
2156 hrtimer_init_sleeper(&t, current); 2190 hrtimer_init_sleeper(&t, current);