Skip to content

Commit

Permalink
Merge "net: add statistics counter for linearization events" from Vlad
Browse files Browse the repository at this point in the history
New counters have been added to net::qp, net::tcp and net::ipv4.

The new counters are exposed via collectd interface.
  • Loading branch information
avikivity committed Aug 2, 2015
2 parents 3cf6bee + d48477b commit 947619e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 13 deletions.
7 changes: 3 additions & 4 deletions net/dpdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ static constexpr uint8_t packet_read_size = 32;
/******************************************************************************/

struct port_stats {
port_stats() {
std::memset(&rx, 0, sizeof(rx));
std::memset(&tx, 0, sizeof(tx));
}
port_stats() : rx{}, tx{} {}

struct {
struct {
Expand Down Expand Up @@ -579,6 +576,7 @@ class dpdk_qp : public net::qp {
// Too fragmented - linearize
if (p.nr_frags() > max_frags) {
p.linearize();
++qp._stats.tx.linearized;
}

build_mbuf_cluster:
Expand Down Expand Up @@ -657,6 +655,7 @@ class dpdk_qp : public net::qp {
if (p.nr_frags() > 1 && qp.port().is_i40e_device() && i40e_should_linearize(head)) {
me(head)->recycle();
p.linearize();
++qp._stats.tx.linearized;

goto build_mbuf_cluster;
}
Expand Down
14 changes: 13 additions & 1 deletion net/ip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ ipv4::ipv4(interface* netif)
, _tcp(*this)
, _icmp(*this)
, _udp(*this)
, _l4({ { uint8_t(ip_protocol_num::tcp), &_tcp }, { uint8_t(ip_protocol_num::icmp), &_icmp }, { uint8_t(ip_protocol_num::udp), &_udp }}) {
, _l4({ { uint8_t(ip_protocol_num::tcp), &_tcp }, { uint8_t(ip_protocol_num::icmp), &_icmp }, { uint8_t(ip_protocol_num::udp), &_udp }})
, _collectd_regs({
//
// Linearized events: DERIVE:0:u
//
scollectd::add_polled_metric(scollectd::type_instance_id(
"ipv4"
, scollectd::per_cpu_plugin_instance
, "total_operations", "linearizations")
, scollectd::make_typed(scollectd::data_type::DERIVE
, [] { return ipv4_packet_merger::linearizations(); })
),
}) {
_frag_timer.set_callback([this] { frag_timeout(); });
}

Expand Down
6 changes: 5 additions & 1 deletion net/ip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ struct ipv4_frag_id::hash : private std::hash<ipv4_address>,
}
};

struct ipv4_tag {};
using ipv4_packet_merger = packet_merger<uint32_t, ipv4_tag>;

class ipv4 {
public:
using clock_type = lowres_clock;
Expand All @@ -313,7 +316,7 @@ private:
ip_packet_filter * _packet_filter = nullptr;
struct frag {
packet header;
packet_merger<uint32_t> data;
ipv4_packet_merger data;
clock_type::time_point rx_time;
uint32_t mem_size = 0;
// fragment with MF == 0 inidates it is the last fragment
Expand All @@ -332,6 +335,7 @@ private:
timer<lowres_clock> _frag_timer;
circular_buffer<l3_protocol::l3packet> _packetq;
unsigned _pkt_provider_idx = 0;
scollectd::registrations _collectd_regs;
private:
future<> handle_received_packet(packet p, ethernet_address from);
bool forward(forward_hash& out_hash_data, packet& p, size_t off);
Expand Down
11 changes: 11 additions & 0 deletions net/net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ qp::qp(bool register_copy_stats,
, std::bind(&decltype(_tx_packetq)::size, &_tx_packetq))
),

//
// Linearization counter: DERIVE:0:U
//
scollectd::add_polled_metric(scollectd::type_instance_id(
_stats_plugin_name
, scollectd::per_cpu_plugin_instance
, "total_operations", "xmit-linearized")
, scollectd::make_typed(scollectd::data_type::DERIVE
, _stats.tx.linearized)
),

//
// Number of packets in last bunch: GAUGE:0:U
//
Expand Down
6 changes: 2 additions & 4 deletions net/net.hh
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ struct qp_stats_good {
};

struct qp_stats {
qp_stats() {
std::memset(&rx, 0, sizeof(rx));
std::memset(&tx, 0, sizeof(tx));
}
qp_stats() : rx{}, tx{} {}

struct {
struct qp_stats_good good;
Expand All @@ -205,6 +202,7 @@ struct qp_stats {

struct {
struct qp_stats_good good;
uint64_t linearized; // number of packets that were linearized
} tx;
};

Expand Down
14 changes: 13 additions & 1 deletion net/packet-util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@

namespace net {

template <typename Offset>
template <typename Offset, typename Tag>
class packet_merger {
private:
static uint64_t& linearizations_ref() {
static thread_local uint64_t linearization_count;
return linearization_count;
}
public:
std::map<Offset, packet> map;

static uint64_t linearizations() {
return linearizations_ref();
}

void merge(Offset offset, packet p) {
bool insert;
auto beg = offset;
Expand Down Expand Up @@ -71,6 +81,7 @@ public:
// Append new data to the old segment, keep the old segment
seg_pkt.append(std::move(p));
seg_pkt.linearize();
++linearizations_ref();
insert = false;
break;
} else {
Expand All @@ -85,6 +96,7 @@ public:

if (insert) {
p.linearize();
++linearizations_ref();
map.emplace(beg, std::move(p));
}

Expand Down
22 changes: 20 additions & 2 deletions net/tcp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ struct tcp_hdr {
void adjust_endianness(Adjuster a) { a(src_port, dst_port, seq, ack, window, checksum, urgent); }
} __attribute__((packed));

struct tcp_tag {};
using tcp_packet_merger = packet_merger<tcp_seq, tcp_tag>;

template <typename InetTraits>
class tcp {
public:
Expand Down Expand Up @@ -284,7 +287,7 @@ private:
tcp_seq urgent;
tcp_seq initial;
std::deque<packet> data;
packet_merger<tcp_seq> out_of_order;
tcp_packet_merger out_of_order;
std::experimental::optional<promise<>> _data_received_promise;
} _rcv;
tcp_option _option;
Expand Down Expand Up @@ -531,6 +534,7 @@ private:
// queue for packets that do not belong to any tcb
circular_buffer<ipv4_traits::l4packet> _packetq;
semaphore _queue_space = {212992};
scollectd::registrations _collectd_regs;
public:
class connection {
lw_shared_ptr<tcb> _tcb;
Expand Down Expand Up @@ -606,7 +610,21 @@ private:
};

template <typename InetTraits>
tcp<InetTraits>::tcp(inet_type& inet) : _inet(inet), _e(_rd()) {
tcp<InetTraits>::tcp(inet_type& inet)
: _inet(inet)
, _e(_rd())
, _collectd_regs({
//
// Linearized events: DERIVE:0:u
//
scollectd::add_polled_metric(scollectd::type_instance_id(
"tcp"
, scollectd::per_cpu_plugin_instance
, "total_operations", "linearizations")
, scollectd::make_typed(scollectd::data_type::DERIVE
, [] { return tcp_packet_merger::linearizations(); })
),
}) {
_inet.register_packet_provider([this, tcb_polled = 0u] () mutable {
std::experimental::optional<typename InetTraits::l4packet> l4p;
auto c = _poll_tcbs.size();
Expand Down
1 change: 1 addition & 0 deletions net/xenfront.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ xenfront_qp::send(packet _p) {

// FIXME: negotiate and use scatter/gather
_p.linearize();
++_stats.tx.linearized;

return _tx_ring.entries.has_room().then([this, p = std::move(_p), frag] () mutable {

Expand Down

0 comments on commit 947619e

Please sign in to comment.