Re: [linux-audio-dev] debugging realtime issues with instrumented kernel

From: Florian Schmidt <mista.tapas@email-addr-hidden>
Date: Tue Apr 12 2005 - 14:33:12 EEST

On Tue, 12 Apr 2005 13:01:58 +0200
Florian Schmidt <mista.tapas@email-addr-hidden> wrote:

> Note though that this check is not garanteed to trigger for possibly
> unsafe code.. It will trigger only if the process really is preempted.

This is a small client i once hacked up to test this feature.. As it
does an explicit sleep() in the 100th process callback, not getting a
preemption report means, that the feature is not enabled in either jack
or the kernel. If you do get an output "signalled" then the check is
working..

Flo

Compile with g++ -o jack_test jack_test.cc -ljack

------------------------ snip

#include <jack/jack.h>
#include <iostream>
#include <sstream>
#include <unistd.h>
#include <signal.h>

jack_client_t *client;
jack_port_t *iport;
jack_port_t *oport;

int wasted_loops = 0;

int sleep_seconds = 1;
int sleep_in_period = 100;
int counter = 0;

int process(jack_nframes_t frames, void *arg) {
        
        // std::cout << "process callback" << std::endl;
        jack_default_audio_sample_t *ibuf;
        ibuf = (jack_default_audio_sample_t*)jack_port_get_buffer(iport, frames);

        jack_default_audio_sample_t *obuf;
        obuf = (jack_default_audio_sample_t*)jack_port_get_buffer(oport, frames);

        for (jack_nframes_t frame = 0; frame < frames; frame++) {
                for (int i = 0; i < wasted_loops; ++i) {
                        // do nothing
                }
                obuf[frame] = ibuf[frame];
        }
        counter++;
        if (counter == sleep_in_period) {
          sleep(sleep_seconds);
        }

        return 0;
}
void signalled(int sig) {
  std::cout << "signalled" << std::endl;
}

int main(int argc, char *argv[]) {
        // default = 60 seconds
        unsigned int seconds_to_run = 60;
        if (argc > 1) {
                std::stringstream sec_stream;
                sec_stream << argv[1];
                sec_stream >> seconds_to_run;
                if (argc > 2) {
                        std::stringstream waste_stream;
                        waste_stream << argv[2];
                        waste_stream >> wasted_loops;
                        std::cout << "wasted loops: " << wasted_loops << std::endl;
                }
        }

        signal(SIGUSR2, signalled);

        std::cout << "seconds to run: " << seconds_to_run << std::endl;
        
        std::stringstream pid_stream;
        pid_stream << getpid();
        
        std::cout << "client_new" << std::endl;
        client = jack_client_new(pid_stream.str().c_str());

        std::cout << "port_register." << std::endl;
        iport = jack_port_register(client, "in", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0);
        oport = jack_port_register(client, "out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsTerminal|JackPortIsOutput, 0);

        std::cout << "set_process_callback" << std::endl;
        jack_set_process_callback(client, process, 0);

        std::cout << "activate" << std::endl;
        jack_activate(client);

        std::cout << "running" << std::endl;

        // while(1) {sleep(1);};
        sleep(seconds_to_run);

        jack_deactivate(client);
        jack_client_close(client);
}

--------------------------- snip

-- 
Palimm Palimm!
http://affenbande.org/~tapas/

Received on Tue Apr 12 16:15:13 2005

This archive was generated by hypermail 2.1.8 : Tue Apr 12 2005 - 16:15:14 EEST