Skip to contentSkip to conversation

Deviation in Xenomai-Solo from vxWorks behaviour

Xenomai-core Niklaus Giger 2 participants 5 messages Sep 14, 2008 – Sep 15, 2008

lore
Share & tools
lore
#0 lore raw

Hi

The attached program works fine under vxWorks 6.6 (powerpc). Running it under the current xenomai-solo (trunk) on my GNU/Debian x86 system it gets stuck at line 82:

Here is the output from vxWorks

Quoted 7 lines

timex tSysMain
assert passed at tSysMain line 66
assert passed at tSysMain line 67
assert passed at tSysMain line 70
assert passed at tSysMain line 71
assert passed at tSysMain line 74
assert passed at tSysMain line 75

Quoted 8 lines

assert passed at tSysMain line 77
assert passed at tSysMain line 78
assert passed at tSysMain line 79
assert passed at tSysMain line 80
assert passed at tSysMain line 82
assert passed at tSysMain line 83
tSysMain done
timex: time of execution = 600 +/- 2 (0%) millisecs

whereas my gdb reports the following

Quoted 26 lines

Starting program:
/home/hcu/celsius/project/metaFrame/bin/BSys/mak/xeno_vx-solo/debug/tst [Thread debugging using libthread_db enabled]
[New Thread 0xb7c056c0 (LWP 32206)]
[New Thread 0xb7f02b90 (LWP 32210)]
[New Thread 0xb7ef1b90 (LWP 32213)]
assert passed at testTask line 66
assert passed at testTask line 67
assert passed at testTask line 70
assert passed at testTask line 71
assert passed at testTask line 74
assert passed at testTask line 75
assert passed at testTask line 77
assert passed at testTask line 78
assert passed at testTask line 79
assert passed at testTask line 80
^C
Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb7c056c0 (LWP 32206)]
0xb7f05424 in __kernel_vsyscall ()
(gdb) t 3
[Switching to thread 3 (Thread 0xb7ef1b90 (LWP 32213))]#0 0xb7f05424 in __kernel_vsyscall () (gdb) i s
#0 0xb7f05424 in __kernel_vsyscall ()
#1 0xb7e9b025 in [email protected] () from /lib/i686/cmov/libpthread.so.0 #2 0xb7eaff2f in syncobj_pend

Quoted 8 lines

(sobj=0x83fd0d0, timeout=0x0, syns=0xb7ef12a4) at syncobj.c:152 #3 0xb7ebff80 in xsem_take (sem=0x83fd0c8, timeout=-1) at semLib.c:83 #4 0xb7ec0837 in semTake (sem_id=138399944, timeout=-1) at semLib.c:404 #5 0x08048a8d in testTask (a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a8=0, a9=0, a10=0) at ../../BSys/src/tst_main.cpp:82 #6 0xb7ec116b in task_trampoline (arg=0x83fcee8) at taskLib.c:255 #7 0xb7e974c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #8 0xb7ceb55e in clone () from /lib/i686/cmov/libc.so.6

It looks like under xenomai a failing semTake(aSemaphore, nWaitTime)) erroneously decrements the counter instead of leaving .

Best regards

Signature · 1 line
NIklaus Giger

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#if defined(__SOLO__) || defined(_WRS_VXWORKS_MAJOR) // #include <vxWorks.h>
#include <semLib.h>
#include <taskLib.h>
#include <tickLib.h>
#include <kernelLib.h>

void testTask(long a1, long a2, long a3, long a4, long a5,

	long a6, long a7, long a8, long a9, long a10);

bool finished;

#endif

#undef FOREVER
#define FOREVER -1

#define OK 0
#ifndef ERROR
#define ERROR -1
#endif

#define assert(cond) \
if (!cond) printf("assert failed at %s line %d\n", __FUNCTION__, __LINE__); \
else printf("assert passed at %s line %d\n", __FUNCTION__, __LINE__);

/**
* Main functions
*/
#if defined(PLAT_VXWORKS) || defined(_WRS_VXWORKS_MAJOR)

