• Tejun Heo's avatar
    workqueue: Factor out need_more_worker() check and worker wake-up · 0219a352
    Tejun Heo authored
    Checking need_more_worker() and calling wake_up_worker() is a repeated
    pattern. Let's add kick_pool(), which checks need_more_worker() and
    open-code wake_up_worker(), and replace wake_up_worker() uses. The following
    conversions aren't one-to-one:
    
    * __queue_work() was using __need_more_work() because it knows that
      pool->worklist isn't empty. Switching to kick_pool() adds an extra
      list_empty() test.
    
    * create_worker() always needs to wake up the newly minted worker whether
      there's more work to do or not to avoid triggering hung task check on the
      new task. Keep the current wake_up_process() and still add kick_pool().
      This may lead to an extra wakeup which isn't harmful.
    
    * pwq_adjust_max_active() was explicitly checking whether it needs to wake
      up a worker or not to avoid spurious wakeups. As kick_pool() only wakes up
      a worker when necessary, this explicit check is no longer necessary and
      dropped.
    
    * unbind_workers() now calls kick_pool() instead of wake_up_worker() adding
      a need_more_worker() test. This avoids spurious wakeups and shouldn't
      break anything.
    
    wake_up_worker() is dropped as kick_pool() replaces all its users. After
    this patch, all paths that wakes up a non-rescuer worker to initiate work
    item execution use kick_pool(). This will enable future changes to improve
    locality.
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    0219a352
workqueue.c 185 KB