Skip to content

Commit

Permalink
engine: Add engine.busyloop option
Browse files Browse the repository at this point in the history
The setting 'engine.busyloop = true' now causes the engine to poll
continuously for new traffic. This can be used to minimize latency in
exchange for pegging the CPU at 100% utilization.
  • Loading branch information
lukego committed Jul 6, 2015
1 parent 256706d commit 7bc538f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ For example: Move packets from input ports to output ports or to a
network adapter.


— Method **myapp:relink**

*Optional*. React to a changes in input/output links (`app.input` and
`app.output`). This method is called after a link reconfiguration but
before the next packets are processed.


— Method **myapp:reconfig** *arg*

*Optional*. Reconfigure the app with a new *arg*. If this method is not
Expand Down Expand Up @@ -207,7 +200,23 @@ following keys are recognized:
Returns monotonic time in seconds as a floating point number. Suitable
for timers.

— Variable **engine.busywait**

If set to true then the engine polls continuously for new packets to
process. This consumes 100% CPU and makes processing latency less
vulnerable to kernel scheduling behavior which can cause pauses of
more than one millisecond.

Default: false

— Variable **engine.Hz**

Frequency at which to poll for new input packets. The default value is
'false' which means to adjust dynamically up to 100us during low
traffic. The value can be overridden with a constant integer saying
how many times per second to poll.

This setting is not used when engine.busywait is true.

## Link (core.link)

Expand Down
16 changes: 16 additions & 0 deletions src/README.md.src
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,23 @@ following keys are recognized:
Returns monotonic time in seconds as a floating point number. Suitable
for timers.

— Variable **engine.busywait**

If set to true then the engine polls continuously for new packets to
process. This consumes 100% CPU and makes processing latency less
vulnerable to kernel scheduling behavior which can cause pauses of
more than one millisecond.

Default: false

— Variable **engine.Hz**

Frequency at which to poll for new input packets. The default value is
'false' which means to adjust dynamically up to 100us during low
traffic. The value can be overridden with a constant integer saying
how many times per second to poll.

This setting is not used when engine.busywait is true.

## Link (core.link)

Expand Down
6 changes: 5 additions & 1 deletion src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Hz = false
sleep = 0
maxsleep = 100

-- busywait: If true then the engine will poll for new data in a tight
-- loop (100% CPU) instead of sleeping according to the Hz setting.
busywait = false

-- Return current monotonic time in seconds.
-- Can be used to drive timers in apps.
monotonic_now = false
Expand Down Expand Up @@ -233,7 +237,7 @@ function main (options)
repeat
breathe()
if not no_timers then timer.run() end
pace_breathing()
if not busywait then pace_breathing() end
until done and done()
if not options.no_report then report(options.report) end
end
Expand Down

0 comments on commit 7bc538f

Please sign in to comment.