Skip to contentSkip to conversation

Do not deprecate binary semaphore or do allow mutex in software interrupt contexts

DISCUSSION Matti Linnanvuori 3 participants 3 messages Sep 11, 2007

lore
Share & tools
lore
#0 lore raw

I thought of a scenario where it seems appropriate to use a binary semaphore or a mutex in a software interrupt context. If a device cannot interrupt when some important variable changes, it can be polled occasionally to update e.g. LEDs to indicate status. Such polling can be done most efficiently in timers that are software interrupts. Timers are more efficient than works because they do not have so much context switching overhead. If the access to the variables of the device must be serialized, a binary semaphore or a mutex is a natural choice. If user-space writing to the device is likely to change the status, it can make sense not to poll the status of the device at the same time. The timer could therefore sensibly call mutex_trylock. Therefore, it seems wrong to me to deprecate binary semaphores and disallow the use of mutexes in software interrupt contexts.

      __________________________________  

Yahoo! Clever: Sie haben Fragen? Yahoo! Nutzer antworten Ihnen. www.yahoo.de/clever

#1 lore raw

On Tue, 11 Sep 2007 06:20:51 -0700 (PDT) Matti Linnanvuori <[email protected]> wrote:

Hi,

Quoted 4 lines

I thought of a scenario where it seems appropriate to use a binary semaphore or a mutex in a software interrupt context. If a device cannot interrupt when some important variable changes, it can be polled occasionally to update e.g. LEDs to indicate status. Such

Quoted 8 lines

polling can be done most efficiently in timers that are software interrupts. Timers are more efficient than works because they do not have so much context switching overhead. If the access to the variables of the device must be serialized, a binary semaphore or a mutex is a natural choice. If user-space writing to the device is likely to change the status, it can make sense not to poll the status of the device at the same time. The timer could therefore sensibly call mutex_trylock.

what do you do if the trylock fails?

Quoted 3 lines

Therefore, it seems wrong to me to deprecate
binary semaphores and disallow the use of mutexes in software interrupt contexts.

to be honest, the scenario describe really smells of broken locking, in fact it really sounds like it wants to use spinlocks instead

Greetings,
Arjan van de Ven

#2 lore raw
Quoted 2 lines

to be honest, the scenario describe really smells of broken locking, in fact it really sounds like it wants to use spinlocks instead

For polling and timer based code its often simpler to do

	del_timer_sync(&my_timer);
	FrobStuff
	add_timer(&my_timer);

especially if "FrobStuff" is likely to change when you next need to poll.

And don't forget regular polling is a good way to really annoy laptop users as it burns power

Alan