All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] debug posix skin - pthread_cond_wait return EPERM
@ 2011-01-20  8:03 Pierre.QUELIN
  2011-01-20  8:28 ` Kolja Waschk
  0 siblings, 1 reply; 30+ messages in thread
From: Pierre.QUELIN @ 2011-01-20  8:03 UTC (permalink / raw)
  To: xenomai

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



Dear,

I am trying to debug a posix application and I noticed what I think is a
bug in the method pthread_cond_wait (). it returns EPERM when the
application is started with gdb.
Could you please help me to understand what is wrong or locate the bug?

Best regards.

Pierre Quélin

------------------------------------
Configuration
------------------------------------
Ubuntu 10.10
Linux xenomai 2.6.35.7-core2xeon-adeos-2.8-00 #1 SMP PREEMPT Mon Dec 6
13:37:41 CET 2010 i686 GNU/Linux

Gnu C 4.4.4-14ubuntu5)
GNU gdb (GDB) 7.2-ubuntu
Gnu make 3.81
util-linux ng 2.17.2)
mount ng 2.17.2 (with libblkid and selinux support)
module-init-tools 3.12
e2fsprogs 1.41.12
Linux C Library 2.12.1
Dynamic linker (ldd) 2.12.1
Procps 3.2.8
Net-tools 1.60
Kbd 1.15
Sh-utils 8.5
Modules Loaded ip6table_filter ip6_tables binfmt_misc ipt_MASQUERADE
iptable_nat nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_state nf_conntrack
ipt_REJECT xt_tcpudp iptable_filter ip_tables x_tables bridge stp kvm_intel
kvm parport_pc ppdev arc4 rt73usb crc_itu_t rt2x00usb rt2x00lib led_class
i3200_edac edac_core mac80211 lp psmouse serio_raw cfg80211 parport hed
floppy e1000 e1000e

------------------------------------
Code
------------------------------------
#include <sys/mman.h> /* line 0 */
#include <pthread.h>

void* bodyA(void*)
{
   pthread_cond_t cond;
   pthread_mutex_t mutex;
   pthread_mutexattr_t attr;
   int res;

   res = pthread_mutexattr_init( &attr );
   res = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
   res = pthread_mutex_init( &mutex, &attr );
   res = pthread_mutexattr_destroy( &attr );
   res = pthread_cond_init( &cond, NULL );

   bool state = false;
   res = pthread_mutex_lock( &mutex );
   while ( !state )
   {
      res = pthread_cond_wait( &cond, &mutex );
      if ( 0 != res )
      {
         res = pthread_mutex_unlock( &mutex );
         return (void*)-1;
      }
      else
      {
         (void)res;
      }
   }
   state = true;
   res = pthread_mutex_unlock( &mutex );

   return 0;
};

void* bodyB(void*)
{
   pthread_cond_t cond;
   pthread_mutex_t mutex;
   pthread_mutexattr_t attr;
   int res;

   res = pthread_mutexattr_init( &attr );
   res = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
   res = pthread_mutex_init( &mutex, &attr );
   res = pthread_mutexattr_destroy( &attr );
   res = pthread_cond_init( &cond, NULL );

   bool state = false;
   res = pthread_mutex_lock( &mutex );
   while ( !state )
   {
      res = pthread_cond_wait( &cond, &mutex );
      if ( 0 != res )
      {
         res = pthread_mutex_unlock( &mutex );
         return (void*)-1;
      }
      else
      {
         (void)res;
      }
   }
   state = true;
   res = pthread_mutex_unlock( &mutex );

   return 0;
};

#define DEFAULT_PRIORITY 100
#define HIGHEST_PRIORITY 2
#define LOWEST_PRIORITY 255

#define wind_normalized_prio(prio, sched_type)  \
  ({ int __p = sched_get_priority_min(sched_type) + ( ( ( LOWEST_PRIORITY -
(prio) ) * ( sched_get_priority_max(sched_type) - sched_get_priority_min
(sched_type) ) ) / LOWEST_PRIORITY ); __p; })

int main()
{
   mlockall(MCL_CURRENT | MCL_FUTURE);

   struct sched_param parA;
   parA.sched_priority = wind_normalized_prio(DEFAULT_PRIORITY,
SCHED_FIFO);
   pthread_t threadA;
   pthread_attr_t pthread_attrA;
   int res;

   res = pthread_attr_init(&pthread_attrA);
   res = pthread_attr_setinheritsched (&pthread_attrA,
PTHREAD_EXPLICIT_SCHED);
   res = pthread_attr_setschedpolicy (&pthread_attrA, SCHED_FIFO);
   res = pthread_attr_setschedparam( &pthread_attrA, &parA );
   res = pthread_create( &threadA, &pthread_attrA, bodyA, NULL );
#ifdef __XENO__
   pthread_set_name_np( threadA, "threadA" );
#endif
   res = pthread_attr_destroy( &pthread_attrA );



   struct sched_param parB;
   parB.sched_priority = wind_normalized_prio(DEFAULT_PRIORITY,
SCHED_FIFO);
   pthread_t threadB;
   pthread_attr_t pthread_attrB;

   res = pthread_attr_init(&pthread_attrB);
   res = pthread_attr_setinheritsched (&pthread_attrB,
PTHREAD_EXPLICIT_SCHED);
   res = pthread_attr_setschedpolicy (&pthread_attrB, SCHED_FIFO);
   pthread_attr_setschedparam( &pthread_attrB, &parB );
   res = pthread_create( &threadB, &pthread_attrB, bodyB, NULL );
#ifdef __XENO__
   pthread_set_name_np( threadB, "threadB" );
#endif
   res = pthread_attr_destroy( &pthread_attrB );


   pthread_cond_t cond;
   pthread_mutex_t mutex;
   pthread_mutexattr_t attr;

   res = pthread_mutexattr_init( &attr );
   res = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
   res = pthread_mutex_init( &mutex, &attr );
   res = pthread_mutexattr_destroy( &attr );
   res = pthread_cond_init( &cond, NULL );

   bool state = false;
   res = pthread_mutex_lock( &mutex );
   while ( !state )
   {
      res = pthread_cond_wait( &cond, &mutex );
      if ( 0 != res )
      {
         res = pthread_mutex_unlock( &mutex );
         return -1;
      }
      else
      {
         (void)res;
      }
   }
   state = true;
   res = pthread_mutex_unlock( &mutex );

   return 0;
}

------------------------------------
Linux without gdb : Ok
------------------------------------

------------------------------------
Linux with gdb : Ok
------------------------------------
Thread [3] 5111 (Suspended : Container)
__kernel_vsyscall() at 0xb7fe1424
pthread_cond_wait@domain.hid()
at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:142
 0xb7fbd4ad
bodyB() at /home/generation/Projets/PosixTest/src/Main.cpp:55 0x8048af1
start_thread() at pthread_create.c:304 0xb7fb8cc9
clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130 0xb7e1469e

Thread [2] 5110 (Suspended : Container)
__kernel_vsyscall() at 0xb7fe1424
pthread_cond_wait@domain.hid()
at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:142
 0xb7fbd4ad
bodyA() at /home/generation/Projets/PosixTest/src/Main.cpp:21 0x8048a01
start_thread() at pthread_create.c:304 0xb7fb8cc9
clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130 0xb7e1469e

Thread [1] 5106 (Suspended : Signal : SIGINT:Interrupt)
__kernel_vsyscall() at 0xb7fe1424
pthread_cond_wait@domain.hid()
at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:142
 0xb7fbd4ad
main() at /home/generation/Projets/PosixTest/src/Main.cpp:131 0x8048dfa

------------------------------------
Xenomai without gdb : Ok
------------------------------------
generation@domain.hid$ cat /proc/xenomai/sched
CPU PID CLASS PRI TIMEOUT TIMEBASE STAT NAME
0 0 idle -1 - master R ROOT/0
1 0 idle -1 - master R ROOT/1
0 5025 rt 0 - master W PosixTest
0 5026 rt 60 - master W threadA
0 5027 rt 60 - master W threadB

------------------------------------
Xenomai with gdb : Nok
------------------------------------

->Step 1 : (break point on pthread_cond_wait)

Thread [2] 5193 (Suspended : Breakpoint)
bodyA() at /home/generation/Projets/PosixTest/src/Main.cpp:21 0x8048b0f
0xb7fc30b2
start_thread() at pthread_create.c:304 0xb7fa4cc9
clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130 0xb7df869e

Thread [1] 5188 (Suspended : Container)
__kernel_vsyscall() at 0xb7fe1424
mmap() at ../sysdeps/unix/sysv/linux/i386/mmap.S:62 0xb7df4a88
allocate_stack() at allocatestack.c:489 0xb7fa563b
__pthread_create_2_1() at pthread_create.c:458 0xb7fa563b
__real_pthread_create() at 0xb7fca382
__wrap_pthread_create() at 0xb7fc2e2f
main() at /home/generation/Projets/PosixTest/src/Main.cpp:110 0x8048e7e

->Step 2 : break point after pthread_cond_wait. pthread_cond_wait retrun 1
(EPERM)

Thread [3] 5204 (Suspended : Container)
__kernel_vsyscall() at 0xb7fe1424
__lll_lock_wait_private()
at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/lowlevellock.S:95
0xb7fac133
_L_lock_2466() at 0xb7fa5d2a
start_thread() at pthread_create.c:295 0xb7fa4ec1
clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130 0xb7df869e

Thread [2] 5193 (Suspended : Step)
bodyA() at /home/generation/Projets/PosixTest/src/Main.cpp:22 0x8048b24
0xb7fc30b2
start_thread() at pthread_create.c:304 0xb7fa4cc9
clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130 0xb7df869e

Thread [1] 5188 (Suspended : Container)

[-- Attachment #2: Type: text/html, Size: 9214 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [Xenomai-help] debug posix skin - pthread_cond_wait return EPERM
@ 2011-01-21  8:43 Pierre.QUELIN
  2011-01-22 14:39 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 30+ messages in thread
From: Pierre.QUELIN @ 2011-01-21  8:43 UTC (permalink / raw)
  To: gilles.chanteperdrix; +Cc: xenomai

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



> Kolja Waschk wrote:
>>>> file cond-torture-posix
>>> Ok. On my side: I call set solib-absolute-prefix to where the debug
>>> binaries for the target filesystem are. And I call
>>> handle SIG34 nostop noprint pass.
>>>
>>> Coud you try and do the same?
>> Is SIG34 the same on blackfin? I do not remember ever having seen SIG34,
only
>> SIG32 ("Real-time event 32")
>>
>> Independent of that, the result is always the same SEGV. I cannot use
the absolute-prefix currently, as the directory layout is different on the
target. So my script is now
>>
>> set solib-absolute-prefix notexistent
>> set
solib-search-path /opt/uClinux/blackfin-linux-dist/staging/usr/lib:/opt/uClinux/bfin-linux-uclibc/bfin-linux-uclibc/runtime/lib

>> file cond-torture-posix
>> handle SIG34 nostop noprint pass
>> target remote 10.0.10.9:2222
>>
>> And regardless whether I add an "break main", the SEGV will occur
immediately after telling gdb to "cont".
>>
>> Does my "try.c" always succeed (all errbits=0x0010) in your environment?
>
> Ok, I get the failure if I set up a breakpoint right after the call to
> pthread_cond_wait, as noted by Pierre. After some debugging, it appears
> that the syscall is restarted whereas it should return to user-spacce
> and let the user-space skin do its job. So, it seems that somehow, the
> behaviour is different for gdb signals than for usual signals.
>
> Working on it now, will tell you when we have a status.

The following patch seems to fix the issue, but I am not yet sure
whether it is really correct:

diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c
index d27494c..717a8a0 100644
--- a/ksrc/nucleus/shadow.c
+++ b/ksrc/nucleus/shadow.c
@@ -770,7 +770,7 @@ static inline void request_syscall_restart(xnthread_t
*thread,
                         if (__xn_interrupted_p(regs)) {
                                     __xn_error_return(regs,
                                                               (sysflags &
__xn_exec_norestart) ?
-
-ERESTARTNOHAND : -ERESTARTSYS);
+                                                              -EINTR :
-ERESTARTSYS);
                                     notify = !xnthread_test_state(thread,
XNDEBUG);
                         }



--
                                                                Gilles.

Sorry but I'm a novice.

As I understand, your patch is a kernel patch and I need to rebuild the
kernel package.
Where can I find the cond-torture-posix application to reproduce the
problem with your test case ?
My PC is a very standard one (Xeon dual core and my distro an Ubuntu 10.10
so I think it's very easy to reproduce the test case.
Do you know if there is a bug tracker where tickets are logged to be
informed when this point will be solved ?

Thank you for you help.

Pierre Quélin

[-- Attachment #2: Type: text/html, Size: 3717 bytes --]

^ permalink raw reply related	[flat|nested] 30+ messages in thread
* Re: [Xenomai-help] debug posix skin - pthread_cond_wait return EPERM
@ 2011-01-24 14:57 Pierre.QUELIN
  0 siblings, 0 replies; 30+ messages in thread
From: Pierre.QUELIN @ 2011-01-24 14:57 UTC (permalink / raw)
  To: gilles.chanteperdrix; +Cc: xenomai

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



>Gilles Chanteperdrix wrote:
>
>Pierre.QUELIN@solystic.com wrote:
>>
>>> Kolja Waschk wrote:
>>>>>> file cond-torture-posix
>>>>> Ok. On my side: I call set solib-absolute-prefix to where the debug
>>>>> binaries for the target filesystem are. And I call
>>>>> handle SIG34 nostop noprint pass.
>>>>>
>>>>> Coud you try and do the same?
>>>> Is SIG34 the same on blackfin? I do not remember ever having seen
SIG34,
>> only
>>>> SIG32 ("Real-time event 32")
>>>>
>>>> Independent of that, the result is always the same SEGV. I cannot use
>> the absolute-prefix currently, as the directory layout is different on
the
>> target. So my script is now
>>>> set solib-absolute-prefix notexistent
>>>> set
>>
solib-search-path /opt/uClinux/blackfin-linux-dist/staging/usr/lib:/opt/uClinux/bfin-linux-uclibc/bfin-linux-uclibc/runtime/lib
>>
>>>> file cond-torture-posix
>>>> handle SIG34 nostop noprint pass
>>>> target remote 10.0.10.9:2222
>>>>
>>>> And regardless whether I add an "break main", the SEGV will occur
>> immediately after telling gdb to "cont".
>>>> Does my "try.c" always succeed (all errbits=0x0010) in your
environment?
>>> Ok, I get the failure if I set up a breakpoint right after the call to
>>> pthread_cond_wait, as noted by Pierre. After some debugging, it appears
>>> that the syscall is restarted whereas it should return to user-spacce
>>> and let the user-space skin do its job. So, it seems that somehow, the
>>> behaviour is different for gdb signals than for usual signals.
>>>
>>> Working on it now, will tell you when we have a status.
>>
>> The following patch seems to fix the issue, but I am not yet sure
>> whether it is really correct:
>>
>> diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c
>> index d27494c..717a8a0 100644
>> --- a/ksrc/nucleus/shadow.c
>> +++ b/ksrc/nucleus/shadow.c
>> @@ -770,7 +770,7 @@ static inline void request_syscall_restart
(xnthread_t
>> *thread,
>>                          if (__xn_interrupted_p(regs)) {
>>                                      __xn_error_return(regs,
>>                                                                (sysflags
&
>> __xn_exec_norestart) ?
>> -
>> -ERESTARTNOHAND : -ERESTARTSYS);
>> +                                                              -EINTR :
>> -ERESTARTSYS);
>>                                      notify = !xnthread_test_state
(thread,
>> XNDEBUG);
>>                          }
>>
>>
>>
>> --
>>                                                                 Gilles.
>>
>> Sorry but I'm a novice.
>>
>> As I understand, your patch is a kernel patch and I need to rebuild the
>> kernel package.
>
>Yes.
>
>> Where can I find the cond-torture-posix application to reproduce the
>> problem with your test case ?
>
>It is part of Xenomai installation.
>
>> My PC is a very standard one (Xeon dual core and my distro an Ubuntu
10.10
>> so I think it's very easy to reproduce the test case.
>> Do you know if there is a bug tracker where tickets are logged to be
>> informed when this point will be solved ?
>
>No. We use the mailing list for this. From our point of view, however,
>the point is solved.

I have not done a lot of tests but it seems to work fine for me in my basic
test case.

Result :
      Thread [3] 2905 (Suspended : Container)
            __kernel_vsyscall() at 0xb7fe1424
            __wrap_pthread_cond_wait() at 0xb7fc4815
            __wrap_pthread_cond_wait() at 0xb7fc479e
            bodyB() at /home/generation/Projets/PosixTest/src/Main.cpp:55
0x8048c11
            0xb7fc30b2
            start_thread() at pthread_create.c:304 0xb7fa4cc9
            clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130
0xb7df869e
      Thread [2] 2904 (Suspended : Container)
            __kernel_vsyscall() at 0xb7fe1424
            __wrap_pthread_cond_wait() at 0xb7fc4815
            __wrap_pthread_cond_wait() at 0xb7fc479e
            bodyA() at /home/generation/Projets/PosixTest/src/Main.cpp:21
0x8048b21
            0xb7fc30b2
            start_thread() at pthread_create.c:304 0xb7fa4cc9
            clone() at ../sysdeps/unix/sysv/linux/i386/clone.S:130
0xb7df869e
      Thread [1] 2900 (Suspended : Signal : SIGINT:Interrupt)
            __kernel_vsyscall() at 0xb7fe1424
            __wrap_pthread_cond_wait() at 0xb7fc4815
            __wrap_pthread_cond_wait() at 0xb7fc479e
            main() at /home/generation/Projets/PosixTest/src/Main.cpp:131
0x8048f42


I don't know if this is the same problem but when I launch the real
application, I have some other troubles link with the debug mode.
I investigate about that and I'll inform you later.

Thank you very much.

>
>Also note that I did not replied to you personally, only to the list,
>because otherwise I receive spam from you.
>

I'm sorry about this.

>--
>                                                                Gilles.

[-- Attachment #2: Type: text/html, Size: 8156 bytes --]

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

end of thread, other threads:[~2011-01-25  9:06 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-20  8:03 [Xenomai-help] debug posix skin - pthread_cond_wait return EPERM Pierre.QUELIN
2011-01-20  8:28 ` Kolja Waschk
2011-01-20 14:55   ` Gilles Chanteperdrix
2011-01-20 16:44     ` Kolja Waschk
2011-01-20 16:56       ` Gilles Chanteperdrix
2011-01-20 17:16         ` Kolja Waschk
2011-01-20 17:30           ` Gilles Chanteperdrix
2011-01-20 18:57             ` Waschk,Kolja
2011-01-20 19:09               ` Gilles Chanteperdrix
2011-01-20 19:22                 ` Waschk,Kolja
2011-01-21 13:09                 ` Kolja Waschk
2011-01-21 14:12                   ` Philippe Gerum
2011-01-21 11:25             ` Kolja Waschk
2011-01-24 12:31               ` Gilles Chanteperdrix
2011-01-25  8:53                 ` Kolja Waschk
2011-01-25  8:51                   ` Gilles Chanteperdrix
2011-01-25  8:55                     ` Gilles Chanteperdrix
2011-01-25  9:06                     ` Kolja Waschk
2011-01-20 18:36           ` Gilles Chanteperdrix
2011-01-20 19:13             ` Gilles Chanteperdrix
2011-01-21 12:03               ` Kolja Waschk
2011-01-21 14:00                 ` Philippe Gerum
2011-01-21 14:16                   ` Kolja Waschk
2011-01-22 15:07                 ` Gilles Chanteperdrix
2011-01-22 15:20                 ` Gilles Chanteperdrix
2011-01-20 17:33         ` [Xenomai-help] gpio Cagnulein
2011-01-20 17:55           ` Gilles Chanteperdrix
2011-01-21  8:43 [Xenomai-help] debug posix skin - pthread_cond_wait return EPERM Pierre.QUELIN
2011-01-22 14:39 ` Gilles Chanteperdrix
2011-01-24 14:57 Pierre.QUELIN

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.