Skip to content
Snippets Groups Projects
  1. Dec 18, 2013
    • Glauber Costa's avatar
      mempool: memory statistics · ca1ac80b
      Glauber Costa authored
      
      This patch adds the basic of memory tracking, and exposes an interface to for
      that data to be collected.
      
      We basically start with all stats at zero, and as we add memory to the System,
      we bump it up and recalculate the watermarks (to avoid recomputing them all the
      time). When a page range comes up, it will be added as free memory.
      
      We operate based on what is currently sitting in the page ranges. This means
      that we are effectively ignoring memory that sit in pools for memory usage. I
      think it is a good assumption because it allow us to focus in the big picture,
      and leave the pools to be used as liquid currency.
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
      ca1ac80b
  2. Dec 17, 2013
  3. Dec 16, 2013
  4. Dec 15, 2013
    • Nadav Har'El's avatar
      Fix race between join() and thread completion · 649654af
      Nadav Har'El authored
      
      thread::destroy() had a "FIXME" comment:
      // FIXME: we have a problem in case of a race between join() and the
      // thread's completion. Here we can see _joiner==0 and not notify
      // anyone, but at the same time join() decided to go to sleep (because
      // status is not yet status::terminated) and we'll never wake it.
      
      This is indeed a bug, which Glauber discovered was hanging the
      tst-threadcomplete.so test once in a while - the test sometimes hangs
      with one thread in the "terminated" state (waiting for someone to join
      it), and a second thread waiting in join() but missed the other thread's
      termination event.
      
      The solution works like this:
      
      join() uses a CAS to set itself as the _joiner. If it succeeded, it
      waits like before for the status to become "terminated". But if the CAS
      failed, it means a concurrent destroy() call beat us at the race, and we
      can just return from join().
      
      destroy() checks (with a CAS) if _joiner was already set - if so we need
      to wake this thread just like in the original code. But if _joiner was
      not yet set, either there is no-one doing join(), or there's a concurrent
      join() call that will soon return (this is what the joiner does when it
      loses the CAS race). In this case, all we need to do is to set the status
      to "terminated" - and we must do it through a _detached_state we saved
      earlier, because if join() already returned the thread may already be
      deleted).
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      649654af
    • Nadav Har'El's avatar
      Add rcu_lock_in_preempt_type · 9f0e1287
      Nadav Har'El authored
      
      Add a new lock, "rcu_read_lock_in_preempt_disabled", which is exactly
      like rcu_read_lock but assuming that preemption is already disabled.
      Because all our rcu_read_lock does is to disable preemption, the new
      lock type currently does absolutely nothing - but in some future
      implementation of RCU it might need to do something.
      
      We'll use the new lock type in the following patch, as an optimization
      over the regular rcu_read_lock.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      9f0e1287
  5. Dec 13, 2013
  6. Dec 11, 2013
  7. Dec 10, 2013
  8. Dec 09, 2013
    • Glauber Costa's avatar
      mmu: don't bail out on huge page failure · eeeaf888
      Glauber Costa authored
      
      Addressing that FIXME, as part of my memory reclamation series. But this
      is ready to go already. The goal is to retry to serve the allocation if a
      huge page allocation fails, and fill the range with the 4k pages.
      
      The simplest and most robust way I've found to do that was to propagate the
      error up until we reach operate(). Being there, all we need to do is to
      re-walk the range with 4k pages instead of 2Mb.
      
      We could theoretically just bail out on huge pages and move hp_end, but,
      specially when we have reclaim, it is likely that one operation will fail while
      the upcoming ones may succeed.
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      [ penberg: s/NULL/nullptr/ ]
      Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
      eeeaf888
  9. Dec 08, 2013
    • Glauber Costa's avatar
      sched: implement pthread_detach · afcf4735
      Glauber Costa authored
      
      I needed to call detach in a test code of mine, and this is isn't implemented.
      The code I wrote to use it may or may not stay in the end, but nevertheless,
      let's implement it.
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      afcf4735
    • Glauber Costa's avatar
      sched: standardize call to _cleanup · d754d662
      Glauber Costa authored
      
      set_cleanup is quite a complicated piece of code. It is very easy to get it to
      race with other thread destruction sites, which was made abundantly clear when
      we tried to implement pthread detach.
      
      This patch tries to make it easier, by restricting how and when set_cleanup can
      be called. The trick here is that currently, a thread may or may not have a
      cleanup function, and through a call to set_cleanup, our decision to cleanup
      may change.
      
      From this point on, set_cleanup will only tell us *how* to cleanup. If and
      when, is a decision that we will make ourselves. For instance, if a thread
      is block-local, the destructor will be called by the end of the block. In
      that case, the _cleanup function will be there anyhow: we'll just not call
      it.
      
      We're setting here a default cleanup function for all created threads, that
      just deletes the current thread object. Anything coming from pthread will try
      to override it by also deleting the pthread object. And again, it is important
      to node that they will set up those cleanup function unconditionally.
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      d754d662
    • Glauber Costa's avatar
      sched: Use an integer for thread ids · 5c652796
      Glauber Costa authored
      
      Linux uses a 32-bit integer for pid_t, so let's do it as well. This is because
      there are function in which we have to return our id back to the application.
      One application is gettid, that we already have in the tree.
      
      Theoretically, we could come up with a mapping between our 64-bit id and the
      Linux one, but since we have to maintain the mapping anyway, we might as well
      just use the Linux pids as our default IDs. The max size for that is 32-bit. It
      is not enough if we're just allocating pids by bumping the counter, but again,
      since we will have to maintain the bitmaps, 32-bit will allow us as much as 4
      billion PIDs.
      
      avi: remove unneeded #include
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      5c652796
    • Glauber Costa's avatar
      sched: initialize clock later · 1d31d9c3
      Glauber Costa authored
      
      Right now we are taking a clock measure very early for cpu initialization.
      That forces an unnecessary dependency between sched and clock initializations.
      
      Since that lock is used to determine for how long the cpu has been running, we
      can initialize the runtime later, when we init the idle thread. Nothing should
      be running before it. After doing this, we can move the sched initialization
      a bit earlier.
      
      Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
      Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
      1d31d9c3
  10. Dec 06, 2013
  11. Dec 05, 2013
  12. Dec 04, 2013
    • Nadav Har'El's avatar
      Add a few missing __*_chk functions · 2f4b8777
      Nadav Har'El authored
      
      When source code is compiled with -D_FORTIFY_SOURCE on Linux, various
      functions are sometimes replaced by __*_chk variants (e.g., __strcpy_chk)
      which can help avoid buffer overflows when the compiler knows the buffer's
      size during compilation.
      
      If we want to run source compiled on Linux with -D_FORTIFY_SOURCE (either
      deliberately or unintentionally - see issue #111), we need to implement
      these functions otherwise the program will crash because of a missing
      symbol. We already implement a bunch of _chk functions, but we are
      definitely missing some more.
      
      This patch implements 6 more _chk functions which are needed to run
      the "rogue" program (mentioned in issue #111) when compiled with
      -D_FORTIFY_SOURCE=1.
      
      Following the philosophy of our existing *_chk functions, we do not
      aim for either ultimate performance or iron-clad security for our
      implementation of these functions. If this becomes important, we
      should revisit all our *_chk functions.
      
      When compiled with -D_FORTIFY_SOURCE=2, rogue still doesn't work, but
      not because of a missing symbol, but because it fails reading the
      terminfo file for a yet unknown reason (a patch for that issue will
      be sent separately).
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
      2f4b8777
    • Avi Kivity's avatar
      008d5245
  13. Dec 03, 2013
  14. Dec 01, 2013
    • Nadav Har'El's avatar
      Fix crash on malformed command line · 082ff373
      Nadav Har'El authored
      
      Before this patch, OSv crashes or continuously reboots when given unknown
      command line paramters, e.g.,
      
              scripts/run.py -c1 -e "--help --z a"
      
      With this patch, it says, as expected that the "--z" option is not
      recognized, and displays the list of known options:
      
          unrecognised option '--z'
          OSv options:
            --help                show help text
            --trace arg           tracepoints to enable
            --trace-backtrace     log backtraces in the tracepoint log
            --leak                start leak detector after boot
            --nomount             don't mount the file system
            --noshutdown          continue running after main() returns
            --env arg             set Unix-like environment variable (putenv())
            --cwd arg             set current working directory
          Aborted
      
      The problem was that to parse the command line options, we used Boost,
      which throws an exception when an unrecognized option is seen. We need
      to catch this exception, and show a message accordingly.
      
      But before this patch, C++ exceptions did not work correctly during this
      stage of the boot process, because exceptions use elf::program(), and we
      only set it up later. So this patch moves the setup of the elf::program()
      object earlier in the boot, to the beginning of main_cont().
      
      Now we'll be able to use C++ exceptions throughout main_cont(), not just
      in command line parsing.
      
      This patch also removes the unused "filesystem" paramter of
      elf::program(), rather than move the initializion of this empty object
      as well.
      
      Fixes #103.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
      082ff373
Loading