Commit Graph

652 Commits

Author SHA1 Message Date
Calle Wilund
63ea446849 Collectd: Use initializer lists + declare < and == operators for clang
Makes scollectd compile on clang++ 3.5.0
2015-04-29 17:00:14 +02:00
Avi Kivity
7071239f49 Merge branch 'master' of github.com:cloudius-systems/seastar 2015-04-29 12:34:15 +03:00
Avi Kivity
c952248dc5 shared_ptr: improve const support
Allow enable_shared_from_this<T>::shared_from_this() to return
a shared_ptr<const T> when called on a const object.

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-04-29 12:32:43 +03:00
Calle Wilund
03da7399a0 sstring: add iostream input (>>)
Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-04-29 11:34:47 +03:00
Pekka Enberg
066a37ad21 shared_ptr: Make shared_ptr work with foreign_ptr
The foreign_ptr wrapper needs 'element_type' to be present in
shared_ptr to be able to access the data.

Fixes the following compilation failure when trying to use shared_ptr
with foreign_ptr:

  In file included from tests/foreign_ptr_test.cc:24:0:
  ./core/distributed.hh: In instantiation of ‘class foreign_ptr<shared_ptr<basic_sstring<char, unsigned int, 15u> > >’:
  tests/foreign_ptr_test.cc:28:54:   required from here
  ./core/distributed.hh:272:56: error: no type named ‘element_type’ in ‘class shared_ptr<basic_sstring<char, unsigned int, 15u> >’
       using element_type = typename PtrType::element_type;

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-04-27 14:39:12 +03:00
Glauber Costa
2b8035a718 sstring: add a fill constructor
std::string has it, we don't.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-04-25 02:02:04 +03:00
Paweł Dziepak
5ffd057fd1 memory: use allocate_large_aligned() if alignment is more than a page
small_pools, which are responsible for allocations up to 16kB, aren't able
to provide a buffer with alignment stricter than a page. This results
in aligned allocations being broken for buffers in the range 4kB - 16kB.
This patch make sure that if the alignment requirement is too big for
small_pool to handle allocate_large_aligned() is used instead.

Fixes #36.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-04-20 10:32:43 +03:00
Paweł Dziepak
5d65f045f5 temporary_buffer: use posix_memalign() return value
The proper way to test whether posix_memalign() failed is to check its
return value, not the content of the pointer.

This also silences "ignoring return value of 'posix_memalign()'" diagnostic
messages.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-04-20 10:32:11 +03:00
Takuya ASADA
6975eeac30 reactor: implement timer for OSv, since OSv does not support timer_create/timer_settime
OSv does not supported timer_create/timer_settime and thread based signal handling.
This patch implements timer function using OSv native timer and timer handler thread witch pinned to the CPU same as reactor thread.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:39 +03:00
Takuya ASADA
db93ae84db dpdk: Use --no-shconf on OSv
DPDK does not work without --no-shconf on OSv, we need to add it.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:38 +03:00
Takuya ASADA
83189367b6 temporary_buffer: Use posix_memalign instead of memalign, since OSv does not have memalign
Required for OSv to prevent missing symbol.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:37 +03:00
Takuya ASADA
991b77863d Use namespace on timer_set to prevent conflict with OSv's timer_set
Since we have same header on OSv too, we need to prevent conflict.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:36 +03:00
Takuya ASADA
00049ea9c7 Fix compile errors with OSv
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:32 +03:00
Avi Kivity
b35ea31cc9 futures: fix map_reduce() future chaining
map_reduce() did not properly chain futures, so the result was bogus.
2015-04-14 15:13:15 +03:00
Avi Kivity
6f5dc8c15e future: fix map_reduce() return type
Needs to return a future.
2015-04-14 14:55:36 +03:00
Avi Kivity
e03a23b53a future: add std::accumulate-style map_reduce variant 2015-04-13 17:11:44 +03:00
Avi Kivity
6e185d21f0 future: remove bogus when_all() forward declaration
Doesn't match the definition, and is unneeded anyway.
2015-04-13 16:23:33 +03:00
Tomasz Grabiec
fd18edc652 core: Do not let exceptions out of posix thread callback
If the callback throws the program will segfault and GDB will be
useless in diagnosing the failure:

  gdb$ run
  ...
  thread_get_info_callback: cannot get thread info: generic error
  gdb$

