summaryrefslogtreecommitdiff
path: root/trafgen.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2017-07-29 12:46:08 +0300
committerTobias Klauser <tklauser@distanz.ch>2017-08-10 09:03:37 +0200
commit19348cec323373d84674c1d2cf34315cbf47c80d (patch)
tree3dd13803e6f9b2e84ff85b90b17a9cbc97bc93ea /trafgen.c
parentd55874b960a8663cc86284fad4d0472ff37b7a7e (diff)
trafgen: dev_io: Change read/write to specify struct packet *
Refactor dev_io_ops read & write to specify struct packet *, it may simplify a bit a caller logic. And it allow to keep required members within one struct packet object. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen.c')
-rw-r--r--trafgen.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/trafgen.c b/trafgen.c
index 207b680..97ac046 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -684,7 +684,7 @@ static void xmit_slowpath_or_die(struct ctx *ctx, unsigned int cpu, unsigned lon
while (likely(sigint == 0 && num > 0 && plen > 0)) {
packet_apply_dyn_elements(i);
retry:
- ret = dev_io_write(ctx->dev_out, packets[i].payload, packets[i].len);
+ ret = dev_io_write(ctx->dev_out, &packets[i]);
if (unlikely(ret < 0)) {
if (errno == ENOBUFS) {
sched_yield();
@@ -937,27 +937,10 @@ static void xmit_packet_precheck(struct ctx *ctx, unsigned int cpu)
static void pcap_load_packets(struct dev_io *dev)
{
- struct timespec tstamp;
- size_t buf_len;
- uint8_t *buf;
- int pkt_len;
+ struct packet *pkt;
- buf_len = round_up(1024 * 1024, RUNTIME_PAGE_SIZE);
- buf = xmalloc_aligned(buf_len, CO_CACHE_LINE_SIZE);
-
- while ((pkt_len = dev_io_read(dev, buf, buf_len, &tstamp)) > 0) {
- struct packet *pkt;
-
- realloc_packet();
-
- pkt = current_packet();
- pkt->len = pkt_len;
- pkt->payload = xzmalloc(pkt_len);
- memcpy(pkt->payload, buf, pkt_len);
- memcpy(&pkt->tstamp, &tstamp, sizeof(tstamp));
- }
-
- free(buf);
+ while ((pkt = dev_io_read(dev)) != 0)
+ /* nothing to do */;
}
static void main_loop(struct ctx *ctx, char *confname, bool slow,