Commit Graph

1446 Commits

Author SHA1 Message Date
Nadav Har'El
c0d7e4e748 core: implement future<> sleep()
Seastar applications obviously cannot use the Posix sleep() function, or
the entire thread will block. This patch implements future<> sleep(duration)
where as expected, the future becomes ready when the given duration passes.

For example, one can do:

    sleep(1s).then([] { std::cout << "Done.\n"; });

This can be useful as an example of futures and continuations in the
Seastar tutorial, and people might find other uses for it.

This sleep() is implemented in terms of timer<>. sleep() is easier to use
and more aligned with the rest of Seastar (it uses then() for the
continuation instead of a set_callback() method). The downside of sleep()
compared to a timer is that it cannot be canceled once started.

In this version, sleep() is implemented without shared_ptr, making the
implementation a tiny bit more efficient. There is still a heap allocation
(this is unavoidable because std::function requires a copyable type)
but no reference counting. Unfortunately, this requires us to use bare
"new" and "delete".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-16 10:02:06 +02:00
Avi Kivity
facb2ffdc6 build: allow disabling debug info generation
Closes #37.
2015-03-16 07:53:54 +02:00
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
Avi Kivity
24bc1b4126 build: improve seastar.pc generation
Generate at build time, so it gets rebuilt even if build/ is wiped out.
2015-03-15 18:13:29 +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
Avi Kivity
f8c69904cd build: fix seastar.pc generation
Need to ensure the directory is there first.
2015-03-15 16:16:41 +02:00
Nadav Har'El
3578d3d016 build: make it easy to compile a Seastar-based project
This patch makes compiling a file "hello.cc" using seastar as simple as:

g++ `pkg-config --cflags --libs build/release/seastar.pc` hello.cc

Our current build system makes it very hard for users to build a project
*using* Seastar - basically requiring them to integrate their project into
the Seastar tree and its Makefile into our "ninja" framework.

This patch simplifies things considerably by doing two things:

First it builds an archive of all Seastar objects - build/$mode/libseastar.a.

But this in itself is not enough - the user wouldn't know how to use it
(currently, -Wl,--whole-archive is needed, unfortunately, because of reliance
of C++ static constructors), and will also need a long list of other
libraries, as wall as various definitions and include paths during compilation.

The solution is to use pkg-config, which has become the de-facto standard
method on Linux for makefiles to figure out how to compile with a certain
library. With this patch, someone can do this for example, to compile
tests/fileiotests.cc:

g++ `pkg-config --cflags --libs build/release/seastar.pc` tests/fileiotest.cc

Note how we have a different ".pc" file for each mode, with the appropriate
compile and link flags. A more eleborate example with separate compile and
link stages will use "pkg-config --cflags" on the compilation stage, and
"--libs" on the linking stage.

Eventually, we should have a "ninja install", which will install libseastar.a
and seastar.pc to their system-wide default location, and then the above
command line will become as simple as:

g++ `pkg-config --cflags --libs seastar` tests/fileiotest.cc

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:49:48 +02:00
Nadav Har'El
d1601b46f2 net: implement net::packed<> in terms of unaligned<>
The previous patch moved most of the functionality of net::packed<>
into a new template unaligned<> (in core/unaligned.hh). So in this
patch we implement net::packed<> in terms of unaligned<>. The former
is basically the same as the latter, with the addition of the
"adjust_endianness" feature that the networking code expects.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:45:14 +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
Avi Kivity
bd00d90806 Merge branch 'gleb/future' of github.com:cloudius-systems/seastar-dev
Future implementation cleanup, from Gleb.
2015-03-15 15:33:25 +02:00
Avi Kivity
d3acb5acc2 linecount: better error handling 2015-03-15 14:48:52 +02:00
Avi Kivity
0537a8ffe5 linecount: don't try to create the file.
It's read-only.
2015-03-15 14:48:31 +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
Shlomi Livne
83998a8934 tests: Boostify the fstream_test
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-12 15:56:25 +02:00
Gleb Natapov
7adf4f935d rpc test program 2015-03-12 15:38:18 +02:00
Gleb Natapov
36b76af7cc Implementation of rpc
To register rpc handler func(param1, param2, param3) both server and client

auto remote_func = myrpc.register_handler(id, func);

This call will return another function that client can use to invoke RPC
calls like this:

remote_func(client, param1, param2, param3);

This call will return future<> with func() result.
2015-03-12 15:38:18 +02:00
Shlomi Livne
83c0196255 tests: make sure each SEASTAR_TEST_CASE has at least a single BOOST_XXX check
SEASTAR_TEST_CASE that did not execute a single BOOST_XXX check was
maakred as "[Message] - Test case .... did not check any assertions" and
is placed in /usr/include/boost/test/impl/results_collector instead of
the correct test file.

Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-12 15:21:29 +02:00
Avi Kivity
3a35fe061b tests: tighten when_all() compare
Fails on one compiler.
2015-03-11 19:31:55 +02:00
Avi Kivity
5b6e23ebde tests: reduce BOOST_REQUIRE() calls
when_all() tests generate two million calls to BOOST_REQUIRE(), which
overwhelms the test result parser.  Replace with two calls and use all_of()
to process the result array.
2015-03-11 19:25:54 +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
Shlomi Livne
a10c6681e3 build: fix jenkins/boost test integration
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-11 17:07:53 +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
293a6e7547 tests: Test distributed::map_reduce() version which takes a functor 2015-03-11 13:33:53 +01:00
Tomasz Grabiec
976c9da314 core: Add distributed::map_reduce() version which takes a functor 2015-03-11 13:33:01 +01:00
Tomasz Grabiec
200f4698b5 tests: Add test for map_reduce() 2015-03-11 13:24:31 +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
Shlomi Livne
820ea940ba tests: generate a boost report file that can be parsed by jenkins
Boost XML report files can be parsed by Jenkins and provide a mean for
jenkins to track specific test cases status.

Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-11 10:03:21 +02:00
Avi Kivity
c89df6748c Merge branch 'master' of https://github.com/raphaelsc/seastar
File output streams, from Raphael.
2015-03-11 09:54:01 +02:00
Raphael S. Carvalho
10a71dadac tests: add fstream testcase 2015-03-10 18:44:40 -03:00
Raphael S. Carvalho
971a3bb0b9 fstream: add file output stream support 2015-03-10 18:44:22 -03:00
Avi Kivity
a3695dbcc4 future: add a test case for runtime sized when_all() 2015-03-10 22:01:55 +02: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
Shlomi Livne
f8d773dd47 tests: fix future unitest that sometimes fails because of scheduling
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-10 16:38:43 +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