Commit Graph

50 Commits

Author SHA1 Message Date
Gleb Natapov
77bd21c387 net: implement bulk sending interface for proxy queue
Take advantage of the bulk interface to send several packets simultaneity
with one submit_to() to remote cpu.
2015-01-06 15:24:10 +02:00
Vlad Zolotarov
02dd7a3e24 packet: Change the type of offload_info.vlan_tci to std::experimental::optional
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-23 16:51:05 +02:00
Gleb Natapov
c8189157ed net: use RSS hash key calculated by HW if available
Some (all?) RSS capable HW provides us with a hash that was used to
select rx queue the packet was delivered to. If such hash is available
it is better to use it to forward packet instead of calculating hash
ourself and suffering cache missed.
2014-12-16 10:53:41 +02:00
Nadav Har'El
3d874892a7 dpdk: enable transmit-side checksumming offload
This patch uses the NIC's capability to calculate in hardware the IP, TCP
and UDP checksums on outgoing packets, instead of us doing this on the
sending CPU. This can save us quite a bit of calculations (especially for
the TCP/UDP checksum of full-sized packets), and avoid cache-polution on
the CPU when sending cold data.

On my setup this patch improves the performance of a single-cpu memcached
by 6%. Together with the recent patch for receive-side checksum offloading,
the total improvement  is 10%.

This patch is somewhat complicated by the fact we have so many different
combinations of checksum-offloading capabilities; While virtio can only
offload layer-4 checksumming (tcp/udp), dpdk lets us offload both ip and
layer-4 checksum. Moreover, some packets are just IP but not TCP/UDP
(e.g., ICMP), and some packets are not even IP (e.g., ARP), so this
patch modifies a few of the hardware-features flags and the per-packet
offload-information flags to fit our new needs.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-10 18:05:02 +02:00
Avi Kivity
b87a76412c packet: avoid hand-rolled deleter chaining, use deleter::append instead
The hand-rolled deleter chaining in packet::append was invalidated
by the make_free_deleter() optimization, since deleter->_next is no longer
guaranteed to be valid (and deleter::operator->() is still exposed, despite
that).

Switch to deleter::append(), which does the right thing.

Fixes a memory leak in tcp_server.
2014-12-09 20:37:17 +02:00
Asias He
89c8c6148f net: Add packet::memory
Add packet::memory() which estimates the memory load (by adding sizeof
packet::impl). Note it will only be accurate after linearize/compact.
2014-12-09 09:59:44 +02:00
Vlad Zolotarov
5cc8785b96 packet: Added HW VLAN stipping option.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-07 17:32:36 +02:00
Avi Kivity
2ee0239a4a Merge branch 'tgrabiec/zero-copy-2' of github.com:cloudius-systems/seastar-dev
Zero-copy memcached get from Tomasz:

"I've measured memcached on muninn/huginn to be 7.5% better with this on vhost
stack."
2014-12-04 16:31:04 +02:00
Tomasz Grabiec
c4335c49f6 core: convert output APIs to work on packets
This way zero-copy supporting code can put data directly to packet
object and pass it through all layers efficiently.
2014-12-04 13:51:26 +01:00
Tomasz Grabiec
72b0794759 packet: add constructor for appending temporary_buffers 2014-12-04 13:37:35 +01:00
Tomasz Grabiec
3a2d74e3d3 packet: add reserve() method 2014-12-04 13:37:35 +01:00
Tomasz Grabiec
f3dada6f1d packet: add constructor for appending deleters
Deleters not always come with fragments. When multiple fragments share
a deleter, first fragments are appended and then one deleter for all
of them.
2014-12-04 13:37:35 +01:00
Tomasz Grabiec
8ffcdac455 packet: move lambdas rather than copy them
Some lambdas are not copyable.
2014-12-04 13:37:35 +01:00
Tomasz Grabiec
2650c68824 packet: add more constructor variants 2014-12-04 13:37:35 +01:00
Asias He
59aa280f0d ip: Add IPv4 reassembly support
If a TCP or UDP IP datagram is fragmented, only the first fragment will
contain the port information. When a fragment without port information
is received, we have no idea which "stream" this fragment belongs to,
thus we no idea how to forward this packet.

