Re: [PATCH 2/5] workqueue: change value of lcpu inqueue_delayed_work_on()

From: Tejun Heo
Date: Mon Aug 13 2012 - 13:03:02 EST


Hello,

On Tue, Aug 14, 2012 at 01:54:22AM +0900, JoonSoo Kim wrote:
> wq = WQ_NON_REENTRANT.
> queue_delayed_work_on(CPU B) is invoked in CPU A, so lcpu = CPU A, cpu = CPU B.
>
> In this case, we call add_time_on(CPU B), then delayed_work_timer_fn()
> is invoked on CPU B.
> delayed_work_timer_fn() calls __queue_work(), then following
> comparisons return true!
>
> gcwq = get_gcwq(cpu);
> if (wq->flags & WQ_NON_REENTRANT &&
> (last_gcwq = get_work_gcwq(work)) && last_gcwq != gcwq) {
>
> I thinks that if we assign cpu to lcpu, above comparisons return
> false, so save some overheads.
> Is there any missing part?

Nope, that sound correct to me.

> And, do u mean @cpu is WORK_CPU_UNBOUND?

@cpu could be WORK_CPU_UNBOUND at that point. The timer will be added
to local CPU but @work->data would be pointing to WORK_CPU_UNBOUND,
again triggering the condition. Given that @cpu being
WORK_CPU_UNBOUND is far more common than an actual CPU number, the
patch would actually increase spurious nrt lookups. The right thing
to do is probably setting cpu to raw_smp_processor_id() beforehand.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/