All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Strange behaviour w/mutex&semaphore
@ 2006-07-20 10:54 ROSSIER Daniel
  2006-07-20 11:03 ` Jan Kiszka
  0 siblings, 1 reply; 7+ messages in thread
From: ROSSIER Daniel @ 2006-07-20 10:54 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]


Hi all,

I've a strange behaviour with the attached piece of code.
It's really simple: there are 3 tasks and we're spinning within the task in order
to simulate task load.

It's a pure academic exercice, so don't try to think about the usefulness of this code ;-)


Actually, after insmod'ing the code into the kernel, the system freezes and
the "meteoDataAcquisition" task is suspended runaway by the internal xenomai watchdog.

Why?

Anything wrong in this code?

Thanks for any advice.

Daniel


[-- Attachment #2: mytry.c --]
[-- Type: application/octet-stream, Size: 2878 bytes --]



#include <linux/module.h>
#include <native/task.h>
#include <native/sem.h>
#include <native/mutex.h>
#include <native/alarm.h>

#define STACK_SIZE 8192
#define MS 1000000 

#define WITH_MUTEX  1  /* semaphore/mutex selection */

RT_TASK busManagementTask;
RT_TASK meteoDataAcquisitionTask;
RT_TASK comHandlingTask;

RT_SEM sema;
RT_MUTEX mutex;

int err;

void meteoDataAcquisition(void *cookie) {

  while(1) {

    if (WITH_MUTEX)
      rt_mutex_lock(&mutex, TM_INFINITE);
    else
      rt_sem_p(&sema, TM_INFINITE);

    rt_timer_spin(10*MS);

    if (WITH_MUTEX)
      rt_mutex_unlock(&mutex);
    else
      rt_sem_v(&sema);

    rt_task_wait_period(NULL);
  }

}

void busManagement(void *cookie) {

  while(1) {

    if (WITH_MUTEX)
      rt_mutex_lock(&mutex, TM_INFINITE);
    else
      rt_sem_p(&sema, TM_INFINITE);

    rt_timer_spin(5*MS);

    if (WITH_MUTEX)
      rt_mutex_unlock(&mutex);
    else
      rt_sem_v(&sema);

    rt_task_wait_period(NULL);
  }
}

void comHandling(void *cookie) {

  while (1) {

    rt_timer_spin(10*MS);

    rt_task_wait_period(NULL);
  }

}

void alarmHandler(RT_ALARM *alarmDesc, void *cookie) {
  printk("#ALERT:\n");
}

void __exit cleanup_module (void) {

  printk("#cleanup\n");

  rt_task_delete(&meteoDataAcquisitionTask);
  rt_task_delete(&busManagementTask);
  rt_task_delete(&comHandlingTask);

  //rt_alarm_delete(&alarmBus);

  rt_mutex_delete(&mutex);
  rt_sem_delete(&sema);


  printk("Bye bye!\n");
}

int __init init_module (void) {

  printk("#starting...\n");

  err = rt_timer_set_mode(MS);
  if (err != 0) {
    printk("Error timer: %d\n", err);
    return -1;
  }

  err = rt_sem_create(&sema, "SEMAPHORE_BUS", 1, S_PRIO);
  if (err != 0) {
    printk("semaphore creation failed: %d\n", err);
    return -1;
  } 

  err = rt_mutex_create(&mutex, "MUTEX_BUS");
  if (err != 0) {
    printk("mutex creation failed: %d\n", err);
    return -1;
  }

  err = rt_task_create(&busManagementTask, "busManagement", STACK_SIZE, 10, 0);
  if (err != 0) {
    printk("task creation failed: %d\n", err);
    return -1;
  }

  err = rt_task_create(&meteoDataAcquisitionTask, "meteoDataAcquisition", STACK_SIZE, 1, 0);
  if (err != 0) {
    printk("task creation failed: %d\n", err);
    return -1;
  }

  err = rt_task_create(&comHandlingTask, "comHandling", STACK_SIZE, 5 , 0);
  if (err != 0) {
    printk("task creation failed: %d\n", err);
    return -1;
  }

  rt_task_set_periodic(&busManagementTask, TM_NOW, 20);
  rt_task_set_periodic(&comHandlingTask, TM_NOW, 20);
  rt_task_set_periodic(&meteoDataAcquisitionTask, 18, 1000); /* Delay this task in order to force priority inversion */

  rt_task_start(&comHandlingTask, comHandling, NULL);
  rt_task_start(&busManagementTask, busManagement, NULL);
  rt_task_start(&meteoDataAcquisitionTask, meteoDataAcquisition, NULL);

  return 0;
}

MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-07-20 12:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-20 10:54 [Xenomai-help] Strange behaviour w/mutex&semaphore ROSSIER Daniel
2006-07-20 11:03 ` Jan Kiszka
2006-07-20 11:17   ` ROSSIER Daniel
2006-07-20 11:49     ` Gilles Chanteperdrix
2006-07-20 11:59       ` ROSSIER Daniel
2006-07-20 12:04     ` Philippe Gerum
2006-07-20 12:44       ` ROSSIER Daniel

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.