Changeset 6b98325


Ignore:
Timestamp:
03/23/15 17:52:17 (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:
773d5e2
Parents:
963b13b
Message:

Removes pconfig_input() and replaces trace_config() with trace_set_<option>

  • Removes trace_pconfig completely - only trace_set_hasher is left now in trace_config
  • Rework user configuration so this is no longer modified directly. Now we just apply it directly to a trace.
  • Many minor documentation fixes and additions
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dag25.c

    r526d9d0 r6b98325  
    583583                /* Live capture is always going to be realtime */
    584584                return -1;
     585        case TRACE_OPTION_HASHER:
     586                /* Lets just say we did this, it's currently still up to
     587                 * the user to configure this correctly. */
     588                return 0;
    585589        }
    586590        return -1;
     
    14801484        printf("\tnone\n");
    14811485        printf("\n");
    1482 }
    1483 
    1484 static int dag_pconfig_input(UNUSED libtrace_t *libtrace,
    1485                              trace_parallel_option_t option, UNUSED void *value)
    1486 {
    1487         /* We don't support any of these! Normally you configure the DAG card
    1488          * externally. */
    1489         switch(option) {
    1490         case TRACE_OPTION_SET_HASHER:
    1491         case TRACE_OPTION_SET_PERPKT_THREAD_COUNT:
    1492         case TRACE_OPTION_TRACETIME:
    1493         case TRACE_OPTION_TICK_INTERVAL:
    1494         case TRACE_OPTION_GET_CONFIG:
    1495         case TRACE_OPTION_SET_CONFIG:
    1496                 return -1;
    1497         }
    1498         /* We don't provide a default option to ensure that future options will
    1499          * generate a compiler warning. */
    1500 
    1501         return -1;
    15021486}
    15031487
     
    15811565        dag_pause_input,
    15821566        NULL,
    1583         dag_pconfig_input,
    15841567        dag_pregister_thread,
    15851568        NULL,
  • lib/format_dpdk.c

    r1407294 r6b98325  
    865865}
    866866
    867 static int dpdk_pconfig_input (libtrace_t *libtrace,
    868                                trace_parallel_option_t option,
    869                                void *data) {
    870         switch (option) {
    871         case TRACE_OPTION_SET_HASHER:
    872                 switch (*((enum hasher_types *) data))
    873                 {
    874                 case HASHER_BALANCE:
    875                 case HASHER_UNIDIRECTIONAL:
    876                         toeplitz_create_unikey(FORMAT(libtrace)->rss_key);
    877                         return 0;
    878                 case HASHER_BIDIRECTIONAL:
    879                         toeplitz_create_bikey(FORMAT(libtrace)->rss_key);
    880                         return 0;
    881                 case HASHER_CUSTOM:
    882                         // We don't support these
    883                         return -1;
    884                 }
    885                 break;
    886         }
    887         return -1;
    888 }
    889 
    890867/**
    891868 * Note here snaplen excludes the MAC checksum. Packets over
     
    913890                FORMAT(libtrace)->promisc=*(int*)data;
    914891                return 0;
     892        case TRACE_OPTION_HASHER:
     893                switch (*((enum hasher_types *) data))
     894                {
     895                case HASHER_BALANCE:
     896                case HASHER_UNIDIRECTIONAL:
     897                        toeplitz_create_unikey(FORMAT(libtrace)->rss_key);
     898                        return 0;
     899                case HASHER_BIDIRECTIONAL:
     900                        toeplitz_create_bikey(FORMAT(libtrace)->rss_key);
     901                        return 0;
     902                case HASHER_CUSTOM:
     903                        // We don't support these
     904                        return -1;
     905                }
     906                break;
    915907        case TRACE_OPTION_FILTER:
    916908                /* TODO filtering */
    917                 break;
    918909        case TRACE_OPTION_META_FREQ:
    919                 break;
    920910        case TRACE_OPTION_EVENT_REALTIME:
    921911                break;
     
    23352325        dpdk_pause_input,                   /* ppause */
    23362326        dpdk_fin_input,                     /* p_fin */
    2337         dpdk_pconfig_input,                 /* pconfig_input */
    23382327        dpdk_pregister_thread,              /* pregister_thread */
    23392328        dpdk_punregister_thread,            /* punregister_thread */
  • lib/format_linux_common.c

    r1407294 r6b98325  
    151151                        return linuxnative_configure_bpf(libtrace,
    152152                                        (libtrace_filter_t *) data);
     153                case TRACE_OPTION_HASHER:
     154                        switch (*((enum hasher_types *)data)) {
     155                                case HASHER_BALANCE:
     156                                        // Do fanout
     157                                        FORMAT_DATA->fanout_flags = PACKET_FANOUT_LB;
     158                                        // Or we could balance to the CPU
     159                                        return 0;
     160                                case HASHER_BIDIRECTIONAL:
     161                                case HASHER_UNIDIRECTIONAL:
     162                                        FORMAT_DATA->fanout_flags = PACKET_FANOUT_HASH;
     163                                        return 0;
     164                                case HASHER_CUSTOM:
     165                                        return -1;
     166                        }
     167                        break;
    153168                case TRACE_OPTION_META_FREQ:
    154169                        /* No meta-data for this format */
     
    510525}
    511526
    512 int linuxcommon_pconfig_input(libtrace_t *libtrace,
    513                               trace_parallel_option_t option,
    514                               void *data)
    515 {
    516         switch(option) {
    517                 case TRACE_OPTION_SET_HASHER:
    518                         switch (*((enum hasher_types *)data)) {
    519                                 case HASHER_BALANCE:
    520                                         // Do fanout
    521                                         FORMAT_DATA->fanout_flags = PACKET_FANOUT_LB;
    522                                         // Or we could balance to the CPU
    523                                         return 0;
    524                                 case HASHER_BIDIRECTIONAL:
    525                                 case HASHER_UNIDIRECTIONAL:
    526                                         FORMAT_DATA->fanout_flags = PACKET_FANOUT_HASH;
    527                                         return 0;
    528                                 case HASHER_CUSTOM:
    529                                         return -1;
    530                         }
    531                         break;
    532                 /* Avoid default: so that future options will cause a warning
    533                  * here to remind us to implement it, or flag it as
    534                  * unimplementable
    535                  */
    536         }
    537 
    538         /* Don't set an error - trace_config will try to deal with the
    539          * option and will set an error if it fails */
    540         return -1;
    541 }
    542 
    543527/* These counters reset with each read */
    544528static void linuxcommon_update_socket_statistics(libtrace_t *libtrace) {
  • lib/format_linux_common.h

    re4f27d1 r6b98325  
    315315int linuxcommon_get_fd(const libtrace_t *libtrace);
    316316int linuxcommon_fin_input(libtrace_t *libtrace);
    317 int linuxcommon_pconfig_input(libtrace_t *libtrace,
    318                               trace_parallel_option_t option,
    319                               void *data);
    320317int linuxcommon_pregister_thread(libtrace_t *libtrace,
    321318                                 libtrace_thread_t *t,
  • lib/format_linux_int.c

    r10c47a0 r6b98325  
    515515        linuxcommon_pause_input,        /* ppause */
    516516        linuxcommon_fin_input,          /* p_fin */
    517         linuxcommon_pconfig_input,      /* pconfig input */
    518517        linuxcommon_pregister_thread,   /* register thread */
    519518        NULL,                           /* unregister thread */
  • lib/format_linux_ring.c

    r10c47a0 r6b98325  
    761761        linuxcommon_pause_input,        /* ppause */
    762762        linuxcommon_fin_input,          /* p_fin */
    763         linuxcommon_pconfig_input,      /* pconfig input */
    764763        linuxcommon_pregister_thread,   /* register thread */
    765764        NULL,                           /* unregister thread */
  • lib/format_pcapfile.c

    r5ab626a r6b98325  
    264264                case TRACE_OPTION_PROMISC:
    265265                case TRACE_OPTION_FILTER:
     266                case TRACE_OPTION_HASHER:
    266267                        /* All these are either unsupported or handled
    267268                         * by trace_config */
  • lib/libtrace.h.in

    r6a082f8 r6b98325  
    12781278        /** If enabled, the libtrace event API will ignore time gaps between
    12791279         * packets when reading from a trace file */
    1280         TRACE_OPTION_EVENT_REALTIME
     1280        TRACE_OPTION_EVENT_REALTIME,
     1281
     1282        /** The hasher function for a parallel libtrace. It is recommended to
     1283         * access this option via trace_set_hasher(). */
     1284        TRACE_OPTION_HASHER
    12811285} trace_option_t;
    12821286
     
    12861290 * @param value         The value to set the option to
    12871291 * @return -1 if option configuration failed, 0 otherwise
    1288  * This should be called after trace_create, and before trace_start
     1292 *
     1293 * This should be called after trace_create(), and before trace_start()
     1294 *
     1295 * @note Please consider using the newer trace_set_X() functions to access
     1296 * this function.
    12891297 */
    12901298DLLEXPORT int trace_config(libtrace_t *libtrace,
    12911299                trace_option_t option,
    12921300                void *value);
     1301
     1302/** Maximum number of bytes to be captured for any given packet
     1303 *
     1304 * @param libtrace The trace object to apply the option to
     1305 * @param snaplen The snap length to set
     1306 * @return -1 if option configuration failed, 0 otherwise
     1307 */
     1308DLLEXPORT int trace_set_snaplen(libtrace_t *trace, int snaplen);
     1309
     1310/** If enabled, places a live capture interface into promiscuous mode
     1311 *
     1312 * @param libtrace The trace object to apply the option to
     1313 * @param promisc
     1314 * @return -1 if option configuration failed, 0 otherwise
     1315 */
     1316DLLEXPORT int trace_set_promisc(libtrace_t *trace, bool promisc);
     1317
     1318/** Apply this filter to all packets read from this trace
     1319 *
     1320 * @param libtrace The trace object to apply the option to
     1321 * @param filter The filter to apply
     1322 * @return -1 if option configuration failed, 0 otherwise
     1323 */
     1324DLLEXPORT int trace_set_filter(libtrace_t *trace, libtrace_filter_t *filter);
     1325
     1326/** Defines the frequency of meta-data reporting, e.g. DUCK packets
     1327 *
     1328 * @param libtrace The trace object to apply the option to
     1329 * @param freq The meta data frequency
     1330 * @return -1 if option configuration failed, 0 otherwise
     1331 */
     1332DLLEXPORT int trace_set_meta_freq(libtrace_t *trace, int freq);
     1333
     1334/** If enabled, the libtrace event API will ignore time gaps between
     1335 * packets when reading from a trace file.
     1336 *
     1337 * @param libtrace The trace object to apply the option to
     1338 * @param realtime True ignores gaps
     1339 * @return -1 if option configuration failed, 0 otherwise
     1340 */
     1341DLLEXPORT int trace_set_event_realtime(libtrace_t *trace, bool realtime);
    12931342
    12941343/** Valid compression types
  • lib/libtrace_int.h

    r6a6e6a8 r6b98325  
    262262// Used for inband tick message
    263263#define READ_TICK -3
     264
     265/**
     266 * Tuning the parallel sizes
     267 * See the user documentation trace_set_x
     268 */
     269struct user_configuration {
     270        size_t cache_size;
     271        size_t thread_cache_size;
     272        bool fixed_count;
     273        size_t burst_size;
     274        size_t tick_interval;
     275        size_t tick_count;
     276        size_t perpkt_threads;
     277        size_t hasher_queue_size;
     278        bool hasher_polling;
     279        bool reporter_polling;
     280        size_t reporter_thold;
     281        bool debug_state;
     282};
     283#define ZERO_USER_CONFIG(config) memset(&config, 0, sizeof(struct user_configuration));
    264284
    265285/** A libtrace input trace
     
    927947         */
    928948        int (*pfin_input)(libtrace_t *trace);
    929        
    930         /** Applies a configuration option to an input trace.
    931          *
    932          * @param libtrace      The input trace to apply the option to
    933          * @param option        The option that is being configured
    934          * @param value         A pointer to the value that the option is to be
    935          *                      set to
    936          * @return 0 if successful, -1 if the option is unsupported or an error
    937          * occurs
    938          */
    939         int (*pconfig_input)(libtrace_t *libtrace,trace_parallel_option_t option,void *value);
    940949
    941950        /**
     
    9921001        NULL,                   /* ppause_input */ \
    9931002        NULL,                   /* pfin_input */ \
    994         NULL,                   /* pconfig_input */ \
    9951003        NULL,                   /* pregister_thread */ \
    9961004        NULL,                   /* punregister_thread */ \
  • lib/libtrace_parallel.h

    r1407294 r6b98325  
    8585        size_t size;
    8686
    87         /* C basic types - we cannot be certian of the size */
     87        /* C basic types - we cannot be certain of the size */
    8888        int sint;
    8989        unsigned int uint;
     
    112112        int type;
    113113};
    114 
    115 typedef enum {
    116         /**
    117          * Sets the hasher function, if NULL(default) no hashing is used a
    118          * cores will get packets on a first in first served basis
    119          */
    120         TRACE_OPTION_SET_HASHER,
    121 
    122         /**
    123          * Libtrace set perpkt thread count
    124          */
    125         TRACE_OPTION_SET_PERPKT_THREAD_COUNT,
    126 
    127         /**
    128          * Delays packets so they are played back in trace-time rather than as fast
    129          * as possible.
    130          */
    131         TRACE_OPTION_TRACETIME,
    132 
    133         /**
    134          * Specifies the interval between tick packets in milliseconds, if 0
    135          * or less this is ignored.
    136          */
    137         TRACE_OPTION_TICK_INTERVAL,
    138         TRACE_OPTION_GET_CONFIG,
    139         TRACE_OPTION_SET_CONFIG
    140 } trace_parallel_option_t;
    141114
    142115/** The libtrace_messages enum
     
    256229        MESSAGE_POST_REPORTER,
    257230
    258         /** Sent to per-packet threads perodically after the configured time
     231        /** Sent to per-packet threads periodically after the configured time
    259232         * interval has passed.
    260233         *
    261234         * This is sent out-of-band with respect to packets and as a result
    262          * can appear after a packet with an later timestamp, or before one
    263          * with an earlier timestamp.
    264          *
    265          * @param data data.uint64_t holds the system timestamp in the
     235         * can appear after a packet with an later time-stamp, or before one
     236         * with an earlier time-stamp.
     237         *
     238         * @param data data.uint64_t holds the system time-stamp in the
    266239         * erf format
    267240         * @param sender should be ignored
     
    280253        MESSAGE_TICK_COUNT,
    281254
    282         /** For specific user defined messages use codes above MESSAGE_USER. */
     255        /** For specific user defined messages use codes of MESSAGE_USER or above. */
    283256        MESSAGE_USER = 1000
    284257};
    285258
    286 /** The hasher types avaliable to libtrace application.
     259/** The hasher types available to libtrace application.
    287260 * These can be selected using trace_set_hasher().
    288261 */
     
    321294typedef struct libtrace_info_t {
    322295        /**
    323          * True if a live format (i.e. packets have to be tracetime).
     296         * True if a live format (i.e. packets have to be trace-time).
    324297         * Otherwise false, indicating packets can be read as fast
    325298         * as possible from the format.
     
    339312} libtrace_info_t;
    340313
    341 
    342 /**
    343  * Tuning the parallel sizes
    344  */
    345 struct user_configuration {
    346         // Packet memory cache settings (ocache_init) total
    347         /**
    348          * See diagrams, this sets the maximum size of freelist used to
    349          * maintain packets and their memory buffers.
    350          * NOTE setting this to less than recommend could cause deadlock a
    351          * trace that manages its own packets.
    352          * A unblockable error message will be printed.
    353          */
    354         size_t packet_cache_size;
    355         /**
    356          * Per thread local cache size for the packet freelist
    357          */
    358         size_t packet_thread_cache_size;
    359         /**
    360          * If true the total number of packets that can be created by a trace is limited
    361          * to the packet_cache_size, otherwise once packet_cache_size is exceeded alloc
    362          * and free will be used to create and free packets, this will be slower than
    363          * using the freelist and could run a machine out of memory.
    364          *
    365          * However this does make it easier to ensure that deadlocks will not occur
    366          * due to running out of packets
    367          */
    368         bool fixed_packet_count;
    369         /**
    370          * When reading from a single threaded input source to reduce
    371          * lock contention a 'burst' of packets is read per pkt thread
    372          * this determines the bursts size.
    373          */
    374         size_t burst_size;
    375         // Each perpkt thread has a queue leading into the reporter
    376         //size_t reporter_queue_size;
    377 
    378         /**
    379          * The tick interval - in milliseconds
    380          * When a live trace is used messages are sent at the tick
    381          * interval to ensure that all perpkt threads receive data
    382          * this allows results to be printed in cases flows are
    383          * not being directed to a certian thread, while still
    384          * maintaining order.
    385          */
    386         size_t tick_interval;
    387 
    388         /**
    389          * Like the tick interval but used in the case of file format
    390          * This specifies the number of packets before inserting a tick to
    391          * every thread.
    392          */
    393         size_t tick_count;
    394 
    395         /**
    396          * The number of per packet threads requested, 0 means use default.
    397          * Default typically be the number of processor threads detected less one or two.
    398          */
    399         size_t perpkt_threads;
    400 
    401         /**
    402          * See diagrams, this sets the maximum size of buffers used between
    403          * the single hasher thread and the buffer.
    404          * NOTE setting this to less than recommend could cause deadlock a
    405          * trace that manages its own packets.
    406          * A unblockable warning message will be printed to stderr in this case.
    407          */
    408         /** The number of packets that can queue per thread from hasher thread */
    409         size_t hasher_queue_size;
    410 
    411         /**
    412          * If true use a polling hasher queue, that means that we will spin/or yeild
    413          * when rather than blocking on a lock. This applies to both the hasher thread
    414          * and perpkts reading the queues.
    415          */
    416         bool hasher_polling;
    417 
    418         /**
    419          * If true the reporter thread will continuously poll waiting for results
    420          * if false they are only checked when a message is received, this message
    421          * is controlled by reporter_thold.
    422          */
    423         bool reporter_polling;
    424 
    425         /**
    426          * Perpkt thread result queue size before triggering the reporter step to read results
    427          */
    428         size_t reporter_thold;
    429 
    430         /**
    431          * Prints a line to standard error for every state change
    432          * for both the trace as a whole and for each thread.
    433          */
    434         bool debug_state;
    435 };
    436 
    437314/**
    438315 * The methods we use to combine multiple outputs into a single output
    439316 * This is not considered a stable API however is public.
    440  * Where possible use built in combiners
    441  *
    442  * NOTE this structure is duplicated per trace and as such can
     317 * Where possible use built in combiners.
     318 *
     319 * @note this structure is duplicated per trace and as such can
    443320 * have functions rewritten, and in fact should if possible.
    444321 */
     
    447324
    448325        /**
    449          * Called at the start of the trace to allow datastructures
    450          * to be initilised and allow functions to be swapped if approriate.
     326         * Called at the start of the trace to allow data-structures
     327         * to be initialised and allow functions to be swapped if appropriate.
    451328         *
    452329         * Also factors such as whether the trace is live or not can
     
    474351        /**
    475352         * Read as many results as possible from the trace.
    476          * Directy calls the users code to handle results from here.
     353         * Directly calls the users code to handle results from here.
    477354         *
    478355         * THIS SHOULD BE NON-BLOCKING AND READ AS MANY AS POSSIBLE
     
    512389
    513390        /**
    514          * Configuration options, what this does is upto the combiner
     391         * Configuration options, what this does is up to the combiner
    515392         * chosen.
    516393         */
     
    574451 *
    575452 * @param libtrace The input trace to start
    576  * @param global_blob Global data related to this trace accessable using trace_get_global()
     453 * @param global_blob Global data related to this trace accessible using trace_get_global()
    577454 * @param per_pkt A user supplied function called when a packet is ready
    578455 * @param reporter A user supplied function called when a result is ready.
    579456 * Optional if NULL the reporter thread will not be started.
    580  * @return 0 on success, otherwise -1 to indicate an error has occured
     457 * @return 0 on success, otherwise -1 to indicate an error has occurred
    581458 *
    582459 * This can also be used to restart an existing parallel trace,
     
    592469 *
    593470 * @param libtrace The parallel trace to be paused
    594  * @return 0 on success, otherwise -1 to indicate an error has occured
     471 * @return 0 on success, otherwise -1 to indicate an error has occurred
    595472 *
    596473 */
     
    598475
    599476/** Stops a parallel trace, causing all threads to exit as if an EOF
    600  * has occured. This replaces trace_interrupt(), allowing
     477 * has occurred. This replaces trace_interrupt(), allowing
    601478 * a specified trace to be stopped.
    602479 *
    603480 * @param libtrace The parallel trace to be stopped
    604  * @return 0 on success, otherwise -1 to indicate an error has occured
     481 * @return 0 on success, otherwise -1 to indicate an error has occurred
    605482 *
    606483 * This should only be called by the main thread.
     
    614491 *
    615492 * Waits for a trace to finish, whether this be due to
    616  * an error occuring, an EOF or trace_pstop.
     493 * an error occurring, an EOF or trace_pstop.
    617494 *
    618495 */
     
    622499 * @name User Data Storage
    623500 *
    624  * These method provide a way for users to store data agaist a trace or
     501 * These method provide a way for users to store data against a trace or
    625502 * a thread.
    626503 *
    627504 * Alternatively one could use global variables and thread local
    628  * storage (__thread), respectively, which in many cases could be simplier.
     505 * storage (__thread), respectively, which in many cases could be simpler.
    629506 *
    630507 * @note We do not lock on reads, instead we rely on the
     
    645522 *
    646523 * @param trace The parallel trace.
    647  * @param data The new value to save agaisnt the trace
     524 * @param data The new value to save against the trace
    648525 * @return The previously stored value
    649526 *
     
    666543 *
    667544 * @param The parallel trace.
    668  * @param data The new value to save agaisnt the trace
     545 * @param data The new value to save against the trace
    669546 * @return The previously stored value
    670547 *
    671  * This function is not thread-safe and is intented only to be
     548 * This function is not thread-safe and is intended only to be
    672549 * called on the currently running thread.
    673550 */
     
    675552
    676553/// @}
     554
     555
     556/**
     557 * @name Parallel Configuration
     558 *
     559 * These methods provide a way to configure the parallel libtrace library.
     560 *
     561 * Many of these options are typically unneeded by most applications as they
     562 * control tuning aspects of the library and are more useful to the
     563 * end user.
     564 *
     565 * To allow the end user to change this configuration libtrace will search for
     566 * three environment variables and apply them to the configuration in the
     567 * following order. Such that the first has the lowest priority.
     568 *
     569 * 1. LIBTRACE_CONF, The global environment configuration
     570 * 2. LIBTRACE_CONF_<FORMAT>, Applied to a given format
     571 * 3. LIBTRACE_CONF_<FORMAT_URI>, Applied the specified trace
     572 *
     573 * E.g.
     574 * - int:eth0 would match LIBTRACE_CONF, LIBTRACE_CONF_INT, LIBTRACE_CONF_INT_ETH0
     575 * - dag:/dev/dag0,0 would match LIBTRACE_CONF, LIBTRACE_CONF_DAG, LIBTRACE_CONF_DAG__DEV_DAG0_0
     576 * - test.erf would match LIBTRACE_CONF, LIBTRACE_CONF_ERF, LIBTRACE_CONF_ERF_TEST_ERF
     577 *
     578 * @note All environment variables names MUST only contain
     579 * [A-Z], [0-9] and [_] (underscore). Any characters
     580 * outside of this range should be capitalised if possible or replaced with an
     581 * underscore.
     582 * @{
     583 */
     584
     585/** Set the maximum number of perpkt threads to use in a trace.
     586 *
     587 * @param[in] trace The parallel input trace
     588 * @param[in] nb The number of threads to use. If 0 use default.
     589 * @return 0 if successful otherwise -1
     590 */
     591DLLEXPORT int trace_set_perpkt_threads(libtrace_t *trace, int nb);
     592
     593/** Set the interval between tick messages in milliseconds.
     594 *
     595 * @param[in] trace The parallel input trace
     596 * @param[in] interval The interval in milliseconds. If 0 this is disabled [default].
     597 * @return 0 if successful otherwise -1
     598 *
     599 * When a underlying parallel live trace is used MESSAGE_TICK_INTERVAL is sent
     600 * every tick interval to all per-packet threads to ensure data is received.
     601 * This allows results to be printed even in cases flows are not being directed
     602 * to a per-packet thread, while still maintaining order etc.
     603 *
     604 * @note Tick count is preferred over tick interval and will be used rather
     605 * than tick interval if possible.
     606 * @see MESSAGE_TICK_INTERVAL, trace_set_tick_count()
     607 */
     608DLLEXPORT int trace_set_tick_interval(libtrace_t *trace, size_t interval);
     609
     610/** Set the count between tick messages.
     611 *
     612 * @param[in] trace The parallel input trace
     613 * @param[in] count The tick count.  If 0 this is disabled [default].
     614 * @return 0 if successful otherwise -1
     615 *
     616 * When an underlying trace is accessed internally by libtrace in a
     617 * single-threaded manner MESSAGE_TICK_COUNT is sent to all per-packet threads
     618 * after every count packets have been seen in the trace. This allows results
     619 * to be printed even in cases flows are not being directed to a per-packet
     620 * thread, while still maintaining order etc.
     621 *
     622 * @see MESSAGE_TICK_COUNT, trace_set_tick_interval()
     623 */
     624DLLEXPORT int trace_set_tick_count(libtrace_t *trace, size_t count);
     625
     626/**
     627 * Delays packets so they are played back in trace-time rather than as fast
     628 * as possible (real-time).
     629 *
     630 * @param A parallel input trace
     631 * @param tracetime If true packets are released with time intervals matching
     632 * the original trace. Otherwise packets are read as fast as possible.
     633 * @return 0 if successful otherwise -1
     634 */
     635DLLEXPORT int trace_set_tracetime(libtrace_t *trace, bool tracetime);
     636
     637/** This sets the maximum size of the freelist used to store empty packets
     638 * and their memory buffers.
     639 *
     640 * @param trace A parallel input trace
     641 * @param size The number of empty packets to cache in memory. Set to the
     642 * default, 0, to autoconfigure this value.
     643 * @return 0 if successful otherwise -1
     644 *
     645 * Internally libtrace maintains a buffer of packet structures, this buffer
     646 * includes a cache per thread and a shared main pool. This configures
     647 * the size of the main pool. If an application is not passing packets
     648 * through to the reducer step --- that is to say returns packets from
     649 * the perpkt function --- this buffer will not need to be used.
     650 *
     651 * @note Setting this too low could cause performance issues or a deadlock. An
     652 * unblockable warning will be printed.
     653 *
     654 * @see trace_set_thread_cache_size(), trace_set_fixed_count()
     655 */
     656DLLEXPORT int trace_set_cache_size(libtrace_t *trace, size_t size);
     657
     658/** This sets the maximum size of the freelist thread cache's used to provide
     659 * faster access than the main shared pool.
     660 *
     661 * @param trace A parallel input trace
     662 * @param size The number of empty packets to cache in memory. Set to the
     663 * default, 0, to autoconfigure this value.
     664 * @return 0 if successful otherwise -1
     665 *
     666 * @see trace_set_cache_size(), trace_set_fixed_count()
     667 */
     668DLLEXPORT int trace_set_thread_cache_size(libtrace_t *trace, size_t size);
     669
     670/** If true the total number of packets that can be created by a trace is limited
     671 * to that set by trace_set_cache_size(), otherwise once exceeded malloc
     672 * and free will be used to create and free packets, this will be slower than
     673 * using the freelist and could run a machine out of memory.
     674 *
     675 * @param trace A parallel input trace
     676 * @param fixed If true the total number of packets is limited, otherwise
     677 * it is not. Defaults to false.
     678 * @return 0 if successful otherwise -1
     679 *
     680 * @see trace_set_thread_cache_size(), trace_set_cache_size()
     681 */
     682DLLEXPORT int trace_set_fixed_count(libtrace_t *trace, bool fixed);
     683
     684/** The number of packets to batch together for processing internally
     685 * by libtrace.
     686 *
     687 * @param trace A parallel input trace
     688 * @param size The total number of packets to batch together. Set to the
     689 * default, 0, to autoconfigure this value.
     690 * @return 0 if successful otherwise -1
     691 *
     692 * Internally libtrace will attempt to read up to this number of packets from
     693 * a format typically values of 10 will get good performance and increasing
     694 * beyond that will should little difference.
     695 *
     696 * @note We still pass a single packet at a time to the perpkt function
     697 */
     698DLLEXPORT int trace_set_burst_size(libtrace_t *trace, size_t size);
     699
     700/**
     701 * See diagrams, this sets the maximum size of buffers used between
     702 * the single hasher thread and the buffer.
     703 * NOTE setting this to less than recommend could cause deadlock a
     704 * trace that manages its own packets.
     705 * A unblockable warning message will be printed to stderr in this case.
     706 */
     707/** The number of packets that can queue per thread from hasher thread */
     708DLLEXPORT int trace_set_hasher_queue_size(libtrace_t *trace, size_t size);
     709
     710/** If true use a polling hasher queue, that means that we will spin/or yield
     711 * when data is not available rather than blocking on a condition.
     712 *
     713 * @param trace A parallel input trace
     714 * @param polling If true the hasher will poll waiting for data, otherwise
     715 * it is not. Defaults to false.
     716 *
     717 * We note this is likely to waste many CPU cycles and could even decrease
     718 * performance.
     719 *
     720 * @return 0 if successful otherwise -1
     721 */
     722DLLEXPORT int trace_set_hasher_polling(libtrace_t *trace, bool polling);
     723
     724/** If true the reporter thread will continuously poll waiting for results
     725 * if false they are only checked when a message is received, this message
     726 * is controlled by reporter_thold.
     727 *
     728 * @param trace A parallel input trace
     729 * @param polling If true the reporter will poll waiting for data, otherwise
     730 * it is not. Defaults to false.
     731 * @return 0 if successful otherwise -1
     732 *
     733 * We note this is likely to waste many CPU cycles and could even decrease
     734 * performance.
     735 *
     736 * @note This setting could be ignored by some reporters.
     737 */
     738DLLEXPORT int trace_set_reporter_polling(libtrace_t *trace, bool polling);
     739
     740/** Set the perpkt thread result queue size before triggering the reporter
     741 * to read results.
     742 *
     743 * @param trace A parallel input trace
     744 * @param thold The threshold on the number of results to enqueue before
     745 * notifying the reporter thread to read them.
     746 * @return 0 if successful otherwise -1
     747 *
     748 *
     749 * @note This setting is generally ignored if trace_set_reporter_polling() is
     750 * set however some combiner functions might ignore trace_set_reporter_polling()
     751 * and still require this to be set.
     752 * @see trace_publish_result(), trace_post_reporter()
     753 */
     754DLLEXPORT int trace_set_reporter_thold(libtrace_t *trace, size_t thold);
     755
     756/** Prints a line to standard error for every state change
     757 * for both the trace as a whole and for each thread.
     758 *
     759 * @param trace A parallel input trace
     760 * @param debug_state If true debug is printed. Defaults false.
     761 * @return 0 if successful otherwise -1.
     762 *
     763 */
     764DLLEXPORT int trace_set_debug_state(libtrace_t *trace, bool debug_state);
    677765
    678766/** Set the hasher function for a parallel trace.
     
    699787 * preferred over the default supplied by libtrace.
    700788 *
    701  * @note When supplying a hasher function it should be thread-safe as it could
     789 * @note When supplying a hasher function it should be thread-safe so it can
    702790 * be run in parallel by libtrace. Ideally this should rely upon no state, other
    703791 * than some form of seed value supplied in data.
    704792 */
    705 DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type, fn_hasher hasher, void *data);
     793DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type,
     794                               fn_hasher hasher, void *data);
     795
     796/// @}
     797
    706798
    707799/** Types of results.
     
    724816        /** The result is a tick message
    725817         *
    726          * @param key The erf timestamp of the tick
     818         * @param key The erf time-stamp of the tick
    727819         */
    728820        RESULT_TICK_INTERVAL,
     
    743835/** Publish a result for to the combiner destined for the reporter thread
    744836 *
    745  * @param libtrace[in] The parallel input trace
    746  * @param t[in] The current per-packet thread
    747  * @param key[in] The key of the result (used for sorting by the combiner)
    748  * @param value[in] The value of the result
    749  * @param type[in] The type of result see the documentation for the result_types enum
     837 * @param[in] libtrace The parallel input trace
     838 * @param[in] t The current per-packet thread
     839 * @param[in] key The key of the result (used for sorting by the combiner)
     840 * @param[in] value The value of the result
     841 * @param[in] type The type of result see the documentation for the result_types enum
    750842 */
    751843DLLEXPORT void trace_publish_result(libtrace_t *libtrace,
     
    797889 * @param[in] t The thread to check, if NULL the current thread will be used [Optional]
    798890 * @param[out] message A pointer to libtrace_message_t structure which will be
    799  * filled with the retrived message.
     891 * filled with the retrieved message.
    800892 *
    801893 * @return The number of messages remaining otherwise -1 upon error.
     
    814906 * @param[in] t The thread to check, if NULL the current thread will be used [Optional]
    815907 * @param[out] message A pointer to libtrace_message_t structure which will be
    816  * filled with the retrived message.
     908 * filled with the retrieved message.
    817909 *
    818910 * @return 0 if successful otherwise -1 upon error or if no packets were available.
     
    9231015 *
    9241016 * @param[in] libtrace the parallel input trace
    925  * @param[in] t Either a per packet thread or NULL to retrive the first packet
     1017 * @param[in] t Either a per packet thread or NULL to retrieve the first packet
    9261018 * of across all per packet threads.
    9271019 * @param[out] packet A pointer to the first packet in the trace. [Optional]
    928  * @param[out] tv The system timestamp when this packet was received. [Optional]
     1020 * @param[out] tv The system time-stamp when this packet was received. [Optional]
    9291021 * @return 1 if we are confident this is the first packet. Otherwise 0 if this
    9301022 * is a best guess (this is only possible int the case t=NULL)
     
    9401032                                     struct timeval **tv);
    9411033
    942 /** Makes a packet safe, a packet will become invaild after a
     1034/** Makes a packet safe, a packet will become invalid after a
    9431035 * pausing a trace.
    9441036 *
    945  * @param pkt[in,out] The packet to make safe
     1037 * @param[in,out] pkt The packet to make safe
    9461038 *
    9471039 * This copies a packet in such a way that it will be able to survive a pause.
     
    9531045/** Makes a result safe if a result contains a packet.
    9541046 *
    955  * @param res[in,out] The result to make safe.
     1047 * @param[in,out] res The result to make safe.
    9561048 *
    9571049 * This ensures the internal content of a result is safe to survive a pause.
     
    9601052DLLEXPORT void libtrace_make_result_safe(libtrace_result_t *res);
    9611053
    962 
    963 DLLEXPORT int trace_parallel_config(libtrace_t *libtrace, trace_parallel_option_t option, void *value);
    964 
    9651054/** In a parallel trace, free a packet back to libtrace.
    9661055 *
     
    9761065
    9771066DLLEXPORT libtrace_info_t *trace_get_information(libtrace_t * libtrace);
    978 DLLEXPORT void parse_user_config(struct user_configuration* uc, char * str);
    979 DLLEXPORT void parse_user_config_file(struct user_configuration* uc, FILE *file);
    980 DLLEXPORT int libtrace_get_perpkt_count(libtrace_t* t);
     1067
     1068/** Sets the configuration of a trace based upon a comma separated list of
     1069 * key value pairs.
     1070 *
     1071 * @param trace A parallel trace which is not running or destroyed
     1072 * @param str A comma separated list of key=value pairs.
     1073 * E.g. \em "burst_size=20,perpkt_threads=2,fixed_count=true"
     1074 * @return 0 if successful otherwise -1. If bad options are passed we will
     1075 * print the error to stderr but still return successful.
     1076 *
     1077 * List of keys:
     1078 * * \b cache_size,\b cs see trace_set_cache_size() [size_t]
     1079 * * \b thread_cache_size,\b tcs see trace_set_thread_cache_size() [size_t]
     1080 * * \b fixed_count,\b fc see trace_set_fixed_count() [bool]
     1081 * * \b burst_size,\b bs see trace_set_burst_size() [size_t]
     1082 * * \b tick_interval,\b ti see trace_set_tick_interval() [size_t]
     1083 * * \b tick_count,\b tc see trace_set_tick_count() [size_t]
     1084 * * \b perpkt_threads,\b pt see trace_set_perpkt_threads() [XXX TBA XXX]
     1085 * * \b hasher_queue_size,\b hqs see trace_set_hasher_queue_size() [size_t]
     1086 * * \b hasher_polling,\b hp see trace_set_hasher_polling() [bool]
     1087 * * \b reporter_polling,\b rp see trace_set_reporter_polling() [bool]
     1088 * * \b reporter_thold,\b rt see trace_set_reporter_thold() [size_t]
     1089 * * \b debug_state,\b ds see trace_set_debug_state() [bool]
     1090 *
     1091 * Booleans can be set as 0/1 or false/true.
     1092 *
     1093 * @note a environment variable interface is provided by default to users via
     1094 * LIBTRACE_CONFIG, see Parallel Configuration for more information.
     1095 *
     1096 * @note this interface is provided to allow a user to configure an application
     1097 * if a libtrace applicate wishes to configure a setting it should use a
     1098 * trace_set_*() function with the same name.
     1099 */
     1100DLLEXPORT int trace_set_configuration(libtrace_t *trace, const char * str);
     1101
     1102/** Sets configuration from a file. This reads every line from the file and
     1103 * interprets each line with trace_set_configuration().
     1104 *
     1105 * @param trace A parallel trace which is not running or destroyed
     1106 * @param file A file pointer which we read each line from
     1107 * @return 0 if successful otherwise -1. If bad options are passed we will
     1108 * print the error to stderr but still return successful.
     1109 *
     1110 * @note We do not close the file pointer upon completion
     1111 */
     1112DLLEXPORT int trace_set_configuration_file(libtrace_t *trace, FILE *file);
     1113
     1114DLLEXPORT int libtrace_get_perpkt_count(libtrace_t* t); // TODO MATCH WITH THE SET_PERPKT
    9811115
    9821116/**
     
    9921126DLLEXPORT void trace_set_combiner(libtrace_t *trace, const libtrace_combine_t *combiner, libtrace_generic_t config);
    9931127
    994 #define ZERO_USER_CONFIG(config) memset(&config, 0, sizeof(struct user_configuration));
    995 
    9961128#endif // LIBTRACE_PARALLEL_H
  • lib/trace.c

    r7718e54 r6b98325  
    556556                return -1;
    557557        }
    558        
     558
     559        if (option == TRACE_OPTION_HASHER)
     560                return trace_set_hasher(libtrace,
     561                                        (enum hasher_types) *((int *) value),
     562                                        NULL, NULL);
     563
    559564        /* If the capture format supports configuration, try using their
    560565         * native configuration first */
     
    608613                        }
    609614                        return -1;
     615                case TRACE_OPTION_HASHER:
     616                        /* Dealt with earlier */
     617                        return -1;
    610618                       
    611619        }
     
    615623        }
    616624        return -1;
     625}
     626
     627DLLEXPORT int trace_set_snaplen(libtrace_t *trace, int snaplen) {
     628        return trace_config(trace, TRACE_OPTION_SNAPLEN, &snaplen);
     629}
     630
     631DLLEXPORT int trace_set_promisc(libtrace_t *trace, bool promisc) {
     632        int tmp = promisc;
     633        return trace_config(trace, TRACE_OPTION_PROMISC, &tmp);
     634}
     635
     636DLLEXPORT int trace_set_filter(libtrace_t *trace, libtrace_filter_t *filter) {
     637        return trace_config(trace, TRACE_OPTION_FILTER, filter);
     638}
     639
     640DLLEXPORT int trace_set_meta_freq(libtrace_t *trace, int freq) {
     641        return trace_config(trace, TRACE_OPTION_META_FREQ, &freq);
     642}
     643
     644DLLEXPORT int trace_set_event_realtime(libtrace_t *trace, bool realtime) {
     645        int tmp = realtime;
     646        return trace_config(trace, TRACE_OPTION_EVENT_REALTIME, &tmp);
    617647}
    618648
  • lib/trace_parallel.c

    r963b13b r6b98325  
    13731373        if (libtrace->config.burst_size <= 0)
    13741374                libtrace->config.burst_size = 10;
    1375         if (libtrace->config.packet_thread_cache_size <= 0)
    1376                 libtrace->config.packet_thread_cache_size = 20;
    1377         if (libtrace->config.packet_cache_size <= 0)
    1378                 libtrace->config.packet_cache_size = (libtrace->config.hasher_queue_size + 1) * libtrace->perpkt_thread_count;
    1379 
    1380         if (libtrace->config.packet_cache_size <
     1375        if (libtrace->config.thread_cache_size <= 0)
     1376                libtrace->config.thread_cache_size = 20;
     1377        if (libtrace->config.cache_size <= 0)
     1378                libtrace->config.cache_size = (libtrace->config.hasher_queue_size + 1) * libtrace->perpkt_thread_count;
     1379
     1380        if (libtrace->config.cache_size <
    13811381                (libtrace->config.hasher_queue_size + 1) * libtrace->perpkt_thread_count)
    13821382                fprintf(stderr, "WARNING deadlocks may occur and extra memory allocating buffer sizes (packet_freelist_size) mismatched\n");
     
    14521452 * configuration structure.
    14531453 *
    1454  * @param libtrace The trace from which we determine the URI
    1455  * @param uc A configuration structure to be configured.
     1454 * @param[in,out] libtrace The trace from which we determine the URI and set
     1455 * the configuration.
    14561456 *
    14571457 * We search for 3 environment variables and apply them to the config in the
     
    14671467 * - test.erf would match LIBTRACE_CONF, LIBTRACE_CONF_ERF, LIBTRACE_CONF_ERF_TEST_ERF
    14681468 *
    1469  * @note All enironment variables names MUST only contian
     1469 * @note All environment variables names MUST only contian
    14701470 * [A-Z], [0-9] and [_] (underscore) and not start with a number. Any characters
    14711471 * outside of this range should be captilised if possible or replaced with an
    14721472 * underscore.
    14731473 */
    1474 static void parse_env_config (libtrace_t *libtrace, struct user_configuration* uc) {
     1474static void parse_env_config (libtrace_t *libtrace) {
    14751475        char env_name[1024] = "LIBTRACE_CONF_";
    14761476        size_t len = strlen(env_name);
     
    15031503        {
    15041504                printf("Got env %s", env);
    1505                 parse_user_config(uc, env);
     1505                trace_set_configuration(libtrace, env);
    15061506        }
    15071507
     
    15121512                if (env) {
    15131513                        printf("Got %s=%s", env_name, env);
    1514                         parse_user_config(uc, env);
     1514                        trace_set_configuration(libtrace, env);
    15151515                }
    15161516                env_name[mark] = '_';
     
    15211521        if (env) {
    15221522                printf("Got %s=%s", env_name, env);
    1523                 parse_user_config(uc, env);
     1523                trace_set_configuration(libtrace, env);
    15241524        }
    15251525}
     
    15691569
    15701570        /* Parses configuration passed through environment variables */
    1571         parse_env_config(libtrace, &libtrace->config);
     1571        parse_env_config(libtrace);
    15721572        verify_configuration(libtrace);
    15731573
     
    16671667                             (void* (*)()) trace_create_packet,
    16681668                             (void (*)(void *))trace_destroy_packet,
    1669                              libtrace->config.packet_thread_cache_size,
    1670                              libtrace->config.packet_cache_size * 4,
    1671                              libtrace->config.fixed_packet_count) != 0) {
     1669                             libtrace->config.thread_cache_size,
     1670                             libtrace->config.cache_size * 4,
     1671                             libtrace->config.fixed_count) != 0) {
    16721672                trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "trace_pstart "
    16731673                              "failed to allocate ocache.");
     
    19171917        // there is a more efficient way to apply it, in this case
    19181918        // it will simply grab the function out of libtrace_t
    1919         if (trace->format->pconfig_input)
    1920                 ret = trace->format->pconfig_input(trace, TRACE_OPTION_SET_HASHER, &type);
     1919        if (trace->format->config_input)
     1920                ret = trace->format->config_input(trace, TRACE_OPTION_HASHER, &type);
    19211921
    19221922        if (ret == -1) {
     
    21622162}
    21632163
    2164 DLLEXPORT int trace_parallel_config(libtrace_t *libtrace, trace_parallel_option_t option, void *value)
    2165 {
    2166         UNUSED int ret = -1;
    2167         switch (option) {
    2168                 case TRACE_OPTION_TICK_INTERVAL:
    2169                         libtrace->config.tick_interval = *((int *) value);
    2170                         return 1;
    2171                 case TRACE_OPTION_SET_HASHER:
    2172                         return trace_set_hasher(libtrace, (enum hasher_types) *((int *) value), NULL, NULL);
    2173                 case TRACE_OPTION_SET_PERPKT_THREAD_COUNT:
    2174                         libtrace->config.perpkt_threads = *((int *) value);
    2175                         return 1;
    2176                 case TRACE_OPTION_TRACETIME:
    2177                         if(*((int *) value))
    2178                                 libtrace->tracetime = 1;
    2179                         else
    2180                                 libtrace->tracetime = 0;
    2181                         return 0;
    2182                 case TRACE_OPTION_SET_CONFIG:
    2183                         libtrace->config = *((struct user_configuration *) value);
    2184                 case TRACE_OPTION_GET_CONFIG:
    2185                         *((struct user_configuration *) value) = libtrace->config;
    2186         }
     2164/**
     2165 * @return True if the trace is not running such that it can be configured
     2166 */
     2167static inline bool trace_is_configurable(libtrace_t *trace) {
     2168        return trace->state == STATE_NEW ||
     2169                        trace->state == STATE_PAUSED;
     2170}
     2171
     2172DLLEXPORT int trace_set_perpkt_threads(libtrace_t *trace, int nb) {
     2173        if (!trace_is_configurable(trace)) return -1;
     2174
     2175        /* TODO consider allowing an offset from the total number of cores i.e.
     2176         * -1 reserve 1 core */
     2177        if (nb >= 0) {
     2178                trace->config.perpkt_threads = nb;
     2179                return 0;
     2180        } else {
     2181                return -1;
     2182        }
     2183}
     2184
     2185DLLEXPORT int trace_set_tick_interval(libtrace_t *trace, size_t interval) {
     2186        if (!trace_is_configurable(trace)) return -1;
     2187
     2188        trace->config.tick_interval = interval;
    21872189        return 0;
    21882190}
     2191
     2192DLLEXPORT int trace_set_tick_count(libtrace_t *trace, size_t count) {
     2193        if (!trace_is_configurable(trace)) return -1;
     2194
     2195        trace->config.tick_count = count;
     2196        return 0;
     2197}
     2198
     2199DLLEXPORT int trace_set_tracetime(libtrace_t *trace, bool tracetime) {
     2200        if (!trace_is_configurable(trace)) return -1;
     2201
     2202        trace->tracetime = tracetime;
     2203        return 0;
     2204}
     2205
     2206DLLEXPORT int trace_set_cache_size(libtrace_t *trace, size_t size) {
     2207        if (!trace_is_configurable(trace)) return -1;
     2208
     2209        trace->config.cache_size = size;
     2210        return 0;
     2211}
     2212
     2213DLLEXPORT int trace_set_thread_cache_size(libtrace_t *trace, size_t size) {
     2214        if (!trace_is_configurable(trace)) return -1;
     2215
     2216        trace->config.thread_cache_size = size;
     2217        return 0;
     2218}
     2219
     2220DLLEXPORT int trace_set_fixed_count(libtrace_t *trace, bool fixed) {
     2221        if (!trace_is_configurable(trace)) return -1;
     2222
     2223        trace->config.fixed_count = fixed;
     2224        return 0;
     2225}
     2226
     2227DLLEXPORT int trace_set_burst_size(libtrace_t *trace, size_t size) {
     2228        if (!trace_is_configurable(trace)) return -1;
     2229
     2230        trace->config.burst_size = size;
     2231        return 0;
     2232}
     2233
     2234DLLEXPORT int trace_set_hasher_queue_size(libtrace_t *trace, size_t size) {
     2235        if (!trace_is_configurable(trace)) return -1;
     2236
     2237        trace->config.hasher_queue_size = size;
     2238        return 0;
     2239}
     2240
     2241DLLEXPORT int trace_set_hasher_polling(libtrace_t *trace, bool polling) {
     2242        if (!trace_is_configurable(trace)) return -1;
     2243
     2244        trace->config.hasher_polling = polling;
     2245        return 0;
     2246}
     2247
     2248DLLEXPORT int trace_set_reporter_polling(libtrace_t *trace, bool polling) {
     2249        if (!trace_is_configurable(trace)) return -1;
     2250
     2251        trace->config.reporter_polling = polling;
     2252        return 0;
     2253}
     2254
     2255DLLEXPORT int trace_set_reporter_thold(libtrace_t *trace, size_t thold) {
     2256        if (!trace_is_configurable(trace)) return -1;
     2257
     2258        trace->config.reporter_thold = thold;
     2259        return 0;
     2260}
     2261
     2262DLLEXPORT int trace_set_debug_state(libtrace_t *trace, bool debug_state) {
     2263        if (!trace_is_configurable(trace)) return -1;
     2264
     2265        trace->config.debug_state = debug_state;
     2266        return 0;
     2267}
     2268
     2269
    21892270
    21902271static bool config_bool_parse(char *value, size_t nvalue) {
     
    21972278}
    21982279
     2280/* Note update documentation on trace_set_configuration */
    21992281static void config_string(struct user_configuration *uc, char *key, size_t nkey, char *value, size_t nvalue) {
    22002282        assert(key);
    22012283        assert(value);
    22022284        assert(uc);
    2203         if (strncmp(key, "packet_cache_size", nkey) == 0
    2204             || strncmp(key, "pcs", nkey) == 0) {
    2205                 uc->packet_cache_size = strtoll(value, NULL, 10);
    2206         } else if (strncmp(key, "packet_thread_cache_size", nkey) == 0
    2207                    || strncmp(key, "ptcs", nkey) == 0) {
    2208                 uc->packet_thread_cache_size = strtoll(value, NULL, 10);
    2209         } else if (strncmp(key, "fixed_packet_count", nkey) == 0
    2210                    || strncmp(key, "fpc", nkey) == 0) {
    2211                 uc->fixed_packet_count = config_bool_parse(value, nvalue);
     2285        if (strncmp(key, "cache_size", nkey) == 0
     2286            || strncmp(key, "cs", nkey) == 0) {
     2287                uc->cache_size = strtoll(value, NULL, 10);
     2288        } else if (strncmp(key, "thread_cache_size", nkey) == 0
     2289                   || strncmp(key, "tcs", nkey) == 0) {
     2290                uc->thread_cache_size = strtoll(value, NULL, 10);
     2291        } else if (strncmp(key, "fixed_count", nkey) == 0
     2292                   || strncmp(key, "fc", nkey) == 0) {
     2293                uc->fixed_count = config_bool_parse(value, nvalue);
    22122294        } else if (strncmp(key, "burst_size", nkey) == 0
    22132295                   || strncmp(key, "bs", nkey) == 0) {
     
    22422324}
    22432325
    2244 DLLEXPORT void parse_user_config(struct user_configuration* uc, char * str) {
     2326DLLEXPORT int trace_set_configuration(libtrace_t *trace, const char *str) {
    22452327        char *pch;
    22462328        char key[100];
    22472329        char value[100];
     2330        char *dup;
    22482331        assert(str);
    2249         assert(uc);
    2250         pch = strtok (str," ,.-");
     2332        assert(trace);
     2333
     2334        if (!trace_is_configurable(trace)) return -1;
     2335
     2336        dup = strdup(str);
     2337        pch = strtok (dup," ,.-");
    22512338        while (pch != NULL)
    22522339        {
    22532340                if (sscanf(pch, "%99[^=]=%99s", key, value) == 2) {
    2254                         config_string(uc, key, sizeof(key), value, sizeof(value));
     2341                        config_string(&trace->config, key, sizeof(key), value, sizeof(value));
    22552342                } else {
    22562343                        fprintf(stderr, "Error parsing %s\n", pch);
     
    22582345                pch = strtok (NULL," ,.-");
    22592346        }
    2260 }
    2261 
    2262 DLLEXPORT void parse_user_config_file(struct user_configuration* uc, FILE *file) {
     2347        free(dup);
     2348
     2349        return 0;
     2350}
     2351
     2352DLLEXPORT int trace_set_configuration_file(libtrace_t *trace, FILE *file) {
    22632353        char line[1024];
     2354        if (!trace_is_configurable(trace)) return -1;
     2355
    22642356        while (fgets(line, sizeof(line), file) != NULL)
    22652357        {
    2266                 parse_user_config(uc, line);
    2267         }
     2358                trace_set_configuration(trace, line);
     2359        }
     2360
     2361        if(ferror(file))
     2362                return -1;
     2363        else
     2364                return 0;
    22682365}
    22692366
  • test/test-format-parallel-hasher.c

    r6a6e6a8 r6b98325  
    208208        libtrace_t *trace;
    209209        int error = 0;
    210         int i;
    211210        int hashercount = 0;
    212211        printf("Testing hasher function\n");
     
    217216
    218217        // Always use 2 threads for simplicity
    219         i = 2;
    220         trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &i);
     218        trace_set_perpkt_threads(trace, 2);
    221219        trace_set_hasher(trace, HASHER_CUSTOM, &hash25_75, &hashercount);
    222220
  • test/test-format-parallel-singlethreaded-hasher.c

    r6a6e6a8 r6b98325  
    206206        libtrace_t *trace;
    207207        int error = 0;
    208         int i;
    209208        int hashercount = 0;
    210209        printf("Testing hasher singlethreaded function\n");
     
    215214
    216215        // Use 1 thread with a hasher
    217         i = 1;
    218         trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &i);
     216        trace_set_perpkt_threads(trace, 1);
    219217        trace_set_hasher(trace, HASHER_CUSTOM, &hash25_75, &hashercount);
    220218
  • test/test-format-parallel-singlethreaded.c

    r6a6e6a8 r6b98325  
    192192        libtrace_t *trace;
    193193        int error = 0;
    194         int i;
    195194        printf("Testing single threaded\n");
    196195
     
    200199
    201200        // Enable the single threaded fallback codepath
    202         i = 1;
    203         trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &i);
     201        trace_set_perpkt_threads(trace, 1);
    204202
    205203        // Start it
  • test/test-format-parallel-stressthreads.c

    r6a6e6a8 r6b98325  
    192192        libtrace_t *trace;
    193193        int error = 0;
    194         int i;
    195194        printf("Testing single threaded\n");
    196195
     
    200199
    201200        // Enable the single threaded fallback codepath
    202         i = 100;
    203         trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &i);
     201        trace_set_perpkt_threads(trace, 100);
    204202
    205203        // Start it
  • test/test-tracetime-parallel.c

    r6c84681 r6b98325  
    6969static void signal_handler(int signal)
    7070{
    71         int i = 0;
    7271        if (signal == SIGALRM) {
    7372                trace_ppause(trace);
     
    7776
    7877                /* Now fullspeed it */
    79                 trace_parallel_config(trace, TRACE_OPTION_TRACETIME, &i);
     78                trace_set_tracetime(trace, false);
    8079
    8180                /* And restart */
     
    155154int test_tracetime(const char *tracename) {
    156155        int error = 0;
    157         int i;
    158156        struct timeval tv;
    159157        double start, end;
     
    167165
    168166        // Always use 2 threads for simplicity
    169         i = 2;
    170         trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &i);
    171         i = 1;
    172         trace_parallel_config(trace, TRACE_OPTION_TRACETIME, &i);
     167        trace_set_perpkt_threads(trace, 2);
     168        trace_set_tracetime(trace, true);
    173169
    174170        // Start it
  • tools/traceanon/traceanon_parallel.c

    r6a6e6a8 r6b98325  
    253253        char *compress_type_str=NULL;
    254254        trace_option_compresstype_t compress_type = TRACE_OPTION_COMPRESSTYPE_NONE;
    255         struct user_configuration uc;
    256         ZERO_USER_CONFIG(uc);
     255        char *config = NULL;
     256        char *config_file = NULL;
    257257
    258258        if (argc<2)
     
    326326                                  break;
    327327                        case 'u':
    328                                   parse_user_config(&uc, optarg);
    329                                   break;
    330                         case 'U':;
    331                                 FILE * f = fopen(optarg, "r");
    332                                 if (f != NULL) {
    333                                         parse_user_config_file(&uc, f);
    334                                 } else {
    335                                         perror("Failed to open configuration file\n");
    336                                         usage(argv[0]);
    337                                 }
     328                                config = optarg;
     329                                break;
     330                        case 'U':
     331                                config_file = optarg;
    338332                                break;
    339333                        default:
     
    372366                return 1;
    373367        }
    374        
    375 
    376        
    377368
    378369        /* open input uri */
     
    427418                trace_destroy_output(writer);
    428419                trace_destroy(trace);
    429                 return 1;
     420                return 1;
    430421        }
    431422
     
    436427         * special case to have.
    437428         */
    438          
    439         int i = 1;
     429
     430        /* Apply config */
     431        if (config) {
     432                trace_set_configuration(trace, config);
     433        }
     434
     435        if (config_file) {
     436                FILE * f = fopen(optarg, "r");
     437                if (f != NULL) {
     438                        trace_set_configuration_file(trace, f);
     439                        fclose(f);
     440                } else {
     441                        perror("Failed to open configuration file\n");
     442                        usage(argv[0]);
     443                }
     444        }
     445
    440446        trace_set_combiner(trace, &combiner_ordered, (libtrace_generic_t){0});
    441         trace_parallel_config(trace, TRACE_OPTION_SET_CONFIG, &uc);
    442447
    443448        //trace_set_hasher(trace, HASHER_CUSTOM, rand_hash, NULL);
  • tools/tracertstats/tracertstats_parallel.c

    r6a6e6a8 r6b98325  
    294294                return;
    295295        }*/
    296         int i = 1;
    297296        trace_set_combiner(trace, &combiner_ordered, (libtrace_generic_t){0});
    298         /* trace_parallel_config(trace, TRACE_OPTION_TRACETIME, &i); */
     297        trace_set_tracetime(trace, true);
     298
    299299        //trace_set_hasher(trace, HASHER_CUSTOM, &bad_hash, NULL);
    300300
    301301        if (trace_get_information(trace)->live) {
    302                 i = (int) (packet_interval * 1000); // Every interval send a tick
    303                 trace_parallel_config(trace, TRACE_OPTION_TICK_INTERVAL, &i);
     302                trace_set_tick_interval(trace, (int) (packet_interval * 1000));
    304303        }
    305304
  • tools/tracestats/tracestats.c

    r5ab626a r6b98325  
    129129                bytes+=wlen;
    130130        }
     131        trace_destroy_packet(packet);
    131132
    132133        stats = trace_get_statistics(trace, NULL);
  • tools/tracestats/tracestats_parallel.c

    r6a6e6a8 r6b98325  
    215215}
    216216
    217 struct user_configuration uc;
    218 
    219 
    220217/* Process a trace, counting packets that match filter(s) */
    221 static void run_trace(char *uri)
     218static void run_trace(char *uri, char *config, char *config_file)
    222219{
    223220
     
    230227                return;
    231228        }
    232        
    233         int option = 2;
     229
     230        //libtrace_filter_t *f = trace_create_filter("udp");
     231        //trace_config(trace, TRACE_OPTION_FILTER, f);
     232
     233        //trace_config(trace, TRACE_OPTION_META_FREQ, &option);
    234234        //option = 10000;
    235     //trace_set_hasher(trace, HASHER_CUSTOM, &rand_hash, NULL);
     235        trace_set_hasher(trace, HASHER_CUSTOM, &rand_hash, NULL);
    236236        //trace_parallel_config(trace, TRACE_OPTION_SET_PERPKT_THREAD_COUNT, &option);
    237         trace_parallel_config(trace, TRACE_OPTION_SET_CONFIG, &uc);
     237
     238        /* Apply config */
     239        if (config) {
     240                trace_set_configuration(trace, config);
     241        }
     242
     243        if (config_file) {
     244                FILE * f = fopen(optarg, "r");
     245                if (f != NULL) {
     246                        trace_set_configuration_file(trace, f);
     247                        fclose(f);
     248                } else {
     249                        perror("Failed to open configuration file\n");
     250                        exit(-1);
     251                }
     252        }
     253
    238254        trace_set_combiner(trace, &combiner_ordered, (libtrace_generic_t){0});
    239255
     
    278294        int i;
    279295        struct sigaction sigact;
    280         ZERO_USER_CONFIG(uc);
     296        char *config = NULL;
     297        char *config_file = NULL;
     298
    281299        while(1) {
    282300                int option_index;
     
    309327                                break;
    310328                        case 'u':
    311                                   parse_user_config(&uc, optarg);
    312                                   break;
    313                         case 'U':;
    314                                 FILE * f = fopen(optarg, "r");
    315                                 if (f != NULL) {
    316                                         parse_user_config_file(&uc, f);
    317                                 } else {
    318                                         perror("Failed to open configuration file\n");
    319                                         usage(argv[0]);
    320                                 }
     329                                config = optarg;
     330                                break;
     331                        case 'U':
     332                                config_file = optarg;
    321333                                break;
    322334                        default:
     
    333345        sigaction(SIGINT, &sigact, NULL);
    334346        sigaction(SIGTERM, &sigact, NULL);
    335        
     347
    336348        for(i=optind;i<argc;++i) {
    337                 run_trace(argv[i]);
     349                run_trace(argv[i], config, config_file);
    338350        }
    339351        if (optind+1<argc) {
Note: See TracChangeset for help on using the changeset viewer.