Changeset 0ec8a7c for lib


Ignore:
Timestamp:
02/27/15 17:31:03 (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:
98dc1ba
Parents:
7718e54
Message:

Change the user interface from a message and a packet to only messages.

Now a packet is a type of message (MESSAGE_PACKET).
I expanded the message structure into seperate arguments such that these
will be passed in registers on x64 systems. As such performance has
remained identical if not better.

I renamed libtrace_generic_types_t to libtrace_generic_t so it was shorter.

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    r2adc1d0 r0ec8a7c  
    35073507        float rfloat;
    35083508        double rdouble;
    3509 } libtrace_generic_types_t;
     3509} libtrace_generic_t;
     3510ct_assert(sizeof(libtrace_generic_t) == 8);
    35103511
    35113512typedef struct libtrace_message_t {
    35123513        int code;
    3513         libtrace_generic_types_t additional;
     3514        libtrace_generic_t additional;
    35143515        libtrace_thread_t *sender;
    35153516} libtrace_message_t;
     
    35183519typedef struct libtrace_result_t {
    35193520        uint64_t key;
    3520         libtrace_generic_types_t value;
     3521        libtrace_generic_t value;
    35213522        int type;
    35223523} libtrace_result_t;
     
    35253526#define RESULT_TICK   2
    35263527
    3527 
    3528 typedef void* (*fn_per_pkt)(libtrace_t* trace, libtrace_packet_t *p, libtrace_message_t *m, libtrace_thread_t *thread);
     3528/**
     3529 * The definition for the main function that the user supplies to process
     3530 * packets.
     3531 *
     3532 * @param trace The trace the packet is related to.
     3533 * @param thread The thread the trace is related to.
     3534 * @param mesg_code The type of data ready, the most important being MESSAGE_PACKET.
     3535 * In this case data.pkt contains the packet.
     3536 * @param data A generic union of types that fit into 8 bytes, containing
     3537 * information dependent upon the mesg_code.
     3538 * @param sender The thread that the message originated from.
     3539 *
     3540 * The values of data and sender depend upon the mesg_code. Please see the
     3541 * documentation for the message as to what value these will contain.
     3542 */
     3543typedef void* (*fn_per_pkt)(libtrace_t* trace,
     3544                            libtrace_thread_t *thread,
     3545                            int mesg_code,
     3546                            libtrace_generic_t data,
     3547                            libtrace_thread_t *sender);
    35293548typedef void (*fn_reporter)(libtrace_t* trace, libtrace_result_t *r, libtrace_message_t *m);
    35303549typedef uint64_t (*fn_hasher)(const libtrace_packet_t* packet, void *data);
     
    35373556DLLEXPORT void libtrace_result_set_key(libtrace_result_t * result, uint64_t key);
    35383557DLLEXPORT uint64_t libtrace_result_get_key(libtrace_result_t * result);
    3539 DLLEXPORT void libtrace_result_set_value(libtrace_result_t * result, libtrace_generic_types_t value);
    3540 DLLEXPORT libtrace_generic_types_t libtrace_result_get_value(libtrace_result_t * result);
    3541 DLLEXPORT void libtrace_result_set_key_value(libtrace_result_t * result, uint64_t key, libtrace_generic_types_t value);
     3558DLLEXPORT void libtrace_result_set_value(libtrace_result_t * result, libtrace_generic_t value);
     3559DLLEXPORT libtrace_generic_t libtrace_result_get_value(libtrace_result_t * result);
     3560DLLEXPORT void libtrace_result_set_key_value(libtrace_result_t * result, uint64_t key, libtrace_generic_t value);
    35423561DLLEXPORT void trace_destroy_result(libtrace_result_t ** result);
    35433562
     
    35493568
    35503569
    3551 DLLEXPORT void trace_publish_result(libtrace_t *libtrace, libtrace_thread_t *t, uint64_t key, libtrace_generic_types_t value, int type);
     3570DLLEXPORT void trace_publish_result(libtrace_t *libtrace, libtrace_thread_t *t, uint64_t key, libtrace_generic_t value, int type);
    35523571typedef struct libtrace_vector libtrace_vector_t;
    35533572
     
    35993618
    36003619enum libtrace_messages {
     3620        MESSAGE_PACKET,
    36013621        MESSAGE_STARTING,
    36023622        MESSAGE_RESUMING,
     
    36133633        MESSAGE_POST_RANGE,
    36143634        MESSAGE_TICK,
    3615         MESSAGE_USER
     3635        MESSAGE_USER = 1000
    36163636};
    36173637
     
    38543874         * chosen.
    38553875         */
    3856         libtrace_generic_types_t configuration;
     3876        libtrace_generic_t configuration;
    38573877};
    38583878
    3859 DLLEXPORT void trace_set_combiner(libtrace_t *trace, const libtrace_combine_t *combiner, libtrace_generic_types_t config);
     3879DLLEXPORT void trace_set_combiner(libtrace_t *trace, const libtrace_combine_t *combiner, libtrace_generic_t config);
    38603880
    38613881#define READ_EOF 0
  • lib/trace_parallel.c

    r7718e54 r0ec8a7c  
    385385                                  libtrace_packet_t **packet,
    386386                                  bool tracetime) {
     387
    387388        if ((*packet)->error > 0) {
    388389                if (tracetime) {
     
    391392                }
    392393                t->accepted_packets++;
    393                 *packet = (*trace->per_pkt)(trace, *packet, NULL, t);
     394                libtrace_generic_t data = {.pkt = *packet};
     395                *packet = (*trace->per_pkt)(trace, t, MESSAGE_PACKET, data, t);
    394396                trace_fin_packet(*packet);
    395397        } else {
    396                 libtrace_message_t message;
    397398                assert((*packet)->error == READ_TICK);
    398                 message.code = MESSAGE_TICK;
    399                 message.additional.uint64 = trace_packet_get_order(*packet);
    400                 message.sender = t;
    401                 (*trace->per_pkt)(trace, NULL, &message, t);
     399                libtrace_generic_t data = {.uint64 = trace_packet_get_order(*packet)};
     400                (*trace->per_pkt)(trace, t, MESSAGE_TICK, data, t);
    402401        }
    403402        return 0;
     
    462461                                     libtrace_packet_t *packets[],
    463462                                     int nb_packets, int *empty, int *offset) {
    464         libtrace_message_t message = {0};
    465463        libtrace_packet_t * packet = NULL;
    466464
    467465        /* Let the user thread know we are going to pause */
    468         message.code = MESSAGE_PAUSING;
    469         message.sender = t;
    470         (*trace->per_pkt)(trace, NULL, &message, t);
     466        (*trace->per_pkt)(trace, t, MESSAGE_PAUSING, (libtrace_generic_t){0}, t);
    471467
    472468        /* Send through any remaining packets (or messages) without delay */
     
    511507        /* Now we do the actual pause, this returns when we resumed */
    512508        trace_thread_pause(trace, t);
    513         message.code = MESSAGE_RESUMING;
    514         (*trace->per_pkt)(trace, NULL, &message, t);
     509        (*trace->per_pkt)(trace, t, MESSAGE_RESUMING, (libtrace_generic_t){0}, t);
    515510        return 1;
    516511}
     
    558553
    559554        /* Let the per_packet function know we have started */
    560         message.code = MESSAGE_STARTING;
    561         message.sender = t;
    562         (*trace->per_pkt)(trace, NULL, &message, t);
    563         message.code = MESSAGE_RESUMING;
    564         (*trace->per_pkt)(trace, NULL, &message, t);
    565 
     555        (*trace->per_pkt)(trace, t, MESSAGE_STARTING, (libtrace_generic_t){0}, t);
     556        (*trace->per_pkt)(trace, t, MESSAGE_RESUMING, (libtrace_generic_t){0}, t);
    566557
    567558        for (;;) {
     
    586577                                        goto eof;
    587578                        }
    588                         (*trace->per_pkt)(trace, NULL, &message, t);
     579                        (*trace->per_pkt)(trace, t, message.code, message.additional, message.sender);
    589580                        /* Continue and the empty messages out before packets */
    590581                        continue;
     
    653644
    654645        // Let the per_packet function know we have stopped
    655         message.code = MESSAGE_PAUSING;
    656         message.sender = t;
    657         (*trace->per_pkt)(trace, NULL, &message, t);
    658         message.code = MESSAGE_STOPPING;
    659         message.additional.uint64 = 0;
    660         (*trace->per_pkt)(trace, NULL, &message, t);
     646        (*trace->per_pkt)(trace, t, MESSAGE_PAUSING, (libtrace_generic_t){0}, t);
     647        (*trace->per_pkt)(trace, t, MESSAGE_STOPPING, (libtrace_generic_t){0}, t);
    661648
    662649        // Free any remaining packets
     
    21012088        return result->key;
    21022089}
    2103 DLLEXPORT void libtrace_result_set_value(libtrace_result_t * result, libtrace_generic_types_t value) {
     2090DLLEXPORT void libtrace_result_set_value(libtrace_result_t * result, libtrace_generic_t value) {
    21042091        result->value = value;
    21052092}
    2106 DLLEXPORT libtrace_generic_types_t libtrace_result_get_value(libtrace_result_t * result) {
     2093DLLEXPORT libtrace_generic_t libtrace_result_get_value(libtrace_result_t * result) {
    21072094        return result->value;
    21082095}
    2109 DLLEXPORT void libtrace_result_set_key_value(libtrace_result_t * result, uint64_t key, libtrace_generic_types_t value) {
     2096DLLEXPORT void libtrace_result_set_key_value(libtrace_result_t * result, uint64_t key, libtrace_generic_t value) {
    21102097        result->key = key;
    21112098        result->value = value;
     
    21552142 * Should only be called by a perpkt thread, i.e. from a perpkt handler
    21562143 */
    2157 DLLEXPORT void trace_publish_result(libtrace_t *libtrace, libtrace_thread_t *t, uint64_t key, libtrace_generic_types_t value, int type) {
     2144DLLEXPORT void trace_publish_result(libtrace_t *libtrace, libtrace_thread_t *t, uint64_t key, libtrace_generic_t value, int type) {
    21582145        libtrace_result_t res;
    21592146        res.type = type;
     
    21682155 * Sets a combiner function against the trace.
    21692156 */
    2170 DLLEXPORT void trace_set_combiner(libtrace_t *trace, const libtrace_combine_t *combiner, libtrace_generic_types_t config){
     2157DLLEXPORT void trace_set_combiner(libtrace_t *trace, const libtrace_combine_t *combiner, libtrace_generic_t config){
    21712158        if (combiner) {
    21722159                trace->combiner = *combiner;
Note: See TracChangeset for help on using the changeset viewer.