To solve this problem, we use "forward twice" method. When IP datagram
which needs fragmentation is received, we forward it using the
frag_id(src_ip, dst_ip, identification, protocol) hash. When all the
fragments are received, we forward it using the connection_id(src_ip,
src_port, dst_ip, dst_port) hash.
2014-12-03 21:40:49 +08:00
Asias He
88a1a37a88 ip: Support IP fragmentation in TX path
Tested with UDP sending large datagrams with ufo off.
2014-11-30 10:16:38 +02:00
Vlad Zolotarov
80396b5153 packet: Use const_cast
The original cast gave an error with -Werror=cast-qual

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-11-23 23:25:38 +02:00
Avi Kivity
174cc6b876 packet: add linearize()
This is helpful for net devices that do not support scatter/gather.
2014-11-04 10:55:04 +02:00
Asias He
345d3a3628 net: Add trim_back to packet 2014-11-04 10:13:36 +02:00
Avi Kivity
929f714e4c net: allow constructing a packet from const data
Since we're copying the data, we can call const_cast<> without fear.
2014-10-28 11:01:37 +02:00
Avi Kivity
d5675c32a7 net: add ostream support for packet
print your packets with

   print("got packet: %s\n", p);

!
2014-10-28 11:01:37 +02:00
Avi Kivity
ae7c071a01 net: fix packet::append with internal data 2014-10-28 11:01:37 +02:00
Asias He
fd56c6345c net: Remove leftover code in packet.hh 2014-10-28 10:42:18 +02:00
Tomasz Grabiec
cec8b6c5de core: fix SIGSEGV in packet::packet(fragment frag, packet&& x)
We move from x._impl in the initializer list, so it will hold nullptr
later.
2014-10-23 11:31:03 +03:00
Asias He
6561bde964 net: Add TCP option support
Maximum segment size and Window scale option are supported currently.
2014-10-22 10:28:06 +03:00
Avi Kivity
61782fcc05 packet: add a vectored constructor with a deleter
Add packet(Iterator, Iterator, deleter).

(unfortunately we have both a template version with a template parameter
named Deleter, and a non-template version with a parameter called deleter.
Need to sort the naming out).
2014-10-21 11:24:27 +03:00
Tomasz Grabiec
930181d361 net: fix packet constructors
Thy did not compile.
2014-10-15 15:50:46 +02:00
Asias He
c2650971b9 virtio-net: Improve RX packet building
Use begin and end iterator to build a packet in one go.
2014-10-13 11:37:56 +08:00
Asias He
5cf3f200c5 net: Introduce ip_protocol_num
We use this in all the places where the ip protocol number is used.
2014-10-13 11:37:56 +08:00
Asias He
05c72b0808 net: UDP checksum offload and UPD fragmentation offload 2014-10-13 11:37:56 +08:00
Asias He
d90bab775d virtio-net: Merge receive buffer 2014-10-09 19:54:50 +03:00
Asias He
f14c04a132 net: Add offload_info to packet class
This is useful for adding tcp segment offload in ethernet driver.
This way, we do not need to parse the TCP packet again.
2014-10-09 19:52:54 +03:00
Gleb Natapov
c8ffffa557 Add packet::free_on_cpu() function
Some packets are processed by a cpu other than the one that allocates it
and its fragments. free_on_cpu() function should be called on a cpu that
does processing and it returns a packet that is deletable by the current
cpu. It is done by copying packet/packet::impl to locally allocated one
and adding new deleter that runs old deleter on original cpu.
2014-10-07 11:04:01 +03:00
Tomasz Grabiec
623129b45b net: add packet constructor which accepts static data 2014-10-06 18:34:28 +02:00
Gleb Natapov
534ce9b0db packet: use delegating constructor instead of duplicating code 2014-10-02 15:43:09 +03:00
Avi Kivity
bc8a940dfa packet: mark as noexcept move constructible 2014-10-02 14:32:34 +03:00
Avi Kivity
a1f3708fab packet: optimize sharing
Move reference counting into the deleter core, instead of relegating it
to a shared_deleter (which has to be allocated) and an external reference
counted (also allocated).  This dramatically reduces dynamic allocations.
2014-09-23 18:57:11 +03:00
Avi Kivity
75f07adb69 packet: store header data inside packet itself
Instead of using internal_deleter, which is unwieldy, store the
header data inside packet::impl which we're allocating anyway.

