Commit Graph

145 Commits

Author SHA1 Message Date
Tomasz Grabiec
1bdb73e5da core: fix buffer overflow in to_sstring() 2014-10-09 20:04:53 +03:00
Tomasz Grabiec
eac955cc73 core: simplify output_stream::write() and flush() results
The result is not used for anything and I am not sure what it could be
used for, as the result carries little (write) to none (flush)
information. So I went ahead and simplified it to be future<> so that
it is easier to return it in places which expect future<>.
2014-10-09 20:02:11 +03:00
Avi Kivity
37ef3bc899 memory: request huge page backing for heap
Worth about 12% on httpd.
2014-10-07 15:23:30 +03:00
Avi Kivity
c6069ac4d9 core: set memory reclaim hook
Allow the memory manager to call us back requesting a reclaim.  Push
the task to the front of the queue, so we don't run out of memory waiting
for it to fire.
2014-10-07 15:14:44 +03:00
Avi Kivity
6746bcfd68 memory: reclaim support
Allow memory users to declare methods of reclaiming memory (reclaimers),
and allow the main loop to declare a safe point for calling these reclaimers.

The memory mananger will then schedule calls to reclaimers when memory runs
low.
2014-10-07 15:14:44 +03:00
Gleb Natapov
19addf6e64 Implement smp handling for posix networking stack
The idea is that only one thread opens listen socket and runs accept().
Other threads emulate listen()/accept() by waiting for connected
socket from the main thread. Main thread distributes connected sockets
according to round robin pattern. Patch introduce new specialization
for server_socket_impl and network_stack: posix_ap_server_socket_impl
and posix_ap_network_stack respectively. _ap_ stand for auxiliary processor.
2014-10-07 11:03:49 +03:00
Gleb Natapov
526312253f Introduce smp::main_thread() function
Sometimes we need to know if we are running on main thread during engine
initialization, before engine._id is available. This function will be
used for that.
2014-10-07 11:03:43 +03:00
Gleb Natapov
850545df6d Catch exception in app template
Print it out and exit program gracefully.
2014-10-07 11:03:39 +03:00
Gleb Natapov
20dcbbd12d Provide engine::exit() call to exit smp program gracefully 2014-10-07 11:03:37 +03:00
Raphael S. Carvalho
5ca6ddc281 reactor: introduce reactor::stat
Basically, wrapping stat around _thread_pool as it might block
waiting for metadata to be read from the underlying device.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-06 21:37:30 +03:00
Avi Kivity
4a080eb008 core: switch to spsc_queue for interthread communication
It's much faster than a normal queue.
2014-10-06 21:37:22 +03:00
Tomasz Grabiec
e4d55258c1 tests: add UDP tests
To start the server:

  $ build/release/tests/udp_server

To start the client:

  $ build/release/tests/udp_client --server localhost:10000
2014-10-06 18:36:42 +02:00
Tomasz Grabiec
f907f6a999 reactor: add getter for network stack 2014-10-06 18:34:43 +02:00
Tomasz Grabiec
ba49d24b01 net: add support for UDPv4 in native and posix stack 2014-10-06 18:34:40 +02:00
Tomasz Grabiec
cf7a084457 core: move some of the networking abstractions to net/api.hh 2014-10-06 18:34:28 +02:00
Tomasz Grabiec
3775dae6fb net: convert ipv4_addr.host from array to uint32_t
It will be easier to convert it to a format on which the native stack
works.
2014-10-06 18:34:28 +02:00
Tomasz Grabiec
269b05afc2 core: add queue::push_eventually()
It's an asynchronous version of blocking push().
2014-10-06 18:34:28 +02:00
Tomasz Grabiec
57bc48ddbb core: add queue::pop_eventually()
It's an asynchronous version of blocking pop().
2014-10-06 18:34:28 +02:00
Nadav Har'El
5db2c1b506 build: Compile-time option to use default memory allocator
Add a compile-time option, DEFAULT_ALLOCATOR, to use the existing
memory allocator (malloc() and friends) instead of redefining it.

This option is a workaround needed to run Seastar on OSv.

Without this workaround, what seems to happen is that some code compiled
into the kernel (notably, libboost_program_options.a) uses the standard
malloc(), while inline code compiled into Seastar uses the seastar free()
to try and free that memory, resulting in a spectacular crash.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-10-06 14:59:36 +03:00
Avi Kivity
255c3ec7a7 reactor.hh: get rid of errant #include 2014-10-05 21:08:12 +03:00
Avi Kivity
2b12c13055 memory: support sized deallocation
With N3778, the compiler can provide us with the size of the object,
so we can avoid looking it up in the page array.  Unfortunately only
implemented in clang at the moment.
2014-10-05 20:24:00 +03:00
Avi Kivity
9cd0e4f405 memory: improve allocation density
Instead of rounding up to a power-of-two, have four equally spaced
regions between powers of two.  For example:

   1024
   1280 (+256)
   1536 (+256)
   1792 (+256)
   2048 (+256)
   2560 (+512)
   3072 (+512)
   3584 (+512)
   4096 (+512)
2014-10-05 19:58:12 +03:00
Avi Kivity
3db75b272e bitops: mark functions as constexpr
Luckily, the gcc builtins are also constexpr.
2014-10-05 19:58:12 +03:00
Avi Kivity
e42158aea6 memory: small allocation support
Allocate small objects within spans, minimizing waste.

