Commit Graph

434 Commits

Author SHA1 Message Date
Pekka Enberg
fa8d120d70 core: Fix shared_ptr pointer casts
Fix compilation errors in the shared_ptr pointer cast functions and
update shared_ptr constructor to take shared_ptr_count_base.

Suggested by Avi.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-01-07 13:50:59 +02:00
Gleb Natapov
3f483b22bc future: add missing std::forward() in do_until_continued() 2015-01-06 14:43:34 +02:00
Avi Kivity
66eea763bf shared_ptr: add comparison operators 2015-01-05 13:24:07 +02:00
Avi Kivity
7a317f78a2 shared_ptr: be friend to self
Needed for converting constructor.
2015-01-05 13:24:06 +02:00
Avi Kivity
f2e25b8442 Merge branch 'shared_ptr'
Split shared_ptr into a traditional polymorphic shared_ptr implementation,
and a lighter-weight, non polymorphic lw_shared_ptr.
2015-01-05 11:29:35 +02:00
Avi Kivity
c7d7494a65 shared_ptr: add some documentation 2015-01-05 10:39:35 +02:00
Avi Kivity
b6d76ed650 shared_ptr: add polymorphic-capable shared pointer
At the cost of doubling the pointer size, this shared_ptr is polymorphic
and can be upcast to a base class.
2015-01-04 23:15:58 +02:00
Avi Kivity
87f63f7b90 shared_ptr: rename to lw_shared_ptr (for light-weight)
The current shared_ptr implementation is efficient, but does not support
polymorphic types.

Rename it in order to make room for a polymorphic shared_ptr.
2015-01-04 22:38:49 +02:00
Shlomi Livne
3362851e55 reactor: add a SIGTERM handler
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-01-04 17:17:33 +02:00
Avi Kivity
33518ea9d0 shared_ptr: fix uninitialized enable_shared_from_this ref count
Caused immediate leak.
2015-01-01 14:29:27 +02:00
Avi Kivity
05a02b93a0 Merge branch 'tcp'
Tcp protects tcbs using a shared_ptr, but in some cases captures an
unprotected [this] in lambdas, which can outlive the shared_ptr.

Introduce and use enable_shared_from_this to fix.

Reviewed-by: Asias He <asias@cloudius-systems.com>
2014-12-31 12:17:21 +02:00
Nadav Har'El
5b071fd224 sstring: support to_sstring() for floating-point
std::to_string() can also convert a floating-point argument to string,
using the "%f" printf format (see
	http://en.cppreference.com/w/cpp/string/basic_string/to_string )
So add this support to our to_sstring() as well.

Note that if you want to use a different format, e.g., "%g", you can,
by using the to_sstring_sprintf function, for example

	to_sstring_sprintf(12345678.9, "%g")

results in "1.23457e+07".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-30 17:00:46 +02:00
Gleb Natapov
6ad9114c0b reactor: add at_destroy() function to the reactor and use it
Unfortunately at_exit() cannot be used to delete objects since when
it runs the reactor is still active and deleted object may still been used.
We need another API that runs its task after reactor is already stopped.
at_destroy() will be such api.
2014-12-30 15:21:10 +02:00
Gleb Natapov
2fb7490bf9 stream: reset subscription's stream pointer in stream's destructor 2014-12-30 15:21:08 +02:00
Nadav Har'El
7a84dff0b2 sstring: constructor from C string
The constructor from "const char_type *" wouldn't really work when
char_type != char, because strlen() won't work on such pointers.

It is more convenient to have a constructor from an ordinary const char *
(e.g., a C string literal), and solve the type problem with an ugly cast.

This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned
char, or signed char), but I think we make this assumption in other places
as well (e.g., in determining the size we need to allocate).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:32 +02:00
Nadav Har'El
f7fbf8ba02 sstring: add operator[]
std::string has an operator[] to get access (read or modify) to one
character in the string. This patch adds the same operator for our
sstring.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:10 +02:00
Nadav Har'El
9be5590fcd sstring: fix character type
The basic_sstring<> template allows picking char_type - which instead of
being just "char" could be chosen to be something similar, like "unsigned char"
or "signed char".

