All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dirk Eibach <eibach@domain.hid>
To: gilles.chanteperdrix@xenomai.org
Cc: Xenomai help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] Time for rt_mutex_acquire
Date: Fri, 17 Aug 2007 13:00:15 +0200	[thread overview]
Message-ID: <46C57FBF.9050108@domain.hid> (raw)
In-Reply-To: <18116.37871.209453.702969@domain.hid>

gilles.chanteperdrix@xenomai.org wrote:
> Dirk Eibach wrote:
>  > 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?
> 
> 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 void
ppc_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);
}


-- 
Dirk Eibach
Entwicklung
Guntermann & Drunck GmbH Systementwicklung





  reply	other threads:[~2007-08-17 11:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 13:11 [Xenomai-help] Time for rt_mutex_acquire Dirk Eibach
2007-08-16 18:14 ` Gilles Chanteperdrix
2007-08-17 11:00   ` Dirk Eibach [this message]
2007-08-17 12:04     ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2007-08-17 12:13 Dirk Eibach
2007-08-17 12:45 ` Jan Kiszka

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=46C57FBF.9050108@domain.hid \
    --to=eibach@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --cc=xenomai@xenomai.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.