extern "C" int tSysMain(const char* arg)

  {
    const char* argv[2];
    argv[0]  = "undefined";
    argv[1]  = arg;
    int argc = sizeof(argv) / sizeof(char*);

#else

int main(int argc, char *const argv[])
{
#endif

#ifdef __SOLO__

    kernelInit(testTask, argc, argv);
    while(!finished) { sleep(1); }
    exit(0);
}

void testTask(long a1, long a2, long a3, long a4, long a5,
long a6, long a7, long a8, long a9, long a10)
{
int argc=0; char *const argv[]={0};
#endif
const unsigned long nWaitTime = 100;
const unsigned long nToleranace = 20;
const unsigned long nToleranceWaitTime = nWaitTime-nToleranace;

  int res, start, now;
  SEM_ID aSemaphore = semCCreate(SEM_Q_PRIORITY, 0);
  // test 3 time with timeout which must fail
  start = tickGet();
  assert(ERROR ==semTake(aSemaphore, nWaitTime));
  assert((tickGet() - start) >= nToleranceWaitTime);

  start = tickGet();
  assert(ERROR ==semTake(aSemaphore, nWaitTime));
  assert((tickGet() - start) >= nToleranceWaitTime);

  start = tickGet();
  assert(ERROR ==semTake(aSemaphore, nWaitTime));
  assert((tickGet() - start) >= nToleranceWaitTime);

  assert(OK == semGive(aSemaphore));
  assert(OK == semTake(aSemaphore, nWaitTime));
  assert(OK == semGive(aSemaphore));
  assert(OK == semGive(aSemaphore));

assert(OK == semTake(aSemaphore, FOREVER));
assert(OK == semTake(aSemaphore, FOREVER));
printf("%s done\n", __FUNCTION__);
#ifdef __SOLO__
finished = true;
return;
#else
return 0;
#endif
}

// ___________________________________________________________________________

#1 lore raw
Quoted 22 lines · Niklaus Giger

Hi

The attached program works fine under vxWorks 6.6 (powerpc). Running it under the current xenomai-solo (trunk) on my GNU/Debian x86 system it gets stuck at line 82:

Here is the output from vxWorks

Quoted 7 lines

timex tSysMain
assert passed at tSysMain line 66
assert passed at tSysMain line 67
assert passed at tSysMain line 70
assert passed at tSysMain line 71
assert passed at tSysMain line 74
assert passed at tSysMain line 75

Quoted 8 lines

assert passed at tSysMain line 77
assert passed at tSysMain line 78
assert passed at tSysMain line 79
assert passed at tSysMain line 80
assert passed at tSysMain line 82
assert passed at tSysMain line 83
tSysMain done
timex: time of execution = 600 +/- 2 (0%) millisecs

Quoted 1 line

whereas my gdb reports the following

Forget about gdb: it is known to affect the threading order. Does the wrong behaviour also happen when running the program without GDB?

Quoted 47 lines
Quoted 26 lines

Starting program:
/home/hcu/celsius/project/metaFrame/bin/BSys/mak/xeno_vx-solo/debug/tst [Thread debugging using libthread_db enabled]
[New Thread 0xb7c056c0 (LWP 32206)]
[New Thread 0xb7f02b90 (LWP 32210)]
[New Thread 0xb7ef1b90 (LWP 32213)]
assert passed at testTask line 66
assert passed at testTask line 67
assert passed at testTask line 70
assert passed at testTask line 71
assert passed at testTask line 74
assert passed at testTask line 75
assert passed at testTask line 77
assert passed at testTask line 78
assert passed at testTask line 79
assert passed at testTask line 80
^C
Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb7c056c0 (LWP 32206)]
0xb7f05424 in __kernel_vsyscall ()
(gdb) t 3
[Switching to thread 3 (Thread 0xb7ef1b90 (LWP 32213))]#0 0xb7f05424 in __kernel_vsyscall () (gdb) i s
#0 0xb7f05424 in __kernel_vsyscall ()
#1 0xb7e9b025 in [email protected] () from /lib/i686/cmov/libpthread.so.0 #2 0xb7eaff2f in syncobj_pend

Quoted 8 lines

(sobj=0x83fd0d0, timeout=0x0, syns=0xb7ef12a4) at syncobj.c:152 #3 0xb7ebff80 in xsem_take (sem=0x83fd0c8, timeout=-1) at semLib.c:83 #4 0xb7ec0837 in semTake (sem_id=138399944, timeout=-1) at semLib.c:404 #5 0x08048a8d in testTask (a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a8=0, a9=0, a10=0) at ../../BSys/src/tst_main.cpp:82 #6 0xb7ec116b in task_trampoline (arg=0x83fcee8) at taskLib.c:255 #7 0xb7e974c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #8 0xb7ceb55e in clone () from /lib/i686/cmov/libc.so.6

It looks like under xenomai a failing semTake(aSemaphore, nWaitTime)) erroneously decrements the counter instead of leaving .

