[PATCH] Timidity polling

View: New views
3 Messages — Rating Filter:   Alert me  

[PATCH] Timidity polling

by Niko Kiirala :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Profiling my laptop power usage with PowerTOP, I noticed Timidity wakes
up rather often, 100 times per second, even when it's not being used.

The curlpit is Timidity ALSA sequencer interface. Examining the source
code, I created the following patch, which should disable this polling,
when it's not needed.

The patch attached, or if it doesn't come through, see
http://fedev.blogspot.com/2007/07/timidity-power-usage.html
A bit more details there, too.

--
Niko Kiirala
niko@...
http://niko.kiirala.com/

[nopoll.diff]

--- interface/alsaseq_c.c~ 2004-07-10 08:07:00.000000000 +0300
+++ interface/alsaseq_c.c 2007-05-12 17:11:49.000000000 +0300
@@ -529,13 +529,18 @@
  }
  if (! ctxp->active || ! IS_STREAM_TRACE) {
  fd_set rfds;
- struct timeval timeout;
  FD_ZERO(&rfds);
  FD_SET(ctxp->fd, &rfds);
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000; /* 10ms */
- if (select(ctxp->fd + 1, &rfds, NULL, NULL, &timeout) < 0)
- goto __done;
+ if (! IS_STREAM_TRACE) {
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 10000; /* 10ms */
+ if (select(ctxp->fd + 1, &rfds, NULL, NULL, &timeout) < 0)
+ goto __done;
+ } else {
+ if (select(ctxp->fd + 1, &rfds, NULL, NULL, NULL) < 0)
+ goto __done;
+ }
  }
  }
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk

Re: [PATCH] Timidity polling

by Stas Sergeev :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

Niko Kiirala wrote:
> The curlpit is Timidity ALSA sequencer interface. Examining the source
> code, I created the following patch, which should disable this polling,
> when it's not needed.
Maybe something like the attached patch
can do instead? I haven't tested, but it
seems in case of (ctxp->active && IS_STREAM_TRACE)
the select() is never executed at all, so
100% of CPU will be consumed no matter what.
I did such a patch for the server interface,
and it was applied. Of course it doesn't
make it inevitably correct, but noone complained
since, and consuming 100% of CPU is certainly
unacceptable.
Though for the server interface I managed to
reduce the CPU usage much further with a few
simple tricks.


--- alsaseq_c.c.old 2006-12-14 23:05:19.000000000 +0300
+++ alsaseq_c.c 2007-07-05 22:21:55.000000000 +0400
@@ -501,6 +501,8 @@
 
 static void doit(struct seq_context *ctxp)
 {
+ fd_set rfds;
+ struct timeval timeout;
  for (;;) {
  while (snd_seq_event_input_pending(ctxp->handle, 1)) {
  if (do_sequencer(ctxp))
@@ -528,15 +530,17 @@
  play_event(&ev);
  aq_fill_nonblocking();
  }
- if (! ctxp->active || ! IS_STREAM_TRACE) {
- fd_set rfds;
- struct timeval timeout;
- FD_ZERO(&rfds);
- FD_SET(ctxp->fd, &rfds);
+
+ FD_ZERO(&rfds);
+ FD_SET(ctxp->fd, &rfds);
+ if (ctxp->active) {
  timeout.tv_sec = 0;
  timeout.tv_usec = 10000; /* 10ms */
  if (select(ctxp->fd + 1, &rfds, NULL, NULL, &timeout) < 0)
  goto __done;
+ } else {
+ if (select(ctxp->fd + 1, &rfds, NULL, NULL, NULL) < 0)
+ goto __done;
  }
  }
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk

Re: [PATCH] Timidity polling

by Niko Kiirala :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thu, 05 Jul 2007 22:58:27 +0400
Stas Sergeev <stsp@...> kirjoitti:

> Maybe something like the attached patch
> can do instead? I haven't tested, but it
> seems in case of (ctxp->active && IS_STREAM_TRACE)
> the select() is never executed at all, so
> 100% of CPU will be consumed no matter what.
> I did such a patch for the server interface,
> and it was applied. Of course it doesn't
> make it inevitably correct, but noone complained
> since, and consuming 100% of CPU is certainly
> unacceptable.
> Though for the server interface I managed to
> reduce the CPU usage much further with a few
> simple tricks.

Yes, looks better. I tried not to modify anything else, but just make
it not poll when idle, so I left that condition of bypassing select()
altogether alone.

For me, this patch seems to work just as well and is less complex code,
so I'm all for it.

--
Niko Kiirala
niko@...
http://niko.kiirala.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk
LightInTheBox - Buy quality products at wholesale price