Changeset b24d186


Ignore:
Timestamp:
01/29/16 11:13:09 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
libtrace4, pfring
Children:
9e7c502, ea911b7
Parents:
21c0d70
Message:

Couple of optimisations introduced after looking at callgrind output

Only reset trace->last_packet to NULL in situations where we aren't
about to immediately read a new packet. The overhead of grabbing
and releasing the mutex to do this is massive for an operation we
are about to immediately overwrite.

Removed loop that checks the integrity of the packet array before
filling it with new data. This consumes a lot of CPU cycles for a
condition that really shouldn't happen anyway -- the fact that we
have asserts here suggest that this is more of a sanity check during
development than a condition we might have to deal with.

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace_int.h

    rd8b05b7 rb24d186  
    383383#define LIBTRACE_STAT_MAGIC 0x41
    384384
    385 void trace_fin_packet(libtrace_packet_t *packet);
     385void trace_fin_packet(libtrace_packet_t *packet, int updatetrace);
    386386void libtrace_zero_thread(libtrace_thread_t * t);
    387387void store_first_packet(libtrace_t *libtrace, libtrace_packet_t *packet, libtrace_thread_t *t);
  • lib/trace.c

    r92a2bf6 rb24d186  
    554554        /* Finish the last packet we read - for backwards compatibility */
    555555        if (libtrace->last_packet)
    556                 trace_fin_packet(libtrace->last_packet);
     556                trace_fin_packet(libtrace->last_packet, 1);
    557557        assert(libtrace->last_packet == NULL);
    558558
     
    700700        /* Finish any the last packet we read - for backwards compatibility */
    701701        if (libtrace->last_packet)
    702                 trace_fin_packet(libtrace->last_packet);
     702                trace_fin_packet(libtrace->last_packet, 1);
    703703        assert(libtrace->last_packet == NULL);
    704704
     
    851851 * use trace_destroy_packet() for those diabolical purposes.
    852852 */
    853 void trace_fin_packet(libtrace_packet_t *packet) {
     853void trace_fin_packet(libtrace_packet_t *packet, int updatetrace) {
    854854        if (packet)
    855855        {
     
    863863                }
    864864
    865                 if (packet->trace) {
     865                if (updatetrace && packet->trace) {
    866866                        pthread_mutex_lock(&packet->trace->libtrace_lock);
    867867                        if (packet->trace->last_packet == packet)
     
    915915                 */
    916916                if (packet->trace == libtrace)
    917                         trace_fin_packet(packet);
     917                        trace_fin_packet(packet, 0);
    918918                do {
    919919                        size_t ret;
     
    938938                                if (filtret == 0) {
    939939                                        ++libtrace->filtered_packets;
    940                                         trace_fin_packet(packet);
     940                                        trace_fin_packet(packet, 0);
    941941                                        continue;
    942942                                }
     
    13171317
    13181318        /* Free the last packet */
    1319         trace_fin_packet(packet);
     1319        trace_fin_packet(packet, 0);
    13201320       
    13211321        /* Store the trace we are reading from into the packet opaque
  • lib/trace_parallel.c

    rd8b05b7 rb24d186  
    421421                dup = trace_copy_packet(pkt);
    422422                /* Release the external buffer */
    423                 trace_fin_packet(pkt);
     423                trace_fin_packet(pkt, 1);
    424424                /* Copy the duplicated packet over the existing */
    425425                memcpy(pkt, dup, sizeof(libtrace_packet_t));
     
    480480                if (trace->perpkt_cbs->message_packet)
    481481                        *packet = (*trace->perpkt_cbs->message_packet)(trace, t, trace->global_blob, t->user_data, *packet);
    482                 trace_fin_packet(*packet);
     482                trace_fin_packet(*packet, 0);
    483483        } else {
    484484                assert((*packet)->error == READ_TICK);
     
    12731273                        packets[i] = tmp;
    12741274                } else {
    1275                         trace_fin_packet(packets[i]);
     1275                        trace_fin_packet(packets[i], 0);
    12761276                }
    12771277        }
     
    13061306        if (libtrace->format->pread_packets) {
    13071307                int ret;
     1308                /*
    13081309                for (i = 0; i < (int) nb_packets; ++i) {
    13091310                        assert(i[packets]);
     
    13151316                        }
    13161317                }
     1318                */
    13171319                do {
    13181320                        ret=libtrace->format->pread_packets(libtrace, t,
     
    25512553        assert(packet);
    25522554        /* Always release any resources this might be holding */
    2553         trace_fin_packet(packet);
     2555        trace_fin_packet(packet, 0);
    25542556        libtrace_ocache_free(&libtrace->packet_freelist, (void **) &packet, 1, 1);
    25552557}
Note: See TracChangeset for help on using the changeset viewer.