Commit Graph

580 Commits

Author SHA1 Message Date
Raphael S. Carvalho
3637b2f09c temporary_buffer: add static method aligned
used to allocate a temporary_buffer with an aligned buf.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-10 16:33:38 +02:00
Nadav Har'El
7a04d1f662 fstream: refactor file input stream interface
The file_input_stream interface was messy: it was not fiber safe (e.g., code
doing seek() in the middle of an ongoing read_exactly()), and went against
the PIMPL philosophy.

So this patch removes the file_input_stream class, and replaces it with a
completely different design:

We now have in fstream.hh a global function:

input_stream<char>
make_file_input_stream(
        lw_shared_ptr<file> file, uint64_t offset = 0,
	uint64_t buffer_size = 8192);

In other words, instead of "seeking" in an input stream, we just open a new
input stream object at a particular offset of the given file. Multiple input
streams might be concurrently active on the same file.

Note how make_file_input_stream now returns a regular "input_stream", not a
subtype, and it can be used just like any normal input_stream to read the stream
starting at the given position.

This patch makes "input_stream" a "final" type: we no longer subclass it in our
code, and we shouldn't in the future because it goes against the PIMPL design
(the subclass should be of the inner workings, like the data_source_impl, not
of input_stream).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 15:39:17 +02:00
Nadav Har'El
20df45de44 scattered_message: Fix include loop
We had an include loop, which can cause problems in some cases:

1. iostream.hh #includes scattered_message.hh #includes reactor.hh
2. reactor.hh #includes iostream.hh

This patch fixes the loop be removing an unnecessary include.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 15:01:51 +02:00
Nadav Har'El
e45a507100 Remove unnecessary forward declarations from reactor.hh
reactor.hh includes forward declarations for input_stream, output_stream
template classes. These are unnecessary, because it #include's iostream.hh,
which contains the full definition of these classes.

These unnecessary forward declarations are harmless in the current code, but
they will become harmful if we change the definitions in iostream.hh (e.g., I
wanted to make input_stream a "final" class).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 15:01:34 +02:00
Gleb Natapov
8fd570d854 core: use perfect forwarding for function object in apply() 2015-03-10 12:57:13 +02:00
Nadav Har'El
4868bde49e Remove duplicate #include in reactor.hh
core/reactor.hh had two #include lines in the middle of the file, which
duplicate previous #include lines in the top of the file. So remove them.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 12:42:11 +02:00
Avi Kivity
8628d98542 shared_ptr: fix reference count loss when creating a derived type with e_s_f_t
make_shared() has a special case for detecting a created class deriving
from enable_shared_from_this<>, so it can point the refcount pointer into
the object's data area instead of creating a shared_ptr_count_base for it.

The code, however, fails to detect a creating class deriving indirectly
from enable_shared_from_this:

   struct base : enable_shared_from_this<base> {};

   struct derived : base {};

   make_shared<derived>();  // <- allocates independent refcount

The result is that the object reference counter lives in two locations.

Fix by detecting the derived class case as well.
2015-03-10 10:56:10 +02:00
Amnon Heiman
29391d9a9b Extending sstring
This patch adds some of the common functionalities from std:string to
sstring.

It adds length (implement by size() )
It define the constant npos to indicate no possition.
It adds the at (reference and const reference)
It define the find char and find sstring methods
and the substr method

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>

need merge sstring
2015-03-08 21:55:57 +02:00
Avi Kivity
e4b5408bbd core: improve apply forwarding
Currently apply() only works with moveable inputs.  Add overloads for
non-moveable inputs (reference and const reference).
2015-03-08 14:58:28 +02:00
Avi Kivity
808ac29cf3 core: mark apply() inline 2015-03-08 14:58:26 +02:00
Shlomi Livne
ee8fa7b07a Block all signals when reactor is deleted
1. Moved all signal handler functions/members into a wrapping class
2. Block all signals on desctuctor call (resetting of signal handler is
not enough since some signals will arive even if we reset signal handler
to SIG_DFL e.g. timer)

