multiple jack clients in one process

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple jack clients in one process

Andrzej Szombierski

Is it officially allowed to have several jack_clients running in one
process (with separate processing threads of course) ?
It seems to work just fine, but as soon as I start activating and
deactivating multiple clients, Strange Things (TM) happen. The Strange
Things are, in my case, scheduling of inactive clients. I've put together
a short example:

--cut--
#include <jack/jack.h>
#include <stdio.h>

volatile int sched_bad;

static int process(jack_nframes_t nframes, void *id)
{
        sched_bad++;

        return 0;
}

int main()
{
        jack_options_t options = JackNullOption;
        jack_status_t status;

        jack_client_t *client = jack_client_open ("TEST", options, &status, NULL);
        jack_set_process_callback(client, process, NULL);
       
        jack_client_t *client2 = jack_client_open ("TEST2", options, &status, NULL);
       
        jack_activate (client);
        jack_deactivate (client);
        jack_activate (client2);

        for(;;) {
                fprintf(stderr, "%d bad\n", sched_bad);
                usleep(100000);
        }
        return 0;
}
--cut--

One would expect that activating a client, then immediately deactivating
it should result in a small number of process() callbacks (ideally zero,
but it's a multithreaded environment). In my example, when I activate
client2 (which, by the way, doesn't have a process calback) the first one
gets scheduled, but in an irregular manner - see for yourself.

Tested on jackd version 0.103.0

--
:: Andrzej Szombierski :: [hidden email] :: http://kuku.eu.org ::
:: [hidden email]  :: radio bez kitu :: http://bezkitu.com ::


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

client deactivation bug [was: multiple jack clients in one process]

Andrzej Szombierski

Apparently jackd randomly schedules inactive clients (instead of
active ones) even in a scenario without multiple clients in one process.
I've attached a simple example in the 'canonical' one-client-per-process
form.

Steps to reproduce:
1. ./jackact-a &
2. ./jackact-b
3. jackact-a gets scheduled in a semi-random manner even though it is
deactivated

The bug:
1. [jackact-a] calls jack_activate
2. jackd activates jackact-a
3. jackd sends a graph-reordered event to all active clients, that is
   jackact-a
4. [jackact-a] opens jack-ack-fifo-*-0, as it's the first active client
5. [jackact-a] calls jack_deactivate
6. jackd deactivates jackact-a
7. jackd sends a graph-reordered event to all *active* clients, that is
   to no-one!
8. [jackact-b] calls jack_activate
9. jackd activates jackact-b
10. jackd sends a graph-reordered event to all active clients, that is
   jackact-b
11. [jackact-b] opens jack-ack-fifo-*-0, as it's the first active client
...
After such scenario two clients simultaneously poll on jack-ack-fifo-*-0.
Which one gets scheduled depends on the kernel's decision, which leads to
nondeterministic behaviour. The real problem is that jackact-a is not
notified that it was kicked out of the graph, and every time it wins the
poll() race, it steals a processing cycle from the active client!
I'm not sure how to solve this without breaking jackd - the details of
the activation mechanism are still a bit of a mystery to me, so I would
really prefer if a JACK developer fixed it. I hope that this bug report
is detailed enough :)

--
:: Andrzej Szombierski :: [hidden email] :: http://kuku.eu.org ::
:: [hidden email]  :: radio bez kitu :: http://bezkitu.com ::

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel

jackact-a.c (982 bytes) Download Attachment
jackact-b.c (462 bytes) Download Attachment