Commit Graph

538 Commits

Author SHA1 Message Date
Avi Kivity
c35b61bda5 distributed: fix return type of lambda-friendly invoke_on()
result_of<> is mean to be used only with its 'type' member; use result_of_t
instead.
2015-02-22 16:20:36 +02:00
Avi Kivity
f116ef8fb6 file: skip . and .. in directory listings 2015-02-20 10:13:15 +02:00
Avi Kivity
842a0f70ca Revert "core: demangle stdout"
This reverts commit a8698fa17c62542a98e928d395f38e66f6ff148c; causes
problems with dpdk.

Conflicts:
	core/stdio.cc
	core/stdio.hh
2015-02-19 18:55:43 +02:00
Avi Kivity
caa83858f0 reactor: handle SIGTERM and SIGINT once
stop() is not prepared to be called twice.
2015-02-19 18:45:50 +02:00
Gleb Natapov
3928092053 smp: put a cache line between smp statistics structures
CPU may automatically prefetch next cache line, so if statistics that
are collected on different cpus resided on adjacent cache lines CPU may
erroneously prefetch cache line that is guarantied to be accessed by
another CPU. Fix it by putting a cache line between two structures.
2015-02-19 17:00:18 +02:00
Vlad Zolotarov
06565c80d5 DPDK: Decouple Rx data buffers
- Allocate the data buffers instead of using the default inline rte_mbuf
     layout.
   - Implement an rx_gc() and add an _rx_gc_poller to call it: we will refill
     the rx mbuf's when at least 64 free buffers.
     This threshold has been chosen as a sane enough number.
   - Introduce the mbuf_data_size == 4K. Allocate 4K buffers for a detached flow.
     We are still going to allocate 2K data buffers for an inline case since 4K
     buffers would require 2 pages per mbuf due to "mbuf_overhead".

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-02-19 16:58:54 +02:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Avi Kivity
a8698fa17c core: demangle stdout
When using print() to debug on smp, it is very annoying to get interleaved
output.

Fix by wrapping stdout with a fake stream that has a line buffer for each
thread.
2015-02-19 09:26:17 +02:00
Glauber Costa
861d2625b2 file_stream: proper seek support.
Our file_stream interface supports seek, but when we try to seek to arbitrary
locations that are smaller than an aio-boundary (say, for instance, f->seek(4)),
we will end up not being able to perform the read.

We need to guarantee the reads are aligned, and will then present to the caller
the buffer properly offset.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-02-18 22:56:07 +02:00
Avi Kivity
84234b5b9a memory: implement the C11 aligned_alloc() function 2015-02-18 19:48:18 +02:00
Avi Kivity
b4098dac2f core: add distributed::invoke_on() variants not requiring a pointer to member
Current variants of distributed<T>::invoke_on() require member function to
invoke, which may be tedious to implement for some cases.  Add a variant
that supports invoking a functor, accepting the local instance by reference.
2015-02-18 16:52:56 +02:00
Avi Kivity
17914a80cd future: add a utility to promote a type to a its own future
Some of the core functions accept functions returning either an immediate
type, or a future, and return a future in either case (e.g. smp::submit_to()).

To make it easier to metaprogram with these functions, provide a utility
that computes the return type, futurize<T>:

   futurize_t<bar>          => future<bar>

   futurize_t<void>         => future<>

   futurize_t<future<bar>>  =>  future<bar>
2015-02-18 16:52:56 +02:00
Avi Kivity
c1abe0e573 smp: remove gratuitous cache miss when no responses are pending
boost::lockfree::spsc_queue::push() writes the producer index even when no
data is pushed, so check whether we need to do any work beforehand.
2015-02-17 18:00:12 +02:00
Avi Kivity
8ca0f21ae6 posix: add missing include 2015-02-15 15:55:35 +02:00
Vlad Zolotarov
5daa8478f4 DPDK_RTE: Add a weak definition for dpdk::qp_mempool_obj_size()
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-02-12 19:20:15 +02:00
Vlad Zolotarov
95bf98977d DPDK: Recover the DPDK 1.7.x support
- Define MARKER type if not defined.
   - Adjust the Tx zero-copy to the rte_mbuf layout in DPDK 1.7.x.
   - README.md:
      - Bump up the DPDK latest version to 1.8.0.
      - Add a new DPDK configuration description.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-02-12 18:54:05 +02:00