Unfortunately some hard-coded uses of "char" were left in the code. This
did not cause any problems for existing code because of implicit conversions,
but it does cause problems once I try to implement operator[] when char_type
is not char. This results in an attempt to return a reference to the result
of a conversion, which is not allowed.

So this patch fixes the leftover uses of "char" to "char_type".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:06 +02:00
Avi Kivity
3cecef365f shared_ptr: implement enable_shared_from_this<>
Mirrors std::enable_shared_from_this<>.
2014-12-29 11:02:31 +02:00
Gleb Natapov
efd6c33af0 reactor: remove no longer needed thread_pool function 2014-12-28 18:19:20 +02:00
Gleb Natapov
3eefc1ada2 reactor: replace thread_pool poller with signal notification
Drops one poller since now signal poller is used to process thread_pool
completions.
2014-12-28 18:19:18 +02:00
Avi Kivity
27955d47f6 Merge branch 'gleb/nopoll' of github.com:cloudius-systems/seastar-dev
Remove pre-poll-mode code, from Gleb:

"This series moves most of eventfd users to use other form of notification
which can be polled without entering the kernel and moving epoll in its own
poller which is enabled only if there is an fd that needs to be polled."

[avi: add -lrt to linker command line]
2014-12-28 15:34:36 +02:00
Gleb Natapov
367bbd75f3 reactor: move epoll to its own poller
Enable it only if there is fd to poll.
2014-12-28 14:54:43 +02:00
Gleb Natapov
889cc69a28 reactor: remove non polling mode 2014-12-28 14:54:43 +02:00
Gleb Natapov
7d3fb282c5 reactor: poll thread pool for completion instead of using eventfd 2014-12-28 14:54:43 +02:00
Gleb Natapov
a57e75ab9f reactor: move timers to use signals instead of timerfd to signal a completion 2014-12-28 14:54:43 +02:00
Gleb Natapov
51b56d90f2 reactor: poll for signals completion instead of using signalfd 2014-12-28 14:54:43 +02:00
Gleb Natapov
3d374110c6 reactor: poll for aio completion instead of using eventfd
io_getevents() avoids system call if timeout is zero and there is no
completed event.
2014-12-28 13:39:59 +02:00
Gleb Natapov
6d7916a9f8 reactor: disable batching during engine termination
SMP messages that are send while engine is been stopped should be
sent immediately because after the engine is stopped they will not be.
2014-12-28 13:37:25 +02:00
Avi Kivity
efe6e4f5eb sstring: fix conversion to std::string with NUL bytes
sstring's std::string conversion uses c_str() to construct the value,
but the conversion is broken if the value contains NUL - both sstring and
std::string can contain NULs, but C strings use them as a terminator.

Fix by using the size+length std::string constructor.
2014-12-28 13:30:24 +02:00
Gleb Natapov
466acedcb2 timer: cancel all timers during reactor destruction
If a timer is not canceled it will try to cancel itself during
destruction which may happen after engine is already destroyed.
2014-12-25 09:14:42 +02:00
Vlad Zolotarov
59403f0774 dpdk: First version that supports both 1.7.x and 1.8.x (current git master) DPDK versions.
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-22 17:37:05 +02:00
Vlad Zolotarov
11c54bd1d5 dpdk: Change the default behavior when --dpdk-pmd is set
1) Make --dpdk-pmd parameter to be a flag instead of a (key, value).
 2) Default to a default hugetlbfs DPDK settings when --hugepages is not
    given and --dpdk-pmd is set.

This will allow a more friendly user experience in general and when one doesn't
want to provide a --hugepages parameter in particular.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-22 17:36:58 +02:00
Vlad Zolotarov
ddf239a943 dpdk: Move the scattered DPDK EAL initialization into the dpdk::eal.
- Move the smp::dpdk_eal_init() code into the dpdk::eal::init() where it belongs.
 - Removed the unused "opts" parameter of dpdk::dpdk_device constructor - all its usage
   has been moved to dpdk::eal::init().
 - Cleanup in reactor.cc: #if HAVE_DPDK -> #ifdef HAVE_DPDK; since we give a -DHAVE_DPDK
   option to a compiler.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-22 17:36:49 +02:00