Best regards

------------------------------------------------------------------------

_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.
#2 lore raw

Am Sonntag 14 September 2008 19.53:13 schrieb Philippe Gerum:

Quoted 25 lines
Quoted 24 lines · Niklaus Giger

Hi

The attached program works fine under vxWorks 6.6 (powerpc). Running it under the current xenomai-solo (trunk) on my GNU/Debian x86 system it gets stuck at line 82:

Here is the output from vxWorks

Quoted 15 lines

timex tSysMain
assert passed at tSysMain line 66
assert passed at tSysMain line 67
assert passed at tSysMain line 70
assert passed at tSysMain line 71
assert passed at tSysMain line 74
assert passed at tSysMain line 75
assert passed at tSysMain line 77
assert passed at tSysMain line 78
assert passed at tSysMain line 79
assert passed at tSysMain line 80
assert passed at tSysMain line 82
assert passed at tSysMain line 83
tSysMain done
timex: time of execution = 600 +/- 2 (0%) millisecs

Quoted 5 lines
Quoted 1 line

whereas my gdb reports the following

Forget about gdb: it is known to affect the threading order. Does the wrong behaviour also happen when running the program without GDB?

Yes. Same behaviour without GDB. I only used gdb because it failed.

Best regards

Signature · 1 line
NIklaus Giger
#3 lore raw
In reply to Philippe Gerum
Quoted 23 lines · Philippe Gerum
Quoted 22 lines · Niklaus Giger

Hi

The attached program works fine under vxWorks 6.6 (powerpc). Running it under the current xenomai-solo (trunk) on my GNU/Debian x86 system it gets stuck at line 82:

Here is the output from vxWorks

Quoted 15 lines

timex tSysMain
assert passed at tSysMain line 66
assert passed at tSysMain line 67
assert passed at tSysMain line 70
assert passed at tSysMain line 71
assert passed at tSysMain line 74
assert passed at tSysMain line 75
assert passed at tSysMain line 77
assert passed at tSysMain line 78
assert passed at tSysMain line 79
assert passed at tSysMain line 80
assert passed at tSysMain line 82
assert passed at tSysMain line 83
tSysMain done
timex: time of execution = 600 +/- 2 (0%) millisecs

Quoted 5 lines
Quoted 1 line

whereas my gdb reports the following

Forget about gdb: it is known to affect the threading order. Does the wrong behaviour also happen when running the program without GDB?

Forget about my previous comment, I misread your description; GDB only affects scheduling when ptraced tasks rely on implicit FIFO ordering like some of the testsuite programs do, but in no case when explicit synchronization (e.g. via sema4s) is involved, of course. I will have a look at the issue and let you know.

Quoted 49 lines
Quoted 47 lines
Quoted 26 lines

Starting program:
/home/hcu/celsius/project/metaFrame/bin/BSys/mak/xeno_vx-solo/debug/tst [Thread debugging using libthread_db enabled]
[New Thread 0xb7c056c0 (LWP 32206)]
[New Thread 0xb7f02b90 (LWP 32210)]
[New Thread 0xb7ef1b90 (LWP 32213)]
assert passed at testTask line 66
assert passed at testTask line 67
assert passed at testTask line 70
assert passed at testTask line 71
assert passed at testTask line 74
assert passed at testTask line 75
assert passed at testTask line 77
assert passed at testTask line 78
assert passed at testTask line 79
assert passed at testTask line 80
^C
Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb7c056c0 (LWP 32206)]
0xb7f05424 in __kernel_vsyscall ()
(gdb) t 3
[Switching to thread 3 (Thread 0xb7ef1b90 (LWP 32213))]#0 0xb7f05424 in __kernel_vsyscall () (gdb) i s
#0 0xb7f05424 in __kernel_vsyscall ()
#1 0xb7e9b025 in [email protected] () from /lib/i686/cmov/libpthread.so.0 #2 0xb7eaff2f in syncobj_pend

Quoted 8 lines

(sobj=0x83fd0d0, timeout=0x0, syns=0xb7ef12a4) at syncobj.c:152 #3 0xb7ebff80 in xsem_take (sem=0x83fd0c8, timeout=-1) at semLib.c:83 #4 0xb7ec0837 in semTake (sem_id=138399944, timeout=-1) at semLib.c:404 #5 0x08048a8d in testTask (a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a8=0, a9=0, a10=0) at ../../BSys/src/tst_main.cpp:82 #6 0xb7ec116b in task_trampoline (arg=0x83fcee8) at taskLib.c:255 #7 0xb7e974c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #8 0xb7ceb55e in clone () from /lib/i686/cmov/libc.so.6

