clock: extract common code between kvmclock and xenclock

A recent commit 34232de90fc982293d9beadab6930b2f013552e9 fixed a bug
in kvmclock. It turns out that xenclock suffers from the same
problems. Both clocks share a lot of logic. This change extracts
common code to pv_based_clock base class which forces xenclock to
inherit the fixes.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: introduce microbenchmark for various locking primitives

Results on my machine:

$ scripts/run.py -e "/tests/misc-lock-perf.so"
OSv v0.09-119-g59c0cec
eth0: 192.168.122.15
dummy      =   0.037 ns/cycle
preempt    =   6.360 ns/cycle
migrate    =   5.297 ns/cycle
mutex      =  25.474 ns/cycle

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
clock: use migration_lock to protect access to per-CPU data

Migration lock is sufficient and a bit faster (20%) than preemption lock.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: initialize init_table to zero, ensure TLS is found

If the ELF code is unable to find the PT_TLS section,
complain loudly and fail.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build.mk: aarch64: don't destroy the instruction at offset 0x10

this caused a lot of self-inflicted pain.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: allow side-by-side aarch64 and x64 builds

Build into build/release.x64 and build/release.aarch64 instead of
build/release.  A build/release symlink is retained to avoid confusion in
the transition period, as all the tooling plus everyone's fingers are used
to it.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: provide a default for CROSS_PREFIX

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: CROSS_PREFIX is always defined

Now that we provide a default, CROSS_PREFIX is always defined, so we can
drop the ifndef.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: use build/$(mode).$(arch) in preference to the build/$(mode) symlink

The symlink is ambiguous when working with multiple targets, so avoid it,
esp. when embedding the output path in the build directory Makefile.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: avoid referring to $(out) in internal Makefile

We're already building in the output directory, no need to state it
explicitly.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: rename *.mak to *.mk

For consistency, and because eclipse groks .mk better.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
elf: reuse page_size definition from mmu headers

Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
lib: Fix size of 'struct rusage'

We are currently stubbing getrusage, and zeroing out the whole structure. The
problem, is that the structure definition for OSv is just not conforming with
the one in the main page: it has a reserved field in the end.

That means that the memset() idiom will just overwrite 16 extra words in the
end with zero. That will cause a stack corruption (since getrusage comes from
the stack).

One could argue that once we would implement getrusage properly that would
disappear. While this is true, zeroing out the entire structure first keeps
being a perfectly valid idiom. There is absolutely no excuse for those reserved
fields in a structure that clearly defined in the syscall manpage.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: Fix RUSAGE definitions

1 is for RUSAGE_THREAD. Linux defines RUSAGE_CHILDREN as -1. That is what we
have to use, since this is how the programs will be compiled.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
time: move process_time to common code

It is useful in other locations. Inside OSv, it is a lot more convenient
to call it and have access to a richer structure than to go through the
clock API.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: Basic getrusage implementation

Most fields will be null, which is in accordance with what we are
already doing for procfs, for example. We can revisit this later. Right
now, this implementation exposes process / thread times through the
getrusage interface, which is a lot more useful.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: move mode-related configuration to conf/*.mk

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: move arch-specific configuration to conf/$(arch).mk

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'build'

Some build cleanups.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
virtio-vring: bug fix in use_indirect()

Use indirect if number of needed descriptors is greater than the number of
currently available descriptors.

This fixes a possible dead-lock situation when the number of needed descriptors is
greater than the size of a virtio ring and add_buf_wait() is used.

A side effect of this fix is that it will also make use_indirect() return TRUE in
cases where add_buf() would fail before: e.g. when _avail_count >= _num / 4 and
desc_needed > _avail_count; which is also a good thing.

Reviewed-by: Dor Laor <dor@cloudius-systems.com>
Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>