Fixes use-after-free when a signal is caught after the reactor is
destroyed.

Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-08 09:20:32 +02:00
Gleb Natapov
4d286f0504 core: drop superfluous qualifier from then_wrapped 2015-03-06 12:52:11 +02:00
Tomasz Grabiec
af82e23c75 core: Use futurize<> to unify then_wrapped() specializations 2015-03-06 11:35:56 +01:00
Tomasz Grabiec
a232b7e6c5 core: Use futurize<> to unify future::then() specializations
As a side benefit, returning non-void non-future is now allowed:

 future<int> x() {
     return later().then([] {
         return 3;
     });
 }
2015-03-06 11:35:56 +01:00
Tomasz Grabiec
f25d7ac068 core: Add futurize::apply()
Invokes given function wrapping the result in a future if necessary.
2015-03-06 11:35:56 +01:00
Tomasz Grabiec
422d642cf4 core: Add futurize::primise_type 2015-03-06 11:35:56 +01:00
Tomasz Grabiec
f5485c667d core: Move futurize<> to future.hh 2015-03-06 11:35:56 +01:00
Gleb Natapov
5d1b10d97a core: properly propogate exception in do_until()
[avi: use std::move(f).then_wrapped() until patch removing rvalue
      qualification from then_wrapped() lands]
2015-03-06 12:12:19 +02:00
Tomasz Grabiec
d674cd7deb core: add make_shared(T&&) overload
Allows for code like this:

  auto p = make_shared(object());
2015-03-04 18:49:26 +02:00
Tomasz Grabiec
83963b23d3 Replace rescue() usages with then_wrapped()
They are pretty much the same. This change removes rescue().
2015-03-04 17:34:59 +01:00
Tomasz Grabiec
e36115e1d4 core: add then_wrapped() overload which works with void-returning callbacks 2015-03-04 17:33:38 +01:00
Calle Wilund
7b5193b80c future: deferring finally() callback
Add "finally" continuation overload for functions returning future type that
awaits finishing the continuation in question before continuing the "present"
one. I.e. a wrapper around "then_wrapped" to remove the need to deal with the
original return value.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-03-04 18:09:34 +02:00
Raphael S. Carvalho
89ec1f8f6a slab: Add reclaimer functionality
Basic explanation of the reclaimer algorithm:
- Each slab page has a descriptor containing information about it, such as
refcnt, vector of free objects, link into LRU, etc.
- The LRU list will only contain slab pages which items are unused, so as
to make the reclaiming process faster and easier. Maintaining the LRU of slab
pages has a performance penalty of ~1.3%. Shlomi suggested an approach where
LRU would no longer exist and timestamp would be used instead to keep track of
recency. Reclaimer would then iterate through all slab pages checking for an
unused slab page with the lowest timestamp.
- Reclaimer will get the least-recently-used slab page from the LRU list,
do all the management stuff required, and iterate through the page erasing any
of the items there contained. Once reclaimer was called, it's likely that slab
memory usage is calibrated, thus slab pages shouldn't be allocated anymore.
- Reclaimer is enabled by default but can be disabled by specifying the slab
size using the application parameter --max-slab-size.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-04 17:40:58 +02:00
Nadav Har'El
68d0cd2441 input_stream: remove buf_size parameter
input_stream's constructor had an unused buf_size parameter. Such a
parameter is not needed - whenever the input_stream needs more
data it calls the underlying data_source's get(), and thus only the
data_source gets to decide the buffer size. Moreover, in some
implementations, this read buffer size will be different each time -
e.g., in a chunk-compressed file, the uncompressed chunk's size will
be different each time.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-04 17:39:16 +02:00
Calle Wilund
56dce3df51 Basic rw-lock impl around semaphore.
Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-03-03 14:58:58 +02:00
Gleb Natapov
590d8da4f1 core: provide "void" promise specialization
Makes it easier to write generic code.
2015-03-01 15:58:36 +02:00
Gleb Natapov
e1aa9f85a1 fix xenstore compilation 2015-03-01 15:29:13 +02:00
Avi Kivity
25168fc73d enum: fix std::hash<> non-specialization for enum types
SFINAE only works for substituted template parameters, not any complication
error (or it would be called CEINAE); therefore hash<T> for enums will fail
to compile, given a non-enum, rather than being ignored.

