PktSrc: Avoid calling ExtractNextPacketInternal() in GetNextTimeout()

This reworks 2aec7640dd (zeek/zeek#2039) to
avoid calling ExtractNextPacketInternal() within GetNextTimeout() for
the non-pseudo-realtime case. Also relates to zeek/zeek#2842.

The intention of the referenced change was to avoid a 0.00002 timeout when
a non-selectable packet source has more packets queued. This was implemented
by checking for a new packet within GetNextTimeout().

The proposed change switches to an predictive approach: Use the result of
the previous ExtractNextPacket() call (stored as had_packet) as an indication
whether more packets are to be expected.

Calling ExtractNextPacketInternal() within GetNextTimeout() may cause
surprising behavior as some packet source may block [1] or spent a significant
amount of time (e.g. applying BPF filters [2]) within ExtractNextPacket().
The result of GetNextTimeout() should be available immediately as guidance
for the main-loop and the actual work should happen within the ->Process()
method.

This change also attempts to separate the pseudo-realtime logic from the
non-pseudo-realtime in an attempt show pseudo-realtime as special.

[1] 00c4d657e0/src/Napatech.cc (L116)
[2] 58b25c8eba/src/Myricom.cc (L250)
This commit is contained in:
Arne Welzel 2023-03-10 09:59:24 +01:00
parent 16bdcd27bd
commit 39c3bb797c
2 changed files with 38 additions and 26 deletions

View file

@ -362,6 +362,8 @@ private:
bool have_packet;
Packet current_packet;
// Did the previous call to ExtractNextPacket() yield a packet.
bool had_packet;
// For BPF filtering support.
std::vector<detail::BPF_Program*> filters;