Skip to content

Commit cbef283

Browse files
koolzznks5295
authored andcommitted
Add Latency Measurement to Speed_Tester NF (#256)
This change adds a new, optional, flag to the Speed_Tester NF. Now, running Speed_Tester with the `-l` flag will generate packets with an additional bit enabled and with a timestamp as data. The NF will now check for the latency bit when run with the `-l` flag, and then it will extract the timestamp and update the average latency. The average latency value will be printed with the NF output. Commit log: * Initial commit for latency - Calculate the latency by timestamping the packets - Average the latency over all packets - Prints the avg nanosec latency * This method is expensive and cuts the throguhput speed * * working latency in packet * Clean up latency code - Add a flag to enable latency measuring - Remove extra testing code * Readme updates * Quick README fix
1 parent 87bd96d commit cbef283

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

examples/speed_tester/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ This program lets you test how fast the manager's TX threads can move packets. I
44

55
Optional Libraries
66
--
7-
libpcap library is required for pcap replay functionality.
8-
To enable pcap replay set `ENABLE_PCAP=1` in the Makefile.
7+
libpcap library is required for pcap replay functionality.
8+
To enable pcap replay set `ENABLE_PCAP=1` in the Makefile.
99
If libpcap is not installed run:
1010
```
1111
sudo apt-get install libpcap-dev
1212
```
1313
Example .pcap files
1414
--
15-
`pcap/` directory has a few example pcap files.
16-
- pktgen_big.pcap, pktgen_large.pcap, pktgen_test1.pcap, pktgen_traffic_sample.pcap are taken from the [Pktgen](../../tools/Pktgen/README.md) example pcap files.
15+
`pcap/` directory has a few example pcap files.
16+
- pktgen_big.pcap, pktgen_large.pcap, pktgen_test1.pcap, pktgen_traffic_sample.pcap are taken from the [Pktgen](../../tools/Pktgen/README.md) example pcap files.
1717
- 64B_download.pcap, 8K_download.pcap are sample web traffic pcap files.
1818

1919
Compilation and Execution
@@ -22,11 +22,11 @@ Compilation and Execution
2222
cd examples
2323
make
2424
cd speed_tester
25-
./go.sh CORELIST SERVICE_ID DST_ID [PRINT_DELAY] [ADVANCED_RINGS] [PACKET_SIZE] [DEST_MAC] [PCAP_FILE]
25+
./go.sh CORELIST SERVICE_ID DST_ID [PRINT_DELAY] [ADVANCED_RINGS] [PACKET_SIZE] [DEST_MAC] [PCAP_FILE] [MEASURE_LATENCY]
2626
2727
OR
2828
29-
sudo ./build/speed_tester -l CORELIST -n 3 --proc-type=secondary -- -r SERVICE_ID -- -d DST [-a] [-p PRINT_DELAY] [-s PACKET_SIZE] [-m DEST_MAC] [-o PCAP_FILENAME]
29+
sudo ./build/speed_tester -l CORELIST -n 3 --proc-type=secondary -- -r SERVICE_ID -- -d DST [-a] [-p PRINT_DELAY] [-s PACKET_SIZE] [-m DEST_MAC] [-o PCAP_FILENAME] [-l]
3030
```
3131

3232
App Specific Arguments
@@ -35,5 +35,6 @@ App Specific Arguments
3535
- `-a`: Use advanced rings interface instead of default `packet_handler`
3636
- `-p PRINT_DELAY`: Number of packets between each print, e.g. `-p 1` prints every packets.
3737
- `-s PACKET_SIZE`: Size of packet, e.g. `-s 32` allocates 32 bytes for the data segment of `rte_mbuf`.
38-
- `-m DEST_MAC`: User specified destination MAC address, e.g. `-m aa:bb:cc:dd:ee:ff` sets the destination address within the ethernet header that is located at the start of the packet data.
38+
- `-m DEST_MAC`: User specified destination MAC address, e.g. `-m aa:bb:cc:dd:ee:ff` sets the destination address within the ethernet header that is located at the start of the packet data.
3939
- `-o PCAP_FILENAME` : The filename of the pcap file to replay
40+
- `-l LATENCY` : Enable latency measurement. This should only be enabled on one Speed Tester NF. Packets must be routed back to the same speed tester NF.

examples/speed_tester/go.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
function usage {
44
echo "$0 CPU-LIST SERVICE-ID DST [-p PRINT] [-n NF-ID] [-a] [-s PACKET-SIZE] [-m DEST-MAC]
5-
[-c PACKET-NUMBER]"
5+
[-c PACKET-NUMBER] [-l]"
66
echo "$0 3,7,9 1 2 --> cores 3,7, and 9, with Service ID 1, and forwards to service ID 2"
77
echo "$0 3,7,9 1 2 1000 --> cores 3,7, and 9, with Service ID 1, forwards to service ID 2, and Print Rate of 1000"
88
echo "$0 3,7,9 1 2 -s 32 --> cores 3,7, and 9, with Service ID 1, forwards to service ID 2, and packet size of 32"
99
echo "$0 3,7,9 1 2 -s 32 -m aa:bb:cc:dd:ee:ff --> cores 3,7, and 9, with Service ID 1, forwards to service ID 2, packet size of 32, and destination MAC address of aa:bb:cc:dd:ee:ff"
1010
echo "$0 5 1 2 -o sample_trafic.pcap --> core 5, with Service ID 1, and forwards to service ID 2, replays sample_trafic.pcap packets (make sure to enable pcap functionality, check README for instructions)"
11+
echo "$0 5 1 2 -l --> core 5, with Service ID 1, forwards to service ID 2, measures latency"
1112
echo "Pass '-a' to signal the NF to use advanced ring manipulation"
1213
exit 1
1314
}
@@ -25,7 +26,7 @@ then
2526
usage
2627
fi
2728

28-
while getopts ":p:n:as:m:o:c:" opt; do
29+
while getopts ":p:n:as:m:o:c:l" opt; do
2930
case $opt in
3031
p) print="-p $OPTARG";;
3132
n) instance="-n $OPTARG";;
@@ -34,9 +35,10 @@ while getopts ":p:n:as:m:o:c:" opt; do
3435
m) dest_mac="-m $OPTARG";;
3536
o) pcap_filename="-o $OPTARG";;
3637
c) pkt_num="-c $OPTARG";;
38+
l) latency="-l";;
3739
\?) echo "Unknown option -$OPTARG" && usage
3840
;;
3941
esac
4042
done
4143

42-
exec sudo $SCRIPTPATH/build/app/speed_tester -l $cpu -n 3 --proc-type=secondary -- -r $service $instance -- -d $dst $print $rings $size $dest_mac $pcap_filename $pkt_num
44+
exec sudo $SCRIPTPATH/build/app/speed_tester -l $cpu -n 3 --proc-type=secondary -- -r $service $instance -- -d $dst $print $rings $size $dest_mac $pcap_filename $pkt_num $latency

examples/speed_tester/speed_tester.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@
7272
#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool"
7373
#define PKT_READ_SIZE ((uint16_t)32)
7474
#define SPEED_TESTER_BIT 7
75+
#define LATENCY_BIT 6
7576
#define LOCAL_EXPERIMENTAL_ETHER 0x88B5
7677
#define DEFAULT_PKT_NUM 128
78+
#define DEFAULT_LAT_PKT_NUM 16
7779
#define MAX_PKT_NUM NF_QUEUE_RINGSIZE
7880

7981
/* Struct that contains information about this NF */
@@ -94,6 +96,11 @@ static uint8_t d_addr_bytes[ETHER_ADDR_LEN];
9496
/* Default number of packets: 128; user can modify it by -c <packet_number> in command line */
9597
static uint32_t packet_number = 0;
9698

99+
/* Variables for measuring packet latency */
100+
static uint8_t measure_latency = 0;
101+
static uint32_t latency_packets = 0;
102+
static uint64_t total_latency = 0;
103+
97104
/*
98105
* Variables needed to replay a pcap file
99106
*/
@@ -106,7 +113,7 @@ static void
106113
usage(const char *progname) {
107114
printf("Usage: %s [EAL args] -- [NF_LIB args] -- -d <destination> [-p <print_delay>] "
108115
"[-a] [-s <packet_length>] [-m <dest_mac_address>] [-o <pcap_filename>] "
109-
"[-c <packet_number>]\n\n", progname);
116+
"[-c <packet_number>] [-l]\n\n", progname);
110117
}
111118

112119
/*
@@ -117,7 +124,7 @@ parse_app_args(int argc, char *argv[], const char *progname) {
117124
int c, i, count, dst_flag = 0;
118125
int values[ETHER_ADDR_LEN];
119126

120-
while ((c = getopt(argc, argv, "d:p:as:m:o:c:")) != -1) {
127+
while ((c = getopt(argc, argv, "d:p:as:m:o:c:l")) != -1) {
121128
switch (c) {
122129
case 'a':
123130
use_direct_rings = 1;
@@ -166,6 +173,9 @@ parse_app_args(int argc, char *argv[], const char *progname) {
166173
return -1;
167174
}
168175
break;
176+
case 'l':
177+
measure_latency = 1;
178+
break;
169179
case '?':
170180
usage(progname);
171181
if (optopt == 'd')
@@ -221,8 +231,14 @@ do_stats_display(struct rte_mbuf* pkt) {
221231
printf("Total packets: %9"PRIu64" \n", cur_pkts);
222232
printf("TX pkts per second: %9"PRIu64" \n", (cur_pkts - last_pkts)
223233
* rte_get_timer_hz() / (cur_cycles - last_cycles));
234+
if (measure_latency && latency_packets > 0)
235+
printf("Avg latency nanoseconds: %6"PRIu64" \n", total_latency/(latency_packets)
236+
* 1000000000 / rte_get_timer_hz());
224237
printf("Initial packets created: %u\n", packet_number);
225238

239+
total_latency = 0;
240+
latency_packets = 0;
241+
226242
last_pkts = cur_pkts;
227243
last_cycles = cur_cycles;
228244

@@ -241,6 +257,15 @@ packet_handler(struct rte_mbuf* pkt, struct onvm_pkt_meta* meta) {
241257
/* one of our fake pkts to forward */
242258
meta->destination = destination;
243259
meta->action = ONVM_NF_ACTION_TONF;
260+
if (measure_latency && ONVM_CHECK_BIT(meta->flags, LATENCY_BIT)) {
261+
uint64_t curtime = rte_get_tsc_cycles();
262+
uint64_t* oldtime = (uint64_t *)(rte_pktmbuf_mtod(pkt, uint8_t *) + packet_size);
263+
if (*oldtime != 0) {
264+
total_latency += curtime - *oldtime;
265+
latency_packets++;
266+
}
267+
*oldtime = curtime;
268+
}
244269
} else {
245270
/* Drop real incoming packets */
246271
meta->action = ONVM_NF_ACTION_DROP;
@@ -391,8 +416,8 @@ int main(int argc, char *argv[]) {
391416
ehdr = (struct ether_hdr *) rte_pktmbuf_append(pkt, packet_size);
392417

393418
/*using manager mac addr for source
394-
*using input string for dest addr
395-
*/
419+
*using input string for dest addr
420+
*/
396421
rte_eth_macaddr_get(0, &ehdr->s_addr);
397422
for (j = 0; j < ETHER_ADDR_LEN; ++j) {
398423
ehdr->d_addr.addr_bytes[j] = d_addr_bytes[j];
@@ -405,6 +430,13 @@ int main(int argc, char *argv[]) {
405430
pmeta->flags = ONVM_SET_BIT(0, SPEED_TESTER_BIT);
406431
pkt->hash.rss = i;
407432
pkt->port = 0;
433+
434+
if (measure_latency && (packet_number < DEFAULT_LAT_PKT_NUM || i % (packet_number/DEFAULT_LAT_PKT_NUM) == 0)) {
435+
pmeta->flags |= ONVM_SET_BIT(0, LATENCY_BIT);
436+
uint64_t* ts = (uint64_t *) rte_pktmbuf_append(pkt, sizeof(uint64_t));
437+
*ts = 0;
438+
}
439+
408440
onvm_nflib_return_pkt(pkt);
409441
}
410442
#ifdef LIBPCAP

0 commit comments

Comments
 (0)