Skip to content

Commit

Permalink
reactor: replace references to reactor::_id by its accessor cpu_id()
Browse files Browse the repository at this point in the history
  • Loading branch information
avikivity committed Nov 1, 2014
1 parent d382a31 commit 7a1f84a
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,9 @@ void smp::listen_all(smp_message_queue* qs)
void smp::start_all_queues()
{
for (unsigned c = 0; c < count; c++) {
_qs[c][engine._id].start();
_qs[c][engine.cpu_id()].start();
}
listen_all(_qs[engine._id]);
listen_all(_qs[engine.cpu_id()]);
}

void smp::configure(boost::program_options::variables_map configuration)
Expand Down
5 changes: 3 additions & 2 deletions core/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ private:
friend class file;
friend class readable_eventfd;
friend class timer;
friend class smp;
};

extern thread_local reactor engine;
Expand All @@ -497,10 +498,10 @@ public:
template <typename Func>
static std::result_of_t<Func()> submit_to(unsigned t, Func func,
std::enable_if_t<returns_future<Func>::value, void*> = nullptr) {
if (t == engine._id) {
if (t == engine.cpu_id()) {
return func();
} else {
return _qs[t][engine._id].submit(std::move(func));
return _qs[t][engine.cpu_id()].submit(std::move(func));
}
}
template <typename Func>
Expand Down
2 changes: 1 addition & 1 deletion core/scollectd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class scollectd::impl {
// Optional
put_cached(part_type::PluginInst,
id.plugin_instance() == per_cpu_plugin_instance ?
std::to_string(engine._id) : id.plugin_instance());
std::to_string(engine.cpu_id()) : id.plugin_instance());
put_cached(part_type::Type, id.type());
// Optional
put_cached(part_type::TypeInst, id.type_instance());
Expand Down
2 changes: 1 addition & 1 deletion net/arp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ unsigned arp::handle_on_cpu(packet& p, size_t off) {
if (i != _arp_for_protocol.end()) {
return i->second->forward(p, off);
}
return engine._id;
return engine.cpu_id();
}

void arp::add(uint16_t proto_num, arp_for_protocol* afp) {
Expand Down
4 changes: 2 additions & 2 deletions net/arp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public:
arp_for_protocol(arp& a, uint16_t proto_num);
virtual ~arp_for_protocol();
virtual future<> received(packet p) = 0;
virtual unsigned forward(packet& p, size_t off) { return engine._id; }
virtual unsigned forward(packet& p, size_t off) { return engine.cpu_id(); }
};

class arp {
Expand Down Expand Up @@ -200,7 +200,7 @@ unsigned arp_for<L3>::forward(packet& p, size_t off)
if (oper == op_reply) {
return std::numeric_limits<unsigned>::max(); // broadcast reply
}
return engine._id;
return engine.cpu_id();
}

template <typename L3>
Expand Down
2 changes: 1 addition & 1 deletion net/ip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unsigned ipv4::handle_on_cpu(packet& p, size_t off)
auto iph = p.get_header<ip_hdr>(off);
auto l4 = _l4[iph->ip_proto];
if (!l4) {
return engine._id;
return engine.cpu_id();
}
return l4->forward(p, off + sizeof(ip_hdr), iph->src_ip, iph->dst_ip);
}
Expand Down
2 changes: 1 addition & 1 deletion net/ip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ip_protocol {
public:
virtual ~ip_protocol() {}
virtual void received(packet p, ipv4_address from, ipv4_address to) = 0;
virtual unsigned forward(packet& p, size_t off, ipv4_address from, ipv4_address to) { return engine._id; }
virtual unsigned forward(packet& p, size_t off, ipv4_address from, ipv4_address to) { return engine.cpu_id(); }
};

class ipv4_tcp final : public ip_protocol {
Expand Down
12 changes: 6 additions & 6 deletions net/net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ future<> interface::dispatch_packet(packet p) {
auto i = _proto_map.find(proto);
if (i != _proto_map.end()) {
l3_rx_stream& l3 = i->second;
auto fw = (engine._id == 0) ? l3.forward(p, sizeof(eth_hdr)) : engine._id;
if (fw != engine._id && fw < smp::count) {
smp::submit_to(fw, [p = std::move(p), cpu = engine._id]() mutable { net::dev->l2inject(p.free_on_cpu(cpu)); });
auto fw = (engine.cpu_id() == 0) ? l3.forward(p, sizeof(eth_hdr)) : engine.cpu_id();
if (fw != engine.cpu_id() && fw < smp::count) {
smp::submit_to(fw, [p = std::move(p), cpu = engine.cpu_id()]() mutable { net::dev->l2inject(p.free_on_cpu(cpu)); });
} else {
if (fw != engine._id) { // broadcast to all cpus
if (fw != engine.cpu_id()) { // broadcast to all cpus
for (unsigned i = 0; i< smp::count; i++) {
if (i != engine._id) {
smp::submit_to(i, [n = p.share(), cpu = engine._id] () mutable { net::dev->l2inject(n.free_on_cpu(cpu)); });
if (i != engine.cpu_id()) {
smp::submit_to(i, [n = p.share(), cpu = engine.cpu_id()] () mutable { net::dev->l2inject(n.free_on_cpu(cpu)); });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion net/posix-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ posix_server_socket_impl::accept() {
static unsigned balance = 0;
auto cpu = balance++ % smp::count;

if (cpu == engine._id) {
if (cpu == engine.cpu_id()) {
std::unique_ptr<connected_socket_impl> csi(new posix_connected_socket_impl(std::move(fd)));
return make_ready_future<connected_socket, socket_address>(
connected_socket(std::move(csi)), sa);
Expand Down
2 changes: 1 addition & 1 deletion net/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ future<> proxy_net_device::send(packet p)
_send_depth++;

// Assumes that there is only one virtio device and it is on cpu 0
smp::submit_to(0, [p = std::move(p), cpu = engine._id]() mutable {
smp::submit_to(0, [p = std::move(p), cpu = engine.cpu_id()]() mutable {
return dev->send(p.free_on_cpu(cpu));
}).then([this] () {
if (_send_depth == _send_queue_length) {
Expand Down
2 changes: 1 addition & 1 deletion net/tcp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ template <typename InetTraits>
unsigned tcp<InetTraits>::forward(packet& p, size_t off, ipaddr from, ipaddr to) {
auto th = p.get_header<tcp_hdr>(off);
if (!th) {
return engine._id;
return engine.cpu_id();
}
auto dst = ntohs(uint16_t(th->dst_port));
auto src = ntohs(uint16_t(th->src_port));
Expand Down
2 changes: 1 addition & 1 deletion net/udp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ unsigned udp_v4::forward(packet& p, size_t off, ipv4_address from, ipv4_address
auto uh = p.get_header<udp_hdr>(off);

if (!uh) {
return engine._id;
return engine.cpu_id();
}

auto dst = ntohs(uint16_t(uh->dst_port));
Expand Down

0 comments on commit 7a1f84a

Please sign in to comment.