All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Adam Rosenberg <adam@alcorn.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: ALSA processor usage is too high
Date: Mon, 08 Nov 2010 11:39:53 +0100	[thread overview]
Message-ID: <4CD7D379.5020100@ladisch.de> (raw)
In-Reply-To: <AANLkTi=7pEPATKneHvZ-U-v7RUe90X-YSR-fqhF3bNx6@mail.gmail.com>

Adam Rosenberg wrote:
> On Fri, Nov 5, 2010 at 3:10 PM, Clemens Ladisch <clemens@ladisch.de> wrote:
> > And you should use poll() with all eight handles so that you don't
> > eat CPU while waiting.)
> 
> I can't use poll because the application has to perform many other
> tasks in a deterministic manner (meaning I can only use threads and
> other processes to notify the main loop to perform some task).

As Mark wrote, this is what poll() was designed for.

> the main loop of my application basically does this:
> while(1)
> {
>   processNextAlsaStream();
>   processMp3Decoder();
>   processLCD();
>   processInputs();
>   processSerial();
> }

With poll(), it would look somewhat like this:

  struct pollfd pollfds[...];
  // fill pollfds with all handles
  while (1)
  {
     poll(...);
     for (1..8)
       if (stream ready for writing)
         processAlsaStream(i);
     if (input ready for reading)
       processInputs();
     if (serial ready for whatever)
       processSerial();
     processMp3Decoder();
  }

If you set the PCM device to non-blocking mode, you do not need to call
avail_update before writing; just try to write as much as you currently
have.

If you want to do something regularly, use the timeout of poll(), or
use a timerfd.

You mentioned threads; these are not directly supported with poll()
because they do not have a file handle, but if you want to wake up the
main loop, you can write to an eventfd or to a pipe created with pipe().


Regards,
Clemens

      parent reply	other threads:[~2010-11-08 10:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-05 14:12 ALSA processor usage is too high Adam Rosenberg
2010-11-05 14:31 ` Clemens Ladisch
2010-11-05 15:19   ` Adam Rosenberg
2010-11-05 17:58     ` Clemens Ladisch
2010-11-05 18:45       ` Adam Rosenberg
2010-11-05 18:51         ` Mark Brown
2010-11-05 19:10         ` Clemens Ladisch
2010-11-05 19:27           ` Adam Rosenberg
2010-11-06  5:30             ` Mark Brown
2010-11-08 10:39             ` Clemens Ladisch [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CD7D379.5020100@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=adam@alcorn.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.