Ignore:
Timestamp:
02/12/15 19:04:26 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
0b01fea
Parents:
771ab22
Message:

Gets the ring format back to a working state, the bulk of the refactoring
is now done.

I've opted to remove the inheritance way of grabbing shared functions
and replaced it with a file containing the common functions. Hopefully
this is more obvious that both int and ring depend on these.

I've also reworked the formats to be stream orientated, which removed
duplicates of heaps of functions. And allows the parallel and single
thread code to be almost identical.

After doing this many of the places where we had differences in
functions between ring and int disappeared.

I've also upped the MAX_ORDER to 11, used in allocating memory
from the kernel for the ring format.
Since this seems to work on the testing machines.
And we'll continue to fallback to smaller values if needed anyway.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • lib/format_linux_common.h

    r771ab22 r6cf3ca0  
    66 */
    77
     8#ifndef FORMAT_LINUX_COMMON_H
     9#define FORMAT_LINUX_COMMON_H
     10
    811#include "libtrace.h"
    912#include "libtrace_int.h"
     
    2326#include <fcntl.h>
    2427
    25 /* MAX_ORDER is defined in linux/mmzone.h. 10 is default for 2.4 kernel.
     28/* MAX_ORDER is defined in linux/mmzone.h. 11 is default for 3.0 kernels.
    2629 * max_order will be decreased by one if the ring buffer fails to allocate.
    27  * Used to get correct sized buffers from the kernel.
    28  */
    29 /* TODO: This is set to 11 in atleast the 3.x kernels. We should investigate
    30  * setting this higher to see if it improves performance. If not, then I guess
    31  * we can just leave it.
    32  */
    33 #define MAX_ORDER 10
    34 
    35 /* Cached page size, the page size shouldn't be changing */
    36 static int pagesize = 0;
    37 
     30 * Used to get the correct sized buffers from the kernel.
     31 */
     32#define MAX_ORDER 11
    3833/* Number of frames in the ring used by both TX and TR rings. More frames
    3934 * hopefully means less packet loss, especially if traffic comes in bursts.
     
    195190        /* Flag indicating whether the statistics are current or not */
    196191        int stats_valid;
    197         /* The actual format being used - ring vs int */
    198         libtrace_rt_types_t format;
    199192        /* The current ring buffer layout */
    200193        struct tpacket_req req;
     
    206199         * so we use a random here to try avoid collisions */
    207200        uint16_t fanout_group;
    208         /* Parent format so we can call parent functions */
    209         struct libtrace_format_t *parent_format;
    210201        /* When running in parallel mode this is malloc'd with an array
    211202         * file descriptors from packet fanout will use, here we assume/hope
     
    231222        /* Used to determine buffer size for the ring buffer */
    232223        uint32_t max_order;
    233         /* Parent format so we can call parent functions */
    234         struct libtrace_format_t *parent_format;
    235224};
    236225
     
    244233} ALIGN_STRUCT(CACHE_LINE_SIZE);
    245234
    246 #define ZERO_LINUX_STREAM {-1, NULL, 0}
     235#define ZERO_LINUX_STREAM {-1, MAP_FAILED, 0}
    247236
    248237
     
    277266#define FORMAT_DATA_OUT DATA_OUT(libtrace)
    278267
    279 #define PARENT FORMAT_DATA->parent_format
    280 #define PARENT_OUT FORMAT_DATA_OUT->parent_format
    281 
    282268#define FORMAT_DATA_HEAD FORMAT_DATA->per_stream->head
    283269#define FORMAT_DATA_FIRST ((struct linux_per_stream_t *)FORMAT_DATA_HEAD->data)
     
    287273        + TPACKET_ALIGN(sizeof(struct tpacket2_hdr))))
    288274
    289 /* TODO: Decide if inheritance is how we want to do this. Basically, ring is
    290  * a subclass of native and so it makes sense to reuse the native code where
    291  * possible. Moving ring into a new file really helps with readability, and
    292  * also helps us not carry so much ring data around in the native format. */
    293 struct libtrace_format_t *get_native_format(void);
    294 
    295 static inline libtrace_linktype_t get_libtrace_link_type(uint16_t linktype)
    296 {
    297         /* Convert the ARPHRD type into an appropriate libtrace link type */
    298         switch (linktype) {
    299                 case LIBTRACE_ARPHRD_ETHER:
    300                 case LIBTRACE_ARPHRD_LOOPBACK:
    301                         return TRACE_TYPE_ETH;
    302                 case LIBTRACE_ARPHRD_PPP:
    303                         return TRACE_TYPE_NONE;
    304                 case LIBTRACE_ARPHRD_IEEE80211_RADIOTAP:
    305                         return TRACE_TYPE_80211_RADIO;
    306                 case LIBTRACE_ARPHRD_IEEE80211:
    307                         return TRACE_TYPE_80211;
    308                 case LIBTRACE_ARPHRD_SIT:
    309                 case LIBTRACE_ARPHRD_NONE:
    310                         return TRACE_TYPE_NONE;
    311                 default: /* shrug, beyond me! */
    312                         printf("unknown Linux ARPHRD type 0x%04x\n",linktype);
    313                         return (libtrace_linktype_t)~0U;
    314         }
    315 }
    316 
    317 static inline libtrace_direction_t get_libtrace_direction(uint8_t pkttype)
    318 {
    319         switch (pkttype) {
    320                 case PACKET_OUTGOING:
    321                 case PACKET_LOOPBACK:
    322                         return TRACE_DIR_OUTGOING;
    323                 case PACKET_OTHERHOST:
    324                         return TRACE_DIR_OTHER;
    325                 default:
    326                         return TRACE_DIR_INCOMING;
    327         }
    328 }
    329 
    330 static libtrace_direction_t set_direction(struct sockaddr_ll * skadr,
    331                                           libtrace_direction_t direction)
    332 {
    333         switch (direction) {
    334                 case TRACE_DIR_OUTGOING:
    335                         skadr->sll_pkttype = PACKET_OUTGOING;
    336                         return TRACE_DIR_OUTGOING;
    337                 case TRACE_DIR_INCOMING:
    338                         skadr->sll_pkttype = PACKET_HOST;
    339                         return TRACE_DIR_INCOMING;
    340                 case TRACE_DIR_OTHER:
    341                         skadr->sll_pkttype = PACKET_OTHERHOST;
    342                         return TRACE_DIR_OTHER;
    343                 default:
    344                         return -1;
    345         }
    346 }
     275/* Common functions */
     276#ifdef HAVE_NETPACKET_PACKET_H
     277int linuxcommon_init_input(libtrace_t *libtrace);
     278int linuxcommon_init_output(libtrace_out_t *libtrace);
     279int linuxcommon_probe_filename(const char *filename);
     280int linuxcommon_config_input(libtrace_t *libtrace, trace_option_t option,
     281                             void *data);
     282void linuxcommon_close_input_stream(libtrace_t *libtrace,
     283                                    struct linux_per_stream_t *stream);
     284int linuxcommon_start_input_stream(libtrace_t *libtrace,
     285                                   struct linux_per_stream_t *stream);
     286inline int linuxcommon_to_packet_fanout(libtrace_t *libtrace,
     287                                        struct linux_per_stream_t *stream);
     288int linuxcommon_pause_input(libtrace_t *libtrace);
     289int linuxcommon_get_fd(const libtrace_t *libtrace);
     290int linuxcommon_fin_input(libtrace_t *libtrace);
     291int linuxcommon_pconfig_input(libtrace_t *libtrace,
     292                              trace_parallel_option_t option,
     293                              void *data);
     294int linuxcommon_pregister_thread(libtrace_t *libtrace,
     295                                 libtrace_thread_t *t,
     296                                 bool reading);
     297int linuxcommon_pstart_input(libtrace_t *libtrace,
     298                             int (*start_stream)(libtrace_t *, struct linux_per_stream_t*));
     299#endif /* HAVE_NETPACKET_PACKET_H */
     300
     301uint64_t linuxcommon_get_captured_packets(libtrace_t *libtrace);
     302uint64_t linuxcommon_get_filtered_packets(libtrace_t *libtrace);
     303uint64_t linuxcommon_get_dropped_packets(libtrace_t *libtrace);
     304inline libtrace_direction_t linuxcommon_get_direction(uint8_t pkttype);
     305inline libtrace_direction_t linuxcommon_set_direction(struct sockaddr_ll * skadr,
     306                                                 libtrace_direction_t direction);
     307inline libtrace_linktype_t linuxcommon_get_link_type(uint16_t linktype);
     308
     309
     310#endif /* FORMAT_LINUX_COMMON_H */
Note: See TracChangeset for help on using the changeset viewer.