Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Daniel Turull and committed by
David S. Miller
43d28b65 0c78a92f

+43 -4
+5
Documentation/networking/pktgen.txt
··· 151 151 152 152 pgset stop aborts injection. Also, ^C aborts generator. 153 153 154 + pgset "rate 300M" set rate to 300 Mb/s 155 + pgset "ratep 1000000" set rate to 1Mpps 154 156 155 157 Example scripts 156 158 =============== ··· 242 240 243 241 flows 244 242 flowlen 243 + 244 + rate 245 + ratep 245 246 246 247 References: 247 248 ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
+38 -4
net/core/pktgen.c
··· 169 169 #include <asm/dma.h> 170 170 #include <asm/div64.h> /* do_div */ 171 171 172 - #define VERSION "2.73" 172 + #define VERSION "2.74" 173 173 #define IP_NAME_SZ 32 174 174 #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ 175 175 #define MPLS_STACK_BOTTOM htonl(0x00000100) ··· 978 978 979 979 sprintf(pg_result, "OK: delay=%llu", 980 980 (unsigned long long) pkt_dev->delay); 981 + return count; 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); 981 1015 return count; 982 1016 } 983 1017 if (!strcmp(name, "udp_src_min")) { ··· 2176 2142 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 2177 2143 hrtimer_set_expires(&t.timer, spin_until); 2178 2144 2179 - remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer)); 2145 + remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer)); 2180 2146 if (remaining <= 0) { 2181 2147 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay); 2182 2148 return; 2183 2149 } 2184 2150 2185 2151 start_time = ktime_now(); 2186 - if (remaining < 100) 2187 - udelay(remaining); /* really small just spin */ 2152 + if (remaining < 100000) 2153 + ndelay(remaining); /* really small just spin */ 2188 2154 else { 2189 2155 /* see do_nanosleep */ 2190 2156 hrtimer_init_sleeper(&t, current);