Time for rt_mutex_acquire
Hello,
I'm wondering how long a rt_mutex_acquire is supposed to take on a PPC405 platform. I'm getting times about 50 usec here, which is too much for my application. Is anything wrong in my kernel/xenomai configuration or is this time to expected?
Cheers,
Dirk
Quoted 6 lines · Dirk Eibach
Hello,
I'm wondering how long a
rt_mutex_acquireis supposed to take on a PPC405 platform. I'm getting times about 50 usec here, which is too much for my application. Is anything wrong in my kernel/xenomai configuration or is this time to expected?
How do you measure this ? Are you sure the mutex is free when you try to acquire it ?
Signature · 1 line
Gilles Chanteperdrix.
Quoted 11 lines · [email protected] wrote:
Quoted 6 lines · Dirk Eibach
Hello,
I'm wondering how long a
rt_mutex_acquireis supposed to take on a PPC405 platform. I'm getting times about 50 usec here, which is too much for my application. Is anything wrong in my kernel/xenomai configuration or is this time to expected?How do you measure this ? Are you sure the mutex is free when you try to acquire it ?
I prepared a small testcase. It shows about 8.300 ticks, which is about 30 usec on my platform (266MHz).
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/mutex.h>
#include <native/task.h>
#include <native/timer.h>
#include <rtdm/rtserial.h>
#define TOGGLE \
do {rt_dev_ioctl(0, _IOR(RTIOC_TYPE_SERIAL, 0xdf, int), 0);} while(0);RT_TASK demo_task;
/* NOTE: error handling omitted. */
static voidppc_getcounter(unsigned long long *v)
{
register unsigned long tbu, tb, tbu2;
loop:
asm volatile ("mftbu %0" : "=r" (tbu) );
asm volatile ("mftb %0" : "=r" (tb) );
asm volatile ("mftbu %0" : "=r" (tbu2));
if (__builtin_expect(tbu != tbu2, 0)) goto loop;
/* The slightly peculiar way of writing the next lines is
compiled better by GCC than any other way I tried. */
((long*)(v))[0] = tbu;
((long*)(v))[1] = tb;
}void demo(void *arg)
{
RT_MUTEX mutex;
rt_mutex_create (&mutex, NULL);
int file_descriptor = rt_dev_open("rtser0", O_RDWR | O_NOCTTY);
unsigned long long count0, count1;
while (1) {
ppc_getcounter(&count0);
rt_mutex_acquire(&mutex, TM_INFINITE);
ppc_getcounter(&count1);
printf("ticks for rt_mutex_acquire: %lld\n", count1- count0);
rt_task_sleep(rt_timer_ns2ticks(1 * 1000000000llu));
rt_mutex_release(&mutex);
rt_task_sleep(rt_timer_ns2ticks(1 * 1000000000llu));
}
}void catch_signal(int sig)
{
}
int main(int argc, char* argv[])
{
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
/* Avoids memory swapping for this program */
mlockall(MCL_CURRENT|MCL_FUTURE);
/*
* Arguments: &task,
* name,
* stack size (0=default),
* priority,
* mode (FPU, start suspended, ...)
*/
rt_task_create(&demo_task, "trivial", 0, 99, 0);
/*
* Arguments: &task,
* task function,
* function argument
*/
rt_task_start(&demo_task, &demo, NULL);
pause();
rt_task_delete(&demo_task);
}Signature · 3 lines
Dirk Eibach Entwicklung Guntermann & Drunck GmbH Systementwicklung
Quoted 9 lines · Dirk Eibach
Quoted 8 lines · [email protected] wrote:
Quoted 6 lines · Dirk Eibach
Hello,
I'm wondering how long a
rt_mutex_acquireis supposed to take on a PPC405 platform. I'm getting times about 50 usec here, which is too much for my application. Is anything wrong in my kernel/xenomai configuration or is this time to expected?
Quoted 6 lines
Quoted 3 lines
How do you measure this ? Are you sure the mutex is free when you try to acquire it ?
I prepared a small testcase. It shows about 8.300 ticks, which is about 30 usec on my platform (266MHz).
Did you try to call ppc_getcounter twice in a raw to measure the overhead of this function ?
Signature · 1 line
Gilles Chanteperdrix