It looks like under xenomai a failing semTake(aSemaphore, nWaitTime)) erroneously decrements the counter instead of leaving .

Best regards

------------------------------------------------------------------------

_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.
#4 lore raw
In reply to Niklaus Giger
Quoted 57 lines · Niklaus Giger

Hi

The attached program works fine under vxWorks 6.6 (powerpc). Running it under the current xenomai-solo (trunk) on my GNU/Debian x86 system it gets stuck at line 82:

Here is the output from vxWorks

Quoted 7 lines

timex tSysMain
assert passed at tSysMain line 66
assert passed at tSysMain line 67
assert passed at tSysMain line 70
assert passed at tSysMain line 71
assert passed at tSysMain line 74
assert passed at tSysMain line 75

Quoted 8 lines

assert passed at tSysMain line 77
assert passed at tSysMain line 78
assert passed at tSysMain line 79
assert passed at tSysMain line 80
assert passed at tSysMain line 82
assert passed at tSysMain line 83
tSysMain done
timex: time of execution = 600 +/- 2 (0%) millisecs

whereas my gdb reports the following

Quoted 26 lines

Starting program:
/home/hcu/celsius/project/metaFrame/bin/BSys/mak/xeno_vx-solo/debug/tst [Thread debugging using libthread_db enabled]
[New Thread 0xb7c056c0 (LWP 32206)]
[New Thread 0xb7f02b90 (LWP 32210)]
[New Thread 0xb7ef1b90 (LWP 32213)]
assert passed at testTask line 66
assert passed at testTask line 67
assert passed at testTask line 70
assert passed at testTask line 71
assert passed at testTask line 74
assert passed at testTask line 75
assert passed at testTask line 77
assert passed at testTask line 78
assert passed at testTask line 79
assert passed at testTask line 80
^C
Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb7c056c0 (LWP 32206)]
0xb7f05424 in __kernel_vsyscall ()
(gdb) t 3
[Switching to thread 3 (Thread 0xb7ef1b90 (LWP 32213))]#0 0xb7f05424 in __kernel_vsyscall () (gdb) i s
#0 0xb7f05424 in __kernel_vsyscall ()
#1 0xb7e9b025 in [email protected] () from /lib/i686/cmov/libpthread.so.0 #2 0xb7eaff2f in syncobj_pend

Quoted 8 lines

(sobj=0x83fd0d0, timeout=0x0, syns=0xb7ef12a4) at syncobj.c:152 #3 0xb7ebff80 in xsem_take (sem=0x83fd0c8, timeout=-1) at semLib.c:83 #4 0xb7ec0837 in semTake (sem_id=138399944, timeout=-1) at semLib.c:404 #5 0x08048a8d in testTask (a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a8=0, a9=0, a10=0) at ../../BSys/src/tst_main.cpp:82 #6 0xb7ec116b in task_trampoline (arg=0x83fcee8) at taskLib.c:255 #7 0xb7e974c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #8 0xb7ceb55e in clone () from /lib/i686/cmov/libc.so.6

Quoted 3 lines

It looks like under xenomai a failing semTake(aSemaphore, nWaitTime)) erroneously decrements the counter instead of leaving .

You were 100% right. The patch below fixes up the sema4 count as required, thanks.

vxworks/semLib.c +8 -5
index 3588160..62f9326 100644
@@ -81,12 +81,15 @@ static STATUS xsem_take(struct wind_sem *sem, int timeout)
 		timespec = NULL;
 
 	ret = syncobj_pend(&sem->u.xsem.sobj, timespec, &syns);
-	if (ret == -ETIMEDOUT)
-		ret = S_objLib_OBJ_TIMEOUT;
-	else if (ret == -EINTR)
-		ret = OK;	/* Flushed. */
-	else if (ret == -EIDRM)
+	if (ret == -EIDRM)
 		return S_objLib_OBJ_DELETED;
+	if (ret) {
+		sem->u.xsem.value++;
+		if (ret == -ETIMEDOUT)
+			ret = S_objLib_OBJ_TIMEOUT;
+		else if (ret == -EINTR)
+			ret = OK;	/* Flushed. */
+	}
 done:
 	syncobj_unlock(&sem->u.xsem.sobj, &syns);
 
Signature · 1 line
Philippe.