Files
scylladb/net/proxy.cc
Gleb Natapov 73f6d943e1 net: separate device initialization from queues initialization
This patch adds new class distributed_device which is responsible for
initializing HW device and it is shared between all cpus. Old device
class responsibility becomes managing rx/tx queue pair and it is local
per cpu. Each cpu have to call distributed_device::init_local_queue() to
create its own device. The logic to distribute cpus between available
queues (in case there is no enough queues for each cpu) is in the
distributed_device currently and not really implemented yet, so only one
queue or queues == cpus scenarios are supported currently, but this can
be fixed later.

The plan is to rename "distributed_device" to "device" and "device"
to "queue_pair" in later patches.
2014-12-09 18:55:14 +02:00

53 lines
1.4 KiB
C++

#include "core/reactor.hh"
#include "proxy.hh"
#include <utility>
namespace net {
class proxy_net_device : public device {
private:
static constexpr size_t _send_queue_length = 1000;
size_t _send_depth = 0;
promise<> _send_promise;
unsigned _cpu;
distributed_device* _dev;
public:
explicit proxy_net_device(unsigned cpu, distributed_device* dev);
virtual future<> send(packet p) override;
};
proxy_net_device::proxy_net_device(unsigned cpu, distributed_device* dev) :
_cpu(cpu),
_dev(dev)
{
}
future<> proxy_net_device::send(packet p)
{
if (_send_depth < _send_queue_length) {
_send_depth++;
device* dev = &_dev->queue_for_cpu(_cpu);
auto cpu = engine.cpu_id();
smp::submit_to(_cpu, [dev, p = std::move(p), cpu]() mutable {
return dev->send(p.free_on_cpu(cpu));
}).then([this] () {
if (_send_depth == _send_queue_length) {
_send_promise.set_value();
}
_send_depth--;
});
if (_send_depth == _send_queue_length) {
_send_promise = promise<>();
return _send_promise.get_future();
}
}
return make_ready_future();
}
std::unique_ptr<device> create_proxy_net_device(unsigned master_cpu, distributed_device* dev) {
return std::make_unique<proxy_net_device>(master_cpu, dev);
}
}