Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon 2015-11-23 17:58:23, Tejun Heo wrote:
> Hello,
> 
> On Wed, Nov 18, 2015 at 02:25:14PM +0100, Petr Mladek wrote:
> > +static int
> > +try_to_cancel_kthread_work(struct kthread_work *work,
> > +				   spinlock_t *lock,
> > +				   unsigned long *flags)
> > +{
> > +	int ret = 0;
> > +
> > +	if (work->timer) {
> > +		/* Try to cancel the timer if pending. */
> > +		if (del_timer(work->timer)) {
> > +			ret = 1;
> > +			goto out;
> > +		}
> > +
> > +		/* Are we racing with the timer callback? */
> > +		if (timer_active(work->timer)) {
> > +			/* Bad luck, need to avoid a deadlock. */
> > +			spin_unlock_irqrestore(lock, *flags);
> > +			del_timer_sync(work->timer);
> > +			ret = -EAGAIN;
> > +			goto out;
> > +		}
> 
> As the timer side is already kinda trylocking anyway, can't the cancel
> path be made simpler?  Sth like
> 
> 	lock(worker);
> 	work->canceling = true;
> 	del_timer_sync(work->timer);
> 	unlock(worker);
> 
> And the timer can do (ignoring the multiple worker support, do we even
> need that?)
> 
> 	while (!trylock(worker)) {
> 		if (work->canceling)
> 			return;
> 		cpu_relax();
> 	}
> 	queue;
> 	unlock(worker);

Why did I not find out this myself ?:-)

Thanks for hint,
Petr

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]