Skip to content
Snippets Groups Projects
  1. Jul 02, 2013
  2. Jul 01, 2013
    • Avi Kivity's avatar
      Merge branch 'sched2' · ef155e5a
      Avi Kivity authored
      Timer-based thread preemption.
      ef155e5a
    • Avi Kivity's avatar
      sched: reduce over-eager timer rearming · 0a2cc13e
      Avi Kivity authored
      If a thread schedules out before its time slice expires (due to blocking)
      and is then made runnable and scheduled back in again, the scheduler will
      update the preemption timer, first cancelling it (or possibly setting it
      for another thread), then re-setting it for the original thread.  Usually
      the new expiration time will be later than the original.
      
      For a context switch intensive load, this causes a lot of timer re-arms,
      which are fairly slow.
      
      Reduce the amount of re-arms by remembering the last expiration time we set.
      If the new expiration time comes after that time, don't bother rearming the
      timer.  Instead, the expiration of the already-set timer will recalculate
      the expiration time and set a new expiration time.
      
      This reduces timer arming greatly, and speeds up context switches back to
      their performance before the preemption patches.
      0a2cc13e
    • Avi Kivity's avatar
      sched: initialize borrow · 3b7ede7d
      Avi Kivity authored
      It will be reset during a future context switch, but best to start with a
      clean slate.
      3b7ede7d
    • Avi Kivity's avatar
      sched: initialize idle thread vruntime · a56b258e
      Avi Kivity authored
      Make sure it starts out high so we don't see needless context switches on
      startup.
      a56b258e
    • Avi Kivity's avatar
      56c55def
    • Avi Kivity's avatar
      sched: preemption timer · 0d1606ce
      Avi Kivity authored
      When switching to a new thread, or when a new thread is queued, calculate
      the vruntime difference to set a timer for the point in time when we need to
      context switch again.
      
      This change makes tst-fpu.so threads run completely in parallel.
      0d1606ce
    • Nadav Har'El's avatar
      ELF: Allow using prelinked libraries · 4723a592
      Nadav Har'El authored
      This patch allows to use shared libraries copied from Linux, even if
      they already underwent "prelink" modifications.
      
      Without this patch, if the prelinked library used one of our library
      functions (e.g., malloc()), its address would not be correctly
      calculated, and the call will be made to a random address, and crash.
      
      A few details about the problem and the fix:
      
      When using a function from a shared library, calls go to a ".plt"
      function, which, to make a long story short, jumps to a address written
      in the ".plt.got" entry for this function.
      
      Normally, and this is what the existing code expected, the .plt.got entry
      is initialized to point to the second instruction in the .plt function
      (after the jump), which calls the linker to look up the function.
      This allows lazy symbol lookup, but after the lookup, the next calls
      to the PLT function will jump to the right function address immediately.
      
      But prelinking changes that - the prelinker looks up the symbols once
      and fills the .plt.got with the addresses it assigned to the functions
      in the other library. These addresses do not make any sense in the
      context of OSV (or any other system besides the one that the prelinker
      ran on), so we cannot use them, and instead need to overwrite them
      again with links to the .plt functions.
      4723a592
    • Avi Kivity's avatar
      sched: adjust timer expiration when the clock is not running · 6085ca37
      Avi Kivity authored
      Change the condition for expiration to allow an exact match between the
      current time and the timer expiration time.
      
      This helps the scheduler keep going when the clock is still not running
      during system startup.  Ideally we shouldn't depend on such details, but
      fixing this is too complicated for now.
      6085ca37
    • Avi Kivity's avatar
      sched: stop vruntime overflow in idle thread · 5c96e31c
      Avi Kivity authored
      We set the idle thread's vruntime at the maximum possible, to ensure it
      has the lowest priority, but this can cause an overflow when we add the
      idle thread's running time.
      
      Detect the overflow and prevent it.
      5c96e31c
    • Avi Kivity's avatar
      sched: simplify vruntime for currently running thread · 667cec20
      Avi Kivity authored
      Since vruntime needs to be advanced by (scaled) running time, when a thread
      starts running, we subtract the start clock value (t1), and when it stops,
      we add the stop clock value (t2), with the end result that we add t2-t1, or
      the running time.
      
      While this works, it makes the code less readable, since the meaning of
      _vruntime is drastically different for running threads - its the vruntime
      minus the reading of the clock at some point in the past.
      
      Simplify by not doing this, and instead keeping the start time in a separate
      field (running_since).
      
      Note _vruntime for a running thread is still subtly different from that of a
      stopped thread, since we need to add this delta time.
      667cec20
    • Avi Kivity's avatar
      trace: fix early function tracer faulting in kvmclock · 5f63b5f6
      Avi Kivity authored
      kvmclock doesn't work before the scheduler is fully initialized, so work
      around it.
      5f63b5f6
    • Avi Kivity's avatar
      sched: set up thread::current() for new threads earlier · 667e1c10
      Avi Kivity authored
      Currently, current() is set during the thread initialization sequence,
      which means that preemption prior to that point will see the wrong current().
      There's an irq_enable() there, but it's not very effective since interrupts
      are only disabled in that place during early smp bringup, and it's not trivial
      to disable interrupts for all new threads (we?
      667e1c10
    • Avi Kivity's avatar
      sched: add interface to access thread-local variables of another thread · 472731b9
      Avi Kivity authored
      This is useful for setting up important thread local variables such as
      s_current.  Since it's quite specialized it's kept private for the moment.
      472731b9
    • Avi Kivity's avatar
      sched: late initialize idle thread · 802d3633
      Avi Kivity authored
      Currenly we initialize the idle thread in the cpu's constructor, which leads
      to a cycle, since a thread's initialization needs the cpu.  This works out
      somehow now, but is fragile and will break with succeeding patches.
      
      Defer idle thread initialization to a later stage.
      802d3633
    • Avi Kivity's avatar
      sched: allow timers to be modified in interrupt disabled context · f5ce1388
      Avi Kivity authored
      Such as the scheduler.
      f5ce1388
    • Avi Kivity's avatar
      mutex: avoid disabling interrupts in spinlock · 2e448a64
      Avi Kivity authored
      We disable interrupts in spinlocks as a way of disabling preemption, since
      preemption with spinlock held will lead to deadlock.  However, we don't
      restore the interrupt flag to its previous state, so we end up inadvertantly
      enabling interrupts if the lock was taken with interrupts disabled in the
      first place.
      
      Fix by switching to preempt_disable() instead of disabling interrupts. Since
      spinlocks are only used by the debug code, it doesn't matter much.
      2e448a64
    • Avi Kivity's avatar
      sched: start with preemption disabled · 695375f6
      Avi Kivity authored
      Usually we don't care if threads are started with preemption enabled or
      disabled, since interrupts are disabled and no preemption can take place
      during thread startup.  However during system bringup we want to avoid
      calls into the scheduler while it is being initialized due to stray
      preempt_enable() calls.
      
      Do this by initializing preempt_counter to 1, and dropping it during
      thread start-up.
      695375f6
    • Avi Kivity's avatar
      clock: change time type to s64 · 073dc612
      Avi Kivity authored
      Easier to compute deltas.  Limits range to 292 years.
      073dc612
    • Avi Kivity's avatar
      sched: add tracepoints for timers · 10690891
      Avi Kivity authored
      10690891
    • Avi Kivity's avatar
      sched: divorce timers from threads · 786a576e
      Avi Kivity authored
      We want to use timers for more than just waking up threads (in this case, for
      the scheduler time slice), so we need to remove the internal dependencies.
      
      The timer class is split into timer_base, which does most of the work,
      and timer, which preserves the original timer interface.
      
      The timer-related parts of 'class thread' are split off into a new class
      timer_base::client, which thread inherits from.
      786a576e
    • Avi Kivity's avatar
      sched: fix timer state machine · 3d768789
      Avi Kivity authored
      Timers currently have two states: expired, and not expired.  But how is
      cancel() to distinguish between an armed-but-not-expired timer, and a timer
      which was never armed (using set())?  It can't, and will probably crash.
      
      Fix by adding a state to the timer.  Now there are three distinct states:
      free, armed, and expired, corresponding to the timer life cycle.
      3d768789
    • Avi Kivity's avatar
      x64: add a separate interrupt stack · b81a47a5
      Avi Kivity authored
      This makes it easier to debug faults that happen in interrupts (e.g. in the
      scheduler)
      
      Note that this means we cannot schedule within an exception (e.g. a page
      fault) for now, since the exception stack is per-cpu while the interrupt
      stack is per-thread (which allow scheduling).  If/when we implement
      scheduling within the page fault handler, we'll either need to trampoline
      to the interrupt stack, or have a per-thread exception stack.
      b81a47a5
    • Glauber Costa's avatar
      xen: import bsd files for xen interface · 801e2b4d
      Glauber Costa authored
      Import the whole xen/interface.h directory (disk space is cheap, going through
      each file seeing what we need and what we don't is not)
      801e2b4d
  3. Jun 30, 2013
    • Dor Laor's avatar
      Implement event index, a virtio optimization · 26e046a3
      Dor Laor authored
      The optimization improves performance by letting each side
      of the ring know what was the last index read by the remote
      party. In case were the other side has older indexes, waiting
      for processing we won't trigger another update (kick or irq,
      depending on the direction).
      The optimization reduces irq injection by a 7%.
      
      Along the way, collapse vring::need_event to the code and use
      std::atomic(s) to access any variable which is shared w/ the host
      26e046a3
    • Guy Zana's avatar
    • Guy Zana's avatar
      7736d91b
    • Guy Zana's avatar
    • Guy Zana's avatar
      cli.js: cast command line arguments to JS strings · 0f32a2f6
      Guy Zana authored
      mainargs is a String[] set by Java (see RhinoCLI.java), some of the commands
      that access the elements of this array fail because the strings are Java strings
      and not Javascript strings.
      
      this patch perform a proper cast on init(), just before invoking the command.
      
      now it's also possible to start a test from the command line, like so:
      
      $ sudo ./scripts/run.py -n -e "java.so -jar /java/cli.jar test <test-name>" -c2 -m1G
      0f32a2f6
    • Avi Kivity's avatar
      cli: add ability to run command in background · dc8114dd
      Avi Kivity authored
      Example:
      
        test foo &
      dc8114dd
    • Nadav Har'El's avatar
      Stub getpwnam(), setuid() and setgid() · c6399e55
      Nadav Har'El authored
      Implement getpwname(), setuid() and setgid() in the simplest way possible
      considering that we don't support any userid except 0:
      
      getpwname() returns user 0 for any username given to it.
      setuid() and setgid() does nothing for uid or gid 0, otherwise fails.
      Where would the caller get this !=0 id anyway?
      
      Memcached needs these calls, because it wants to be clever and
      warn the user against running it as root....
      c6399e55
    • Nadav Har'El's avatar
      libc: implement signal() · 1ca1bd43
      Nadav Har'El authored
      Implement the signal() function. This is hardly a useful function in OSV,
      first because our signal support is pretty broken, and second because
      sigaction() is a much more portable API that should always be preferred.
      
      Nevertheless, memcached uses signal() (to catch SIGINT, which it will
      never get in OSV...), so let's implement it for the sake of completeness.
      1ca1bd43
Loading