Vlad Zolotarov
21f4c88c85 DPDK: zero_copy_tx - initial attempt
Send packets without copying fragments data:
   - Poll all the Tx descriptors and place them into a circular_buffer.
     We will take them from there when we need to send new packets.
   - PMD will return the completed buffers descriptors to the Tx mempool.
     This way we are going to know that we may release the buffer.
   - "move" the packet object into the last segment's descriptor's private data.
     When this fragment is completed means the whole packet has been sent
     and its memory may be released. So, we will do it by calling the packet's
     destructor.

Exceptions:
   - Copy if hugepages backend is not enabled.
   - Copy when we failed to send in a zero-copy flow (e.g. when we failed
     to translate a buffer virtual address).
   - Copy if first frag requires fragmentation below 128 bytes level - this is
     in order to avoid headers splitting.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>

New in v5:
   - NULL -> nullptr across the board.
   - Removed unused macros: MBUF_ZC_PRIVATE() and max_frags_zc.
   - Improved the local variables localization according to Nadav's remarks.
   - tx_buf class:
      - Don't regress the whole packet to the copy-send if a single fragment failed to be sent
        in a zero-copy manner (e.g. its data failed the virt2phys translation). Send only such a
        fragment in a copy way and try to send the rest of the fragments in a zero-copy way.
      - Make set_packet() receive packet&&.
      - Fixed the comments in check_frag0(): we check first 128 bytes and not first 2KB.
        starting from v2.
      - Use assert() instead of rte_exit() in do_one_frag().
      - Rename in set_one_data_buf() and in copy_one_data_buf(): l -> buf_len
      - Improve the assert about the size of private data in the tx_buf class:
         - Added two MARKER fields at the beginning and at the end of the private fields section
           which are going to be allocated on the mbuf's private data section.
         - Assert on the distance between these two markers.
      - Replace the sanity_check() (checks that packet doesn't have a zero-length) in a
        copy-flow by an assert() in a general function since this check
        is relevant both for a copy and for a zero-copy flows.
      - Make a sanity_check to be explicitly called frag0_check.
      - Make from_packet() receive packet&&.
      - In case frag0_check() fails - copy only the first fragment and
        not the whole packet.
   - tx_buf_factory class:
      - Change the interface to work with tx_buf* instead of tx_buf&.
      - Better utilize for-loop facilities in gc().
      - Kill the extra if() in the init_factory().
      - Use std::deque instead of circular_buffer for storing elements in tx_buf_factory.
      - Optimize the tx_buf_factory::get():
         - First take the completed buffers from the mempool and only if there
           aren't any - take from the factory's cache.
      - Make Tx mempools using cache: this significantly improves the performance despite the fact that it's
        not the right mempool configuration for a single-producer+single-consumer mode.
      - Remove empty() and size() methods.
   - Add comments near the assert()s in the fast-path.
   - Removed the not-needed "inline" qualifiers:
      - There is no need to specify "inline" qualifier for in-class defined
        methods INCLUDING static methods.
      - Defining process_packets() and poll_rx_once() as inline degraded the
        performance by about 1.5%.
   - Added a _tx_gc_poller: it will call tx_buf_factory::gc().
   - Don't check a pointer before calling free().
   - alloc_mempool_xmem(): Use posix_memalign() instead of memalign().

New in v4:
   - Improve the info messages.
   - Simplified the mempool name creation code.
   - configure.py: Opt-out the invalid-offsetof compilation warning.

New in v3:
   - Add missing macros definitions dropped in v2 by mistake.

New in v2:
   - Use Tx mbufs in a LIFO way for better cache utilization.
   - Lower the frag0 non-split thresh to 128 bytes.
   - Use new (iterators) semantics in circular_buffer.
   - Use optional<packet> for storing the packing in the mbuf.
   - Use rte_pktmbuf_alloc() instead of __rte_mbuf_raw_alloc().
   - Introduce tx_buf class:
      - Hide the private rte_mbuf area handling.
      - Hide packet to rte_mbuf cluster translation handling.
   - Introduce a "Tx buffers factory" class:
      - Hide the rte_mbuf flow details:
            mempool->circular_buffer->(PMD->)mempool
   - Templatization:
      - Make huge_pages_mem_backend a dpdk_qp class template parameter.
      - Unite the from_packet_xxx() code into a single template function.
      - Unite the translate_one_frag() and copy_one_frag() into a single
        template function.
2015-02-12 11:04:07 +02:00
Vlad Zolotarov
4d0f2d3e4c DPDK_RTE: Give rte_eal_init() -m parameter when we use hugetlbfs
When we use hugetlbfs we will give mempools external buffer for allocations
but the mempool internals still need memory.
We will assume that each CPU core is going to have a HW QP ("worst" case) and
provide the DPDK with enough memory to be able to allocate them all.

The memory above is subtracted from the total amount of memory given to the application
(with -m seastar application parameter).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-02-11 19:27:12 +02:00
Vlad Zolotarov
18f35236db memory: Move page_size, page_bits and huge page size definitions to header
They are going to be used in more places (not just in memory.cc).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-02-11 19:27:12 +02:00
Avi Kivity
d7eb4e96fb app-template: add support for positional options
Example:

    app_template app;
    namespace bpo = boost::program_options;
    app.add_positional_options({
        { "file", bpo::value<std::string>(), "File to process", 1 },
    });
2015-02-11 15:38:51 +02:00
Avi Kivity
af0bf06836 core: add file_data_source, file_input_stream
Implement a character stream backed by a file.
2015-02-11 15:38:51 +02:00
Avi Kivity
d31de31aac core: add input_stream::reset()
Useful for seekable streams, to drop existing buffered data.
2015-02-11 15:38:49 +02:00
Avi Kivity
2dadcdc5e7 core: make some data_source internals available to derived classes
Useful for adding functionality such as seekable streams.
2015-02-10 19:00:45 +02:00
Avi Kivity
381814aeaf stream.hh: add missing include 2015-02-10 18:59:38 +02:00
Avi Kivity
951a93a534 file.hh: add missing include 2015-02-10 18:59:16 +02:00
Tomasz Grabiec
331d5e1569 core: Fail do_until() future when the callback throws
Otherwise we will aband the result promise, which results in abort.
2015-02-10 14:47:42 +02:00
Raphael S. Carvalho
bf41da8974 core: small optimization when constructing std::vector<cpu>
Size of std::vector<cpu> can be pre-determined, then let's reserve memory ahead
of time so that push back calls would be optimized.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-08 19:05:45 +02:00
Avi Kivity
7a704f7a40 sstring: fix truncation in compare()
If the difference between the sizes of the two strings is larger than can
be represented by an int, truncation will occur and the sign of the result
is undefined.

Fix by using explicit tests and return values.
2015-02-08 11:41:22 +02:00
Pekka Enberg
9a55e9fd22 sstring: Add 'compare' and 'operator<'
Add string comparison functions to basic_sstring that are required for
C++ containers such as std::map and std::multimap.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-02-08 11:12:31 +02:00
Pekka Enberg
fc7cb5ab5e shared_ptr: Fix assignment of polymorphic types
Fix the assignment operator to work with polymorphic types.

Suggested by Nadav.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-02-08 10:24:21 +02:00
Nadav Har'El
a9ef189a54 core: add support for enum types as hash-table keys
This patchs adds a header file, "core/enum.hh"; Code which includes
this header file will be able to use an enumerated type as the key in a
hash table.

The header file implements a hash function for *all* enumerated types,
by using the standard hash function of the underlying integer type.
2015-02-07 12:33:48 +02:00
Gleb Natapov
89763c95c9 core: optimise timer completions vs periodic timers
The way periodic timers are rearmed during timer completion causes
timer_settime() to be called twice for each periodic timer completion:
once during rearm and second time by enable_fn(). Fix it by providing
another function that only re-adds timer into timers container, but do
not call timer_settime().
2015-01-29 12:43:28 +02:00
Avi Kivity
59c0d7e893 smp: fix work item deletion
Delete it after completion, not after responding.
2015-01-29 12:14:05 +02:00
Gleb Natapov
bcae5f2538 smp: fix memory leak in smp queue
Delete completed items. Fixes regression from ff4aca2ee0.
2015-01-29 11:49:24 +02:00
Avi Kivity
b3dd1c8285 Merge branch 'signal' of ../seastar
Simplify signal handling.
2015-01-29 10:08:27 +02:00
Tomasz Grabiec
7a55f21b29 core: Move _timer to an instance field
So that the callback which is set on it and which is allocated on CPU
0 is destroyed on CPU 0 when the clock dies. Otherwise we can attempt
to delete it after the CPU thread is gone if CPU 0 != main thread.
2015-01-28 16:18:55 +02:00
Tomasz Grabiec
8a126b9088 core: Fix use-after-free error on _threads
When smp::configure() is called from non-main thread, then the global
state which it allocates will be destroyed after reactor is destroyed,
because it will be destroyed from the main thread and the reactor will
be destroyed together with the thread which called
smp::configure(). This will result in SIGSEGV when allocator tries to
free _threads vector across CPU threads because the target CPU was
alrady freed. See issue #10.

To fix this, I introduced smp::cleanup() method which should cleanup
all global state and should be called in the same thread in which
smp::configure() was called.

I need to call smp::configure() from non-main thread for integration
with boost unit testing framework.
2015-01-28 16:18:53 +02:00
Tomasz Grabiec
555977f5e6 core: drop BSD license text from resource.hh 2015-01-28 16:18:50 +02:00
Gleb Natapov
bb072fc5c9 core: add iterator for circular_buffer container 2015-01-28 13:49:09 +02:00
Takuya ASADA
be5568ae31 distributed: handle invoke_on with void return value
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-01-28 13:48:18 +02:00
Avi Kivity
38839293f9 reactor: simplify timer handling
Instead of scheduling timer processing to happen in the future,
process timers in the context of the poller (signal poller for high
resolution timer, lowres time poller for low resolution timers).

This both reduces timer latency (not very important) but removes a
use of promise/future in a repetitive task, which is error prone.
2015-01-28 11:29:16 +02:00
Avi Kivity
770214ea63 reactor: simplify signal handling
Signals can be repetitive, and therefore are not a good match for
promise/future, which are single shot.

Replace with plain callbacks.
2015-01-28 11:07:14 +02:00
Avi Kivity
a9c0fbd8f7 timer: add constructor from callback 2015-01-27 18:57:59 +02:00
Gleb Natapov
5454c79613 core: allocate reactors on each cpu instead of using thread_local variable
I see TLS init function for engine high in cache miss profile. And yes,
this patch has #define.
2015-01-27 14:46:49 +02:00
Gleb Natapov
7a92efe8d1 core: add local engine accessor function
Do not use thread local engine variable directly, but use accessor
instead.
2015-01-27 14:46:49 +02:00
Gleb Natapov
18d212b04e core: do not use separate thread_local variable to track pending signals
Access to thread_local variable goes throw a helper function.
2015-01-27 12:33:10 +02:00
Gleb Natapov
74f9f1fdd2 core: prefetch different amount of work items for different queues
Incoming item processing usually takes more work then completion
item processing. Prefetch more completion items to make sure they are
ready before access.
2015-01-25 17:51:21 +02:00
Gleb Natapov
0383459b93 core: prefetch only valid addresses
Prefethcing non mapped address incurs address translation cost.
2015-01-25 17:51:21 +02:00
Gleb Natapov
ff4aca2ee0 core: prefetch work items before processing 2015-01-25 14:48:30 +02:00
Gleb Natapov
b9554219dc core: add prefetch functions 2015-01-25 14:48:30 +02:00