public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [Semaphore API] down_interruptible_timeout
@ 2015-06-15  8:43 Mason
  2015-06-15 16:56 ` Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: Mason @ 2015-06-15  8:43 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Peter Zijlstra, Thomas Gleixner, Andrew Morton

Hello,

The semaphore API provides several flavors of the down primitive:

  down, down_interruptible, down_killable, down_trylock, down_timeout

As far as I can tell, they all call __down_common (except down_trylock,
which returns 1 where the others would sleep).

I was looking for a version
1) with a timeout
2) that could be interrupted
e.g. down_interruptible_timeout, but it doesn't exist.

It seems

  __down_common(sem, TASK_INTERRUPTIBLE, timeout);

would work as expected, no?

Do you know why it is not offered?
(Maybe there is a better way to achieve the same thing?)


[POST SCRIPTUM EDIT]
I found this 2007 discussion:
http://thread.gmane.org/gmane.linux.kernel/498034

At the time, Andrew said
"Nobody else has needed to invent new locking infrastructure
to do such things and I'd prefer not to do so now."
I suppose this is still true :-)
[/EDIT]


My use-case is pretty simple:

A) process-context kernel thread fills a FIFO and calls down(&fifo_empty);
B) ISR handles the FIFO-empty interrupt with up(&fifo_empty);

However, in case something goes wrong and the interrupt never fires,
I don't want the process to be stuck in an uninterruptible sleep.

Perhaps I can set a tiny timeout (e.g. 10 µs) and not worry about
the interruptible part for such a small duration? (Hmm, __down_common
calls schedule_timeout, which is jiffies-based. I don't think there
is a hrtimers flavor. So µs timeouts would be off the table?)

Or I could use the interruptible version, and let the user kill the
operation if necessary.

I'd like to hear your comments and suggestions.

Regards.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Semaphore API] down_interruptible_timeout
  2015-06-15  8:43 [Semaphore API] down_interruptible_timeout Mason
@ 2015-06-15 16:56 ` Thomas Gleixner
  2015-06-16 15:43   ` Mason
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Gleixner @ 2015-06-15 16:56 UTC (permalink / raw)
  To: Mason; +Cc: LKML, Ingo Molnar, Peter Zijlstra, Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 727 bytes --]

On Mon, 15 Jun 2015, Mason wrote:
> A) process-context kernel thread fills a FIFO and calls down(&fifo_empty);
> B) ISR handles the FIFO-empty interrupt with up(&fifo_empty);
> 
> However, in case something goes wrong and the interrupt never fires,
> I don't want the process to be stuck in an uninterruptible sleep.
> 
> Perhaps I can set a tiny timeout (e.g. 10 µs) and not worry about
> the interruptible part for such a small duration? (Hmm, __down_common
> calls schedule_timeout, which is jiffies-based. I don't think there
> is a hrtimers flavor. So µs timeouts would be off the table?)
> 
> Or I could use the interruptible version, and let the user kill the
> operation if necessary.

Use a completion.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Semaphore API] down_interruptible_timeout
  2015-06-15 16:56 ` Thomas Gleixner
@ 2015-06-16 15:43   ` Mason
  0 siblings, 0 replies; 3+ messages in thread
From: Mason @ 2015-06-16 15:43 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Ingo Molnar, Peter Zijlstra, Andrew Morton

On 15/06/2015 18:56, Thomas Gleixner wrote:

> On Mon, 15 Jun 2015, Mason wrote:
> 
>> A) process-context kernel thread fills a FIFO and calls down(&fifo_empty);
>> B) ISR handles the FIFO-empty interrupt with up(&fifo_empty);
>>
>> However, in case something goes wrong and the interrupt never fires,
>> I don't want the process to be stuck in an uninterruptible sleep.
>>
>> Perhaps I can set a tiny timeout (e.g. 10 µs) and not worry about
>> the interruptible part for such a small duration? (Hmm, __down_common
>> calls schedule_timeout, which is jiffies-based. I don't think there
>> is a hrtimers flavor. So µs timeouts would be off the table?)
>>
>> Or I could use the interruptible version, and let the user kill the
>> operation if necessary.
> 
> Use a completion.

Thanks for the pointer. I will also read the following LKML thread.
http://thread.gmane.org/gmane.linux.kernel/664514

Regards.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-16 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-15  8:43 [Semaphore API] down_interruptible_timeout Mason
2015-06-15 16:56 ` Thomas Gleixner
2015-06-16 15:43   ` Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox