Skip to content

Commit 624a3f9

Browse files
author
Matthew P. Grosvenor
committed
Revert "Refactor start state"
This reverts commit 8ba5bc9.
1 parent 8ba5bc9 commit 624a3f9

15 files changed

+80
-1241
lines changed

Makefile

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GLOBAL_CFLAGS=-g -std=c99 -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -f
66
RELEASE_CFLAGS=$(INCLUDES) $(GLOBAL_CFLAGS) -O3 -Wall -DNDEBUG -DNOIFASSERT
77
ASSERT_CFLAGS=$(INCLUDES) $(GLOBAL_CFLAGS) -O3 -Wall -DNDEBUG
88
DEBUG_CFLAGS=$(INCLUDES) $(GLOBAL_CFLAGS) -Werror -Wall -Wextra -pedantic
9-
BIN=bin/exact-capture bin/exact-pcap-extract bin/exact-pcap-parse bin/exact-pcap-match bin/exact-pcap-analyze
9+
BIN=bin/exact-capture bin/exact-pcap-extract bin/exact-pcap-parse bin/exact-pcap-match
1010

1111
EXACTCAP_SRCS=$(wildcard src/*.c) $(wildcard src/**/*.c)
1212
EXACTCAP_HDRS=$(wildcard src/*.h) $(wildcard src/**/*.h)
@@ -29,10 +29,6 @@ bin/exact-pcap-parse: utils/exact-pcap-parse.c $(EXACTCAP_HDRS) $(LIBCAHSTE_HDRS
2929
mkdir -p bin
3030
$(CC) $(CFLAGS) utils/exact-pcap-parse.c $(LDFLAGS) -o $@
3131

32-
bin/exact-pcap-analyze: utils/exact-pcap-analyze.c src/utils.c $(EXACTCAP_HDRS) $(LIBCAHSTE_HDRS)
33-
mkdir -p bin
34-
$(CC) $(CFLAGS) utils/exact-pcap-analyze.c src/utils.c $(LDFLAGS) -lexanic -o $@
35-
3632
bin/exact-pcap-match: utils/exact-pcap-match.c $(EXACTCAP_HDRS) $(LIBCAHSTE_HDRS)
3733
mkdir -p bin
3834
$(CC) $(CFLAGS) utils/exact-pcap-match.c $(LDFLAGS) -o $@

src/data_structs/timespecps.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <stdint.h>
1616

1717
typedef struct timespecps {
18-
int64_t tv_sec;
19-
int64_t tv_psec;
18+
uint64_t tv_sec;
19+
uint64_t tv_psec;
2020
} __attribute__((packed)) timespecps_t;
2121

2222

src/exact-capture-listener.c

-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ void* listener_thread (void* params)
426426
inargs.args.exa.interface_tx = NULL;
427427
inargs.args.exa.kernel_bypass = lparams->kernel_bypass;
428428
inargs.args.exa.promisc = lparams->promisc;
429-
inargs.args.exa.clear_buff = lparams->clear_buff;
430429
int err = eio_new (&inargs, &istream);
431430
if (err)
432431
{

src/exact-capture-listener.h

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ typedef struct
5353

5454
bool kernel_bypass;
5555
bool promisc;
56-
bool clear_buff;
5756

5857
} listener_params_t;
5958

src/exact-capture.c

-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ static struct
103103
ch_bool no_log_ts;
104104
ch_bool no_kernel;
105105
ch_bool no_promisc;
106-
ch_bool clear_buff;
107106
ch_word verbosity;
108107
bool no_overflow_warn;
109108
bool debug_log;
@@ -769,7 +768,6 @@ static CH_VECTOR(pthread)* start_listener_threads(cpu_set_t listener_cpus)
769768
lparams->ltid = lthreads->count;
770769
lparams->promisc = !options.no_promisc;
771770
lparams->kernel_bypass = options.no_kernel;
772-
lparams->clear_buff = options.clear_buff;
773771

774772
if(parse_device(lparams->interface, lparams->exanic_dev,
775773
&lparams->exanic_dev_num, &lparams->exanic_port))
@@ -950,7 +948,6 @@ int main (int argc, char** argv)
950948
ch_opt_addbi (CH_OPTION_FLAG, 'w', "no-warn-overflow", "No warning on overflows", &options.no_overflow_warn, false);
951949
ch_opt_addbi (CH_OPTION_FLAG, 'S', "no-spin", "No spinner on the output", &options.no_spinner, false);
952950
ch_opt_addii (CH_OPTION_OPTIONAL, 'p', "perf-test", "Performance test mode [0-7]", &options.calib_mode, 0);
953-
ch_opt_addbi (CH_OPTION_FLAG, 'C', "clear-buff", "Clear all pending rx packets before starting", &options.clear_buff, false);
954951

955952
ch_opt_parse (argc, argv);
956953

src/exactio/exactio_bring.c

+64-91
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static inline eio_error_t eio_bring_server_connect(eio_stream_t* this)
392392
}
393393

