bsd: add missing include to random.h

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ring_spsc: introduce emplace() method

The method accepts a template functor which can be used to construct
the element in-place. Useful when storing large objects to avoid
copying cost.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
core: introduce unordered_ring_mpsc

It's supposed to be an efficient multiple-producer single-consumer
non-blocking container based on per-CPU rings.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: add test for unordered_ring_mpsc

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: C++'ify random_harvestq.c

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: make random_harvest() non-blocking

We need to make it non-blocking to use it in interrupt context.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: collect entropy from interrupts

This is based on the FreeBSD implementation with slight
modifications. FreeBSD collects 2 bits of entropy from each interrupt,
based on:

 - interrupt vector number
 - current thread id
 - cycles counter

We collect 1 bit from the following information:

 - interrupt vector number
 - instruction pointer
 - cycles counter

For the reference I will describe what Linux is doing. Linux is using
the following information for entropy:

 - interrupt vector number
 - instruction pointer
 - cycles counter
 - jiffies counter

This information is hashed on Linux using a cryptographically unsecure
(but fast) hash into a per-CPU pool on every interrupt. Once every 64
interrupts or if a second has passed they feed the accumulated hash to
the common entropy pool and credit it for 1 bit of entropy.

 === Performance tests ===

I have performed tests on my laptop with netperf and iperf. The
results are below. I didn't see significant impact on performance.

$ netperf -H osv

=== Before ===

Size   Size    Size     Time     Throughput
bytes  bytes   bytes    secs.    10^6bits/sec

 65536  16384  16384    10.00    1998.67
 65536  16384  16384    10.00    1958.58
 65536  16384  16384    10.00    1976.67
 65536  16384  16384    10.00    2050.17
 65536  16384  16384    10.00    2069.08

avg = 2010.63
stdev = 42.39

=== After ===

Recv   Send    Send
Socket Socket  Message  Elapsed
Size   Size    Size     Time     Throughput
bytes  bytes   bytes    secs.    10^6bits/sec

 65536  16384  16384    10.00    1938.42
 65536  16384  16384    10.00    2003.05
 65536  16384  16384    10.00    2055.37
 65536  16384  16384    10.00    2016.63
 65536  16384  16384    10.00    1982.83

avg = 1999.26
stdev = 38.56

$ iperf -c osv -P 10 | grep SUM

=== Before ===

[SUM]  0.0-10.0 sec  1.85 GBytes  1.58 Gbits/sec
[SUM]  0.0-10.0 sec  1.78 GBytes  1.52 Gbits/sec
[SUM]  0.0-10.1 sec  1.84 GBytes  1.57 Gbits/sec
[SUM]  0.0-10.0 sec  1.77 GBytes  1.51 Gbits/sec
[SUM]  0.0-10.0 sec  1.92 GBytes  1.64 Gbits/sec
[SUM]  0.0-10.0 sec  1.87 GBytes  1.60 Gbits/sec
[SUM]  0.0-10.1 sec  1.78 GBytes  1.52 Gbits/sec
[SUM]  0.0-10.0 sec  1.83 GBytes  1.57 Gbits/sec
[SUM]  0.0-10.0 sec  1.78 GBytes  1.52 Gbits/sec

avg   = 1.82 [GBytes]
stdev = 0.05 [GBytes]

=== After ===

[SUM]  0.0-10.0 sec  1.85 GBytes  1.59 Gbits/sec
[SUM]  0.0-10.0 sec  1.82 GBytes  1.56 Gbits/sec
[SUM]  0.0-10.0 sec  1.83 GBytes  1.57 Gbits/sec
[SUM]  0.0-10.0 sec  1.82 GBytes  1.56 Gbits/sec
[SUM]  0.0-10.0 sec  2.02 GBytes  1.73 Gbits/sec
[SUM]  0.0-10.0 sec  1.81 GBytes  1.55 Gbits/sec
[SUM]  0.0-10.1 sec  1.80 GBytes  1.53 Gbits/sec
[SUM]  0.0-10.0 sec  1.50 GBytes  1.28 Gbits/sec
[SUM]  0.0-10.0 sec  1.83 GBytes  1.57 Gbits/sec
[SUM]  0.0-10.0 sec  1.89 GBytes  1.61 Gbits/sec

avg   = 1.82 [GBytes]
stdev = 0.12 [GBytes]

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: Print warning when no hw source of entropy is available

live_entropy_source_empty() is introduced for the purpose of checking
whether or not any live entropy source was registered.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
fs: add openat systemcall

openat system call be used to open a file relative to passed directory
fd.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: add dirfd api

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
test: add openat testcase

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libzfs: define unresolved devid_get function

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libzfs: disable BSD specific geom_gettree call

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zfs: skip character devices for ZFS pool lookup

ZFS zpool would only be created on block devices passed to OSv instance.
This patch removes all character devices being lookedup for a pool. The
change is essential, since reading from console for example would block
indefinitely.

Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zpool: fix pool import assert when name starts with number

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zfs: ioctl(TRYIMPORT) must fail if config buf is insufficient

ZFS maintains pool configuration in nvlist inside VDEV label. Block
devices which are part of a pool are called as VDEVs. VDEVs form a
hierarchical tree like structure. A VDEV label contains information
describing this physical VDEV as well as all VDEVs which share common
top level logical VDEV.

When pool is imported, ZFS finds appropriate block device and reads
VDEV label for pool configuration. Since a single VDEV only maintains
information about all VDEVs which share common logical VDEV. It has to
refresh the configuration information to know about other logical VDEVs.

ZFS uses IOCTL(ZFS_IOC_POOL_TRYIMPORT) to try a pool import. The
TRYIMPORT also returns, to caller, complete pool configuration along
with it's health information. However, if the passed buffer from
userland is insufficient to capture all config information, it must
fail with ENOMEM. Instructing the caller, to pass larger buffer. The
expected size of the buffer is also passed to caller. The caller,
refresh_config() then allocates larger buffer and retries ioctl.

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
elf: initial implementation of getauxval

getauxval is a quite arcane function that returns characteristics of the ELF
loader. For the initial support of RPM, only a couple of fields are needed.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tcp_output(): maximize LSO frames size

Maximizing the LSO packet size we reduce the CPU usage both in
the Guest, and in HV.

This improves the netperf TCP_STREAM test performance when it's executed vs
the netserver on the same host where we run an OSv Guest (8GB RAM, 1 vCPU)
by the following margins:

message size    compared to origin
64              30.18%
128             31.86%
256             59.60%
512             97.88%
1024            214.14%
2048            247.84%
4096            208.82%
8192            106.49%
16384           38.51%
32768           12.69%
65536           5.01%

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Add routes API

This patch adds an api for the ip route table.
A call to:
http://localhost:8000/network/route/
returns a list of the available routes.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: change zfs rwlock implementation to use OSv's rwlock instead of mutex

Gleb explains:

  This is needed for common sense. I do not see improvement with
  Cassandra unfortunately.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>