Commit Graph

509 Commits

Author SHA1 Message Date
Pekka Enberg
34018b2b65 shared_ptr: Fix assignment of polymorphic types
Fix the assignment operator to work with polymorphic types.

Suggested by Nadav.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-02-06 10:06:01 +02:00
Pekka Enberg
4732653538 basic_sstring: Add 'compare' and 'operator<'
Add string comparison functions to basic_sstring that are required for
C++ containers such as std::map and std::multimap.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-02-06 10:06:01 +02:00
Gleb Natapov
89763c95c9 core: optimise timer completions vs periodic timers
The way periodic timers are rearmed during timer completion causes
timer_settime() to be called twice for each periodic timer completion:
once during rearm and second time by enable_fn(). Fix it by providing
another function that only re-adds timer into timers container, but do
not call timer_settime().
2015-01-29 12:43:28 +02:00
Avi Kivity
59c0d7e893 smp: fix work item deletion
Delete it after completion, not after responding.
2015-01-29 12:14:05 +02:00
Gleb Natapov
bcae5f2538 smp: fix memory leak in smp queue
Delete completed items. Fixes regression from ff4aca2ee0.
2015-01-29 11:49:24 +02:00
Avi Kivity
b3dd1c8285 Merge branch 'signal' of ../seastar
Simplify signal handling.
2015-01-29 10:08:27 +02:00
Tomasz Grabiec
7a55f21b29 core: Move _timer to an instance field
So that the callback which is set on it and which is allocated on CPU
0 is destroyed on CPU 0 when the clock dies. Otherwise we can attempt
to delete it after the CPU thread is gone if CPU 0 != main thread.
2015-01-28 16:18:55 +02:00
Tomasz Grabiec
8a126b9088 core: Fix use-after-free error on _threads
When smp::configure() is called from non-main thread, then the global
state which it allocates will be destroyed after reactor is destroyed,
because it will be destroyed from the main thread and the reactor will
be destroyed together with the thread which called
smp::configure(). This will result in SIGSEGV when allocator tries to
free _threads vector across CPU threads because the target CPU was
alrady freed. See issue #10.

To fix this, I introduced smp::cleanup() method which should cleanup
all global state and should be called in the same thread in which
smp::configure() was called.

I need to call smp::configure() from non-main thread for integration
with boost unit testing framework.
2015-01-28 16:18:53 +02:00
Tomasz Grabiec
555977f5e6 core: drop BSD license text from resource.hh 2015-01-28 16:18:50 +02:00
Gleb Natapov
bb072fc5c9 core: add iterator for circular_buffer container 2015-01-28 13:49:09 +02:00
Takuya ASADA
be5568ae31 distributed: handle invoke_on with void return value
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-01-28 13:48:18 +02:00
Avi Kivity
38839293f9 reactor: simplify timer handling
Instead of scheduling timer processing to happen in the future,
process timers in the context of the poller (signal poller for high
resolution timer, lowres time poller for low resolution timers).

This both reduces timer latency (not very important) but removes a
use of promise/future in a repetitive task, which is error prone.
2015-01-28 11:29:16 +02:00
Avi Kivity
770214ea63 reactor: simplify signal handling
Signals can be repetitive, and therefore are not a good match for
promise/future, which are single shot.

Replace with plain callbacks.
2015-01-28 11:07:14 +02:00
Avi Kivity
a9c0fbd8f7 timer: add constructor from callback 2015-01-27 18:57:59 +02:00
Gleb Natapov
5454c79613 core: allocate reactors on each cpu instead of using thread_local variable
I see TLS init function for engine high in cache miss profile. And yes,
this patch has #define.
2015-01-27 14:46:49 +02:00
Gleb Natapov
7a92efe8d1 core: add local engine accessor function
Do not use thread local engine variable directly, but use accessor
instead.
2015-01-27 14:46:49 +02:00
Gleb Natapov
18d212b04e core: do not use separate thread_local variable to track pending signals
Access to thread_local variable goes throw a helper function.
2015-01-27 12:33:10 +02:00
Gleb Natapov
74f9f1fdd2 core: prefetch different amount of work items for different queues
Incoming item processing usually takes more work then completion
item processing. Prefetch more completion items to make sure they are
ready before access.
2015-01-25 17:51:21 +02:00
Gleb Natapov
0383459b93 core: prefetch only valid addresses
Prefethcing non mapped address incurs address translation cost.
2015-01-25 17:51:21 +02:00
Gleb Natapov
ff4aca2ee0 core: prefetch work items before processing 2015-01-25 14:48:30 +02:00
Gleb Natapov
b9554219dc core: add prefetch functions 2015-01-25 14:48:30 +02:00
Vlad Zolotarov
85b62d8132 memory: hugetlbfs mapping may not be invalid
Turn a condition into an assert() since if a mapping is invalid this may
only mean that we have a bug.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-01-25 13:22:11 +02:00
Tomasz Grabiec
24227fd933 shared_ptr: Add helpers for hashing shared_ptr<> by value 2015-01-25 13:12:04 +02:00
Raphael S. Carvalho
be7dbcbf50 core: improve reactor::receive_signal()
receive_signal() uses the unordered map _signal_handlers (signo mapped to
signal_handler) to either register a signal or find an existing one, and
from there get a future from the promise associated with that signal.
The problem is _signal_handlers.emplace() being called unconditionally,
resulting in the constructor from signal_handler always being called to
needlessly re-register the same handler, even when the signo is already
inserted in the map.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-01-25 13:10:55 +02:00
Gleb Natapov
b250b53004 core: remove reference to smp_message_queue from async_work_item
It is unused.
2015-01-22 13:25:30 +02:00
Gleb Natapov
d83e4c49fc smp: put fields used by different cores on different cache lines 2015-01-22 13:25:30 +02:00
Avi Kivity
a8054e5aae memory: init virt to phys mapping after binding memory to node
Binding may cause memory to move, so initialize the page map after it is done.
2015-01-22 12:38:22 +02:00
Avi Kivity
285d4af077 memory: adjust pagemap parsing
The pfn is in bits 0:54 inclusive, we missed the high bit.