394394
//Map the file into memory
395-
void* mem = mmap( NULL, total_mem_req, PROT_READ | PROT_WRITE, MAP_SHARED, bring_fd, 0);
395+
void* mem = mmap( NULL, total_mem_req, PROT_READ | PROT_WRITE, MAP_SHARED , bring_fd, 0);
396396
if(mem == MAP_FAILED){
397397
ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
398398
result = EIO_EINVALID;
@@ -487,8 +487,6 @@ static inline eio_error_t eio_bring_server_connect(eio_stream_t* this)
487487
}
488488
ch_log_debug1("Waiting for client to connect to bring %s...Done\n", priv->name);
489489

490-
491-
492490
priv->closed = 0;
493491
result = EIO_ENONE;
494492
return result;
@@ -508,31 +506,6 @@ static eio_error_t eio_bring_client_connect(eio_stream_t* this)
508506
bring_priv_t* priv = IOSTREAM_GET_PRIVATE(this);
509507

510508

511-
//Calculate the amount of memory we will need
512-
//Each slot has a requested size, plus some header
513-
const int64_t mem_per_slot = priv->slot_size + sizeof(bring_slot_header_t);
514-
//Round up each slot so that it's a multiple of 64bits.
515-
const int64_t slot_aligned_size = round_up(mem_per_slot, getpagesize());
516-
//Figure out the total memory commitment for slots
517-
const int64_t mem_per_ring = slot_aligned_size * priv->slot_count;
518-
//Allocate for both server-->client and client-->server connections
519-
const int64_t total_ring_mem = mem_per_ring * 2;
520-
//Include the memory required for the headers -- Make sure there's a place for the synchronization pointer
521-
const int64_t header_mem = round_up(sizeof(bring_header_t),getpagesize());
522-
//All memory required
523-
const int64_t total_mem_req = total_ring_mem + header_mem;
524-
525-
ch_log_debug1("Client calculated memory requirements\n");
526-
ch_log_debug1("-------------------------\n");
527-
ch_log_debug1("mem_per_slot %li\n", mem_per_slot);
528-
ch_log_debug1("slot_sligned %li\n", slot_aligned_size);
529-
ch_log_debug1("mem_per_ring %li\n", mem_per_ring);
530-
ch_log_debug1("total_ring_mem %li\n", total_ring_mem);
531-
ch_log_debug1("header_mem %li\n", header_mem);
532-
ch_log_debug1("total_mem_req %li\n", total_mem_req);
533-
ch_log_debug1("-------------------------\n");
534-
535-
536509
//Now there is a bring file and it should have a header in it
537510
int bring_fd = shm_open(priv->name, O_RDWR, (mode_t)(0666));
538511
if(bring_fd < 0){
@@ -542,74 +515,74 @@ static eio_error_t eio_bring_client_connect(eio_stream_t* this)
542515
}
543516

