Add rwlock read-lock benchmark to tests/misc-mutex

This patchs adds to tests/misc-mutex measurements of rwlock's reader
lock.

As I explain below, this is both a benchmark of rwlock itself (showing
the sad state it is in), and another benchmark for contended mutexes.

Ideally, in a read-mostly workload, we'd like to see a very quick
reader lock and excellent scalability (one CPU reading shouldn't bother
another CPU reading). But what we measure in this benchmark is the
complete opposite :-( Instead of a read-lock cycle taking a couple of
nanoseconds we measure uncontended read lock cycle at 50ns, twice slower
than a mutex (understandable, given rwlock's implementation); When two
threads on two different cpus want to read concurrently, the lock cycle,
jumps to 1800ns.

The reason for this slowness is twofold: First, we need a better, scalable,
rwlock implementation ;-) But second, taking as a given that we do have the
current rwlock implementation, which translates concurrent read access to a
mutex contention, we could benefit from better performance when the mutex
is contended. Adding spinning to the mutex dropped the 1800 ns
read-lock/unlock cycle to just 110 ns.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix SCOPE_LOCK to be usable twice in the same scope.

Asias discovered that if SCOPE_LOCK is used twice in the same block,
it gives a compilation error because the same lock name is used for
both.

The existing code attempted to solve this problem using __COUNTER__,
but did it wrongly... The problem is that the "##" c-preprocessor
operator does concatenation before macro expansion, so the literal string
"__COUNTER__" was used, not a numeric counter as we had hoped.
To do this correctly, we need to pass the task to another macro, or
two actually!

A more detailed explanation about the solution:

* #define CONCATENATE2(x, y) x##y
This macro concatenates the two literal arguments passed to it, and only
then does macro expansion. Naively calling CONCATENATE2(_SCOPE_LOCK,
__COUNTER__) would result in just the string _SCOPE_LOCK__COUNTER.

* #define CONCATENATE(x, y) CONCATENATE2(x, y)
CONCATENATE(_SCOPE_LOCK, __COUNTER__) expands to CONCATENATE2(_SCOPE_LOCK,
<actual counter>) and that is now exapnded again to get the actual
behaviour we need.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
rwlock: Prevent construction of rwlock_for_* objects

rwlock_for_read, rwlock_for_write are just meant to be interfaces, and
shouldn't be instanciated. We have a private constructor to ensure that
they are never constructed. Unfortunately, because of a gcc (<4.9) bug
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56429) an explicit
"=default" constructor is always public, so this protection doesn't
work at all, and rwlock_for_* objects can be created (and obviously
crash when used).

This patch changes the "default" constructor to an empty constructor,
which does the same thing but avoids this gcc bug.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
zfs: automatically import extra pools

This patch will provide OSv with an important functionality when
multiple ZFS pools are being used in the system. It follows a ZFS on
Linux scheme where all available pools in the system are imported and
their dataset mounted during system initialization process.

It was tested both locally and on EC2.

Details on EC2 test: Started a EC2 instance, created a new ZFS pool
comprising two additional non-ephemeral disks, stopped the instance,
re-started the instance, meaning a new OSv instance, and checked that
the new ZFS pool would be automatically available on subsequent OSv
instances.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
timer_task: use external lock

timer_task has an internal mutex lock which protects various timer_task
operations. This patch changes the lock to a reference to an external
lock. This way, instead of doing recursive locking, we can share the lock
with serial_timer_task's mutex lock.

tests/tst-async.c is modified to use the new locking scheme.

Signed-off-by: Asias He <asias@cloudius-systems.com>
mempool: remove contention inside unfill_page_buffer()

This change reduces page buffer pressure caused by virtio-net
allocations, showign up as contention inside unfill_page_buffer() and
refill_page_buffer(). The virtio-net subsystem allocates pages on one
CPU which are then scattered across all other CPUs and freed to their
per-CPU buffers. To mitigate that, this change enables caching of
pages used by virtio-net.
_pl -> _page_pool