console: support poll()

poll() on the console was never implemented, and always returned 0
(i.e., no input is available). This patch fixes the various use
cases of poll() on the console.

The easy part is polling for current availability of input. The slightly
harder part is how to blocking until input becomes available. For that,
the line discipline needs to know which "file" structures hold it, to
know what to call "poll_wake" on. Everying is made simpler by changing
the code so that only a single file structure refers to our single console.
We can have several fds pointing to the console (multiple separate opens
of the console, or dup()), but all of them refer to a single file structure.

This patch also includes a new test, tests/tst-console.cc, for
the console, including the current poll() issues. This test works
even with no user input, but can test more fine points if the user
does press some keys while it is working (I used this while developing
the fixes in this patch).

Note that while this patch fixes poll() on fd 0, poll will still not work
on /dev/console because the VFS layer hides the poll implementation.
This is issue #515, and should be fixed separately.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
setup.py: add missing comma

As noticed by Morgan Wang, a comma is missing in the setup.py code,
resulting in an error locating package g++-multiliblibssl-dev.

Fixes #517.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: use poll_wake() in eventfd implementation

Nadav pointed out that 79fa4e8adf9b3065ea7f9c039f396ffa78f3e8ff ("libc:
add poll_[un]install() functions to event_fd") basically duplicates much
of already implemented poll() logic. What eventfd was actually lacking
before that patch were calls to poll_wake() in appropriate places.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: poll() when waiting for ANSI codes response

Fixes #513.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: Fix depends/build for executable

Properly reference our version of Lua.
Add missing packages to scripts/setup.py.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
api/sched.h - improve const correctness

Some inline functions that do not modify a cpu_set cannot take a const
one. Noticed while trying to use this functions.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: allow migrating an existing thread

We already allow pinning a new thread to a particular CPU. This patch
allows moving an existing thread to a particular CPU. The new API is
currently limited to a thread moving itself, via a new function thread::pin()
and cannot be used by one thread to moving another thread.

There's a subtle point in a running thread migrating itself: It must not
start to run on the target CPU before it stops running on this CPU.
So this thread's code cannot "wake" itself on a remote CPU, or it might
run in two places concurrently for a short duration. So we need an
auxiliary thread to do this migration for us. Instead of re-using an
existing auxiliary thread (e.g., the load balancer), this patch takes
the quick-of-dirty approach of temporarily creating a new thread just
for this purpose. Since this function will likely be called rarely,
I believe this inefficient approach is "good enough".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Support Linux affinity-setting functions

We already support the Linux pthread_attr_setaffinity_np() function to
pin a newly-created thread to a particular CPU. This patch adds support
for the Linux sched_setaffinity() and pthread_setaffinity_np() functions
which pin an existing thread to a CPU.

Currently, our support is limited to a one-cpu cpu set, and only to
pinning the calling thread (not one thread pinning another thread).
This is a useful case, as some thread APIs (including the one in C++11)
have no support for creating a pinned thread, so the users need to create
a thread and then have it pin itself.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests/misc-ctxsw - eliminate OSv-only code

Because OSv did not support the Linux function sched_setaffinity(),
we had in tests/misc-ctxsw.cc alternative OSv-only code. Now that
sched_setaffinity() is supported, we can drop this OSv-only code.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Update the Wiki URL in error message

Update the Wiki URL to match the new Wiki structure

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Tzach Livyatan <tzach@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
add option "nohalt" to use osv::poweroff() instead of osv::halt() if Guest aborted

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
drivers: add TIOCGWINSZ support to ioctl

ruby test script need TIOCGWINSZ.
hard-coded about window size to 80x25

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: add words for filtering error to tests/testing.py

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts: add test script for CRuby

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Tester script to compile and execute tests

tester.py - compilation / execution of test dirctories

usage: Tester run [-h] [--config_param CONFIG_PARAM] directory
[directory ...]
usage: Tester compile [-h] [--config_param CONFIG_PARAM] directory
[directory ...]

can be used manually to compile/run tests

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
EC2 Tester script to launch an instance and run tests

ec2-tester.sh - ec2 tester script that will launch an EC2 instance for
tests and run the tests using tester.py

requires setting of AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY

usage: ec2_tester.sh [-h] [--help] [--src src] [--override-image image]
[--region region] [--zone zone] [--placement-group placement-group]
[--osv-version osv-version] test-directory ...

ec2-tester will:
- create an ami from a raw image
- start an instance using the ami
- verify the instance is accesible (ping)
- use tester.py to run tests toward the initiated instance
- clean all temporary item at the end

can be used manually to launch an EC2 instance and run tests

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
apps: update to latest

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
testing.py: Fix broken regular expression

It's a regular expression so "[BUG]" matches messages with any of the
three characters in it...  The bug was introduced in commit 0f41b2b
("scripts: add words for filtering error to tests/testing.py").

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tools/cpiod: Show bad CPIO magic

If the CPIO magic check fails, include the faulty magic in the exception
message to give some clues to the poor sod who needs to debug the
issue.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tools/cpiod: mkdirp() error reporting

If mkdirp() fails, be kind to the person debugging a dubious issue and
don't be silent about it.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>