Changed the way delays happen in the packetizer.
authorKevin Klues <klueska@parcad.millennium.berkeley.edu>
Wed, 5 May 2010 05:43:16 +0000 (22:43 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:47 +0000 (17:35 -0700)
Tuned to spit out packets at about 40K per second.

tools/packetizer/Makefile
tools/packetizer/packetizer.cpp

index 8f059fa..a0381b9 100644 (file)
@@ -1,2 +1,5 @@
 all: packetizer.cpp
        gcc -o packetizer -I. -lstdc++ packetizer.cpp
+
+clean: 
+       rm -rf packetizer
index 0464757..c1b7f03 100644 (file)
@@ -2,6 +2,7 @@
 #include <net/ethernet.h>
 #include <netinet/in.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <netdb.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 # define debug(...) do { } while(0)
 #endif
 
+static __inline uint64_t
+read_tsc(void)
+{
+    uint64_t tsc;
+    __asm __volatile("rdtsc" : "=A" (tsc));
+    return tsc;
+}
+
 packetizer::packetizer(const char *target_mac, const char *eth_device, 
                             const char *filename)
 {
@@ -64,9 +73,12 @@ int packetizer::start()
        printf("Starting to packetize the file: %s\n", filename);
        file.read(p.payload, MAX_PAYLOAD_SIZE);
        while(file) {
-               printf("Sending chunk %d\n", seqno);
+               //printf("Sending chunk %d\n", seqno);
                ret = ::sendto(sock, (char*)&p, p.size(), 0,
                               (sockaddr*)&myaddr,sizeof(myaddr));
+               
+               volatile uint64_t tsc = read_tsc();
+               while((read_tsc() - tsc) < 34800);
                if (ret < 0)
                  throw std::runtime_error("sending packet failed!");
                p.header.seqno = htons(next_seqno());
@@ -80,7 +92,7 @@ int packetizer::start()
                               (sockaddr*)&myaddr,sizeof(myaddr));
                if (ret < 0)
                  throw std::runtime_error("sending packet failed!");
-               printf("Sending chunk %d\n", seqno);
+               //printf("Sending chunk %d\n", seqno);
        }
        printf("Last chunk had %u bytes...\n", file.gcount());
 }