All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about kernel timers
@ 2006-07-25 22:01 Lee Revell
  2006-07-28  1:18 ` Lee Revell
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lee Revell @ 2006-07-25 22:01 UTC (permalink / raw)
  To: alsa-devel

I am writing a driver in which every time some event occurs, two
single-shot timers must be scheduled.  This event could happen many
times per second so many of these timers can be pending at once.  Can
someone point me to an example of a driver that does something like
this?

All the ALSA drivers I can find that use timers have a single periodic
timer and use a struct timer_list in the card record.  However I think
this is not an option for me, as I must create new timers on the fly.

I've found that the kernel Oopses if you allocate a timer on the stack,
so I use kmalloc().  It seems to work, but leaks memory, as there's no
opportunity to free() all the timer_lists I'm creating on the fly.

Can I do this with a single struct timer_list?  Is it possible to
schedule multiple timers using add_timer() then changing the parameters
and add_timer() again?

It seems that this should be documented somewhere but it's not - LDD3
was no help.  All the examples were very simplistic.

Lee


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: Question about kernel timers
  2006-07-25 22:01 Question about kernel timers Lee Revell
@ 2006-07-28  1:18 ` Lee Revell
  2006-07-28  7:01   ` Clemens Ladisch
  2006-07-28  8:00 ` James Courtier-Dutton
  2006-07-28 10:06 ` Takashi Iwai
  2 siblings, 1 reply; 6+ messages in thread
From: Lee Revell @ 2006-07-28  1:18 UTC (permalink / raw)
  To: alsa-devel

On Tue, 2006-07-25 at 18:01 -0400, Lee Revell wrote:
> I've found that the kernel Oopses if you allocate a timer on the
> stack, so I use kmalloc().  It seems to work, but leaks memory, as
> there's no opportunity to free() all the timer_lists I'm creating on
> the fly.
> 

I've solved this problem by passing a pointer to the struct timer_list
to the timer function, and kfree()ing it at the end.  It seems pretty
ugly but it works.

Lee


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: Question about kernel timers
  2006-07-28  1:18 ` Lee Revell
@ 2006-07-28  7:01   ` Clemens Ladisch
  0 siblings, 0 replies; 6+ messages in thread
From: Clemens Ladisch @ 2006-07-28  7:01 UTC (permalink / raw)
  To: Lee Revell; +Cc: alsa-devel

Lee Revell wrote:
> On Tue, 2006-07-25 at 18:01 -0400, Lee Revell wrote:
> > I've found that the kernel Oopses if you allocate a timer on the
> > stack, so I use kmalloc().  It seems to work, but leaks memory, as
> > there's no opportunity to free() all the timer_lists I'm creating on
> > the fly.
> 
> I've solved this problem by passing a pointer to the struct timer_list
> to the timer function, and kfree()ing it at the end.  It seems pretty
> ugly but it works.

When the device is closed, you have to cancel all timers (or wait for
them to finish), so I think you have to put them into a list or
something like that.

Is there an upper bound on the number of timers?

Another possibility would be to use one timer and to write your own
event handling logic, but this is probably not worth the effort.


Regards,
Clemens

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: Question about kernel timers
  2006-07-25 22:01 Question about kernel timers Lee Revell
  2006-07-28  1:18 ` Lee Revell
@ 2006-07-28  8:00 ` James Courtier-Dutton
  2006-07-28 15:14   ` Lee Revell
  2006-07-28 10:06 ` Takashi Iwai
  2 siblings, 1 reply; 6+ messages in thread
From: James Courtier-Dutton @ 2006-07-28  8:00 UTC (permalink / raw)
  To: Lee Revell; +Cc: alsa-devel

Lee Revell wrote:
> I am writing a driver in which every time some event occurs, two
> single-shot timers must be scheduled.  This event could happen many
> times per second so many of these timers can be pending at once.  Can
> someone point me to an example of a driver that does something like
> this?
> 
> All the ALSA drivers I can find that use timers have a single periodic
> timer and use a struct timer_list in the card record.  However I think
> this is not an option for me, as I must create new timers on the fly.
> 
> I've found that the kernel Oopses if you allocate a timer on the stack,
> so I use kmalloc().  It seems to work, but leaks memory, as there's no
> opportunity to free() all the timer_lists I'm creating on the fly.
> 
> Can I do this with a single struct timer_list?  Is it possible to
> schedule multiple timers using add_timer() then changing the parameters
> and add_timer() again?
> 
> It seems that this should be documented somewhere but it's not - LDD3
> was no help.  All the examples were very simplistic.
> 
> Lee
> 

What is the purpose of these event timers?
I can't think of any sound card that needs this sort of stuff.
Can you use polling instead?

James


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: Question about kernel timers
  2006-07-25 22:01 Question about kernel timers Lee Revell
  2006-07-28  1:18 ` Lee Revell
  2006-07-28  8:00 ` James Courtier-Dutton
@ 2006-07-28 10:06 ` Takashi Iwai
  2 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2006-07-28 10:06 UTC (permalink / raw)
  To: Lee Revell; +Cc: alsa-devel

At Tue, 25 Jul 2006 18:01:56 -0400,
Lee Revell wrote:
> 
> I am writing a driver in which every time some event occurs, two
> single-shot timers must be scheduled.  This event could happen many
> times per second so many of these timers can be pending at once.  Can
> someone point me to an example of a driver that does something like
> this?
> 
> All the ALSA drivers I can find that use timers have a single periodic
> timer and use a struct timer_list in the card record.  However I think
> this is not an option for me, as I must create new timers on the fly.
> 
> I've found that the kernel Oopses if you allocate a timer on the stack,
> so I use kmalloc().  It seems to work, but leaks memory, as there's no
> opportunity to free() all the timer_lists I'm creating on the fly.
> 
> Can I do this with a single struct timer_list?  Is it possible to
> schedule multiple timers using add_timer() then changing the parameters
> and add_timer() again?
> 
> It seems that this should be documented somewhere but it's not - LDD3
> was no help.  All the examples were very simplistic.

Can workq be used instead?  You can schedule tasks with
schedule_delayed_work() with a certain delay.
Using workq, the multiple calls wouldn't be no longer problem.


Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: Question about kernel timers
  2006-07-28  8:00 ` James Courtier-Dutton
@ 2006-07-28 15:14   ` Lee Revell
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Revell @ 2006-07-28 15:14 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

On Fri, 2006-07-28 at 09:00 +0100, James Courtier-Dutton wrote:
> What is the purpose of these event timers?
> I can't think of any sound card that needs this sort of stuff.
> Can you use polling instead?
> 

It's a driver for a MIDI device that has to snoop the MIDI stream for
note-on/note-off and perform several operations on some custom hardware
- one immediately, and two more many milliseconds later.

Lee


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

end of thread, other threads:[~2006-07-28 15:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-25 22:01 Question about kernel timers Lee Revell
2006-07-28  1:18 ` Lee Revell
2006-07-28  7:01   ` Clemens Ladisch
2006-07-28  8:00 ` James Courtier-Dutton
2006-07-28 15:14   ` Lee Revell
2006-07-28 10:06 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.