diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-05-10 06:40:18 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-05-11 12:01:53 +0200 |
commit | f7f7eb1613b405026410299f6ca6a4e340bf47c8 (patch) | |
tree | f8e344fc2a8e16ddd08f1e91e6312d9b159d6450 /src | |
parent | b4e7f84704b0bb8ed8834d307d24a4c5487619de (diff) |
Improve command processing efficiency
When processing commands with throttling switched off, RDTSC
instruction was executed, but the result was never used. This
patch eliminates the unneeded instruction.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_base.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 931203b..ad8666a 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -786,24 +786,29 @@ int xs::socket_base_t::process_commands (int timeout_, bool throttle_) // If we are asked not to wait, check whether we haven't processed // commands recently, so that we can throttle the new commands. - - // Get the CPU's tick counter. If 0, the counter is not available. - uint64_t tsc = xs::clock_t::rdtsc (); - - // Optimised version of command processing - it doesn't have to check - // for incoming commands each time. It does so only if certain time - // elapsed since last command processing. Command delay varies - // depending on CPU speed: It's ~1ms on 3GHz CPU, ~2ms on 1.5GHz CPU - // etc. The optimisation makes sense only on platforms where getting - // a timestamp is a very cheap operation (tens of nanoseconds). - if (tsc && throttle_) { - - // Check whether TSC haven't jumped backwards (in case of migration - // between CPU cores) and whether certain time have elapsed since - // last command processing. If it didn't do nothing. - if (tsc >= last_tsc && tsc - last_tsc <= max_command_delay) - return 0; - last_tsc = tsc; + // This doesn't apply when the throttling is turned off. + if (throttle_) { + + // Get the CPU's tick counter. If 0, the counter is not available. + uint64_t tsc = xs::clock_t::rdtsc (); + + // Optimised version of command processing - it doesn't have to + // check for incoming commands each time. It does so only if + // certain time elapsed since last command processing. Command + // delay varies depending on CPU speed: With max_command_delay set + // to 3000000 it's ~1ms on 3GHz CPU, ~2ms on 1.5GHz CPU etc. + // The optimisation makes sense only on platforms where getting + // timestamp is a very cheap operation (tens of nanoseconds). + if (tsc) { + + // Check whether TSC haven't jumped backwards (in case of + // migration between CPU cores) and whether certain time have + // elapsed since last command processing. If it didn't do + // nothing. + if (tsc >= last_tsc && tsc - last_tsc <= max_command_delay) + return 0; + last_tsc = tsc; + } } // Check whether there are any commands pending for this thread. |