• Zhenzhong Duan's avatar
    sched/clock: Use static_branch_likely() with sched_clock_running · c5105d76
    Zhenzhong Duan authored
    sched_clock_running is enabled early at bootup stage and never
    disabled. So hint that to the compiler by using static_branch_likely()
    rather than static_branch_unlikely().
    
    The branch probability mis-annotation was introduced in the original
    commit that converted the plain sched_clock_running flag to a static key:
    
      46457ea4 ("sched/clock: Use static key for sched_clock_running")
    
    Steve further notes:
    
      | Looks like the confusion was the moving of the "!":
      |
      | -       if (unlikely(!sched_clock_running))
      | +       if (!static_branch_unlikely(&sched_clock_running))
      |
      | Where, it was unlikely that !sched_clock_running would be true, but
      | because the "!" was moved outside the "unlikely()" it makes the test
      | "likely()". That is, if we added an intermediate step, it would have
      | been:
      |
      |         if (!likely(sched_clock_running))
      |
      | which would have prevented the mistake that this patch fixes.
    
      [ mingo: Edited th...
    c5105d76
clock.c 12.1 KB