Changeset 54ef438 for lib


Ignore:
Timestamp:
12/10/18 11:14:57 (23 months ago)
Author:
Shane Alcock <salcock@…>
Branches:
develop
Children:
24fe0f5, 509ee47, c2fe7b6
Parents:
c337c9f9
Message:

ndag: just read one "batch" of packets per pread call

Previously, we would stay in pread until we got close to the
full number of packets requested or a non-blocking read gave us
no new packets.

This meant that we could in theory waste time doing an unnecessary
non-blocking read that was going to fail, when instead we could
just assume that we were going to be called again shortly anyway
if the user wanted more packets.

It's a bit tenuous when I try to explain it, but it seems to save
us a bit of CPU time in practice...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_ndag.c

    r8a58afd r54ef438  
    10541054        }
    10551055
    1056         zerotv.tv_sec = 0;
    1057         zerotv.tv_usec = 0;
    1058 
    10591056        for (i = 0; i < rt->sourcecount; i++) {
    10601057                if (rt->sources[i].sock == -1) {
     
    10881085        }
    10891086
     1087        zerotv.tv_sec = 0;
     1088        zerotv.tv_usec = 0;
    10901089        if (select(maxfd + 1, &fds, NULL, NULL, &zerotv) == -1) {
    10911090                /* log the error? XXX */
     
    12591258        rt = (recvstream_t *)t->format_data;
    12601259
    1261 
    12621260        do {
    12631261                /* Only check for messages once per batch */
     
    12651263                        rem = receive_encap_records_block(libtrace, rt,
    12661264                                packets[read_packets]);
    1267                 } else {
    1268                         rem = receive_encap_records_nonblock(libtrace, rt,
    1269                                 packets[read_packets]);
    1270                 }
    1271 
    1272                 if (rem < 0) {
    1273                         return rem;
    1274                 }
    1275 
    1276                 if (rem == 0) {
    1277                         break;
     1265                        if (rem < 0) {
     1266                                return rem;
     1267                        }
     1268
     1269                        if (rem == 0) {
     1270                                break;
     1271                        }
    12781272                }
    12791273
Note: See TracChangeset for help on using the changeset viewer.