Changeset ee58d0d


Ignore:
Timestamp:
08/12/11 14:22:16 (9 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
c29a0e0
Parents:
44028d4
Message:
  • Improved performance by caching more stuff, especially L2 headers and various "remaining" values - not much point caching something if you need to re-read the entire packet to calculate "remaining" still :)
  • Also improved performance of trace_get_layer2 by avoiding an effective double call of trace_get_packet_buffer
  • Fixed bug with payload length calculation if the packet has extra padding beyond what the IP len states
  • Improved (hopefully) performance when reading ERF traces by avoiding updating the drops counter if the loss counter was zero (should save an ntohs at least)
Location:
lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lib/format_erf.c

    r5f329ab ree58d0d  
    431431                /* No idea how we get this yet */
    432432
    433         } else {
     433        } else if (erfptr->lctr) {
    434434                DATA(libtrace)->drops += ntohs(erfptr->lctr);
    435435        }
  • lib/libtrace.h.in

    r9ca0b29 ree58d0d  
    421421        int capture_length;             /**< Cached capture length */
    422422        int payload_length;             /**< Cached payload length */
     423        void *l2_header;                /**< Cached link header */
     424        libtrace_linktype_t link_type;  /**< Cached link type */
     425        uint32_t l2_remaining;          /**< Cached link remaining */
    423426        void *l3_header;                /**< Cached l3 header */
    424427        uint16_t l3_ethertype;          /**< Cached l3 ethertype */
     428        uint32_t l3_remaining;          /**< Cached l3 remaining */
    425429        void *l4_header;                /**< Cached transport header */
    426430        uint8_t transport_proto;        /**< Cached transport protocol */
     431        uint32_t l4_remaining;          /**< Cached transport remaining */
    427432} libtrace_packet_t;
    428433
  • lib/protocols_l2.c

    r14cc9ce ree58d0d  
    350350        if (remaining == NULL)
    351351                remaining = &dummyrem;
    352        
    353         meta = trace_get_packet_meta(packet, linktype, remaining);
     352
     353        if (packet->l2_header) {
     354                /* Use cached values */
     355                *linktype = packet->link_type;
     356                *remaining = packet->l2_remaining;
     357                return packet->l2_header;
     358        }
     359
     360        /* Code looks a bit inefficient, but I'm actually trying to avoid
     361         * calling trace_get_packet_buffer more than once like we used to.
     362         */
     363       
     364        meta = trace_get_packet_buffer(packet, linktype, remaining);
    354365
    355366        /* If there are no meta-data headers, we just return the start of the
    356367         * packet buffer, along with the linktype, etc.
    357368         */
    358         if (meta == NULL)
    359                 return trace_get_packet_buffer(packet, linktype, remaining);
    360        
     369        switch(*linktype) {
     370                /* meta points to a layer 2 header! */
     371                case TRACE_TYPE_HDLC_POS:
     372                case TRACE_TYPE_ETH:
     373                case TRACE_TYPE_ATM:
     374                case TRACE_TYPE_80211:
     375                case TRACE_TYPE_NONE:
     376                case TRACE_TYPE_POS:
     377                case TRACE_TYPE_AAL5:
     378                case TRACE_TYPE_DUCK:
     379                case TRACE_TYPE_LLCSNAP:
     380                case TRACE_TYPE_PPP:
     381                case TRACE_TYPE_METADATA:
     382                case TRACE_TYPE_NONDATA:
     383                        ((libtrace_packet_t*)packet)->link_type = *linktype;
     384                        ((libtrace_packet_t*)packet)->l2_header = meta;
     385                        ((libtrace_packet_t*)packet)->l2_remaining = *remaining;
     386                        return meta;
     387                case TRACE_TYPE_LINUX_SLL:
     388                case TRACE_TYPE_80211_RADIO:
     389                case TRACE_TYPE_80211_PRISM:
     390                case TRACE_TYPE_PFLOG:
     391                        break;
     392        }
     393
    361394        /* If there are meta-data headers, we need to skip over them until we
    362395         * find a non-meta data header and return that.
     
    381414                                case TRACE_TYPE_METADATA:
    382415                                case TRACE_TYPE_NONDATA:
     416                                        ((libtrace_packet_t*)packet)->link_type = *linktype;
     417                                        ((libtrace_packet_t*)packet)->l2_header = meta;
     418                                        ((libtrace_packet_t*)packet)->l2_remaining = *remaining;
    383419                                        return meta;
    384420                                case TRACE_TYPE_LINUX_SLL:
     
    396432                meta = nexthdr;
    397433        }
     434
    398435}
    399436
  • lib/protocols_l3.c

    rd247823 ree58d0d  
    126126                        return NULL;
    127127                }
     128                /* If the packet features extra "padding", we probably
     129                 * don't want that counting as possible payload, e.g. for
     130                 * payload length calculations */
     131                if (*remaining > ntohs(ipptr->ip_len))
     132                        *remaining = ntohs(ipptr->ip_len);
     133
    128134                *remaining-=(ipptr->ip_hl * 4);
    129135        }
     
    223229        if (packet->l3_header)
    224230        {
     231                /*
    225232                link = trace_get_packet_buffer(packet,&linktype,remaining);
    226233
    227234                if (!link)
    228235                        return NULL;
     236                */
    229237
    230238                *ethertype = packet->l3_ethertype;
    231                 *remaining -= (packet->l3_header - link);
     239                /* *remaining -= (packet->l3_header - link); */
     240                *remaining = packet->l3_remaining;
    232241
    233242                return packet->l3_header;
     
    276285        ((libtrace_packet_t*)packet)->l3_ethertype = *ethertype;
    277286        ((libtrace_packet_t*)packet)->l3_header = iphdr;
     287        ((libtrace_packet_t*)packet)->l3_remaining = *remaining;
    278288
    279289        return iphdr;
  • lib/protocols_transport.c

    r9cc1266 ree58d0d  
    147147
    148148        if (packet->l4_header) {
     149                /*
    149150                void *link;
    150151                libtrace_linktype_t linktype;
     
    152153                if (!link)
    153154                        return NULL;
     155                */
    154156                *proto = packet->transport_proto;
    155                 *remaining -= (packet->l4_header - link);
     157                /* *remaining -= (packet->l4_header - link); */
     158                *remaining = packet->l4_remaining;
    156159                return packet->l4_header;
    157160        }
     
    185188        ((libtrace_packet_t *)packet)->transport_proto = *proto;
    186189        ((libtrace_packet_t *)packet)->l4_header = transport;
     190        ((libtrace_packet_t *)packet)->l4_remaining = *remaining;
    187191
    188192
  • lib/trace.c

    rb6664e8 ree58d0d  
    18221822void trace_clear_cache(libtrace_packet_t *packet) {
    18231823
     1824        packet->l2_header = NULL;
    18241825        packet->l3_header = NULL;
    18251826        packet->l4_header = NULL;
     1827        packet->link_type = 0;
    18261828        packet->l3_ethertype = 0;
    18271829        packet->transport_proto = 0;
    18281830        packet->capture_length = -1;
    18291831        packet->payload_length = -1;
     1832        packet->l2_remaining = 0;
     1833        packet->l3_remaining = 0;
     1834        packet->l4_remaining = 0;
    18301835
    18311836}
Note: See TracChangeset for help on using the changeset viewer.