modules/lua: fix the build

The assignment to PREFIX env var had no effect on the makefile
variable 'PREFIX', so it resolved to an enpty string. We need to put
it inside eval.

This fixes the build for me:

$ make image=cli
...
make[2]: Entering directory '/home/tgrabiec/src/osv/modules/lua'
PREFIX=/home/tgrabiec/src/osv/modules/lua
cd build/luarocks-2.1.2 && \
    ./configure --prefix=/out --force-config \
    --with-lua-include=/src --lua-version=5.2
Lua interpreter found: /usr/bin/lua5.2...
Lua version detected: 5.2
Looking for Lua... lua5.2 found in $PATH: /usr/bin
Checking Lua includes... lua.h not found (looked in /src, /src/lua/5.2, /src/lua5.2)
You may want to use the flag --with-lua or --with-lua-include. See --help.

configure failed.

Makefile:75: recipe for target 'build/luarocks-2.1.2/Makefile' failed
make[2]: *** [build/luarocks-2.1.2/Makefile] Error 1
make[2]: Leaving directory '/home/tgrabiec/src/osv/modules/lua'

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
gdb: fix padding for short bits str

bits2str() uses the length of bits chars to add paddings when printing
fields. This patch fixes the situation when length of bits chars is
less than len('none').

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
gdb: show offset/path for file mapped vma in 'osv mmap'

Before:
(gdb) osv mmap
0x0000000000000000 0x0000000000000000 [0 kB]           flags=none     perm=none
0x0000100000000000 0x00001000000a4000 [656 kB]         flags=fmF      perm=rx
0x00001000002a3000 0x00001000002a9000 [24 kB]          flags=fmF      perm=rw
0x0000100000400000 0x0000100000415000 [84 kB]          flags=fmF      perm=rx
0x0000100000614000 0x0000100000615000 [4 kB]           flags=fmF      perm=r
0x0000100000615000 0x0000100000616000 [4 kB]           flags=fmF      perm=rw
0x0000200000000000 0x0000200000001000 [4 kB]           flags=p        perm=none
0x0000200000001000 0x0000200000100000 [1020 kB]        flags=p        perm=rw
...

After:
(gdb) osv mmap
0x0000000000000000 0x0000000000000000 [0 kB]           flags=none     perm=none
0x0000100000000000 0x00001000000a4000 [656 kB]         flags=fmF      perm=rx   offset=0x00000000 path=/libhttpserver.so
0x00001000002a3000 0x00001000002a9000 [24 kB]          flags=fmF      perm=rw   offset=0x000a3000 path=/libhttpserver.so
0x0000100000400000 0x0000100000415000 [84 kB]          flags=fmF      perm=rx   offset=0x00000000 path=/usr/lib/libgcc_s.so.1
0x0000100000614000 0x0000100000615000 [4 kB]           flags=fmF      perm=r    offset=0x00014000 path=/usr/lib/libgcc_s.so.1
0x0000100000615000 0x0000100000616000 [4 kB]           flags=fmF      perm=rw   offset=0x00015000 path=/usr/lib/libgcc_s.so.1
0x0000200000000000 0x0000200000001000 [4 kB]           flags=p        perm=none
0x0000200000001000 0x0000200000100000 [1020 kB]        flags=p        perm=rw
...

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Clean up tests/misc-mutex.cc

tests/misc-mutex.cc includes some mutex benchmarks and tests, but was
a big mess and this patch cleans some of the dead code, useless stuff,
and over-verbose output.

The test now includes 4 main parts:

* Measure the size in bytes of the mutual exclusion primitives, spinlock
  and mutex (this comes out to 1 byte and 40 bytes, respectively).

* Measure the single-CPU uncontended lock/unlock cycle, for both mutex
  and spinlock. On my machine this shows about 25ns, and 12ns, respectively.

* Measure the lock/unlock cycle when several threads in a tight loop
  requesting the same lock. We try 2 threads, 4 threads (on 4 cpus),
  and 20 threads on 4 cpus.
  Here the mutex is significantly slower than the spinlock, because the
  spinlock only context-switches when the thread's time slice is over,
  while the mutex context-switches on most lock/unlock cycles, as we
  sleep while waiting for another thread to release the lock.

* Additional correctness tests, less useful as benchmarks.

Reviewed-by: Dor Laor <dor@cloudius-systems.com>
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
revert "make image=", add new "make modules="

This is a compromise between some people's insistance (see issue #390)
that we shouldn't have modules added by default, and other people's
just-as-vigorous insistance that some modules, like httpserver, are
essential in every image.

What this patch does is to:

  1. return "make image=..." to how it used to be, i.e., only modules
     explicitly listed on this list, and their dependencies, are added
     to the image, and no "default" modules are added.

  2. A new "make modules=..." behaves like "make image=" does before
     this patch, i.e., it builds an image using both the listed modules,
     and the default modules. "make modules=x,-httpserver" will still work,
     if anyone wants to do this.

Internally, what this patch does is to add to the module list syntax a
prefix "!" which signifies we want this list exactly, without defaults.
The "make modules" doesn't add this prefix, while "make image" does
(i.e., "make image=x" is equivalent to "make modules=!x").

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
routecache: Remove debugging printout

This removes the following debuggign printout from OSv boot that was
added in commit c9f3702 ("Route Cache patch #2"):

  routecache.hh: caching route for fea9fea9 ffffff

Reviewed-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
httpserver: document /os/cmdline

Be more explicit about what we are doing

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
release-ec2: introduce AWS region/zone/placement group parameters

These parameters define created AMIs/instances placement,
useful for performance tests where instances locality matter.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader: remove redundant postfix incrementation

It only tricks a (hasted) reader that this actually means that we want
to skip first element but in fact, because it is postfix, it has no
effect whatsoever.
loader: handle opt_leak before commands are run
loader: print boot chart once, before commands are run
core: introduce applicaton abstraction

This introduces an abstration for OSv processes, called
"application". It represents an execution of a single command. The
goal of having this is to have a uniform interface for managaing
processes on OSv. This class is responsible for tracking all resources
associated with a running application.

For example, this will be used to track termination callbacks which an
application can register and which will be executed when application
termination is requested.
core: track current application context

We need to know to which application current thread belongs so that we
can expose per-application APIs like termination callback registreation.

In the future this could be also used to decide which threads should
be terminated when application falls out of its main().
core: add support for requesting application's termination

Application can register as many callbacks as it wants. The callbacks
will be executed exactly once when after application termination is
requested. If callback is registerred after termination was already
requested it is executed immediately. This way we avoid races between
callback registration and termination.
core: introduce application::get_return_code()
core: sprinkle tracepoints around application management code
core: add application::get_command()
httpserver: add termination handler
core: request termination of detached commands before proceeding to shutdown

Letting commands run while we shut down may result in page faults due
to DSOs getting unmapped while in use. This is often the case with
httpserver. This change will make OSv trigger termination of detached
commands before it shuts down. The callback is supposed to cause the
application to return from its main() in a timely manner.
core: integrate osv::run with osv::application

osv::application models a process more accurately than osv::run and
hence it should be used instead in most of the places which currently
use osv::run. This change moves osv::run() logic into osv::application
and makes the run() variants create an application.

Because users of run() are expected to get informed whether
application was run or not we need to change the API so that
application() will thrown a launch_error, instead of aborting, which
can be then caught by interested parties. This has a nice feature of
propagating more details about why we can't run the application.