Commit Graph

670 Commits

Author SHA1 Message Date
Avi Kivity
2f10793898 core: add open_flags::exclusive (O_EXCL) 2015-05-13 13:23:18 +03:00
Avi Kivity
bf527c2842 future: add range-based parallel_for_each variant 2015-05-13 10:53:13 +03:00
Avi Kivity
f3c8994535 distributed: add map_reduce() variant accepting an initial value
Separating the initial value (and accumulator) from the reducer function
can result in simpler invocations.

Unfortunately, the name conflicts with another variant, so we have to name
the method map_reduce0.
2015-05-12 16:57:50 +03:00
Avi Kivity
50d65f1d86 smp: protect lifetime of function parameter to submit_to()
When submit_to() calls to a different core, and when the function to
be executed is a temporary (the usual case), we copy it to the heap for
the duration of execution.  However when the function happens to execute
locally, we don't copy it, which can lead to a use-after-free if the function
defers.

Fix by detecting the case of local execution of a temporary function, and
copying it to the heap in that case.
2015-05-12 14:33:18 +03:00
Avi Kivity
6173d1af62 Merge branch 'calle/scollectd-fixes' of github.com:cloudius-systems/seastar-dev
collectd fixes, from Calle.
2015-05-12 12:42:19 +03:00
Calle Wilund
ad5feda8ae Collectd: Fix registration/deregistration and reg. anchor managment
Obviously, I was sleeping or something when I wrote the reg/unreg code, since
using copy semantics for anchors is equivalent with double unregistrations.
Luckily, unregister was broken as well, so counters did stay active. Which
however broke things once actual non-persistent counters were added. Doh.

* Anchors must be non-copyable
* Above makes creating std::vector<registration> from initializer list
tricky, so added helper type "registrations" which inherits vector<reg>
but constructs from initializer_list<type_instance_id>, avoiding illegal
copying.
* Both register and unregister were broken (map semantics does not overwrite
on insert, only [] or iterator operation).
* Modified the various registration callsites to use registrations and move
semantics.
2015-05-12 11:30:44 +02:00
Calle Wilund
2646fa188f Collectd: Add virtual destructor to value_list
Since we bind actual std::functions etc, a virtual destructor is needed.
2015-05-12 11:30:44 +02:00
Calle Wilund
e941b5a378 Collectd: Make sure get_instance_ids only returns active id:s 2015-05-12 11:30:44 +02:00
Calle Wilund
db9869639c Collectd: change string types to sstring 2015-05-12 11:30:44 +02:00
Avi Kivity
4cea444fb2 collectd: avoid using an exception as end-of-packet indicator
Collectd uses an exception to signal that the buffer space in the packet
is exhausted and a new packet needs to be started.  This violates the
"exceptions are for exceptional conditions" guideline, but more practically,
makes it hard to use the gdb "catch throw" command to trap exceptions.

Fix by using a data member to store the overflow condition instead.
2015-05-11 18:02:41 +03:00
Avi Kivity
0e23702dfd core: add make_directory() API 2015-05-11 13:33:33 +03:00
Amnon Heiman
9477e41577 collectd: Add an API to scollectd data
The scollectd is an infrastructure that allows different part of the
code to register internal counters and the infrastructure would send it
periodically to an external server.

This patch adds and API to the scollectd that allows to inquire a
register value and the names of the registered values.

The collectd_value structure is used to return a single value that can
be of type: double or signed and unsigned 64 bit long.

The definition of the API are found in scollectd_api.hh

The inquiries are for the local cpu, it is up to the caller to call a
relevent cpu.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-05-07 15:23:28 +03:00
Avi Kivity
f3afe9051f Merge branch 'shared_ptr'
const support for lw_shared_ptr<>.
2015-05-06 13:27:00 +03:00
Amnon Heiman
f4f6c0a4a3 smp: add all_cpus() helper
This adds a static method to return a range object to smp.
with this patch it is possible to use:

for (auto i : smp::all_cpus())

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-05-06 11:49:45 +03:00
Avi Kivity
fe9c5a2750 shared_ptr: const correctness for lw_shared_ptr::use_count() 2015-05-06 11:41:51 +03:00
Avi Kivity
211c77bf52 shared_ptr: add const support for lw_shared_ptr 2015-05-06 11:41:33 +03:00
Raphael S. Carvalho
36701cafcb iostream: make close() flush
This change is intended to make close() flush the stream before
proceeding with the close itself. This improves the situation
where we have to guarantee that the stream is flushed before
closing it.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-05-05 10:11:18 +03:00
Avi Kivity
a28f0efd9a sstring: add iterator range constructor 2015-04-30 15:03:27 +03:00
Calle Wilund
992a6ea21e Collectd: Use initializer lists + declare < and == operators for clang
Makes scollectd compile on clang++ 3.5.0
2015-04-30 10:00:07 +03: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