Each object size class has its own pool, and its own freelist.  On overflow
free objects are pushed into the spans; if a span is completely free, it is
returned to the main free list.
2014-10-05 19:58:10 +03:00
Avi Kivity
c407f5e091 memory: hook standard library allocation functions 2014-10-05 19:57:46 +03:00
Avi Kivity
b849b6b4cd memory: add support for aligned large allocations 2014-10-05 19:57:46 +03:00
Avi Kivity
86c0b7b7c9 memory: add per-cpu memory allocator
Largely inspired by tcmalloc, but simpler.  No support for small allocations
at the moment.
2014-10-05 19:57:40 +03:00
Avi Kivity
8806fbd4d4 smp: use posix_thread instead of std::thread
Friendlier towards our allocator, which doesn't support malloc/free on
different cpus.
2014-10-05 19:00:09 +03:00
Avi Kivity
4e9f7804c9 core: switch thread_pool to posix_thread
std::thread allocates, which interferes with the seastar memory allocator,
which doesn't support allocation in worker threads.
2014-10-05 19:00:09 +03:00
Avi Kivity
50c4dcbd5f posix: posix_thread: allocate stack manually
Otherwise, the stack is allocated on the creating thread and destroyed
on the created thread, which we don't support.
2014-10-05 19:00:04 +03:00
Avi Kivity
08706fcc6d posix: wrap mmap() for anonymous maps
Automatically munmap() when the result is destroyed.
2014-10-05 18:49:38 +03:00
Avi Kivity
1cd888c4a9 posix: move posix_thread implementation to new source file 2014-10-05 18:49:36 +03:00
Avi Kivity
10ea65cc0b posix: support std::move()ing a posix_thread
Useful for storing in containers.
2014-10-05 18:45:51 +03:00
Avi Kivity
96c83e1bdd posix: add pthread wrapper
std::thread allocates memory, while we want a non allocating version
for the worker threads.
2014-10-05 18:09:09 +03:00
Avi Kivity
1dbab3504c posix: add missing includes 2014-10-05 18:09:09 +03:00
Avi Kivity
7a16599f70 core: add bit operations library 2014-10-05 18:09:09 +03:00
Avi Kivity
a597379db8 core: add align_down() 2014-10-05 18:09:09 +03:00
Avi Kivity
0bbd42bc63 core: extract align_up() into an include file 2014-10-05 18:09:09 +03:00
Avi Kivity
ef96af29f2 future: avoid generalized lambda in forward_to()
Crashes gdb with -O0.
2014-10-05 15:44:49 +03:00
Avi Kivity
4cc5ce93de Merge branch 'tgrabiec/virtio-back-pressure' of github.com:cloudius-systems/seastar-dev
Back pressure from virtio into the rest of the stack, plus removal os the
virtio tx queue, from Tomek.

Conflicts:
	net/virtio.cc
2014-10-05 09:59:43 +03:00
Tomasz Grabiec
6fa9cd7ac9 core: introduce do_until() and keep_doing() 2014-10-04 11:27:23 +02:00
Gleb Natapov
0a3df514cb smp: fix completion handling in inter_thread_work_queue
Currently completion processing start during object creation, but since
all object are created by main thread they all run on the same cpu which
is incorrect. This patch starts completion processing on correct cpu.
2014-10-02 15:49:53 +03:00
Avi Kivity
98665bf944 reactor: switch _pending_tasks to circular_buffer
This lets us get rid of the double buffering, since we can pop tasks off
one end while inserting them on the other.
2014-10-02 14:32:34 +03:00
Avi Kivity
2d012e1df8 queue: switch to circular_buffer 2014-10-02 14:32:34 +03:00
Avi Kivity
dacf81745e core: add circular_buffer
Since we have lots of queues, we need an efficient queue structure,
esp. for moveable types.  libstdc++'s std::deque is quite hairy,
and boost's circular_buffer_space_optimized uses assignments instead of
constructors, which are both slower and less available than constructors.

This patch implements a growable circular buffer for these needs.
2014-10-02 14:32:32 +03:00
Avi Kivity
42db87a8c2 core: add helper functions for "transferring" objects
Here, transferring is defined as moving an object to a new location
(either via a move or copy constructor) and destroying the source.  This
is useful when implementing containers.
2014-10-02 14:28:14 +03:00
Tomasz Grabiec
6fa3212888 core: fix missing error propagation when intermediate future is involved
Test case (added in the next patch):

    promise<> p1;
    promise<> p2;

    auto f = p1.get_future().then([f = std::move(p2.get_future())] () mutable {
        return std::move(f); // this future will fail
    }).then([] {
        // never reached, that's ok
    });

    p1.set_value();
    p2.set_exception(std::runtime_error("boom"));

    // f should get resolved eventually with error, but was not
2014-10-01 13:45:28 +02:00
Tomasz Grabiec
d9bf08c1b3 core: introduce future::finally()
The callback passed to it will be executed when future gets resolved,
successfully or not. The returned future will mimic the state of the
target future.
2014-10-01 13:45:28 +02:00
Tomasz Grabiec
fcb55c1f04 core: introduce future::forward_to()
It causes that when future is resolved, the target promise will be
resolved too with the same state.
2014-10-01 13:45:28 +02:00
Tomasz Grabiec
07d6df11a8 core: introduce make_exception_future() which works with exception objects 2014-10-01 13:45:25 +02:00