From d11803d1b998f2a4e90f0cd263baede0d637e528 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 11 Dec 2014 15:05:05 +0200 Subject: [PATCH] smp: batch request processing We're currently using boost::lockfree::consume_all() to consume smp requests, but this has two problems: 1. consume_all() calls consume_one() internally, which means it accesses the ring index once per message 2 we interleave calling the request function with accessing the ring, which allows the other side to access the ring again, bouncing ring cache lines. Fix by copying all available items in one show, using pop(array), and then processing them afterwards. --- core/reactor.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/reactor.cc b/core/reactor.cc index e3487b239d..0abd918615 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -712,11 +712,15 @@ void smp_message_queue::complete() { } size_t smp_message_queue::process_incoming() { - return _pending.consume_all([this] (smp_message_queue::work_item* wi) { + work_item* items[queue_length]; + auto nr = _pending.pop(items); + for (unsigned i = 0; i < nr; ++i) { + auto wi = items[i]; wi->process().then([this, wi] { respond(wi); }); - }); + } + return nr; } void smp_message_queue::start() {