Changeset 07de3c6 for lib


Ignore:
Timestamp:
11/14/17 11:47:17 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
Children:
7e09388
Parents:
eb70703
Message:

Why count the number of buffers available every time?

Surely it is much more efficient to just have a counter that
gets modified each time a buffer is filled or empty...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_ndag.c

    reb70703 r07de3c6  
    6464        uint64_t recordcount;
    6565
     66        int bufavail;
     67
    6668        struct mmsghdr mmsgbufs[RECV_BATCH_SIZE];
    6769} streamsock_t;
     
    598600                 * move on. */
    599601                ssock->savedsize[nr] = 0;
     602                ssock->bufavail ++;
     603
     604                assert(ssock->bufavail > 0 && ssock->bufavail <= ENCAP_BUFFERS);
    600605                nr ++;
    601606                if (nr == ENCAP_BUFFERS) {
     
    688693        ssock->monitorptr = mon;
    689694        ssock->saved = (char **)malloc(sizeof(char *) * ENCAP_BUFFERS);
     695        ssock->bufavail = ENCAP_BUFFERS;
    690696        ssock->startidle = 0;
    691697
     
    767773}
    768774
    769 static void init_receivers(streamsock_t *ssock, int required) {
     775static int init_receivers(streamsock_t *ssock, int required) {
    770776
    771777        int wind = ssock->nextwriteind;
     
    773779
    774780        for (i = 0; i < required; i++) {
     781                if (i >= RECV_BATCH_SIZE) {
     782                        break;
     783                }
     784
    775785                ssock->mmsgbufs[i].msg_len = 0;
    776786                ssock->mmsgbufs[i].msg_hdr.msg_iov->iov_base = ssock->saved[wind];
     
    780790                wind ++;
    781791        }
    782 }
    783 
    784 static int count_receivers(streamsock_t *ssock) {
    785 
    786         int wind = ssock->nextwriteind;
    787         int i;
    788         int avail = 0;
    789 
    790         for (i = 0; i < RECV_BATCH_SIZE; i++) {
    791                 if (wind == ENCAP_BUFFERS) {
    792                         wind = 0;
    793                 }
    794 
    795                 if (ssock->savedsize[wind] != 0) {
    796                         /* No more empty buffers */
    797                         break;
    798                 }
    799 
    800                 avail ++;
    801                 wind ++;
    802         }
    803 
    804         return avail;
     792
     793        return i;
    805794}
    806795
     
    830819        ssock->savedsize[index] = msglen;
    831820        ssock->nextwriteind ++;
     821        ssock->bufavail --;
     822
     823        assert(ssock->bufavail >= 0);
    832824
    833825        if (ssock->nextwriteind >= ENCAP_BUFFERS) {
     
    876868                int *gottime, recvstream_t *rt) {
    877869
    878         int avail, ret, ndagstat, i;
     870        int ret, ndagstat, i, avail;
    879871        int toret = 0;
    880872
     
    883875        }
    884876
    885         avail = count_receivers(ssock);
    886 
    887         if (avail == 0) {
     877        if (ssock->bufavail == 0) {
    888878                /* All buffers were full, so something must be
    889879                 * available. */
     
    891881        }
    892882
    893         if (avail < RECV_BATCH_SIZE / 2) {
     883        if (ssock->bufavail < RECV_BATCH_SIZE / 2) {
    894884                return 1;
    895885        }
    896886
    897         init_receivers(ssock, avail);
     887        avail = init_receivers(ssock, ssock->bufavail);
    898888
    899889        ret = recvmmsg(ssock->sock, ssock->mmsgbufs, avail,
Note: See TracChangeset for help on using the changeset viewer.