Vlad Zolotarov
7ec062e222 dpdk: Move dpdk_eal class into a separate file
- Make it's methods static.
 - Rename dpdk::dpdk_eal -> dpdk::eal

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2014-12-22 17:36:42 +02:00
Gleb Natapov
b958a44304 smp: create seastar threads using DPDK when compiled with DPDK support
DPDK initialization creates its own threads and assumes that application
uses them, otherwise things do not work correctly (rte_lcore_id()
returns incorrect value for instance). This patch uses DPDK threads to
run seastar main loop making DPDK APIs work as expected.
2014-12-18 14:43:37 +02:00
Avi Kivity
c09694d76c reactor: fix corruption in _pollers
register_poller() (and unregister_poller()) adjusts _pollers, but it may be
called while iterating it, and since std::vector<> mutations invalidate
iterators, corruption occurs.

Fix by deferring manipulation of _pollers into a task, which is executed at
a time where _pollers is not touched.
2014-12-17 16:56:20 +02:00
Avi Kivity
481080feb8 reactor: refactor reactor::poller
Currently, reactor::_pollers holds reactor::poller pointers; since these
are movable types, it's hard to maintain _pollers, as the pointers can keep
changing.

Refactor poller so that _pollers points at an internal type, which does not
move when a reactor::poller moves.  This requires getting rid of
std::function, since it lacks a comparison operator.
2014-12-17 16:20:52 +02:00
Avi Kivity
a0daeae865 sstring: optimize release()
By switching to malloc/free, we can use make_free_deleter(), which
does not require extra memory.
2014-12-16 14:55:02 +02:00
Avi Kivity
692ee47456 deleter: introduce make_object_deleter
When we have an object acting as resource guard for memory, we can convert
it into a deleter using

  make_deleter([obj = std::move(obj)] {})

introduce a simpler interface

  make_object_deleter(std::move(obj))

for doing the same thing.
2014-12-16 14:55:02 +02:00
Avi Kivity
3e4c53300d Merge branch 'mq' of ssh://github.com/cloudius-systems/seastar-dev
Multiqueue support for #cpu != #q, from Gleb.
2014-12-16 11:11:22 +02:00
Gleb Natapov
ad29ccd3df net: start dhcp after the stack is created on all cpus 2014-12-15 17:30:13 +02:00
Asias He
42c4085f29 timer: Introduce lowres_clock 2014-12-15 19:39:33 +08:00
Asias He
f1e46791f5 timer: Drop unused ulong_bits 2014-12-15 19:39:33 +08:00
Asias He
db0124ef05 timer: Add now() for timer_set 2014-12-15 19:39:33 +08:00
Asias He
0242d402b7 timer: Drop Clock template parameter in time_set 2014-12-15 19:39:33 +08:00
Asias He
62fff15e54 timer: Make timer a template 2014-12-15 19:39:33 +08:00
Avi Kivity
c56dcaf17a smp: fix cross-cpu access in poll mode
We look at _poll mode in another cpu's cache accidentally, as pard of
the peer->idle() call.

Fix by looking at our own _poll variable first; they should all be the same.
2014-12-15 11:30:06 +02:00
Avi Kivity
4ab36be8c9 reactor: fix pointless allocation in wait_and_process()
wait_and_process() expects an std::function<>, but we pass it a lambda,
forcing it to allocate.

Prepare the sdt::function<> in advance, so it can pass by reference.
2014-12-14 15:58:56 +02:00
Avi Kivity
535b447343 circular_buffer: get rid of {pre|post}_push_{front|back}
As Nadav suggests, with the simplified circular_buffer implementation they
no longer provide any value and only obfuscate the code.
2014-12-14 10:00:43 +02:00
Avi Kivity
94a1cdd6e4 Merge branch 'circular_buffer'
circular_buffer simplifications and enhancements.
2014-12-13 18:45:47 +02:00