trace: reduce tracepoint fast-path overhead

While we compile a tracepoint into a single nop instruction, there is still
overhead on the fast path: since the compiler believes it is calling a
function (a belief which happens to be correct, since if the tracepoint
is enabled, it will), the compiler must assume that all the side effects
of calling an out-of-line function will happen: registers will be clobbered,
and memory may be read or written.

However, the tracepoint slow path doesn't touch any memory that the compiler
is interested in - it just writes to some buffer, and cannot affect the
calling function in any way.  So we pretend that we aren't calling a
a function, by calling it from assembly, and saving and restoring all
caller-saved registers.

Note 1: we don't save and restore fpu registers
Note 2: in some cases, we prevent the compiler from flushing data to memory
        (e.g. strings).

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tcp_output.cc: added tracepoints allowing to debug the Tx flow

   - Follow after socket buffer life.
   - Follow after the cwin, offset of unacknowledged data, current TCP sequence.
   - Follow after the sending/not-sending reason.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio: added some tracepoints

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
TSO: descrease the maximum aggregation size

Take headers into an account.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio::kick(): fix missed notification #2

This is a follow up patch for a 053bcf8e18539d commit.
It handles the same issue when EVENT_IDX_CAP is not supported
by HV (e.g. GCE currently doesn't support this feature).

When EVENT_IDX_CAP is not negotiated there is a possible race:
     1) Guest reads the _used->flags before updating the _avail->idx and
        before HV cleared the VRING_USED_F_NO_NOTIFY.
     2) HV clears the VRING_USED_F_NO_NOTIFY flag and goes to sleep since
        _avail->idx hasn't been updated yet.
     3) Guest updates the _avail->idx but doesn't wakes the HV since it has
        read the old _used->_flags value in (1).

As a result the pending work will not be handled.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio::net::xmit_one_locked(): call the kick_pending() only once before staring to poll

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio::net::try_xmit_one_locked(): call vring::add_buf() instead of vring::avail_ring_has_room()

Try to actually send the frame instead of checking if it's going to succeed.
This achieves a few goals:
  1) It optimizes the succeesfull sending flow in terms of branching, because the
     current code would check virtually the same twice in this case:
        - First, it calls vring::avail_ring_has_room() from try_xmit_one_locked().
        - Second, it'll check for the available buffers in vring::add_buf().
  2) vring::add_buf() kick()s the HV if there are no available buffers, which
     is going to improve the latency of buffers freeing. The current code won't
     kick the HV right until it's going to poll in xmit_one_locked() in the worker
     thread, which is a long time after it.

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