It's not possible to specialize hash<> for enums, since the primary template
does not have en extra Enable template argument for use with enable_if.  We
therefore rename it to enum_hash<> and require users to explicitly define
hash<MyEnum> as inheriting from it.
2015-03-01 13:36:30 +02:00
Avi Kivity
1e5df06f9a shared_ptr: provide default std::hash<> specializations
Folloing std::shared_ptr.
2015-03-01 13:36:17 +02:00
Glauber Costa
eb384236fd iostream: extend eof condition to read_exactly users as well
We currently only signal eof for consume() users. If one is calling
read_exactly, eof will never be signalled.

This might make some sense in continuous streams, but specially when
dealing with files, eof is a natural part of line that can and will
happen all the time. Every "read-until-finish" file-loop will at some
point rely on eof.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-03-01 09:48:51 +02:00
Tomasz Grabiec
1fadd7d608 net: Move ipv4_addr constructor to the source file
boost::join() provided by boost/algorithm/string.hpp conflicts with
boost::join() from boost/range/join.hpp. It looks like a boost issue
but let's not pollute the namespace unnecesssarily.

Regarding the change in configure.py, it looks like scollectd.cc is
part of the 'core' package, but it needs 'net/api.hh', so I added
'net/net.cc' to core.
2015-02-26 17:34:27 +02:00
Glauber Costa
9861bfca01 open_file_dma: allow the specification of open flags
It is sometimes frustrating to use open_file_dma, because it has the hardcoded
behavior of always assuming O_CREAT. Sometimes this is not desirable, and it
would be nice to have the option not to do so.

Note that, by design, I am only including in the open_flags enum things that we
want the user of the API to control. Stuff like O_DIRECT should not be
optional, and therefore is not included in the visible interface.

Because of that I am changing the function signature to include a paramater
that specifies whether or not we should create the file if it does not exist.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-02-26 17:30:02 +02:00
Raphael S. Carvalho
6dea362304 Add experimental::string_view option to scattered_message::append_static
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-25 19:29:36 -03:00
Raphael S. Carvalho
03ae698ce1 core: Add slab allocator
* Slab allocator resembles the one used by stock memcached, where
it's composed of slab classes and slab classes are composed of
chunks of the same size.
* Per-slab-class LRU is also available.
* Slab allocator exports stats to collectd.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-25 19:29:36 -03:00
Gleb Natapov
11f5a8e398 add default constructors to iostreams and connected_socket
Makes life of a programmer easier since it allows to define variables of
those types ahead of object creation.
2015-02-25 12:50:03 +02:00
Nadav Har'El
b64f26832e reactor: terminate cleanly in or_terminate()
The ".or_terminate()" continuation is needed when one needs to exit the
application on an unhandled exception, instead of just letting the event
loop continue to spin forever.

or_terminate() currently calls std::terminate() which only incidentally
(as a gcc-specific implementation) prints out the exception's type; It
then calls abort(), which results in a painfully slow core dump. This
abort() is NOT helpful, because at that point the debugger can only find
where abort() was called, not where the original exception was thrown (see
issue #32).

So instead of calling std::terminate(), this patch switches to calling
engine().exit(), to cleanly shut down the application, without dumping
core. It also prints, like gcc's std::terminate(), the exception's type.
This printing requires non-standard gcc extensions.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-02-25 12:28:34 +02:00
Avi Kivity
3d81e06353 shared_ptr: fix dynamic_pointer_cast() dropping a ref after failure
If the input to dynamic_pointer_cast() faild the conversion, we leaked
a reference to the input object.
2015-02-25 11:05:45 +02:00
Avi Kivity
0d7b878539 memory: sprinkle magic attributes to allow building with -flto 2015-02-24 15:10:33 +02:00
Avi Kivity
f730ae9814 sstring: add static_assert to prevent use on >1 byte types 2015-02-23 18:23:18 +02:00
Avi Kivity
9519f04b0b sstring: remove unused to_sstring() declaration
The actual overloads are sufficient.
2015-02-23 18:11:39 +02:00
Avi Kivity
51ff807a11 sstring: fix to_sstring() for all sstring types
sstring is a family of types (basic_string<...>), make to_sstring work for
all of them.
2015-02-23 17:26:10 +02:00
Avi Kivity
fbf8844079 Move input_stream and output_stream to their own header 2015-02-23 10:15:19 +02:00
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