Commit Graph

679 Commits

Author SHA1 Message Date
Avi Kivity
0bd48b37ed future: consolidate task_with_state, task_with_ready_state
The internal structs task_with_state and task_with_ready_state are
identical except for their constructors.  Merge them into a new
struct continuation.
2015-05-23 11:40:39 +03:00
Gleb Natapov
0c549eeca6 reactor: fix unintentional timer copying in reactor destructor 2015-05-21 16:33:20 +03:00
Gleb Natapov
f77d3bbf52 net: extend connect() API to allow to bind to specific local address/port 2015-05-20 17:10:00 +03:00
Nadav Har'El
eda6a528eb iostream: consume() - fix hung test
The test tests/memcached/test_ascii_parser hung after the change to
consume(). The problem was that consume() notified the consumer of an
EOF by sending it an empty buffer, and then it expected to get back a
message that it shouldn't read more (by setting the unconsumed buffer),
if it didn't, it continued to send empty buffers in a never-ending loops.

So this patch changes consume() to send one empty buffer to the consumer
on the end-of-file, and then stop (regardless of what the consumer returns).

It would have probably made sense to *not* send an empty buffer to the
consumer after the data is done - not even once - but if we change this
behavior, it will break the existing tests.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Tested-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
2015-05-20 14:14:59 +03:00
Nadav Har'El
c5f61666d3 input_stream::consume() overhaul
Our input_stream::consume() mechanism allows feeding data from an input
stream into a consumer, piece by piece, until the consumer doesn't want
any more. It currently assumed the input can block (when reading from disk),
but the consumption is assumed to be immediate. This patch adds support for
blocking in the consumption function: The consumer now returns a future
which it promises to fulfill after consuming the given buffer.

This patch goes further by somewhat simplifying (?) the interface of the
consumer. Instead of receiving a mysterious "done" lambda the consumer
is supposed to call when done (doesn't want any more input), the consumer
now returns a future<optional<temporary_buffer<char>>, which means:

1. The future is fulfilled when the consumer is done with this buffer
   and either wants more - or wants to stop.

2. If the consumer wants to stop, it returns the *remaining* part of the
   buffer it didn't want to process (this will be pushed back into the
   input stream).

3. If the consumer is not done, and wants to consume more, it returns an
   unset optional.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-05-19 19:33:18 +03:00
Avi Kivity
1cf95e4bd8 Merge branch 'thread' of github.com:cloudius-systems/seastar-dev
This patchset adds thread support to seastar.  Threads can use the normal
seastar API, and may also "block" by calling future<>::get() on an
unavailable future.  Synchronous and asynchronous code may be intermixed.

Threads may not issue blocking operating system calls.
2015-05-18 15:27:22 +03:00
Avi Kivity
784e03aa31 thread: use setjmp/longjmp for context switches
swapcontext() is expensive as it invokes system calls.  Replace it with
setjmp()/longjmp().  We still use setcontext() initially, since that's
the most reasonable portable method of setting up a stack.

Context switch time (measured by thread_context_switch) is reduced to
120ns (from 450ns), with inefficiencies in the test itself and in future<>
dominating.
2015-05-17 17:22:48 +03:00
Avi Kivity
cd0ae463b3 core: thread support
Add a thread class that can be used to launch a blockable thread of
execution.  Within a thread, future<>::get() can be called on an
unavailable future, in which case it blocks until the future is made ready.
2015-05-17 15:57:11 +03:00
Nadav Har'El
902d5b21ca sleep: Fix use-after-free in sleep()
The implementation of sleep() looks like a game of Seastar golf - doing
something in the minimum number of lines possible :-) Unfortunately, it
looks very clever, but not quite right. sleep() usually works correctly,
but the sanitizer (in the debug build) catches a use after free.

The problem was that we delete an object which contains a timer which
contains the callback (and std::function) - from inside this callback.

The workaround in this patch is to use our future chaining to only delete
the sleeper object after its future became ready - and at that point, none
of the sleeper object or code is needed any more.

This patch also includes a regression test for this issue. The test looks
silly (just sleeps and checks nothing), but in the debugging build it
failed (with a sanitizer reporting use-after-free) before this patch.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-05-14 11:26:58 +03:00
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