544517
ch_log_debug1("Doing bring connect client on %s\n", priv->name);
545-
//
546-
// //Resize the file big enough to read the bring header only
547-
// if(ftruncate(bring_fd,sizeof(bring_header_t))){
548-
// ch_log_error( "Could not resize shared region \"%s\" to size=%li. Error=%s\n",
549-
// priv->name,
550-
// sizeof(bring_header_t),
551-
// strerror(errno)
552-
// );
553-
// result = EIO_EINVALID;
554-
// goto error_close_file;
555-
// }
556-
//
557-
// //Map the file into memory
558-
// void* mem_tmp = mmap( NULL, sizeof(bring_header_t), PROT_READ, MAP_SHARED, bring_fd, 0);
559-
// if(mem_tmp == MAP_FAILED){
560-
// ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
561-
// result = EIO_EINVALID;
562-
// goto error_close_file;
563-
// }
564-
//
565-
// //Memory must be page aligned otherwise we're in trouble (TODO - could pass alignment though the file and check..)
566-
// //ch_log_debug3("memory mapped at address =%p\n", mem);
567-
// if( ((uint64_t)mem_tmp) != (((uint64_t)mem_tmp) & ~0xFFF)){
568-
// ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
569-
// result = EIO_EINVALID;
570-
// goto error_close_file;
571-
// }
572-
//
573-
// //This is a sort of nasty atomic access. Which doesn't leave crap lying around like POSIX semaphores do
574-
// ch_log_debug1("Looking for bring header on %s\n", priv->name);
575-
// bring_header_t* header_tmp_ptr = mem_tmp;
576-
// __sync_synchronize();
577-
// while(header_tmp_ptr->magic != BRING_MAGIC_SERVER){
578-
// __sync_synchronize();
579-
// usleep(100 * 1000);
580-
// }
581-
// ch_log_debug1("Looking for bring header... Done.\n");
582-
//
583-
// bring_header_t header_tmp = *(bring_header_t*)(mem_tmp);
584-
//// ch_log_debug1("Got bring header\n");
585-
//// ch_log_debug1("Client read bring memory offsets\n");
586-
//// ch_log_debug1("-------------------------\n");
587-
//// ch_log_debug1("total_mem %016lx (%li)\n", header_tmp.total_mem, header_tmp.total_mem);
588-
//// ch_log_debug1("rd_slots %016lx (%li)\n", header_tmp.rd_slots, header_tmp.rd_slots);
589-
//// ch_log_debug1("rd_slots_size %016lx (%li)\n", header_tmp.rd_slots_size, header_tmp.rd_slots_size);
590-
//// ch_log_debug1("rd_slots_usr_size %016lx (%li)\n", header_tmp.rd_slot_usr_size, header_tmp.rd_slot_usr_size);
591-
//// ch_log_debug1("rd_mem_start_offset %016lx (%li)\n", header_tmp.rd_mem_start_offset, header_tmp.rd_mem_start_offset);
592-
//// ch_log_debug1("rd_mem_len %016lx (%li)\n", header_tmp.rd_mem_len, header_tmp.rd_mem_len);
593-
//// ch_log_debug1("wr_slots %016lx (%li)\n", header_tmp.wr_slots, header_tmp.wr_slots);
594-
//// ch_log_debug1("wr_slots_size %016lx (%li)\n", header_tmp.wr_slots_size, header_tmp.wr_slots_size);
595-
//// ch_log_debug1("wr_slots_usr_size %016lx (%li)\n", header_tmp.wr_slot_usr_size, header_tmp.wr_slot_usr_size);
596-
//// ch_log_debug1("wr_mem_start_offset %016lx (%li)\n", header_tmp.wr_mem_start_offset,header_tmp.wr_mem_start_offset);
597-
//// ch_log_debug1("wr_mem_len %016lx (%li)\n", header_tmp.wr_mem_len, header_tmp.wr_mem_len);
598-
//// ch_log_debug1("-------------------------\n");
599-
//
600-
// munmap(mem_tmp, sizeof(bring_header_t));//Done with the temporary mapping, do the real one now
601518

