Re: Fw: [PATCH -mm] workqueue: debug possible endless loop in cancel_rearming_delayed_work

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Jarek Poplawski <jarkao2@...>
Cc: Andrew Morton <akpm@...>, Ingo Molnar <mingo@...>, <linux-kernel@...>
Date: Monday, April 23, 2007 - 12:33 pm

On 04/23, Jarek Poplawski wrote:

This will change the API. Currently it is possible to do:

	cancel_delayed_work(dwork);
	schedule_delayed_work(dwork, delay);

and we have such a code. With the change you propose this can't work.


Look,

	void cancel_rearming_delayed_work(struct delayed_work *dwork)
	{
		struct work_struct *work = &dwork->work;
		struct cpu_workqueue_struct *cwq = get_wq_data(work);
		struct workqueue_struct *wq;
		const cpumask_t *cpu_map;
		int retry;
		int cpu;

		if (!cwq)
			return;

	retry:
		spin_lock_irq(&cwq->lock);
		list_del_init(&work->entry);
		__set_bit(WORK_STRUCT_PENDING, work_data_bits(work));
		retry = try_to_del_timer_sync(&dwork->timer) < 0;
		spin_unlock_irq(&cwq->lock);

		if (unlikely(retry))
			goto retry;

		// the work can't be re-queued and the timer can't
		// be re-started due to WORK_STRUCT_PENDING

		wq = cwq->wq;
		cpu_map = wq_cpu_map(wq);

		for_each_cpu_mask(cpu, *cpu_map)
			wait_on_work(per_cpu_ptr(wq->cpu_wq, cpu), work);

		work_clear_pending(work);
	}

I think this almost works, except:

	- we should change run_workqueue() to call work_clear_pending()
	  under cwq->lock. I'd like to avoid this.

	- this is racy wrt cpu-hotplug. We should re-check get_wq_data()
	  when we take the lock. This is easy.

	- we should factor out the common code with cancel_work_sync().

I may be wrong, still had no time to concentrate on this with a "clear head".
May be tomorrow.


Why?


May be you are right, but still I don't think we should introduce
the new flag to implement this imho not-so-useful feature.

Oleg.

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Fw: [PATCH -mm] workqueue: debug possible endless loop i..., Oleg Nesterov, (Mon Apr 23, 12:33 pm)