All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Issue with Auto relax and nested mutexes
@ 2012-01-09 20:50 Makarand Pradhan
  2012-01-10 15:11 ` Philippe Gerum
  0 siblings, 1 reply; 23+ messages in thread
From: Makarand Pradhan @ 2012-01-09 20:50 UTC (permalink / raw)
  To: xenomai@xenomai.org

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

Hi,

I am running kernel 3.0.0, xenomai: 2.6, powerpc 8360.

I am noticing an issue while using the auto relax feature related to 
mutexes. I am using nested mutexes. The code is attached to this email.

The problem is that I am not relaxing after a RT thread grabs and 
releases a mutex. On further investigation, it was noted that the rescnt 
is not going down to 0. Another observation is that I do not hit 
rt_mutex_release in the kernel in the problem scenario, I believe when 
the thread undergoes a priority inversion. This may be a problem as the 
rescnt would not get decremented.  Not sure how the mutex is releasing 
wiithout hitting rt_mutex_relase or am I missing anything?

If I have both the tasks running at priority 0, I stay in the secondary 
domain, rt_mutex_release is invoked as expected, the rescnt goes down to 
0 when all the mutexes are released.

Has anyone faced this problem?

Rgds,
Makarand





-- 
___________________________________________________________________________
NOTICE OF CONFIDENTIALITY:
This e-mail and any attachments may contain confidential and privileged information.  If you are
not the intended recipient, please notify the sender immediately by return e-mail and delete this
e-mail and any copies.  Any dissemination or use of this information by a person other than the
intended recipient is unauthorized and may be illegal.
_____________________________________________________________________

  


[-- Attachment #2: prio.c --]
[-- Type: text/x-csrc, Size: 2123 bytes --]

#include <xenomai/asm-generic/bits/current.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <stdio.h>
#include <native/task.h>
#include <native/mutex.h>
#include <nucleus/thread.h>
#include <rtdk.h>
#include <stdlib.h>
#include <unistd.h>

RT_TASK task0, task1, task2; 
RT_MUTEX mux1, mux2, mux3, mux4;
char buff[8192];

void task1_func(void *arg)
{
	RT_TASK_INFO info;
	int current_in_primary = 0;

	while(true)
	{
		rt_task_inquire(&task1, &info);
		current_in_primary = !(xeno_get_current_mode() & XNRELAX);
		rt_printf("bP: %i, cp: %i, mode: %i\n", 
			info.bprio, info.cprio, current_in_primary);
                rt_mutex_acquire(&mux1, TM_INFINITE);
                rt_mutex_acquire(&mux2, TM_INFINITE);
                rt_mutex_acquire(&mux3, TM_INFINITE);
		rt_printf("Acquire complete\n");

		rt_task_sleep(2222222222LL);
		rt_mutex_release(&mux3);
		rt_mutex_release(&mux2);
		rt_mutex_release(&mux1);
		rt_printf("Release complete\n");
	}
}

void task2_func(void *arg)
{
	int counter = 0;
	while(true)
	{
		if (2 == counter)
		{
			rt_printf("Grabbing mux in HP\n");
			rt_mutex_acquire(&mux1, TM_INFINITE);
			rt_mutex_acquire(&mux2, TM_INFINITE);
			rt_mutex_acquire(&mux3, TM_INFINITE);
			rt_printf("Mux held by Task2\n");
		}
		rt_mutex_acquire(&mux4, TM_INFINITE);
		rt_task_sleep(4444444444LL);
		if (2 == counter)
		{
			rt_mutex_release(&mux3);
			rt_mutex_release(&mux2);
			rt_mutex_release(&mux1);
		}
		rt_mutex_release(&mux4);
		counter++;
	}
}

int main(int argc, char **argv)
{
	int prio1, prio2;

	if (argc == 1)
	{
		printf("Pl enter prio1 prio1\n");
		exit (0);
	}

	prio1 = atoi(argv[1]);
	prio2 = atoi(argv[2]);

	mlockall(MCL_CURRENT|MCL_FUTURE);

	rt_print_auto_init(1);

	rt_task_shadow(&task0, "Task 0", 10, 0);

	rt_mutex_create(&mux1, "test_mux1");
	rt_mutex_create(&mux2, "test_mux2");
	rt_mutex_create(&mux3, "test_mux3");
	rt_mutex_create(&mux4, "test_mux4");

	printf("Spawning: tasks\n");
	rt_task_spawn(&task1, "TTTTTTTTTTT", 0, prio1, 0, task1_func, NULL);
	rt_task_spawn(&task2, "TASK2", 0, prio2, 0, task2_func, NULL);

	while (1) {
		rt_task_sleep(5000000LL);
	}
}

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

end of thread, other threads:[~2012-01-23 15:01 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-09 20:50 [Xenomai-help] Issue with Auto relax and nested mutexes Makarand Pradhan
2012-01-10 15:11 ` Philippe Gerum
2012-01-10 15:26   ` Makarand Pradhan
2012-01-10 15:38     ` Philippe Gerum
2012-01-10 15:40     ` Makarand Pradhan
2012-01-10 15:40       ` Philippe Gerum
2012-01-10 15:42         ` Philippe Gerum
2012-01-10 15:51           ` Makarand Pradhan
2012-01-10 17:51             ` Philippe Gerum
2012-01-10 18:08             ` Philippe Gerum
2012-01-10 18:39               ` Makarand Pradhan
2012-01-10 19:10                 ` Makarand Pradhan
2012-01-10 20:30                   ` Philippe Gerum
2012-01-18 22:41                   ` Makarand Pradhan
2012-01-19 10:17                     ` Gilles Chanteperdrix
2012-01-19 11:25                     ` Philippe Gerum
2012-01-19 12:29                       ` Gilles Chanteperdrix
2012-01-19 15:35                         ` Makarand Pradhan
2012-01-19 15:22                       ` Makarand Pradhan
2012-01-19 15:49                         ` Philippe Gerum
2012-01-19 16:22                           ` Makarand Pradhan
2012-01-19 16:39                             ` Makarand Pradhan
2012-01-23 15:01                               ` Makarand Pradhan

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.