602-
if(ftruncate(bring_fd,total_mem_req)){
519+
//Resize the file big enough to read the bring header only
520+
if(ftruncate(bring_fd,sizeof(bring_header_t))){
521+
ch_log_error( "Could not resize shared region \"%s\" to size=%li. Error=%s\n",
522+
priv->name,
523+
sizeof(bring_header_t),
524+
strerror(errno)
525+
);
526+
result = EIO_EINVALID;
527+
goto error_close_file;
528+
}
529+
530+
//Map the file into memory
531+
void* mem_tmp = mmap( NULL, sizeof(bring_header_t), PROT_READ, MAP_SHARED, bring_fd, 0);
532+
if(mem_tmp == MAP_FAILED){
533+
ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
534+
result = EIO_EINVALID;
535+
goto error_close_file;
536+
}
537+
538+
//Memory must be page aligned otherwise we're in trouble (TODO - could pass alignment though the file and check..)
539+
//ch_log_debug3("memory mapped at address =%p\n", mem);
540+
if( ((uint64_t)mem_tmp) != (((uint64_t)mem_tmp) & ~0xFFF)){
541+
ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
542+
result = EIO_EINVALID;
543+
goto error_close_file;
544+
}
545+
546+
//This is a sort of nasty atomic access. Which doesn't leave crap lying around like POSIX semaphores do
547+
ch_log_debug1("Looking for bring header on %s\n", priv->name);
548+
bring_header_t* header_tmp_ptr = mem_tmp;
549+
__sync_synchronize();
550+
while(header_tmp_ptr->magic != BRING_MAGIC_SERVER){
551+
__sync_synchronize();
552+
usleep(100 * 1000);
553+
}
554+
ch_log_debug1("Looking for bring header... Done.\n");
555+
556+
bring_header_t header_tmp = *(bring_header_t*)(mem_tmp);
557+
// ch_log_debug1("Got bring header\n");
558+
// ch_log_debug1("Client read bring memory offsets\n");
559+
// ch_log_debug1("-------------------------\n");
560+
// ch_log_debug1("total_mem %016lx (%li)\n", header_tmp.total_mem, header_tmp.total_mem);
561+
// ch_log_debug1("rd_slots %016lx (%li)\n", header_tmp.rd_slots, header_tmp.rd_slots);
562+
// ch_log_debug1("rd_slots_size %016lx (%li)\n", header_tmp.rd_slots_size, header_tmp.rd_slots_size);
563+
// ch_log_debug1("rd_slots_usr_size %016lx (%li)\n", header_tmp.rd_slot_usr_size, header_tmp.rd_slot_usr_size);
564+
// ch_log_debug1("rd_mem_start_offset %016lx (%li)\n", header_tmp.rd_mem_start_offset, header_tmp.rd_mem_start_offset);
565+
// ch_log_debug1("rd_mem_len %016lx (%li)\n", header_tmp.rd_mem_len, header_tmp.rd_mem_len);
566+
// ch_log_debug1("wr_slots %016lx (%li)\n", header_tmp.wr_slots, header_tmp.wr_slots);
567+
// ch_log_debug1("wr_slots_size %016lx (%li)\n", header_tmp.wr_slots_size, header_tmp.wr_slots_size);
568+
// ch_log_debug1("wr_slots_usr_size %016lx (%li)\n", header_tmp.wr_slot_usr_size, header_tmp.wr_slot_usr_size);
569+
// ch_log_debug1("wr_mem_start_offset %016lx (%li)\n", header_tmp.wr_mem_start_offset,header_tmp.wr_mem_start_offset);
570+
// ch_log_debug1("wr_mem_len %016lx (%li)\n", header_tmp.wr_mem_len, header_tmp.wr_mem_len);
571+
// ch_log_debug1("-------------------------\n");
572+
573+
munmap(mem_tmp, sizeof(bring_header_t));//Done with the temporary mapping, do the real one now
574+
575+
if(ftruncate(bring_fd,header_tmp.total_mem)){
603576
ch_log_error( "Could not resize shared region \"%s\" to size=%li. Error=%s\n",
604577
priv->name,
605-
total_mem_req,
578+
header_tmp.total_mem,
606579
strerror(errno)
607580
);
608581
result = EIO_EINVALID;
609582
goto error_close_file;
610583
}
611584

612-
void* mem = mmap( NULL, total_mem_req, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB , bring_fd, 0);
585+
void* mem = mmap( NULL, header_tmp.total_mem, PROT_READ | PROT_WRITE, MAP_SHARED , bring_fd, 0);
613586
if(mem == MAP_FAILED){
614587
ch_log_error("Could not memory map bring file \"%s\". Error=%s\n", priv->name, strerror(errno));
615588
result = EIO_EINVALID;
@@ -625,7 +598,7 @@ static eio_error_t eio_bring_client_connect(eio_stream_t* this)
625598
}
626599

627600
//Pin the pages so that they don't get swapped out
628-
if(mlock(mem,total_mem_req)){
601+
if(mlock(mem,header_tmp.total_mem)){
629602
ch_log_fatal("Could not lock memory map. Error=%s\n", strerror(errno));
630603
//result = EIO_EINVALID;
631604
//goto error_unmap_file;
@@ -661,10 +634,10 @@ static eio_error_t eio_bring_client_connect(eio_stream_t* this)
661634
return EIO_ENONE;
662635

663636
error_unlock_mem:
664-
munlock(mem, total_mem_req);
637+
munlock(mem, header_tmp.total_mem);
665638

666639
//error_unmap_file:
667-
munmap(mem, total_mem_req);
640+
munmap(mem, header_tmp.total_mem);
668641

669642
error_close_file:
670643
close(bring_fd);
@@ -694,7 +667,7 @@ static eio_error_t bring_construct(eio_stream_t* this, bring_args_t* args)
694667
bring_priv_t* priv = IOSTREAM_GET_PRIVATE(this);
695668

696669
//Make a local copy of the filename in case the supplied name goes away
697-
const uint16_t name_len = strnlen(filename,1024); //Safety bug here? What's a reasonable max on filename size?
670+
const uint16_t name_len = strlen(filename); //Safety bug here? What's a reasonable max on filename size?
698671
priv->name = calloc(1, name_len + 1);
699672
if(!priv->name){
700673
ch_log_debug3("Could allocate filename buffer for file \"%s\". Error=%s\n", filename, strerror(errno));

src/exactio/exactio_exanic.c

-19
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ static eio_error_t exa_construct(eio_stream_t* this, exa_args_t* args)
298298
const char* interface_tx = args->interface_tx;
299299
const bool promisc = args->promisc;
300300
const bool kernel_bypass = args->kernel_bypass;
301-
const bool clear_buff = args->clear_buff;
302301

303302
exa_priv_t* priv = IOSTREAM_GET_PRIVATE(this);
304303

@@ -322,24 +321,6 @@ static eio_error_t exa_construct(eio_stream_t* this, exa_args_t* args)
322321
return 1;
323322
}
324323

325-
if(clear_buff){
326-
fprintf(stderr, "Warning: clearing rx buffer on %s\n", interface_rx);
327-
const size_t rx_buff_sz = 64 * 1024;
328-
char rx_buff[rx_buff_sz];
329-
int64_t clear_cnt = -1;
330-
for(ssize_t err = -1; err != 0; clear_cnt++){
331-
err =exanic_receive_frame(priv->rx, rx_buff, rx_buff_sz, NULL);
332-
if(err < 0){
333-
fprintf(stderr,"Warning: rx error %li on %s\n", err, interface_rx);
334-
}
335-
}
336-
if(clear_cnt > 0){
337-
fprintf(stderr, "Cleared stale packets from rx buffer on %s\n",
338-
interface_rx);
339-
}
340-
fprintf(stderr,"Done clearing rx buffer on %s\n", interface_rx);
341-
}
342-
343324
if(set_exanic_params(priv->rx_nic, priv->rx_dev, priv->rx_port,
344325
promisc,kernel_bypass)){
345326
return 1;

src/exactio/exactio_exanic.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ typedef struct {
3030
char* interface_tx;
3131
bool promisc;
3232
bool kernel_bypass;
33-
bool clear_buff;
3433
} exa_args_t;
3534

3635
NEW_IOSTREAM_DECLARE(exa,exa_args_t);

0 commit comments

Comments
 (0)