This adds some complication when we need to reallocate impl (if
the number of fragments overflows), but usually saves two allocations:
one for the internal_deleter and one for the data itself.
2014-09-23 18:02:18 +03:00
Avi Kivity
e223f748ec core: great deleter rename
deleter::share() is causing massive amounts of allocation.  First,
since usually a packet's deleter is not a shared_deleter, we need to
allocate that shared_deleter.  Second, we need an external reference
count which requires yet another allocation.

Making reference counting part of the deleter class would solve both of
these problems, but we cannot easily do that, since users hold
std::unique_ptr<deleter> which is clearly not sharable.

We could do a massive s/unique_ptr/shared_ptr/ here, but that would have
the side effect of making sharing "too easy" - you simply copy the pointer.
We'd like to keep it explicit.

So to make the change easier, rename the existing unique_ptr<deleter> as
plain "deleter", whereas the old "deleter" becomes deleter::impl:

  old name              new name
  --------              --------
  deleter               deleter::impl
  unique_ptr<deleter>   deleter

with exactly the same semantics.  A later patch can then add explicit sharing.
2014-09-23 11:15:31 +03:00
Avi Kivity
e76328b2c9 packet: add zero-copy single-fragment constructor
Useful for converting a temporary_buffer<> into a packet.
2014-09-23 10:37:56 +03:00
Avi Kivity
d131b4cce3 packet: optimize appending to an empty packet
The tcp does this quite often, so optimize this trivial append by
moving the packet in.
2014-09-22 17:57:18 +03:00
Avi Kivity
6dc0e9ba79 packet: fix allocation failure path
Since we allocate impl with a custom allocator, we must provide a
custom deallocator in case the constructor throws.

Found by Pekka and clang.
2014-09-22 15:53:04 +03:00
Avi Kivity
7f7a550f98 net: extend packet by doubling fragment vector size
Avoid quadratic behavior
2014-09-22 14:26:34 +03:00
Avi Kivity
4c10d9c270 packet: fix early free when extending packet
If the fragment vector runs out of space, we extend it, but we forgot
to move the deleter, resulting in an early free.  Flagged by address
sanitizer.
2014-09-22 14:14:37 +03:00
Avi Kivity
2f103a8558 packet: reduce allocations for the fragment array
Instead of having an std::vector<> manage the fragment array,
allocate it at the end of the impl struct and manage it manually.

The result isn't pretty but it does remove an allocation.
2014-09-17 11:31:22 +03:00
Avi Kivity
804aec33fd packet: fix appending constructor
We did not actually append the fragment.
2014-09-17 09:49:39 +03:00
Tomasz Grabiec
791797669f net: make offset == 0 by default in packet::get_header() to simplify call sites 2014-09-16 18:48:13 +03:00
Avi Kivity
48ba89f060 packet: optimize move()ing packets around
Move all data fields into an 'impl' struct (pimpl idiom) so that move()ing
a packet becomes very cheap.  The downside is that we need an extra
allocation, but we can later recover that by placing the fragment array
in the same structure.

Even with the extra allocation, performance is up ~10%.
2014-09-16 15:50:35 +03:00
Avi Kivity
37c90fe54e net: make packet data members private
This will assist in future refactoring.
2014-09-16 11:24:13 +03:00
Avi Kivity
812ac77d2f net: spit out packet class into its own files 2014-09-16 10:13:09 +03:00