Commit Graph

1002 Commits

Author SHA1 Message Date
Avi Kivity
52be2f2bf4 Merge branch 'virtio'
Futures are great for complicated asynchronous operations, but for a
synchronous operation like destroying a packet after transmit, or
converting a buffer to a packet during receive, they're overkill.

This patchset fixes those two cases in virtio, in which futures
are used as an abstraction layer between vring and the transmit/receive
queues, by converting vring into a template, so that the completion function
can be adjusted for the transmit or receive case during compile time instead
of at run time.

10% improvement on httpd with --smp 1, >20% with --smp 3.
2014-12-15 11:29:35 +02:00
Avi Kivity
508322c7da virtio: de-futurize receive
Move completion handling (destroy packet, adjust descriptors count) to
a completion function rather than a future.  Reduces allocations and task
executed.
2014-12-14 18:49:01 +02:00
Avi Kivity
1ee959d3e2 virtio: de-futurize transmit
Move completion handling (destroy packet, adjust descriptors count) to
a completion function rather than a future.  Reduces allocations and task
executed.
2014-12-14 18:49:01 +02:00
Avi Kivity
c7c0aebf07 virtio: abstract vring request completions
Currently vring request completions are handled by fulfilling a promise
contained in the request.  While promises are very flexible, this comes
at a cost (allocating and executing a task), and this flexibility is unneeded
when request handling is very regular (such as in virtio-net rx and tx
completion handling).

Make vring more flexible by allowing the completion function to be specified
as a template parameter.  No changes to the actual users - they now specify
the completion function as fulfilling the same promise as vring previously
did.
2014-12-14 18:49:01 +02:00
Avi Kivity
a86faf0209 virtio: de-virtualize virt_to_phys
It is not a device property, but a system property.
2014-12-14 18:49:01 +02:00
Avi Kivity
f3d2908757 virtio: move buffer and config out of vring class
Prior to templating it, best to get the common elements out.
2014-12-14 18:49:01 +02:00
Avi Kivity
fcbcc19231 virtio: remove buffer_chain class
It's a concept that is instantiated by its users, not a true class.
2014-12-14 18:49:01 +02:00
Avi Kivity
5c4ae7a726 virtio: minor code movement 2014-12-14 18:49:01 +02:00
Avi Kivity
d14da53171 virtio: move into 'namespace virtio' 2014-12-14 18:49:01 +02:00
Avi Kivity
4ab36be8c9 reactor: fix pointless allocation in wait_and_process()
wait_and_process() expects an std::function<>, but we pass it a lambda,
forcing it to allocate.

Prepare the sdt::function<> in advance, so it can pass by reference.
2014-12-14 15:58:56 +02:00
Avi Kivity
ea2cfbbcd8 virtio: fix indentation 2014-12-14 10:28:48 +02:00
Avi Kivity
535b447343 circular_buffer: get rid of {pre|post}_push_{front|back}
As Nadav suggests, with the simplified circular_buffer implementation they
no longer provide any value and only obfuscate the code.
2014-12-14 10:00:43 +02:00
Avi Kivity
94a1cdd6e4 Merge branch 'circular_buffer'
circular_buffer simplifications and enhancements.
2014-12-13 18:45:47 +02:00
Avi Kivity
209e0958d2 Merge branch 'nettx'
More virtio and smp batching.
2014-12-13 18:45:25 +02:00
Avi Kivity
9de1b10724 circular_buffer: add unsafe array access method
By allowing access-past-the-end, we can prefetch ahead of the queue without
checking the current queue size.
2014-12-11 22:20:50 +02:00
Avi Kivity
ec0fb398fb circular_buffer: optimize by using masking instead of tests
Since we control the capacity, we can force it to be a power of two,
and use masking instead of tests to handle wraparound.

A side benefit is that we don't have to allocate an extra element.
2014-12-11 22:14:02 +02:00
Avi Kivity
aaf9884064 circular_buffer: fix pop_front(), pop_back()
These methods should destroy the objects they are popping.

We probably haven't seen any leaks since we usually move() the item
before popping it.
2014-12-11 21:55:09 +02:00
Avi Kivity
746dfae355 circular_buffer: add array dereference operator
Useful for prefetching.
2014-12-11 21:32:56 +02:00
Avi Kivity
8a5a8192e4 Merge branch 'hugepages' of ../seastar
Allow backing seastar memory with hugetlbfs files.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-11 19:25:06 +02:00
Avi Kivity
d11803d1b9 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.
2014-12-11 19:20:50 +02:00
Avi Kivity
5855f0c82a smp: batch completion processing
We're currently using boost::lockfree::consume_all() to consume
smp completions, 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.
2014-12-11 19:20:50 +02:00
Avi Kivity
04488eebea smp: batch messages across smp request/response queues
Instead of incurring the overhead of pushing a message down the queue (two
cache line misses), amortize of over 16 messages (3/4 cache line misses per
batch).

Batch size is limited by poll frequency, so we should adjust that
dynamically.
2014-12-11 19:20:50 +02:00
Avi Kivity
2717ac3c37 smp: improve _pending_fifo flushing
Instead of flushing pending items one by one, flush them all at once,
amortizing the write to the index.
2014-12-11 19:20:50 +02:00
Avi Kivity
b6485bcb7c smp: initialize _pending_fifo on sending cpu
If it needs to be resized, it will cause a deallocation on the wrong cpu,
so initialize it on the sending cpu.