So let's fail in a better way.
2015-04-10 18:46:13 +02:00
Calle Wilund
819bf6244e collectd: remove extra braces from parameter packing expression
Added to make clang happy, but causes compilation failure with more than
one bound value in value list. Using paranthesis instead.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-04-09 12:48:45 +03:00
Calle Wilund
1bdf366f79 reactor: fix broken errno check fixing missing file behaviour
Code checked "result" instead of "error" (where actual error code is)

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-04-09 12:46:43 +03:00
Glauber Costa
aa1f33df22 output_stream: generalize basic_sstring writes further
The current code assumes that the sstring will have the same char_type as the
output_stream.  That was working well, until I was forced to change the type of
my basic_sstring to another one that is backed by signed chars.

Of course, the best solution for this would be to change the output_stream (as
well as the input_stream), to take a signed char as well.

And oh boy, have I tried. The data_sink assumes a char type, and when it tries
to allocate a new buffer from it, the buffer will have no other choice than to
be of a char type. Fix that one, and another one appears.

I eventually gave up when the code wouldn't compile because struct fragment has
a char type - and both using a template for such a simple struct, as well as
sprinkling casts all over the place where it is used, sounded like horrible
ideas to me.

It's true that quitters never win, and winners never quit. But for now, my
proposal would be to generalize the write code to accept basic_sstrings of
general types. At least the cast lives in a single place.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-04-09 12:03:40 +03:00
Glauber Costa
1760a8c5ad output_stream: generalize string writing
All basic_sstring writes the same way. Using sstring as the signature would
require other users that are using other variants of basic_sstring to add their
own signatures.

This general version will cover those use cases as well.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-04-08 19:36:59 +03:00
Asias He
7c1bcc3ded core: Add args_as_tuple type for function_traits
Signed-off-by: Asias He <asias@cloudius-systems.com>
2015-04-08 17:10:51 +03:00
Takuya ASADA
db113d04f7 dpdk: ignore RTE_MBUF_REFCNT on v2.0.0 or later
Latest DPDK(which will be v2.1.0) causes compile error when referencing RTE_MBUF_REFCNT because it defained as "#pragma GCC poison RTE_MBUF_REFCNT".
And that configuration entry is not available v2.0.0 or later.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-08 09:02:17 +03:00
Avi Kivity
0c971d0959 sstring: fix std::string conversion for char_type != char 2015-04-08 08:55:45 +03:00
Raphael S. Carvalho
3c908f1ed0 core: Add do_for_each variant
This variant is intended to simplify do_for_each idiom where the
iterators begin() and end() will be implicit.

Allowing the user to do something as follow:
	return do_for_each(map, [] { ... });

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-04-07 23:10:34 +03:00
Avi Kivity
558af3d9a5 shared_ptr: add nullptr_t overloads 2015-04-07 21:04:57 +03:00
Amnon Heiman
b90e4ef4d3 sstring: cleanup replace implementation
This do a clean up in the sstring replace method, it also uses a
std::move for optimization.

The missing cbeging and cend method were edded to return a
const_iterator

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-04-06 18:01:20 +03:00
Avi Kivity
3c4edd9eeb sstring: fix string_view interface
string_view is also a template, taking char_type as a parameter.  Need to
use it in order to have a string_view that is compatible with our sstring.
2015-04-05 20:00:10 +03:00
Amnon Heiman
04b5bad2b7 Adding insert replace and erase to sstring
The boost::replace_all uses insert and erase to perform a change, those
method are missing from sstring.

Following the std:string implemntation the implementation of both
functionalities is based on the replace method, either as c string
replace or with templated iterators.

