Changeset 7ebf768 for lib


Ignore:
Timestamp:
02/14/18 15:51:27 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, etsilive, master, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
Children:
3004d6c
Parents:
6445c52
Message:

Avoid multiple byteswaps of the same variable in format_dag.

In particular, we can cache the timestamp of the next packet
in a socket buffer rather than re-read it from the buffer every
time we call select_next_packet() -- maybe not such a big issue
when you have two sockets per thread, but very wasteful when you
have 8 sockets per thread.

Keep a local copy of rlen in host byte order when preparing a
packet, so we don't have to repeatedly swap it. Compiler
optimization might make this improvement irrelevant, though?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_ndag.c

    r6445c52 r7ebf768  
    8787        int nextwriteind;
    8888        int savedsize[ENCAP_BUFFERS];
     89        uint64_t nextts;
    8990        uint32_t startidle;
    9091        uint64_t recordcount;
     
    587588        uint16_t ndag_reccount = 0;
    588589        int nr;
     590        uint16_t rlen;
    589591
    590592        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
     
    629631        if ((ndag_reccount & 0x8000) != 0) {
    630632                /* Record was truncated -- update rlen appropriately */
    631                 erfptr->rlen = htons(ssock->savedsize[nr] -
    632                                 (ssock->nextread - ssock->saved[nr]));
    633         }
    634         ssock->nextread += ntohs(erfptr->rlen);
     633                rlen = ssock->savedsize[nr] -
     634                                (ssock->nextread - ssock->saved[nr]);
     635                erfptr->rlen = htons(rlen);
     636        } else {
     637                rlen = ntohs(erfptr->rlen);
     638        }
     639        ssock->nextread += rlen;
     640        ssock->nextts = 0;
    635641
    636642        assert(ssock->nextread - ssock->saved[nr] <= ssock->savedsize[nr]);
     
    652658
    653659        packet->order = erf_get_erf_timestamp(packet);
    654         packet->error = packet->payload ? ntohs(erfptr->rlen) :
    655                         erf_get_framing_length(packet);
    656         return ntohs(erfptr->rlen);
     660        packet->error = rlen;
     661        return rlen;
    657662}
    658663
     
    734739        ssock->bufwaiting = 0;
    735740        ssock->startidle = 0;
     741        ssock->nextts = 0;
    736742
    737743        for (i = 0; i < ENCAP_BUFFERS; i++) {
     
    876882
    877883        assert(ssock->bufavail >= 0);
    878 
    879         if (ssock->nextwriteind >= ENCAP_BUFFERS) {
     884        if (ssock->nextwriteind >= ENCAP_BUFFERS) {
    880885                ssock->nextwriteind = 0;
    881886        }
     
    11121117        dag_record_t *daghdr;
    11131118
     1119        /* If we only have one source, then no need to do any
     1120         * timestamp parsing or byteswapping.
     1121         */
     1122        if (rt->sourcecount == 1) {
     1123                if (readable_data(&(rt->sources[0]))) {
     1124                        return &(rt->sources[0]);
     1125                }
     1126                return NULL;
     1127        }       
     1128
     1129
    11141130        for (i = 0; i < rt->sourcecount; i ++) {
    11151131                if (!readable_data(&(rt->sources[i]))) {
     
    11171133                }
    11181134
    1119                 daghdr = (dag_record_t *)(rt->sources[i].nextread);
    1120                 currentts = bswap_le_to_host64(daghdr->ts);
     1135                if (rt->sources[i].nextts == 0) {
     1136                        daghdr = (dag_record_t *)(rt->sources[i].nextread);
     1137                        currentts = bswap_le_to_host64(daghdr->ts);
     1138                        rt->sources[i].nextts = currentts;
     1139                } else {
     1140                        currentts = rt->sources[i].nextts;
     1141                }
    11211142
    11221143                if (earliest == 0 || earliest > currentts) {
Note: See TracChangeset for help on using the changeset viewer.