Commit Graph

429 Commits

Author SHA1 Message Date
Asias He
0ffaa0cbdd net: Reorder net/stack.cc
Makes the file more readable. Now, The classes are defined in orders.
2014-10-13 11:33:47 +08:00
Avi Kivity
2d85ac902f build: disable sanitizers for static builds
Fixes static debug builds.
2014-10-12 19:56:49 +03:00
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
Asias He
d90bab775d virtio-net: Merge receive buffer 2014-10-09 19:54:50 +03:00
Asias He
a111b2fa1e net: TCP segment offload and UDP fragmentation offload support
Only tx path is added for now. Will enable rx path when merge receive
buffer feature is supported in virtio-net.

UDP fragmentation offload is not hooked up, will do in a separate patch.
2014-10-09 19:52:55 +03:00
Asias He
f14c04a132 net: Add offload_info to packet class
This is useful for adding tcp segment offload in ethernet driver.
This way, we do not need to parse the TCP packet again.
2014-10-09 19:52:54 +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
Avi Kivity
252ca596bb Merge branch 'smp'
From Gleb:

"This patchset adds smp support for networking. Posix and native stack
implementation are completely disjoint, but present the same API to an
application. Speaking about application API it is the same as before,
but application is expected to create server socket on all cpus, otherwise
some connection will stuck or reset."
2014-10-07 11:04:22 +03:00
Gleb Natapov
304f6a317e Run httpd on all available cpus 2014-10-07 11:04:07 +03:00
Gleb Natapov
2a662af092 Forward received packet according to classification 2014-10-07 11:04:05 +03:00
Gleb Natapov
cc9146403d Proxy net interface
Only one cpu can talk to virtio NIC directly (at least without
multiqueue), so other cpus receive packets from the one that drives
virtio and forward packets that need to be send back. This is done
by proxy net interface.
2014-10-07 11:04:03 +03:00
Gleb Natapov
c8ffffa557 Add packet::free_on_cpu() function
Some packets are processed by a cpu other than the one that allocates it
and its fragments. free_on_cpu() function should be called on a cpu that
does processing and it returns a packet that is deletable by the current
cpu. It is done by copying packet/packet::impl to locally allocated one
and adding new deleter that runs old deleter on original cpu.
2014-10-07 11:04:01 +03:00
Gleb Natapov
4e7d8a8506 Introduce packet classification mechanism
Classifier returns what cpu a packets should be processed on. It may
return special broadcast identifier. The patch includes classifier for
tcp, udp and arp. Arp classifier broadcasts arp reply to all cpus. Default
classifier does not forward packet.
2014-10-07 11:03:57 +03:00
Gleb Natapov
0b59abafa7 Add net::device::l2inject function
Will need it later to handle forwarded packets. Also save net::device
pointer in thread local variable to get to device instance easily. When
we ill have more then one device per cpu we will have to change to
something more sophisticated.
2014-10-07 11:03:52 +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
Avi Kivity
daca47af67 Merge branch 'tgrabiec/udp' of github.com:cloudius-systems/seastar-dev
Posix and native UDP from Tomek.
2014-10-06 20:00:28 +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
623129b45b net: add packet constructor which accepts static data 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
Tomasz Grabiec
b27b200e94 virtio: simplify rxq buffer preparation 2014-10-06 19:28:59 +03:00
Avi Kivity
b255039284 build: re-add -g flag
Dropped accidentally in 00fc8fb38a.
2014-10-06 18:17:11 +03: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
Nadav Har'El
90d99c4009 build: add option to compile as PIE or SO.
This is the first step in a journy of many miles, to be able to run
Seastar applications (such as httpd or memcached) on top of OSv.

This patch adds a configure.py option "-so" to build the applications as
shared-objects instead of executables. It also adds the option "-pie" to
build position-independent executables instead.

These are needed to run a Seastar application on OSv, as OSv cannot run
a normal position-dependent executable. Note that currently, PIE won't
actually work (because of OSv bug #352 - unfortunately Seastar uses
thread_local in one place) - so only "-so" is useful to build an application
to run in OSv.

The resulting shared-object doesn't yet run on OSv (many bugs ahead, as
well as missing features), but it's a start.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-10-06 09:50:18 +03:00
Avi Kivity
255c3ec7a7 reactor.hh: get rid of errant #include 2014-10-05 21:08:12 +03:00
Avi Kivity
20c27ceebd build: properly quote configure parameters 2014-10-05 20:49:37 +03:00
Avi Kivity
00fc8fb38a build: split --cflags into --cflags and --ldflags
clang dislikes some cflags if given to its linker.  Unfortunately this
means some options will need to be repeated.
2014-10-05 20:46:18 +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
0019c858a6 README: remove gperftools, unneeded 2014-10-05 20:05:41 +03:00
Avi Kivity
fa6b731a68 Merge branch 'memory'
This patchset adds a memory allocator, inspired by tcmalloc,
that paritions memory into per-cpu pools and only allows allocation
from local memory.  As a result it is very efficient.
2014-10-05 19:58:55 +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