Should have no effect in systems with less than a few exabytes of memory.
2015-01-21 19:06:30 +02:00
Avi Kivity
90e77cc3a0 semaphore: support for breaking a semaphore
Tell all waiters that something bad happened and they should all go away.

Can be used only once; waiters should clean up and there must not be any
new waiters.
2015-01-20 11:29:48 +02:00
Avi Kivity
a6dea57f5b semaphore: add missing include 2015-01-20 11:29:26 +02:00
Avi Kivity
811fba9bc1 Merge branch 'align'
Aligned allocation facility.
2015-01-19 20:15:51 +02:00
Avi Kivity
93ae11cf63 resource: fix off-by-type getting number of processing units
Effect was to lose hyperthreads on NUMA machines.
2015-01-19 16:11:11 +02:00
Avi Kivity
e0d5bd2fb8 collectd: improve default hostname 2015-01-19 15:58:24 +02:00
Avi Kivity
45f9c86943 memory: provide C++ facilities for aligned allocation
new (with_alignment(64)) foo(...)   // cache aligned foo
  std::vector<foo, aligned_allocator<foo, 64>> // cached aligned foo vector
2015-01-19 09:49:32 +02:00
Avi Kivity
b22186e623 memory: fix small aligned allocations
When size > align, we simply call the small allocator with the provided size,
but that does not guarantee any alignment above the default.

Round the allocation size to the nearest power of two in that case, to
guarantee alignment.
2015-01-19 09:49:32 +02:00
Gleb Natapov
e3915cfcf8 reactor: call pause instruction in idle loop 2015-01-18 12:37:05 +02:00
Gleb Natapov
2ff006da4a core: calculate system load and report it via collectd 2015-01-18 12:37:05 +02:00
Gleb Natapov
1ef2808750 reactor: return proper value from pollers
Currently most of them return true no matter if any work was actually
done. Fix it to return true only if poll did any work.
2015-01-18 12:37:05 +02:00
Avi Kivity
80bcf3f973 memory: provide virt-to-phys translation API
Convert virtual addresses to physical addresses.  Only works when
--hugepages is in effect.
2015-01-15 18:23:19 +02:00
Avi Kivity
d77d0cddca posix: implement pread() interface 2015-01-15 18:22:07 +02:00
Avi Kivity
e746eb7f84 future: fix make_exception_future build error
Add missing std::.
2015-01-15 15:19:02 +02:00
Avi Kivity
311e1c834e future: fix future::then_wrapped() in exception case
Calling state.get() will throw the exception instead of calling the function,
thus denying the called function the chance to deal with the exception.

Fix by constructing the future directly from state.
2015-01-15 15:19:02 +02:00
Avi Kivity
809c6edee2 reactor: periodically call into allocator to drain cross-cpu free items 2015-01-15 15:19:02 +02:00
Avi Kivity
e57be410b5 memory: support cross-cpu freeing
Currently we require that memory be freed on the same cpu it was allocated.
This does not impose difficulties on the user code, since our code is already
smp-unsafe, and so must use message-passing to run the destructor on the
origin cpu, so memory is naturally freed there as well.

However, library code does not run under our assumptions, specifically
std::exception_ptr, which we do transport across cores.

To support this use case, add low-performance support for cross-cpu frees,
using an atomic singly linked list per core.
2015-01-15 15:19:00 +02:00
Avi Kivity
30aa81819a app: handle command line parsing errors 2015-01-15 10:46:44 +02:00
Asias He
8ed3584a5e app: Allow -h to show help message
It only supports -help at the moment. It is quite annoying to see:

   $ ./httpd -h
   terminate called after throwing an instance of
   'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::unknown_option> >'
     what():  unrecognised option '-h'
   Aborted

Support both -h and --help.
2015-01-15 10:31:31 +02:00
Gleb Natapov
c6c6c6055d core: add various statistics about smp communication 2015-01-14 16:50:49 +02:00
Gleb Natapov
354280fd7c core: scollectd: use move instead of forward on rvalue reference 2015-01-14 16:50:48 +02:00
Gleb Natapov
340a871a98 core: use seastar shared ptr in scollectd 2015-01-14 16:50:48 +02:00
Gleb Natapov
660434c3a0 core: change collectd to be a namespace instead of class
Class was used because it provides better encapsulation, but namespace
is easier to deal with.
2015-01-14 16:50:48 +02:00