workqueue: set delayed_work->timer function on initialization
delayed_work->timer.function is currently initialized during
queue_delayed_work_on().  Export delayed_work_timer_fn() and set
delayed_work timer function during delayed_work initialization
together with other fields.

This ensures the timer function is always valid on an initialized
delayed_work.  This is to help mod_delayed_work() implementation.

To detect delayed_work users which diddle with the internal timer,
trigger WARN if timer function doesn't match on queue.

Change-Id: If67450393f155a632123ce3163804e5611fa96e6
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
workqueue: make queueing functions return bool
All queueing functions return 1 on success, 0 if the work item was
already pending.  Update them to return bool instead.  This signifies
better that they don't return 0 / -errno.

This is cleanup and doesn't cause any functional difference.

While at it, fix comment opening for schedule_work_on().

Change-Id: I2ff331b0210f153b53d1ec648975f90adfc4c1ae
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
workqueue: implement mod_delayed_work[_on]() parte 2 xD porque borre lo anterior

Change-Id: Ia06c132ed3fb3be171fda266f14a8fc7f7342d29
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
Fix typo

Change-Id: Idd6bc05a8951aba3fe6e644df4017bb172bd10e8
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
Small corrections

Change-Id: Ia300616389ea92e166607e7e6899931d9b78e68c
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
Workqueue remove panic

Change-Id: I5097bf31057ea0395d039af903b2949aba66134b
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
workqueue: Fix permission for power_efficient

Change-Id: I8a058dc45525963d1197110257e2eb386c7d5153
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
 workqueue: Added null check and warning

If work item is already in queue get_work_cwq() will return null.
so null check is added to avoid crash in delayed_work_timer_on()

Change-Id: I23977f33eac33962dec343c9af0cd63fbd6d7ff2
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
 workqueue: change BUG_ON() to WARN_ON()

This BUG_ON() can be triggered if you call schedule_work() before
calling INIT_WORK().  It is a bug definitely, but it's nicer to just
print a stack trace and return.

Change-Id: Idbc1ac58bda4655bfe3c47908edcef6979d7dd59
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
 workqueue: unify local CPU queueing handling

Queueing functions have been using different methods to determine the
local CPU.

* queue_work() superflously uses get/put_cpu() to acquire and hold the
  local CPU across queue_work_on().

* delayed_work_timer_fn() uses smp_processor_id().

* queue_delayed_work() calls queue_delayed_work_on() with -1 @cpu
  which is interpreted as the local CPU.

* flush_delayed_work[_sync]() were using raw_smp_processor_id().

* __queue_work() interprets %WORK_CPU_UNBOUND as local CPU if the
  target workqueue is bound one but nobody uses this.

This patch converts all functions to uniformly use %WORK_CPU_UNBOUND
to indicate local CPU and use the local binding feature of
__queue_work().  unlikely() is dropped from %WORK_CPU_UNBOUND handling
in __queue_work().

Change-Id: Ie7ea48c5581ebd4f8d3239da35aa8f47279520cf
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
 workqueue: fix zero @delay handling of queue_delayed_work_on()

If @delay is zero and the dealyed_work is idle, queue_delayed_work()
queues it for immediate execution; however, queue_delayed_work_on()
lacks this logic and always goes through timer regardless of @delay.

This patch moves 0 @delay handling logic from queue_delayed_work() to
queue_delayed_work_on() so that both functions behave the same.

Change-Id: Ieb6f83854d9d73513d00c699757334c9f6bd620d
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>
workqueue: factor out __queue_delayed_work() from
 queue_delayed_work_on()

This is to prepare for mod_delayed_work[_on]() and doesn't cause any
functional difference.

Change-Id: I5150b6a6cf83e88eb78f101cadea581d7c529749
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>