virtio: Use emplace_back instead of push_back

We can skip to construct a vring::sg_node.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio: Add add_out_sg and add_in_sg helper

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio: Add init_sg helper

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: Replace magic values by constants

Reviewed-by: Dor Laor <dor@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: print stats asynchronously in fs/bdev write tests

Printing asynchronously is not affected by write() stalls and hence the period
for partial amount can be more or less constant.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix assertion failure during many-cpu boot

While booting with many cpus (e.g., run.py -c 20, but I sometimes saw this
with as few as 7), we crashed while trying to sleep with preemption disabled:

Assertion failed: preemptable() (/home/nyh/osv/include/sched.hh: do_wait_until: 605)
Aborted

Turns out that since commit 223b2252815f22 (half a year ago), main_cont()
ran smp_launch() with preemption disabled. But smp_launch creates threads,
and thread's constructor may sleep (e.g., on the thread_list_mutex), and
we cannot do this with preemption disabled...

So dropped the preempt_disable()/enable() from main_cont(). The reasoning for
it as expressed in 223b2252815f22 appears to be no longer relevant.

Fixes #130.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
poll: move away from bsd msleep()

With net channels, poll() needs to wait not only on poll wakeups and the
timeout, but also requests from network interfaces to flush net channels
for polled sockets.

In preparation for that, switch from bsd msleep() to native wait_until().

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
virtio-blk: Switch to sched::thread_handle for thread wakeup

The lock used to protect _waiting_request_thread can go away.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-blk: Do not use std::stringstream for _driver_name

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-net: Do not use std::stringstream for _driver_name

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bio: Add bio_private

This can be used by the low-level driver to store private data, e.g.
virtio-scsi driver uses it to store a virtio-scsi request bound to this
bio.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bio: Introduce BIO_SCSI

bio with BIO_SCSI flag contains a SCSI command.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-scsi: Initial support

This adds initial virtio-scsi support. We have no scsi layer in osv, in
this implementation virtio-scsi works directly with the bio layer. It
translates BIO_READ, BIO_WRITE and BIO_FLUSH to SCSI CMD.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mempool: memory statistics

This patch adds the basic of memory tracking, and exposes an interface to for
that data to be collected.

We basically start with all stats at zero, and as we add memory to the System,
we bump it up and recalculate the watermarks (to avoid recomputing them all the
time). When a page range comes up, it will be added as free memory.

We operate based on what is currently sitting in the page ranges. This means
that we are effectively ignoring memory that sit in pools for memory usage. I
think it is a good assumption because it allow us to focus in the big picture,
and leave the pools to be used as liquid currency.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Trivial: pipe.cc doesn't need to include af_local.h

af_local.h declares a couple of functions implemented in af_local.cc.
There is no reason for pipe.cc to include it.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Make BSD code use hardware atomics

Currently we use implementation from
bsd/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c
which is using global mutex.

This showes up on wait profile of ZFS writes:

(...)
   \-- 469.96 us (0.00%, #250) arc_do_user_evicts
       \-- 469.96 us (0.00%, #250) dbuf_do_evict
           |-- 355.93 us (0.00%, #154) dbuf_destroy
(...)
           |   \-- 76.60 us (0.00%, #53) zrl_add
           |                             atomic_cas_32
           |                             lockfree_mutex_lock
           |                             sched::thread::wait()
           |
           |-- 66.14 us (0.00%, #56) dbuf_clear
           |                         zrl_add
           |                         atomic_cas_32
           |                         lockfree_mutex_lock
           |                         sched::thread::wait()
           |
           \-- 47.89 us (0.00%, #40) dbuf_rele_and_unlock
                                     atomic_add_64_nv
                                     lockfree_mutex_lock
                                     sched::thread::wait()

This patch switches to amd64 implementation.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
test.py: Bring back tst-threadcomplete.so

Commit 649654a ("Fix race between join() and thread completion") fixed
the problem so bring back the test case.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: allow image cacheing during build

Since there's no user data on the image, we can safely cache it, improving
build performance.  Helpful duing 'git bisect'.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
runtime: Fix hard-coded _SC_PAGESIZE

Just came across this. Trivial to fix.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mprotect() should not fail if it encounters non present pte

mprotect() should fails with ENOMEM if it is called on non mapped
virtual address, but this check is done by mmu::ismapped().

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