Changeset 9e429e8 for lib/format_dpdk.c


Ignore:
Timestamp:
09/19/14 15:40:01 (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:
11cf9b1
Parents:
d994324 (diff), ea602cd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'upsteam/master' into develop

Conflicts:

README
lib/format_dpdk.c
lib/format_linux.c
lib/trace.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dpdk.c

    r50ce607 r9e429e8  
    6060#include <unistd.h>
    6161#include <endian.h>
     62#include <string.h>
     63
     64/* We can deal with any minor differences by checking the RTE VERSION
     65 * Typically DPDK backports some fixes (typically for building against
     66 * newer kernels) to the older version of DPDK.
     67 *
     68 * These get released with the rX suffix. The following macros where added
     69 * in these new releases.
     70 *
     71 * Below this is a log of version that required changes to the libtrace
     72 * code (that we still attempt to support).
     73 *
     74 * Currently 1.5 to 1.7 is supported.
     75 */
    6276#include <rte_eal.h>
     77#include <rte_version.h>
     78#ifndef RTE_VERSION_NUM
     79#       define RTE_VERSION_NUM(a,b,c,d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
     80#endif
     81#ifndef RTE_VER_PATCH_RELEASE
     82#       define RTE_VER_PATCH_RELEASE 0
     83#endif
     84#ifndef RTE_VERSION
     85#       define RTE_VERSION RTE_VERSION_NUM(RTE_VER_MAJOR,RTE_VER_MINOR, \
     86        RTE_VER_PATCH_LEVEL, RTE_VER_PATCH_RELEASE)
     87#endif
     88
     89/* 1.6.0r2 :
     90 *      rte_eal_pci_set_blacklist() is removed
     91 *      device_list is renamed ot pci_device_list
     92 *
     93 * Replaced by:
     94 *      rte_devargs (we can simply whitelist)
     95 */
     96#if RTE_VERSION <= RTE_VERSION_NUM(1, 6, 0, 1)
     97#       define DPDK_USE_BLACKLIST 1
     98#else
     99#       define DPDK_USE_BLACKLIST 0
     100#endif
     101
     102/*
     103 * 1.7.0 :
     104 *      rte_pmd_init_all is removed
     105 *
     106 * Replaced by:
     107 *      Nothing, no longer needed
     108 */
     109#if RTE_VERSION < RTE_VERSION_NUM(1, 7, 0, 0)
     110#       define DPDK_USE_PMD_INIT 1
     111#else
     112#       define DPDK_USE_PMD_INIT 0
     113#endif
     114
    63115#include <rte_per_lcore.h>
    64116#include <rte_debug.h>
     
    207259    int nb_tx_buf; /* The number of packet buffers in the tx ring */
    208260    struct rte_mempool * pktmbuf_pool; /* Our packet memory pool */
     261#if DPDK_USE_BLACKLIST
    209262    struct rte_pci_addr blacklist[BLACK_LIST_SIZE]; /* Holds our device blacklist */
     263        unsigned int nb_blacklist; /* Number of blacklist items in are valid */
     264#endif
    210265    char mempool_name[MEMPOOL_NAME_LEN]; /* The name of the mempool that we are using */
    211     unsigned int nb_blacklist; /* Number of blacklist items in are valid */
    212266    uint8_t rss_key[40]; // This is the RSS KEY
    213267#if HAS_HW_TIMESTAMPS_82580
     
    262316 * So blacklist all devices except the one that we wish to use so that
    263317 * the others can still be used as standard ethernet ports.
    264  */
    265 static void blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist)
     318 *
     319 * @return 0 if successful, otherwise -1 on error.
     320 */
     321#if DPDK_USE_BLACKLIST
     322static int blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist)
    266323{
    267324        struct rte_pci_device *dev = NULL;
     
    287344
    288345        rte_eal_pci_set_blacklist(format_data->blacklist, format_data->nb_blacklist);
    289 }
     346        return 0;
     347}
     348#else /* DPDK_USE_BLACKLIST */
     349#include <rte_devargs.h>
     350static int blacklist_devices(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist)
     351{
     352        char pci_str[20] = {0};
     353        snprintf(pci_str, sizeof(pci_str), PCI_PRI_FMT,
     354                 whitelist->domain,
     355                 whitelist->bus,
     356                 whitelist->devid,
     357                 whitelist->function);
     358        if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, pci_str) < 0) {
     359                return -1;
     360        }
     361        return 0;
     362}
     363#endif
    290364
    291365/**
     
    441515
    442516
    443 static inline int dpdk_init_enviroment(char * uridata, struct dpdk_format_data_t * format_data,
     517/**
     518 * XXX This is very bad XXX
     519 * But we have to do something to allow getopts nesting
     520 * Luckly normally the format is last so it doesn't matter
     521 * DPDK only supports modern systems so hopefully this
     522 * will continue to work
     523 */
     524struct saved_getopts {
     525        char *optarg;
     526        int optind;
     527        int opterr;
     528        int optopt;
     529};
     530
     531static void save_getopts(struct saved_getopts *opts) {
     532        opts->optarg = optarg;
     533        opts->optind = optind;
     534        opts->opterr = opterr;
     535        opts->optopt = optopt;
     536}
     537
     538static void restore_getopts(struct saved_getopts *opts) {
     539        optarg = opts->optarg;
     540        optind = opts->optind;
     541        opterr = opts->opterr;
     542        optopt = opts->optopt;
     543}
     544
     545static inline int dpdk_init_environment(char * uridata, struct dpdk_format_data_t * format_data,
    444546                                        char * err, int errlen) {
    445547    int ret; /* Returned error codes */
     
    451553    int i;
    452554    struct rte_config *cfg = rte_eal_get_configuration();
     555        struct saved_getopts save_opts;
    453556   
    454557#if DEBUG
     
    457560    rte_set_log_level(RTE_LOG_WARNING);
    458561#endif
    459     /* Using proc-type auto allows this to be either primary or secondary
    460      * Secondary allows two instances of libtrace to be used on different
    461      * ports. However current version of DPDK doesn't support this on the
    462      * same card (My understanding is this should work with two separate
    463      * cards).
     562    /*
     563     * Using unique file prefixes mean separate memory is used, unlinking
     564     * the two processes. However be careful we still cannot access a
     565     * port that already in use.
    464566     *
    465567     * Using unique file prefixes mean separate memory is used, unlinking
     
    518620    //snprintf(cpu_number, sizeof(cpu_number), "%x", 0x1 << (my_cpu - 1));
    519621
    520         /* Give this a name */
     622
     623        /* Give the memory map a unique name */
    521624        snprintf(mem_map, sizeof(mem_map), "libtrace-%d", (int) getpid());
    522625    /* rte_eal_init it makes a call to getopt so we need to reset the
    523626     * global optind variable of getopt otherwise this fails */
     627        save_getopts(&save_opts);
    524628    optind = 1;
    525629    if ((ret = rte_eal_init(argc, argv)) < 0) {
     
    528632        return -1;
    529633    }
    530 
     634        restore_getopts(&save_opts);
    531635    // These are still running but will never do anything with DPDK v1.7 we
    532636    // should remove this XXX in the future
     
    545649    dump_configuration();
    546650#endif
     651
     652#if DPDK_USE_PMD_INIT
    547653    /* This registers all available NICs with Intel DPDK
    548654     * These are not loaded until rte_eal_pci_probe() is called.
     
    553659        return -1;
    554660    }
     661#endif
    555662
    556663    /* Black list all ports besides the one that we want to use */
    557     blacklist_devices(format_data, &use_addr);
     664        if ((ret = blacklist_devices(format_data, &use_addr)) < 0) {
     665                snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed,"
     666                         " are you sure the address is correct?: %s", strerror(-ret));
     667                return -1;
     668        }
    558669
    559670    /* This loads DPDK drivers against all ports that are not blacklisted */
     
    595706    FORMAT(libtrace)->promisc = -1;
    596707    FORMAT(libtrace)->pktmbuf_pool = NULL;
     708#if DPDK_USE_BLACKLIST
    597709    FORMAT(libtrace)->nb_blacklist = 0;
     710#endif
    598711    FORMAT(libtrace)->paused = DPDK_NEVER_STARTED;
    599712    FORMAT(libtrace)->mempool_name[0] = 0;
     
    604717#endif
    605718       
    606     if (dpdk_init_enviroment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
     719    if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
    607720        trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err);
    608721        free(libtrace->format_data);
     
    628741    FORMAT(libtrace)->promisc = -1;
    629742    FORMAT(libtrace)->pktmbuf_pool = NULL;
     743#if DPDK_USE_BLACKLIST
    630744    FORMAT(libtrace)->nb_blacklist = 0;
     745#endif
    631746    FORMAT(libtrace)->paused = DPDK_NEVER_STARTED;
    632747    FORMAT(libtrace)->mempool_name[0] = 0;
     
    637752#endif
    638753
    639     if (dpdk_init_enviroment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
     754    if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) {
    640755        trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "%s", err);
    641756        free(libtrace->format_data);
     
    815930
    816931    /* First time started we need to alloc our memory, doing this here
    817      * rather than in enviroment setup because we don't have snaplen then */
     932     * rather than in environment setup because we don't have snaplen then */
    818933    if (format_data->paused == DPDK_NEVER_STARTED) {
    819934        if (format_data->snaplen == 0) {
     
    18071922                if (!trace_apply_filter(trace->filter, packet)) {
    18081923                    /* Failed the filter so we loop for another packet */
     1924                    trace->filtered_packets ++;
    18091925                    continue;
    18101926                }
    18111927            }
     1928            trace->accepted_packets ++;
    18121929        } else {
    18131930            /* We only want to sleep for a very short time - we are non-blocking */
Note: See TracChangeset for help on using the changeset viewer.