Skip to content
Snippets Groups Projects
  1. Jun 05, 2013
    • Avi Kivity's avatar
      trace: improve fast path · b03979d9
      Avi Kivity authored
      When a tracepoint is disabled, we want it to have no impact on running code.
      
      This patch changes the fast path to be a single 5-byte nop instruction.  When
      a tracepoint is enabled, the nop is patched to a jump instruction to the
      out-of-line slow path.
      b03979d9
  2. May 27, 2013
    • Nadav Har'El's avatar
      Add "memory clobber" to STI and CLI instructions · a200bb7a
      Nadav Har'El authored
      When some code section happens to be called from both thread context and
      interrupt context, and we need mutual exclusion (we don't want the interrupt
      context to start while the critical section is in the middle of running in
      thread context), we surround the critical code section with CLI and STI.
      
      But we need the compiler to assure us that writes to memory done between
      the calls to CLI and STI stay between them. For example, if we have
      
          thread context:                 interrupt handler:
      
            CLI;                          a--;
            a++;
            STI;
      
      We don't want the a++ to be moved by the compiler before the CLI. We also
      don't want the compiler to save a's value in a register and only actually
      write it back to the memory location 'a' after the STI (when an interrupt
      handler might be concurrently writing). We also don't want the compiler
      to remember a's last value in a register and use it again after the next
      CLI.
      
      To ensure these things, we need the "memory clobber" option on both the CLI
      and STI instructions. The "volatile" keyword is not enough - it guarantees
      that the instruction isn't deleted or moved, but not that stuff that
      should have been in memory isn't just in registers.
      
      Note that Linux also has these memory clobbers on sti() and cli().
      Linus Torvals explains in a post from 1996 why these were necessary:
      http://lkml.indiana.edu/hypermail/linux/kernel/9605/0214.html
      
      All that being said, we never noticed a bug caused by the missing
      "memory" clobbers. But better safe than sorry....
      a200bb7a
  3. May 26, 2013
    • Avi Kivity's avatar
      x64: use wrfsbase for faster context switching, when available · 3c9ba28d
      Avi Kivity authored
      Drops context switch time by ~80ns.
      3c9ba28d
    • Avi Kivity's avatar
      x64: add wrfsbase accessor · bb33c998
      Avi Kivity authored
      Faster way to write fsbase on newer processors.
      bb33c998
    • Nadav Har'El's avatar
      signal handling: fix FPU clobbering bug · 94a7015e
      Nadav Har'El authored
      This patch adds missing FPU-state saving when calling signal handlers.
      The state is saved on the stack, to allow nesting of signal handling
      (delivery of a second signal while a first signal's handler is running).
      
      In Linux calling conventions, the FPU state is caller-saved, i.e., a
      called function can use FPU at will because the caller is assumed to have
      saved it if needed. However, signal handlers are called asynchronously,
      possibly in the middle of some FPU computation without that computation
      getting a chance to save its state. So we must save this state before calling
      the signal handling function.
      
      Without this fix, we had problems even if the signal handlers themselves
      did not use the FPU. A typical scenario - which we encountered in the
      "sunflow" benchmark - is that the signal handler does something which uses
      a mutex (e.g., malloc()) and causes a reschedule. The reschedule, not a
      preempt(), thinks it does not need to save the FPU state, and the thread
      we switch to clobbers this state.
      94a7015e
  4. May 18, 2013
  5. May 07, 2013
  6. May 06, 2013
  7. May 01, 2013
    • Nadav Har'El's avatar
      Unify "mutex_t" and "mutex" types · 3c692eaa
      Nadav Har'El authored
      Previously we had two different mutex types - "mutex_t" defined by
      <osv/mutex.h> for use in C code, and "mutex" defined by <mutex.hh>
      for use in C++ code. This is difference is unnecessary, and causes
      a mess for functions that need to accept either type, so they work
      for both C++ and C code (e.g., consider condvar_wait()).
      
      So after this commit, we have just one include file, <osv/mutex.h>
      which works both in C and C++ code. This results in the same type
      and same functions being defined, plus some additional conveniences
      when in C++, such as method variants of the functions (e.g.,
      m.lock() in addition to mutex_lock(m)), and the "with_lock" function.
      
      The mutex type is now called either "mutex_t" or "struct mutex" in
      C code, or can also be called just "mutex" in C++ code (all three
      names refer to an identical type - there's no longer a different
      mutex_t and mutex type).
      
      This commit also modifies all the includers of <mutex.hh> to use
      <osv/mutex.h>, and fixes a few miscelleneous compilation issues
      that were discovered in the process.
      3c692eaa
  8. Apr 28, 2013
  9. Apr 24, 2013
  10. Apr 23, 2013
  11. Apr 22, 2013
    • Nadav Har'El's avatar
      Allow creation of a new sched::thread pinned to a specific CPU. · 9e7ee944
      Nadav Har'El authored
      Previously, we had the option to create a pinned thread, but it always
      runs on the same CPU as the current thread, which is kind of odd. Changed
      the boolean attribute "pinned" to a cpu* attribute specifying the cpu to
      pin to.
      
      Example code to run a start a new thread pinned on cpu 1:
      new sched::thread([&]{...}, sched::thread::attr(sched::cpus[1]));
      
      I need this feature to test the cross-CPU TLB flushing feature - I need
      to be able to run two threads on two different CPUs.
      9e7ee944
  12. Apr 14, 2013
  13. Apr 11, 2013
  14. Apr 08, 2013
    • Nadav Har'El's avatar
      Fix memory leak in thread creation · 68284de3
      Nadav Har'El authored
      Thread object creation used to leak one page for the FPU state (thanks
      Avi for spotting this). Fix this (add a destructor which frees the page)
      and add to the test-suite a test for checking that thread creation doesn't
      leak memory - and while we're at it, also checked that alloc_page() and
      malloc() at various sizes do not leak memory.
      68284de3
    • Nadav Har'El's avatar
      Free TCB (and thread-local storage) area on thread destruction. · 1f68d677
      Nadav Har'El authored
      We forgot to free the TCB allocated buffer on thread destruction, causing
      a leak of around 1000 bytes per thread creation. We still have another
      leak (exactly one page per thread object creation) that I'm trying to find :(
      1f68d677
  15. Apr 04, 2013
  16. Apr 03, 2013
    • Nadav Har'El's avatar
      Handle #DE (divide error) exception · 372c4a73
      Nadav Har'El authored
      In the existing code, #PF was handled correctly (generating a SIGSEGV),
      but on most other x86 hardware exceptions, we just abort()ed the kernel.
      
      The #DE (divide error) exception should, like #PF, generate a signal
      (the inappropriately-named SIGFPE), and this patch does this. Strangely,
      the SPECjvm2008 benchmark depends on this behavior (I didn't check its
      source code to figure out why).
      
      To make it easier to generate other signals in the future, I abstracted
      the existing function handle_segmentation_fault() into a more general
      generate_signal() which is used in both #PF and #DE handling.
      372c4a73
  17. Mar 21, 2013
  18. Mar 19, 2013
  19. Mar 07, 2013
  20. Mar 06, 2013
  21. Mar 04, 2013
  22. Mar 03, 2013
    • Avi Kivity's avatar
      sched: preemption · 378e8aa1
      Avi Kivity authored
      Split the core scheduler into a function for calling from interrupts, and
      a wrapper for calling it from normal paths.  Call the preemptible path from
      interrupt handlers.
      378e8aa1
Loading