Changeset 84dbd79


Ignore:
Timestamp:
10/24/18 15:32:05 (22 months ago)
Author:
Shane Alcock <salcock@…>
Branches:
ringperformance
Parents:
f96ad61
Message:

Improve performance by removing wasteful sanity checking in pread

While these sanity checks would normally be a very good idea,
they actually end up consuming a lot of CPU cycles at high
packet rates and could reduce capture and processing throughput.

  • the sanity checks mostly protect against things that should *never* be touched (i.e setting packet buffer types to invalid values etc) by anyone other than libtrace itself. I know that we can't trust users to not do stupid stuff with the pointers we give them, but we also can't be wasting the CPU time of sensible users by constantly checking that they are not doing something weird either.
  • often, a pread will not use all of the packets in the array so we're frequently checking the integrity of packets that have not been used since the last time we checked them. Again, this is a waste of time that really starts to add up at high packet rates.

I accept that removing these checks might not be to everyone's
liking. I think there is scope to put them back in at some
later point, probably wrapped inside some preprocessor
conditional which will allow people to choose whether to build
"safe" libtrace vs "high-performance" libtrace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace_parallel.c

    r37ee856 r84dbd79  
    13371337        if (libtrace->format->pread_packets) {
    13381338                int ret;
    1339                 for (i = 0; i < (int) nb_packets; ++i) {
    1340                         assert(i[packets]);
    1341                         if (!(packets[i]->buf_control==TRACE_CTRL_PACKET ||
    1342                               packets[i]->buf_control==TRACE_CTRL_EXTERNAL)) {
    1343                                 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,
    1344                                               "Packet passed to trace_read_packet() is invalid\n");
    1345                                 return -1;
    1346                         }
    1347                         packets[i]->which_trace_start = libtrace->startcount;
    1348                 }
    13491339                do {
    13501340                        ret=libtrace->format->pread_packets(libtrace, t,
     
    13551345                                return ret;
    13561346                        }
    1357 
    13581347                        if (libtrace->filter) {
    13591348                                int remaining;
     
    13721361                                        trace_set_capture_length(packets[i],
    13731362                                                        libtrace->snaplen);
     1363                                packets[i]->which_trace_start = libtrace->startcount;
    13741364                        }
    13751365                } while(ret == 0);
Note: See TracChangeset for help on using the changeset viewer.