Commit Graph

605 Commits

Author SHA1 Message Date
Avi Kivity
d2c0e485f8 posix: fix posix::recv return
Shuts up warning in gcc 5, and is aligned with the other methods.
2015-03-15 20:18:17 +02:00
Nadav Har'El
25c37c92f5 core: fix engine_exit()
engine_exit() without a parameter is meant to do engine().exit(0).
We do this, but forget to return from this function, so after calling
engine().exit(0), it continued on and crashed.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 16:17:25 +02:00
Nadav Har'El
1f8e0dbbab unaligned: new header file for unaligned access
This patch adds a new header file, "core/unaligned.hh", which defines a
new operation, unaligned_cast<T*>(p). This works exctly like
reinterpret_cast<T*>(p) except it is safe to use even when the address
of p is not a multiple of alignof(T).

A long comment in the header file explains why this unaligned_cast<>
is necessary on some esoteric architectures and to quiet gcc's
-fsanitize=alignment.

The header file also defines a new template for holding an unaligned
version of type - unaligned<T>. unaligned<T> is almost identical to our
existing net::packed<>, so the next patch will implement net::packed
in terms of unaligned<>.

The unaligned_cast<> and unaligned<> templates are of course generally
useful outside the network code, which is why I wanted them out of the
networking header files and namespace.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:44:56 +02:00
Gleb Natapov
c3ba8678e4 core: consolidate finally() implemetations 2015-03-15 14:44:58 +02:00
Gleb Natapov
186e25717e core: consolidate then() and then_wrapped() code 2015-03-15 14:18:43 +02:00
Gleb Natapov
ad63b70d53 core: remove unused structure future_task 2015-03-15 14:11:51 +02:00
Gleb Natapov
c138e31a2a core: check future_avail_count in then_wrapped 2015-03-15 12:41:26 +02:00
Gleb Natapov
ecb72e995a core: drop superfluous qualifier from or_terminate 2015-03-15 12:18:44 +02:00
Tomasz Grabiec
74e34ed6a4 core: Use futurize<> to simplify smp::submit_to() 2015-03-14 11:40:48 +02:00
Tomasz Grabiec
7bc7951192 core: Use perfect forwarding in invoke_on()/submit_to()
Makes invoking non-copyable lambdas possible:

  distributed<T> t;

  non_copyable_type x;
  t.invoke_on(0, [x = std::move(x)] (auto& t) {});

As a side effect this could save some copyable lambdas from being
needlesly copied.
2015-03-13 19:20:13 +02:00
Avi Kivity
d5817ab965 Merge branch 'gleb/rpc' of github.com:cloudius-systems/seastar-dev
Conflicts:
	configure.py
2015-03-12 16:30:15 +02:00
Avi Kivity
45cffd5681 core: add seastar API
One file, seastar.hh, containing all the main entry points as free functions.
Most classes are forward-declared to avoid the need to #include the entire
world.
2015-03-11 19:11:01 +02:00
Gleb Natapov
0838a0ce2f core: drop future<> casting to rvalue before call to then_wrapped()
No longer required.
2015-03-11 17:19:23 +02:00
Avi Kivity
e659ca2629 Merge branch 'when_all' of github.com:cloudius-systems/seastar-dev
when_all() variant for runtime-sized lists of futures.
2015-03-11 17:06:23 +02:00
Raphael S. Carvalho
a4aae5b6ab fstream: fix comment
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-11 14:45:43 +02:00
Tomasz Grabiec
976c9da314 core: Add distributed::map_reduce() version which takes a functor 2015-03-11 13:33:01 +01:00
Tomasz Grabiec
56f6d12bae core: Fix map_reduce() which incorrectly moves away arguments 2015-03-11 13:21:23 +01:00
Gleb Natapov
8f168d3abc helpers to get function's return parameters and argument list 2015-03-11 12:39:49 +02:00
Raphael S. Carvalho
971a3bb0b9 fstream: add file output stream support 2015-03-10 18:44:22 -03:00
Avi Kivity
239475e10b future: add runtime-sized variant of when_all()
Add a when_all() variant that waits for a runtime variable number of
futures, all of the same type.  The function returns a future containing
a vector of all input futures, each in ready state, containing either
a result or an exception.
2015-03-10 22:00:02 +02:00
Avi Kivity
baf62adbab future: make when_all(Future... future) mode selective
Currently we have one version of when_all(), that accepts a compile
type variable number of independently typed futures.  We wish to add more
overloads, but for that, we must ensure that this variant doesn't match them.

Accomplish this by requiring that the first argument be a future, and don't
accept any other type.
2015-03-10 21:55:54 +02:00
Raphael S. Carvalho
de5a70282d core: add truncate entry to open_flags
It will be used when opening a file intended to be used with a
'file_output_stream'.
2015-03-10 16:09:48 -03:00
Raphael S. Carvalho
fe896fa4e4 core: add truncate function to file class 2015-03-10 15:43:39 -03:00
Raphael S. Carvalho
1a1368342b output_stream: add allocate_buffer method to data_sink and use it
allocate_buffer was added to data_sink as a virtual method, so that
a class extending it can override its implementation.
output_stream will also start using allocate_buffer whenever it
needs a temporary buffer.
2015-03-10 15:39:56 -03:00
Nadav Har'El
8b4117cc66 fstream: use temporary_buffer<char>::aligned
In fstream.cc, use the convenient new temporary_buffer<char>::aligned()
function for creating an aligned temporary buffer - instead of repeating
its implementation.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 17:25:42 +02:00
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