From 7bc538f465674c086d96f2f1b456c090e95c67c4 Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Mon, 6 Jul 2015 17:27:40 +0200 Subject: [PATCH] engine: Add engine.busyloop option 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. --- src/README.md | 23 ++++++++++++++++------- src/README.md.src | 16 ++++++++++++++++ src/core/app.lua | 6 +++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/README.md b/src/README.md index 3b31faf223..f178cfded5 100644 --- a/src/README.md +++ b/src/README.md @@ -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 @@ -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) diff --git a/src/README.md.src b/src/README.md.src index f4c200d213..c9abcd9680 100644 --- a/src/README.md.src +++ b/src/README.md.src @@ -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) diff --git a/src/core/app.lua b/src/core/app.lua index f9ffb25644..84806f740c 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -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 @@ -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