Not all the variation of insert, replace and erase where added, but it
will be possible to add them in the future if needed by calling the
existing functionality.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-04-05 09:51:28 +03:00
Nadav Har'El
4e21cedc0f Add do_with() utility
Add a convenient function do_with(rvalue, func) which ensures that a
(moved copy of) rvalue will live until the future returned by func
concludes, and that func is passed this object.

Needing to do this is a recurring idiom in Seastar applications.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
[avi: mark inline]
2015-04-02 10:27:38 +03:00
Gleb Natapov
58c62dd121 core: drop superfluous qualifier from discard_result 2015-04-01 11:33:19 +03:00
Raphael S. Carvalho
6f3e25d935 core: add future<> remove_file()
So far, we haven't had a function to asynchronously remove a file.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-31 17:35:40 +03:00
Raphael S. Carvalho
f49888c649 fstream: sync file when file output stream is closed
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-31 10:26:03 +03:00
Amnon Heiman
cb535f1fa9 Add file_type method to the reactor
This method check the file type and retrun an optional value, if the
file does not exists no value is return.

On other errors an exception will be thrown.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
0faf9cbb56 Adding back, find_last_of and append to sstring
This adds the back method that return a reference or const reference to
the last char in an sstring.

find_last_of, which return the index of the last occurance of a char in
the string.

And append with append C string to a string.

The logic and definition are similiar to the std::string.

Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Paweł Dziepak
d3504f90a9 memory: fix trimming of allocated spans
Trimmers may request buffers smaller than n_pages, the original value
passed to allocate_large_and_trim(). That's why t.nr_page should be
used as a final size of the allocated span.

Another issue with the handling of span trimming is the order of operations
when pages from the beginning of the buffer are trimmed. In such case
span is updated to point to the actual beginning of the requested buffer,
but afterwards it is used to retrieve span->span_size value which is expected
to be the size of the originally allocated page span. Because the span
pointer was changed the value is invalid and the trimming doesn't free
all trimmed pages.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-03-30 14:21:36 +03:00
Avi Kivity
7cf25ce492 distributed: fix use-after-move
distributed::stop() passes the pointer to the instance being destroyed
by reference, in an attempt to keep things clean (by nulling the pointer
after deleting it).  This is illegal, however, since the lambda is moved
in the bowels of submit_to().  In release mode this is optimized away so
the code works, but in debug mode it leads to a crash.

Fix by capturing by value instead (could also have been fixed by switching
the enclosing capture to a reference).

Credit to Gleb for identifying the problem.
2015-03-30 11:18:16 +03:00
Tomasz Grabiec
8abd982ec9 distributed: Do not move arguments when passing to many cores 2015-03-25 09:39:34 +01:00
Raphael S. Carvalho
54875279f6 slab: fix comment
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-24 10:12:47 +02:00
Raphael S. Carvalho
087a34a544 slab: free slab page if page desc alloc failed
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-24 10:12:46 +02:00
Tomasz Grabiec
6692435757 core: Implement operator<< for smart pointers
It will allow to implement generic join(), which works with
sequences of things, and use it on std::vector<shared_ptr<printable>>
2015-03-23 11:49:18 +02:00
Avi Kivity
6852f21463 future: mark state as invalid when moving away from *this
Avoid inconsistency between an future thinking it's an exception, while
the exception pointer is null.

Fixes smp_test.
2015-03-18 12:34:32 +02:00
Tomasz Grabiec
a7d6e22baf sstring: fix bounds checks in find()
'end' iterator was set past the end if pos != 0.
2015-03-17 15:37:54 +02:00
Avi Kivity
ceb4778ad2 Merge branch 'log-exceptions' 2015-03-16 10:14:23 +02:00
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
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
Avi Kivity
b968f80695 future: report abandoned failed futures
Report an abandoned future containing an exception, corresponding to
an uncaught exception in an ordinary program.
2015-03-15 15:44:08 +02:00