Changeset 1407294


Ignore:
Timestamp:
03/18/15 16:31:49 (6 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:
963b13b
Parents:
6c84681
Message:

Remove HASHER_HARDWARE and doc/code tidies

We don't want to expose this option to the user as it was only used internally.
As it happens we can completely remove it if needed.

Remove error handling from start thread and fix gcc warning in start thread.

Location:
lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dpdk.c

    re3d534f r1407294  
    879879                        toeplitz_create_bikey(FORMAT(libtrace)->rss_key);
    880880                        return 0;
    881                 case HASHER_HARDWARE:
    882881                case HASHER_CUSTOM:
    883882                        // We don't support these
  • lib/format_linux_common.c

    ra978dec r1407294  
    527527                                        return 0;
    528528                                case HASHER_CUSTOM:
    529                                 case HASHER_HARDWARE:
    530529                                        return -1;
    531530                        }
  • lib/libtrace_parallel.h

    r6a6e6a8 r1407294  
    284284};
    285285
     286/** The hasher types avaliable to libtrace application.
     287 * These can be selected using trace_set_hasher().
     288 */
    286289enum hasher_types {
    287         /**
    288          * Balance load across CPUs best as possible, this is basically to say do
    289          * not care about hash. This might still might be implemented
    290          * using a hash or round robin etc. under the hood depending on the format
     290        /** Balance load across per-packet threads as best as possible, this is
     291         * basically to say I do not care about where packets are sent. This
     292         * might still might be implemented using a hash or round robin etc.
     293         * depending on the format and libtrace configuration.
    291294         */
    292295        HASHER_BALANCE,
    293296
    294         /** Use a hash which is bi-directional for TCP flows, that is packets with
    295          * the same hash are sent to the same thread. All non TCP packets will be
    296          * sent to the same thread. UDP may or may not be sent to separate
    297          * threads like TCP, this depends on the format support.
     297        /** Use a hash which is bi-directional for TCP and UDP flows, that is
     298         * packets with the same 5-tuple are sent to the same per-packet thread.
     299         * All non TCP/UDP packets will be sent to the same thread.
     300         *
     301         * @note it is possible that UDP packets may not be spread across
     302         * per-packet threads, depending upon the format support. In this case
     303         * they would be directed to a single per-packet thread.
    298304         */
    299305        HASHER_BIDIRECTIONAL,
    300306
    301         /**
    302          * Use a hash which is uni-directional across TCP flows, that means the
    303          * opposite directions of the same 5 tuple might end up on separate cores.
    304          * Otherwise is identical to HASHER_BIDIRECTIONAL
     307        /** Use a hash which is uni-directional across TCP and UDP flows, this
     308         * means the opposing directions of the same 5-tuple might end up on
     309         * different per-packet threads.
     310         * Otherwise this is identical to HASHER_BIDIRECTIONAL
    305311         */
    306312        HASHER_UNIDIRECTIONAL,
    307313
    308314        /**
    309          * Always use the user supplied hasher, this currently disables native
    310          * support and is likely significantly slower.
    311          */
    312         HASHER_CUSTOM,
    313 
    314         /**
    315          * This is not a valid option, used internally only!!! TODO remove
    316          * Set by the format if the hashing is going to be done in hardware
    317          */
    318         HASHER_HARDWARE
     315         * Always use the user supplied hasher, this disables native
     316         * support in and is likely significantly slower.
     317         */
     318        HASHER_CUSTOM
    319319};
    320320
     
    676676/// @}
    677677
    678 
    679 /** TODO DOXS
     678/** Set the hasher function for a parallel trace.
     679 *
     680 * @param[in] trace The parallel trace to apply the hasher to
     681 * @param[in] type The type of hashing to apply, see enum hasher_types
     682 * @param[in] hasher A hasher function to use [Optional]
     683 * @param[in] data Data passed to the hasher function [Optional]
     684 *
     685 * @return 0 if successful otherwise -1 on error
     686 *
     687 * The hasher function in a parallel trace can be used to control which
     688 * per-packet thread a packets is processed by.
     689 *
     690 * HASHER_BALANCE is the default and will dispatch packets as fast as possible
     691 * to all threads arbitrarily. As such when called the hasher and
     692 * data parameters must be set to NULL.
     693 *
     694 * HASHER_CUSTOM will force the libtrace to use the user defined function. As
     695 * such the hasher parameter must be supplied.
     696 *
     697 * With other defined hasher types we will try to push the hashing into the format
     698 * by default. In this case the hasher parameter is optional and will be
     699 * preferred over the default supplied by libtrace.
     700 *
     701 * @note When supplying a hasher function it should be thread-safe as it could
     702 * be run in parallel by libtrace. Ideally this should rely upon no state, other
     703 * than some form of seed value supplied in data.
    680704 */
    681705DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type, fn_hasher hasher, void *data);
     
    685709 * as such making use of built-in types is important.
    686710 *
    687  * User specific results should be defined as values greater than RESULT_USER(1000)
     711 * Custom result types users should be defined as RESULT_USER(1000) or greater.
    688712 *
    689713 */
     
    731755                                    int type);
    732756
    733 /** Check if a dedicated hasher thread is being used
     757/** Check if a dedicated hasher thread is being used.
    734758 *
    735759 * @return True if the trace has dedicated hasher thread otherwise false.
     760 *
     761 * This is valid once the trace is running after calling trace_pstart().
    736762 */
    737763DLLEXPORT bool trace_has_dedicated_hasher(libtrace_t * libtrace);
  • lib/trace_parallel.c

    r6a6e6a8 r1407294  
    657657
    658658        pthread_exit(NULL);
    659 };
     659}
    660660
    661661/**
     
    13141314
    13151315/**
     1316 * @return the number of CPU cores on the machine. -1 if unknown.
     1317 */
     1318SIMPLE_FUNCTION static int get_nb_cores() {
     1319        // TODO add BSD support
     1320        return sysconf(_SC_NPROCESSORS_ONLN);
     1321}
     1322
     1323/**
    13161324 * Verifies the configuration and sets default values for any values not
    13171325 * specified by the user.
    13181326 */
    13191327static void verify_configuration(libtrace_t *libtrace) {
    1320         bool require_hasher = false;
    1321 
    1322         /* Might we need a dedicated hasher thread? */
    1323         if (libtrace->hasher && libtrace->hasher_type != HASHER_HARDWARE) {
    1324                 require_hasher = true;
    1325         }
    13261328
    13271329        if (libtrace->config.hasher_queue_size <= 0)
     
    13291331
    13301332        if (libtrace->config.perpkt_threads <= 0) {
    1331                 // TODO add BSD support
    1332                 libtrace->perpkt_thread_count = sysconf(_SC_NPROCESSORS_ONLN);
     1333                libtrace->perpkt_thread_count = get_nb_cores();
    13331334                if (libtrace->perpkt_thread_count <= 0)
    13341335                        // Lets just use one
     
    13541355                libtrace->combiner = combiner_unordered;
    13551356
    1356 
    13571357        /* Figure out if we are using a dedicated hasher thread? */
    1358         if (require_hasher && libtrace->perpkt_thread_count > 1) {
     1358        if (libtrace->hasher && libtrace->perpkt_thread_count > 1) {
    13591359                libtrace->hasher_thread.type = THREAD_HASHER;
    13601360        }
     
    13821382                       int perpkt_num,
    13831383                       const char *name) {
    1384         int ret;
     1384        pthread_attr_t attrib;
     1385        cpu_set_t cpus;
     1386        int ret, i;
    13851387        assert(t->type == THREAD_EMPTY);
    13861388        t->trace = trace;
     
    13891391        t->type = type;
    13901392        t->state = THREAD_RUNNING;
    1391         ret = pthread_create(&t->tid, NULL, start_routine, (void *) trace);
     1393
     1394        CPU_ZERO(&cpus);
     1395        for (i = 0; i < get_nb_cores(); i++)
     1396                CPU_SET(i, &cpus);
     1397        pthread_attr_init(&attrib);
     1398        pthread_attr_setaffinity_np(&attrib, sizeof(cpus), &cpus);
     1399
     1400        ret = pthread_create(&t->tid, &attrib, start_routine, (void *) trace);
     1401        pthread_attr_destroy(&attrib);
    13921402        if (ret != 0) {
    13931403                libtrace_zero_thread(t);
    1394                 trace_set_err(trace, ret, "Failed to create a thread");
     1404                trace_set_err(trace, ret, "Failed to create a thread of type=%d\n", type);
    13951405                return -1;
    13961406        }
     
    15681578                                   THREAD_HASHER, hasher_entry, -1,
    15691579                                   "hasher-thread");
    1570                 if (ret != 0) {
    1571                         trace_set_err(libtrace, errno, "trace_pstart "
    1572                                       "failed to start a hasher thread.");
     1580                if (ret != 0)
    15731581                        goto cleanup_started;
    1574                 }
    15751582                libtrace->pread = trace_pread_packet_hasher_thread;
    15761583        } else {
     
    15921599                                   THREAD_PERPKT, perpkt_threads_entry, i,
    15931600                                   name);
    1594                 if (ret != 0) {
    1595                         trace_set_err(libtrace, errno, "trace_pstart "
    1596                                       "failed to start a perpkt thread.");
     1601                if (ret != 0)
    15971602                        goto cleanup_threads;
    1598                 }
    15991603        }
    16001604
     
    16061610                                   THREAD_REPORTER, reporter_entry, -1,
    16071611                                   "reporter_thread");
    1608                 if (ret != 0) {
    1609                         trace_set_err(libtrace, errno, "trace_pstart "
    1610                                       "failed to start reporter thread.");
     1612                if (ret != 0)
    16111613                        goto cleanup_threads;
    1612                 }
    16131614        }
    16141615
     
    16181619                                   THREAD_KEEPALIVE, keepalive_entry, -1,
    16191620                                   "keepalive_thread");
    1620                 if (ret != 0) {
    1621                         trace_set_err(libtrace, errno, "trace_pstart "
    1622                                       "failed to start keepalive thread.");
     1621                if (ret != 0)
    16231622                        goto cleanup_threads;
    1624                 }
    16251623        }
    16261624
     
    17601758                        libtrace_message_t message = {0};
    17611759                        message.code = MESSAGE_DO_PAUSE;
    1762                         trace_message_thread(libtrace, &libtrace->perpkt_threads[i], &message);
     1760                        ASSERT_RET(trace_message_thread(libtrace, &libtrace->perpkt_threads[i], &message), != -1);
    17631761                        if(trace_has_dedicated_hasher(libtrace)) {
    17641762                                // The hasher has stopped and other threads have messages waiting therefore
     
    18701868}
    18711869
    1872 /**
    1873  * Set the hasher type along with a selected function, if hardware supports
    1874  * that generic type of hashing it will be used otherwise the supplied
    1875  * hasher function will be used and passed data when called.
    1876  *
    1877  * @return 0 if successful otherwise -1 on error
    1878  */
    18791870DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type, fn_hasher hasher, void *data) {
    18801871        int ret = -1;
    1881         if (type == HASHER_HARDWARE || (type == HASHER_CUSTOM && !hasher) || (type == HASHER_BALANCE && hasher)) {
     1872        if ((type == HASHER_CUSTOM && !hasher) || (type == HASHER_BALANCE && hasher)) {
    18821873                return -1;
    18831874        }
     
    19001891
    19011892        if (ret == -1) {
    1902                 // We have to deal with this ourself
    1903                 // This most likely means single threaded reading of the trace
     1893                /* We have to deal with this ourself */
    19041894                if (!hasher) {
    19051895                        switch (type)
     
    19181908                                        toeplitz_init_config(trace->hasher_data, 0);
    19191909                                        return 0;
    1920                                 case HASHER_HARDWARE:
    1921                                         return -1;
    19221910                        }
    19231911                        return -1;
    19241912                }
    19251913        } else {
    1926                 // The hardware is dealing with this yay
    1927                 trace->hasher_type = HASHER_HARDWARE;
     1914                /* If the hasher is hardware we zero out the hasher and hasher
     1915                 * data fields - only if we need a hasher do we do this */
     1916                trace->hasher = NULL;
     1917                trace->hasher_data = NULL;
    19281918        }
    19291919
     
    20572047{
    20582048        int i;
    2059         int missed;
     2049        int missed = 0;
    20602050        if (message->sender == NULL)
    20612051                message->sender = get_thread_descriptor(libtrace);
Note: See TracChangeset for help on using the changeset viewer.