Skip to content
  • Peter Zijlstra's avatar
    cputimer: Cure lock inversion · 607ce3ed
    Peter Zijlstra authored
    commit bcd5cff7 upstream.
    
    There's a lock inversion between the cputimer->lock and rq->lock;
    notably the two callchains involved are:
    
     update_rlimit_cpu()
       sighand->siglock
       set_process_cpu_timer()
         cpu_timer_sample_group()
           thread_group_cputimer()
             cputimer->lock
             thread_group_cputime()
               task_sched_runtime()
                 ->pi_lock
                 rq->lock
    
     scheduler_tick()
       rq->lock
       task_tick_fair()
         update_curr()
           account_group_exec()
             cputimer->lock
    
    Where the first one is enabling a CLOCK_PROCESS_CPUTIME_ID timer, and
    the second one is keeping up-to-date.
    
    This problem was introduced by e8abccb7 ("posix-cpu-timers: Cure
    SMP accounting oddities").
    
    Cure the problem by removing the cputimer->lock and rq->lock nesting,
    this leaves concurrent enablers doing duplicate work, but the time
    wasted should be on the same order otherwise wasted spinning on the
    lock and the greater-than as...
    607ce3ed