Does not break with circular_buffer<>, but it's not going to be a
circular_buffer<> for long.
2014-12-11 19:20:50 +02:00
Avi Kivity
503f1bf4d0 virtio: batch transmitted packets
Instead of placing packets directly into the virtio ring, add them to
a temporary queue, and flush it when we are polled.  This reduces
cross-cpu writes and kicks.
2014-12-11 19:20:50 +02:00
Avi Kivity
97dff83461 virtio: don't try to complete after posting a buffer, if in poll mode
We will poll for it soon anyway, and completing too soon simply reduces
batching.
2014-12-11 19:15:46 +02:00
Avi Kivity
4e653081a4 virtio: poll mode support
With a new --virtio-poll-mode, poll queues instead of waiting for an
interrupt.

Increases httpd throughput by about 12%.
2014-12-11 19:15:46 +02:00
Pekka Enberg
0a12cb6d65 README: Add libpciaccess-devel package to pre-requisites
It's needed on Fedora to build Seastar.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2014-12-11 14:15:18 +02:00
Gleb Natapov
da53dcff80 net: simplify calculation of number of queues 2014-12-11 13:06:38 +02:00
Gleb Natapov
649210b5b6 net: rename net::distributed_device to net::device 2014-12-11 13:06:32 +02:00
Gleb Natapov
0e70ba69cf net: rename net::device to net::qp 2014-12-11 13:06:27 +02:00
Gleb Natapov
8ff89f7f01 net: remove unused device_placement struct 2014-12-11 13:06:22 +02:00
Avi Kivity
db88632456 reactor: wire up hugetlbfs support 2014-12-11 12:25:31 +02:00
Avi Kivity
4453fd1d6a memory: add support for allocating memory via hugetlbfs
This is a little tricky, since we only know we want hugetlbfs after memory
has been initialized, so we start up in anonymous memory, and later
switch to hugetlbfs by copying it to hugetlb-backed memory and mremap()ing
it back into place.
2014-12-11 12:25:31 +02:00
Avi Kivity
ca2c7d8767 memory: abstract mmap() call
To support hugepages, we will need a different mmap() call, so abstract
it out.
2014-12-11 12:25:31 +02:00
Avi Kivity
0043c1a994 memory: drop duplicate madvise() call 2014-12-11 12:25:31 +02:00
Avi Kivity
38443e2c4c posix: change file_desc mmap API to return an mmap_area
An mmap_area munmap()s itself when destroyed, reclaiming memory.
2014-12-11 12:25:31 +02:00
Avi Kivity
158c61063b posix: allow providing the hint/addr parameter to mmap 2014-12-11 12:25:31 +02:00
Avi Kivity
fe8785fb6a posix: allow specifiying mmap flags
Change 'shared' to a flags parameter so that we can specify flags other
than MAP_PRIVATE or MAP_SHARED.
2014-12-11 12:25:31 +02:00
Avi Kivity
ee339bb6ea posix: fix file_desc::map() flags parameter name
It's actually protection, not flags, so change to align with the syscall
to avoid confusion.
2014-12-11 12:25:31 +02:00
Avi Kivity
2e0035dac8 posix: fix file_desc::map() error checking
mmap(2) returns MAP_FAILED on error, not nullptr.
2014-12-11 12:25:31 +02:00
Avi Kivity
c95927f223 posix: add file_desc::size() 2014-12-11 12:25:31 +02:00
Avi Kivity
160907bf05 posix: add support for ftruncate() 2014-12-10 20:04:13 +02:00
Avi Kivity
91dc788a33 posix: add support for creating temporary files 2014-12-10 20:04:13 +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
Asias He
53f95abd96 virtio: Fix feature setup
This fixes a big tcp_server rx regression.

Before:
========== rxrx ============
Server:  192.168.66.123:10000
Connections:  100
Bytes Sent(MiB):  10000
Total Time(Secs):  85.074086675           --->> big regression!!!
Bandwidth(MiB/Sec):  117.54460601148733

After:
========== rxrx ============
Server:  192.168.66.123:10000
Connections:  100
Bytes Sent(MiB):  10000
Total Time(Secs):  9.905637754
Bandwidth(MiB/Sec):  1009.5261151622362
2014-12-10 11:01:54 +02:00
Avi Kivity
fa5c61d4e4 temporary_buffer: fix wrong oom check
If malloc(0) is allowed to return nullptr, so don't throw an exception in
that case.
2014-12-10 10:33:29 +02:00
Avi Kivity
9aadcb7718 Merge branch 'deleter'
Fix a memory leak in packet and bugs in the deleter class that make it likely.
2014-12-10 09:53:59 +02:00
Avi Kivity
441331f158 temporary_buffer: fix missing exception
Since we switched temporary_buffer to malloc(), it now longer throws
an exception after running out of memory, which leads to a segfault
when referencing a null buffer.
2014-12-10 09:53:37 +02:00
Avi Kivity
9ae2075d54 deleter: remove bad/unused interfaces 2014-12-09 20:37:44 +02:00