[Xenomai-core] [PULL REQUEST] analogy: sensoray s526 and bug fixes

2010-01-11 Thread Alexis Berlemont
The following changes since commit 3c6b84c9ca7cfc0a9551fd835861f4a05ce7e649:
   Gilles Chanteperdrix (1):
 skins: factor user-space tacks sizes handling code

are available in the git repository at:

   ssh+git://git.xenomai.org/xenomai-abe.git analogy

Alessio Margan (1):
   analogy: rename s526 driver (analogy_s526)

Alexis Berlemont (3):
   analogy: fix the tests of the subdevice flags in the basic checks
   analogy: do not check the range if no range descriptor is found
   analogy: fix an ugly access in NI MIO driver

Simon Boulay (8):
   analogy: add s526 driver
   analogy: some cosmetic change in s526 driver
   analogy: fix misuses of the instruction field data_size
   analogy: [s526] Remove dead code from attach function.
   analogy: [s526] Remove dead code from gpct_insn_config function.
   analogy: [s526] Cleanups; mainly generic comments from skel.c
   analogy: [s526] Remove useless HAVE_DIO option
   analogy: [s526] Cleanups; remove unused defines and variables

  ksrc/drivers/analogy/Config.in |3 +-
  ksrc/drivers/analogy/Kconfig   |1 +
  ksrc/drivers/analogy/Makefile  |3 +-
  ksrc/drivers/analogy/command.c |3 +-
  ksrc/drivers/analogy/instruction.c |2 +-
  .../analogy/national_instruments/mio_common.c  |7 +-
  ksrc/drivers/analogy/sensoray/Config.in|2 +
  ksrc/drivers/analogy/sensoray/Kconfig  |5 +
  ksrc/drivers/analogy/sensoray/Makefile |   30 +
  ksrc/drivers/analogy/sensoray/s526.c   |  755 

  ksrc/drivers/analogy/subdevice.c   |   29 +-
  ksrc/drivers/analogy/transfer.c|3 +-
  12 files changed, 825 insertions(+), 18 deletions(-)
  create mode 100644 ksrc/drivers/analogy/sensoray/Config.in
  create mode 100644 ksrc/drivers/analogy/sensoray/Kconfig
  create mode 100644 ksrc/drivers/analogy/sensoray/Makefile
  create mode 100644 ksrc/drivers/analogy/sensoray/s526.c

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


[Xenomai-core] [PULL REQUEST] 2.5.x maintenance - Preparation to 2.6.33 and fixes

2010-01-11 Thread Philippe Gerum

The following changes since commit c6e02d98c5139dd8088b69e7ad1e36d2603c2c11:
  Gilles Chanteperdrix (1):
hal: adapt to I-pipe patches for Linux 2.6.32+

are available in the git repository at:

  git://git.xenomai.org/xenomai-rpm.git for-upstream

Philippe Gerum (22):
  powerpc: some cleanup in kernel stack vsid handling
  powerpc: silence compiler noise when FPU support is disabled
  powerpc: improve platform detection with --enable-linux-build
  nucleus: fix interrupt masking in rpi_next
  asm-generic: introduce rthal_irq_descp() supporting 2.6.33 and earlier
  arm: use generic rthal_irq_descp()
  nios2: use generic rthal_irq_descp()
  blackfin: use generic rthal_irq_descp()
  x86: use generic rthal_irq_descp()
  powerpc: use generic rthal_irq_descp()
  x86: always check whether irq descriptors are present
  arm: always check whether irq descriptors are present
  blackfin: always check whether irq descriptors are present
  nios2: always check whether irq descriptors are present
  powerpc: always check whether irq descriptors are present
  wrappers: introduce rthal_irqdesc_lock/unlock()
  powerpc: use rthal_irqdesc_lock/unlock()
  arm: use rthal_irqdesc_lock/unlock()
  x86: use rthal_irqdesc_lock/unlock()
  blackfin: use rthal_irqdesc_lock/unlock()
  nios2: use rthal_irqdesc_lock/unlock()
  nucleus: rework skin reference counting

 configure  |9 +++-
 configure.in   |9 +++-
 include/asm-arm/wrappers.h |1 -
 include/asm-blackfin/hal.h |2 -
 include/asm-generic/wrappers.h |   14 ++
 include/asm-nios2/hal.h|2 -
 include/asm-powerpc/bits/pod.h |   71 +--
 include/asm-powerpc/wrappers.h |1 -
 include/asm-x86/wrappers_32.h  |1 -
 include/asm-x86/wrappers_64.h  |1 -
 ksrc/arch/arm/hal.c|   26 +++-
 ksrc/arch/blackfin/hal.c   |   22 --
 ksrc/arch/nios2/hal.c  |   22 --
 ksrc/arch/powerpc/hal.c|   29 ++---
 ksrc/arch/x86/hal-common.c |   22 ++
 ksrc/nucleus/shadow.c  |   90 
 16 files changed, 176 insertions(+), 146 deletions(-)

-- 
Philippe.



___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH] Sensoray 526 analogy driver

2010-01-11 Thread Alexis Berlemont
Hi,

On Mon, Jan 11, 2010 at 5:08 PM, Alessio Margan @ IIT
 wrote:
> Hi,
>
> I try to configure sensoray counters to generate PWM signal
>
> #define SUBD_CNT 0
> #define SUBD_AI 1
> #define SUBD_AO 2
> #define SUBD_DIO 3
>
> insn.type = A4L_INSN_CONFIG;
> insn.idx_subd = SUBD_COUNTER;
> insn.chan_desc = CHAN(channel);
> insn.data_size = sizeof(dataC) / sizeof(dataC[0]);
> insn.data = data;
> data[0] = A4L_INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR;
> data[1] = cmReg.value;
> data[2] = down_ticks;
> data[3] = up_ticks;
>
> ret = a4l_snd_insn(&dsc, &insn);
>
> in a4l_do_insn the subdevice is check in this way but the test for
> counter, and I think also for dio, fails due
> to A4L_SUBD_MASK_SPECIAL bit
>
> #define A4L_SUBD_UNUSED (A4L_SUBD_MASK_SPECIAL|0x1)
> #define A4L_SUBD_COUNTER (A4L_SUBD_MASK_SPECIAL|0x40)
> #define A4L_SUBD_DIO (A4L_SUBD_MASK_SPECIAL|0x20)
>
> /* Checks the subdevice's characteristics */
> if ((subd->flags & A4L_SUBD_UNUSED) != 0) {
> __a4l_err("a4l_do_insn: wrong subdevice selected 0x%X\n",subd->flags);
> return -EINVAL;
> }
>
> there is something wrong or I miss something ?
You miss nothing. There was a bug in the subdevice's flags checking line:
The problem is here: if ((subd->flags & A4L_SUBD_UNUSED) != 0) {

I fixed it in my git repo one week ago.

Either you clone my git repot or you wait for the pull request I will
make tonight.

Regards,

>
> TIA
>
> Alessio
>
>
> --
>
> ISTITUTO ITALIANO
> DI TECNOLOGIA
>
> Alessio Margan
> /Senior Technician/
> mail me 
>
> Via Morego, 30 16163 Genova
> 
>
> www.iit.it 
>
> *Legal Disclaimer*
> This electronic message contains information that is confidential. The
> information is intended for the use of the addressee only. If you are
> not the addressee we would appreciate your notification in this respect.
> Please note that any disclosure, copy, distribution or use of the
> contents of this message is prohibited and may be unlawful. We have
> taken every reasonable precaution to ensure that any kind of attachment
> to this e-mail has been swept for viruses. However, we cannot accept
> liability for any damage sustained as a result of software viruses and
> would advise you to carry out your own virus checks before opening any
> attachment.
> *Avvertenza legale*
> Questo messaggio Email contiene informazioni confidenziali riservate ai
> soli destinatari. Qualora veniate in possesso di tali informazioni senza
> essere definito come destinatario vi reghiamo di leggere le seguenti
> note. Ogni apertura, copia, distribuzione del contenuto del messaggio e
> dei suoi allegati è proibito e potrebbe violare le presenti leggi.
> Abbiamo attivato ogni possibile e ragionevole precauzione per assicurare
> che gli allegati non contengano virus. Comunque non assumeremo alcuna
> responsabilità per ogni eventuale danno causato da virus software e
> simili in quanto è onere del destinatario verificarne l’assenza in ogni
> allegato attuando propri indipendenti controlli.
>
>
> ___
> Xenomai-core mailing list
> Xenomai-core@gna.org
> https://mail.gna.org/listinfo/xenomai-core
>
>
Alexis.

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


[Xenomai-core] [PATCH] Sensoray 526 analogy driver

2010-01-11 Thread Alessio Margan @ IIT
Hi,

I try to configure sensoray counters to generate PWM signal

#define SUBD_CNT 0
#define SUBD_AI 1
#define SUBD_AO 2
#define SUBD_DIO 3

insn.type = A4L_INSN_CONFIG;
insn.idx_subd = SUBD_COUNTER;
insn.chan_desc = CHAN(channel);
insn.data_size = sizeof(dataC) / sizeof(dataC[0]);
insn.data = data;
data[0] = A4L_INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR;
data[1] = cmReg.value;
data[2] = down_ticks;
data[3] = up_ticks;

ret = a4l_snd_insn(&dsc, &insn);

in a4l_do_insn the subdevice is check in this way but the test for 
counter, and I think also for dio, fails due
to A4L_SUBD_MASK_SPECIAL bit

#define A4L_SUBD_UNUSED (A4L_SUBD_MASK_SPECIAL|0x1)
#define A4L_SUBD_COUNTER (A4L_SUBD_MASK_SPECIAL|0x40)
#define A4L_SUBD_DIO (A4L_SUBD_MASK_SPECIAL|0x20)

/* Checks the subdevice's characteristics */
if ((subd->flags & A4L_SUBD_UNUSED) != 0) {
__a4l_err("a4l_do_insn: wrong subdevice selected 0x%X\n",subd->flags);
return -EINVAL;
}

there is something wrong or I miss something ?

TIA

Alessio


-- 

ISTITUTO ITALIANO
DI TECNOLOGIA

Alessio Margan
/Senior Technician/
mail me 

Via Morego, 30 16163 Genova 


www.iit.it 

*Legal Disclaimer*
This electronic message contains information that is confidential. The 
information is intended for the use of the addressee only. If you are 
not the addressee we would appreciate your notification in this respect. 
Please note that any disclosure, copy, distribution or use of the 
contents of this message is prohibited and may be unlawful. We have 
taken every reasonable precaution to ensure that any kind of attachment 
to this e-mail has been swept for viruses. However, we cannot accept 
liability for any damage sustained as a result of software viruses and 
would advise you to carry out your own virus checks before opening any 
attachment.
*Avvertenza legale*
Questo messaggio Email contiene informazioni confidenziali riservate ai 
soli destinatari. Qualora veniate in possesso di tali informazioni senza 
essere definito come destinatario vi reghiamo di leggere le seguenti 
note. Ogni apertura, copia, distribuzione del contenuto del messaggio e 
dei suoi allegati è proibito e potrebbe violare le presenti leggi. 
Abbiamo attivato ogni possibile e ragionevole precauzione per assicurare 
che gli allegati non contengano virus. Comunque non assumeremo alcuna 
responsabilità per ogni eventuale danno causato da virus software e 
simili in quanto è onere del destinatario verificarne l’assenza in ogni 
allegato attuando propri indipendenti controlli.


___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH 1/1] rtdk: various fixes.

2010-01-11 Thread Gilles Chanteperdrix
Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> Jan Kiszka wrote:
>>> Gilles Chanteperdrix wrote:
 When exiting a process, rtdk buffers are not flushed. Fix that by
 introducing a destructor for the library which flushes the buffers.

 When forking, if the main thread has an rt_printf buffer, it is reused by
 the child, which is a good thing, however, it is not emptied, so could 
 cause
 the same message to be printed twice. Fix that by emptying the main thread
 buffer upon fork.

 When spawning the rt_print thread, it uses a stack size of
 PTHREAD_STACK_MIN, which may be too small for printf to work reliably on
 some architectures, set the stack size to the
 empirically-known-to-be-working size of... 32Kb.
 ---
  src/rtdk/init.c |5 +
  src/rtdk/internal.h |1 +
  src/rtdk/rt_print.c |   21 -
  3 files changed, 26 insertions(+), 1 deletions(-)

 diff --git a/src/rtdk/init.c b/src/rtdk/init.c
 index 2084c73..b864175 100644
 --- a/src/rtdk/init.c
 +++ b/src/rtdk/init.c
 @@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void 
 __init_rtdk(void)
  {
__rt_print_init();
  }
 +
 +static __attribute__ ((destructor)) void __exit_rtdk(void)
 +{
 +  __rt_print_exit();
 +}
 diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
 index bd15b2d..345d4fa 100644
 --- a/src/rtdk/internal.h
 +++ b/src/rtdk/internal.h
 @@ -23,6 +23,7 @@
  #include 
  
  void __rt_print_init(void);
 +void __rt_print_exit(void);
  
  void __real_free(void *ptr);
  void *__real_malloc(size_t size);
 diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
 index c6b5c55..dae7d7b 100644
 --- a/src/rtdk/rt_print.c
 +++ b/src/rtdk/rt_print.c
 @@ -455,7 +455,7 @@ static void spawn_printer_thread(void)
pthread_attr_t thattr;
  
pthread_attr_init(&thattr);
 -  pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
 +  pthread_attr_setstacksize(&thattr, 32768);
>>> Mmh... maybe rather $something +PTHREAD_STACK_MIN?
>> No, PTHREAD_STACK_MIN sucks, it is not appropriate, and have very
>> varying values on different platforms. On some plaforms, with some
>> versions of glibc, it is 4096, way too small, so that printf generates a
>> segfault due to a stack overflow.
>>
>> However, due to the work done when solving the stack issue reported by
>> Stefan, I hid the magic constants in a function called xeno_stacksize
>> and xeno_stacksize(0) gives a reasonnable default value.
> 
> OK, then go for this service (is it already merged)?

it is pending, was waiting for Stefan confirmation that it fixed his
issue, should be pushed soon.

-- 
Gilles Chanteperdrix, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH 1/1] rtdk: various fixes.

2010-01-11 Thread Gilles Chanteperdrix
Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> Jan Kiszka wrote:
>>> Gilles Chanteperdrix wrote:
 When exiting a process, rtdk buffers are not flushed. Fix that by
 introducing a destructor for the library which flushes the buffers.

 When forking, if the main thread has an rt_printf buffer, it is reused by
 the child, which is a good thing, however, it is not emptied, so could 
 cause
 the same message to be printed twice. Fix that by emptying the main thread
 buffer upon fork.

 When spawning the rt_print thread, it uses a stack size of
 PTHREAD_STACK_MIN, which may be too small for printf to work reliably on
 some architectures, set the stack size to the
 empirically-known-to-be-working size of... 32Kb.
 ---
  src/rtdk/init.c |5 +
  src/rtdk/internal.h |1 +
  src/rtdk/rt_print.c |   21 -
  3 files changed, 26 insertions(+), 1 deletions(-)

 diff --git a/src/rtdk/init.c b/src/rtdk/init.c
 index 2084c73..b864175 100644
 --- a/src/rtdk/init.c
 +++ b/src/rtdk/init.c
 @@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void 
 __init_rtdk(void)
  {
__rt_print_init();
  }
 +
 +static __attribute__ ((destructor)) void __exit_rtdk(void)
 +{
 +  __rt_print_exit();
 +}
 diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
 index bd15b2d..345d4fa 100644
 --- a/src/rtdk/internal.h
 +++ b/src/rtdk/internal.h
 @@ -23,6 +23,7 @@
  #include 
  
  void __rt_print_init(void);
 +void __rt_print_exit(void);
  
  void __real_free(void *ptr);
  void *__real_malloc(size_t size);
 diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
 index c6b5c55..dae7d7b 100644
 --- a/src/rtdk/rt_print.c
 +++ b/src/rtdk/rt_print.c
 @@ -455,7 +455,7 @@ static void spawn_printer_thread(void)
pthread_attr_t thattr;
  
pthread_attr_init(&thattr);
 -  pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
 +  pthread_attr_setstacksize(&thattr, 32768);
>>> Mmh... maybe rather $something +PTHREAD_STACK_MIN?
>> No, PTHREAD_STACK_MIN sucks, it is not appropriate, and have very
>> varying values on different platforms. On some plaforms, with some
>> versions of glibc, it is 4096, way too small, so that printf generates a
>> segfault due to a stack overflow.
>>
>> However, due to the work done when solving the stack issue reported by
>> Stefan, I hid the magic constants in a function called xeno_stacksize
>> and xeno_stacksize(0) gives a reasonnable default value.
> 
> OK, then go for this service (is it already merged)?
> 
pthread_create(&printer_thread, &thattr, printer_loop, NULL);
  }
  
 @@ -464,6 +464,15 @@ static void forked_child_init(void)
struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
struct print_buffer **pbuffer = &first_buffer;
  
 +  if (my_buffer) {
 +  /* Any content of my_buffer should be printed by our parent,
 + not us. */
 +  memset(my_buffer->ring, 0, my_buffer->size);
 +
 +  my_buffer->read_pos  = 0;
 +  my_buffer->write_pos = 0;
 +  }
 +
>>> Ack.
>>>
/* re-init to avoid finding it locked by some parent thread */
pthread_mutex_init(&buffer_lock, NULL);
  
 @@ -518,3 +527,13 @@ void __rt_print_init(void)
spawn_printer_thread();
pthread_atfork(NULL, NULL, forked_child_init);
  }
 +
 +void __rt_print_exit(void)
 +{
 +  if (buffers) {
 +  /* Flush the buffers. Do not call print_buffers here
 +   * since we do not know if our stack is big enough. */
 +  nanosleep(&print_period, NULL);
 +  nanosleep(&print_period, NULL);
 +  }
 +}
>>> IIRC, that's what cleanup_buffer is supposed to do, triggered by the
>>> pthread key destruction. Can you explain why it failed in your scenario.
>> pthread_key destruction is called when a thread is cancelled. My
>> testcase was calling exit.
> 
> exit() does not trigger these cleanup hooks? Too bad.
> 
>> Besides, cleanup_buffer flushes the buffers
>> from the context of the calling thread, which is a bad idea, due to the
>> stack sizes situation.
> 
> If a thread requesting rt_printk services is not capable of performing
> this work during it's cleanup, when there is no significant stack load,
> I would say it's misconfigured /wrt stack size.

Ok, but is is printf which causes the significant stack load. It is fine
with me. However, in the case of exit, the main thread is not even
necessarily supposed to be able to call rt_printf, so, I think leaving
the job to the printing thread is better.

-- 
Gilles Chanteperdrix, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

__

Re: [Xenomai-core] [PATCH 1/1] rtdk: various fixes.

2010-01-11 Thread Jan Kiszka
Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
>> Gilles Chanteperdrix wrote:
>>> When exiting a process, rtdk buffers are not flushed. Fix that by
>>> introducing a destructor for the library which flushes the buffers.
>>>
>>> When forking, if the main thread has an rt_printf buffer, it is reused by
>>> the child, which is a good thing, however, it is not emptied, so could cause
>>> the same message to be printed twice. Fix that by emptying the main thread
>>> buffer upon fork.
>>>
>>> When spawning the rt_print thread, it uses a stack size of
>>> PTHREAD_STACK_MIN, which may be too small for printf to work reliably on
>>> some architectures, set the stack size to the
>>> empirically-known-to-be-working size of... 32Kb.
>>> ---
>>>  src/rtdk/init.c |5 +
>>>  src/rtdk/internal.h |1 +
>>>  src/rtdk/rt_print.c |   21 -
>>>  3 files changed, 26 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/src/rtdk/init.c b/src/rtdk/init.c
>>> index 2084c73..b864175 100644
>>> --- a/src/rtdk/init.c
>>> +++ b/src/rtdk/init.c
>>> @@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void 
>>> __init_rtdk(void)
>>>  {
>>> __rt_print_init();
>>>  }
>>> +
>>> +static __attribute__ ((destructor)) void __exit_rtdk(void)
>>> +{
>>> +   __rt_print_exit();
>>> +}
>>> diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
>>> index bd15b2d..345d4fa 100644
>>> --- a/src/rtdk/internal.h
>>> +++ b/src/rtdk/internal.h
>>> @@ -23,6 +23,7 @@
>>>  #include 
>>>  
>>>  void __rt_print_init(void);
>>> +void __rt_print_exit(void);
>>>  
>>>  void __real_free(void *ptr);
>>>  void *__real_malloc(size_t size);
>>> diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
>>> index c6b5c55..dae7d7b 100644
>>> --- a/src/rtdk/rt_print.c
>>> +++ b/src/rtdk/rt_print.c
>>> @@ -455,7 +455,7 @@ static void spawn_printer_thread(void)
>>> pthread_attr_t thattr;
>>>  
>>> pthread_attr_init(&thattr);
>>> -   pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
>>> +   pthread_attr_setstacksize(&thattr, 32768);
>> Mmh... maybe rather $something +PTHREAD_STACK_MIN?
> 
> No, PTHREAD_STACK_MIN sucks, it is not appropriate, and have very
> varying values on different platforms. On some plaforms, with some
> versions of glibc, it is 4096, way too small, so that printf generates a
> segfault due to a stack overflow.
> 
> However, due to the work done when solving the stack issue reported by
> Stefan, I hid the magic constants in a function called xeno_stacksize
> and xeno_stacksize(0) gives a reasonnable default value.

OK, then go for this service (is it already merged)?

> 
>>> pthread_create(&printer_thread, &thattr, printer_loop, NULL);
>>>  }
>>>  
>>> @@ -464,6 +464,15 @@ static void forked_child_init(void)
>>> struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
>>> struct print_buffer **pbuffer = &first_buffer;
>>>  
>>> +   if (my_buffer) {
>>> +   /* Any content of my_buffer should be printed by our parent,
>>> +  not us. */
>>> +   memset(my_buffer->ring, 0, my_buffer->size);
>>> +
>>> +   my_buffer->read_pos  = 0;
>>> +   my_buffer->write_pos = 0;
>>> +   }
>>> +
>> Ack.
>>
>>> /* re-init to avoid finding it locked by some parent thread */
>>> pthread_mutex_init(&buffer_lock, NULL);
>>>  
>>> @@ -518,3 +527,13 @@ void __rt_print_init(void)
>>> spawn_printer_thread();
>>> pthread_atfork(NULL, NULL, forked_child_init);
>>>  }
>>> +
>>> +void __rt_print_exit(void)
>>> +{
>>> +   if (buffers) {
>>> +   /* Flush the buffers. Do not call print_buffers here
>>> +* since we do not know if our stack is big enough. */
>>> +   nanosleep(&print_period, NULL);
>>> +   nanosleep(&print_period, NULL);
>>> +   }
>>> +}
>> IIRC, that's what cleanup_buffer is supposed to do, triggered by the
>> pthread key destruction. Can you explain why it failed in your scenario.
> 
> pthread_key destruction is called when a thread is cancelled. My
> testcase was calling exit.

exit() does not trigger these cleanup hooks? Too bad.

> Besides, cleanup_buffer flushes the buffers
> from the context of the calling thread, which is a bad idea, due to the
> stack sizes situation.

If a thread requesting rt_printk services is not capable of performing
this work during it's cleanup, when there is no significant stack load,
I would say it's misconfigured /wrt stack size.

Jan



signature.asc
Description: OpenPGP digital signature
___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH 1/1] rtdk: various fixes.

2010-01-11 Thread Gilles Chanteperdrix
Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> When exiting a process, rtdk buffers are not flushed. Fix that by
>> introducing a destructor for the library which flushes the buffers.
>>
>> When forking, if the main thread has an rt_printf buffer, it is reused by
>> the child, which is a good thing, however, it is not emptied, so could cause
>> the same message to be printed twice. Fix that by emptying the main thread
>> buffer upon fork.
>>
>> When spawning the rt_print thread, it uses a stack size of
>> PTHREAD_STACK_MIN, which may be too small for printf to work reliably on
>> some architectures, set the stack size to the
>> empirically-known-to-be-working size of... 32Kb.
>> ---
>>  src/rtdk/init.c |5 +
>>  src/rtdk/internal.h |1 +
>>  src/rtdk/rt_print.c |   21 -
>>  3 files changed, 26 insertions(+), 1 deletions(-)
>>
>> diff --git a/src/rtdk/init.c b/src/rtdk/init.c
>> index 2084c73..b864175 100644
>> --- a/src/rtdk/init.c
>> +++ b/src/rtdk/init.c
>> @@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void __init_rtdk(void)
>>  {
>>  __rt_print_init();
>>  }
>> +
>> +static __attribute__ ((destructor)) void __exit_rtdk(void)
>> +{
>> +__rt_print_exit();
>> +}
>> diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
>> index bd15b2d..345d4fa 100644
>> --- a/src/rtdk/internal.h
>> +++ b/src/rtdk/internal.h
>> @@ -23,6 +23,7 @@
>>  #include 
>>  
>>  void __rt_print_init(void);
>> +void __rt_print_exit(void);
>>  
>>  void __real_free(void *ptr);
>>  void *__real_malloc(size_t size);
>> diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
>> index c6b5c55..dae7d7b 100644
>> --- a/src/rtdk/rt_print.c
>> +++ b/src/rtdk/rt_print.c
>> @@ -455,7 +455,7 @@ static void spawn_printer_thread(void)
>>  pthread_attr_t thattr;
>>  
>>  pthread_attr_init(&thattr);
>> -pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
>> +pthread_attr_setstacksize(&thattr, 32768);
> 
> Mmh... maybe rather $something +PTHREAD_STACK_MIN?

No, PTHREAD_STACK_MIN sucks, it is not appropriate, and have very
varying values on different platforms. On some plaforms, with some
versions of glibc, it is 4096, way too small, so that printf generates a
segfault due to a stack overflow.

However, due to the work done when solving the stack issue reported by
Stefan, I hid the magic constants in a function called xeno_stacksize
and xeno_stacksize(0) gives a reasonnable default value.

> 
>>  pthread_create(&printer_thread, &thattr, printer_loop, NULL);
>>  }
>>  
>> @@ -464,6 +464,15 @@ static void forked_child_init(void)
>>  struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
>>  struct print_buffer **pbuffer = &first_buffer;
>>  
>> +if (my_buffer) {
>> +/* Any content of my_buffer should be printed by our parent,
>> +   not us. */
>> +memset(my_buffer->ring, 0, my_buffer->size);
>> +
>> +my_buffer->read_pos  = 0;
>> +my_buffer->write_pos = 0;
>> +}
>> +
> 
> Ack.
> 
>>  /* re-init to avoid finding it locked by some parent thread */
>>  pthread_mutex_init(&buffer_lock, NULL);
>>  
>> @@ -518,3 +527,13 @@ void __rt_print_init(void)
>>  spawn_printer_thread();
>>  pthread_atfork(NULL, NULL, forked_child_init);
>>  }
>> +
>> +void __rt_print_exit(void)
>> +{
>> +if (buffers) {
>> +/* Flush the buffers. Do not call print_buffers here
>> + * since we do not know if our stack is big enough. */
>> +nanosleep(&print_period, NULL);
>> +nanosleep(&print_period, NULL);
>> +}
>> +}
> 
> IIRC, that's what cleanup_buffer is supposed to do, triggered by the
> pthread key destruction. Can you explain why it failed in your scenario.

pthread_key destruction is called when a thread is cancelled. My
testcase was calling exit. Besides, cleanup_buffer flushes the buffers
from the context of the calling thread, which is a bad idea, due to the
stack sizes situation.

-- 
Gilles Chanteperdrix, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH 1/1] rtdk: various fixes.

2010-01-11 Thread Jan Kiszka
Gilles Chanteperdrix wrote:
> When exiting a process, rtdk buffers are not flushed. Fix that by
> introducing a destructor for the library which flushes the buffers.
> 
> When forking, if the main thread has an rt_printf buffer, it is reused by
> the child, which is a good thing, however, it is not emptied, so could cause
> the same message to be printed twice. Fix that by emptying the main thread
> buffer upon fork.
> 
> When spawning the rt_print thread, it uses a stack size of
> PTHREAD_STACK_MIN, which may be too small for printf to work reliably on
> some architectures, set the stack size to the
> empirically-known-to-be-working size of... 32Kb.
> ---
>  src/rtdk/init.c |5 +
>  src/rtdk/internal.h |1 +
>  src/rtdk/rt_print.c |   21 -
>  3 files changed, 26 insertions(+), 1 deletions(-)
> 
> diff --git a/src/rtdk/init.c b/src/rtdk/init.c
> index 2084c73..b864175 100644
> --- a/src/rtdk/init.c
> +++ b/src/rtdk/init.c
> @@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void __init_rtdk(void)
>  {
>   __rt_print_init();
>  }
> +
> +static __attribute__ ((destructor)) void __exit_rtdk(void)
> +{
> + __rt_print_exit();
> +}
> diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
> index bd15b2d..345d4fa 100644
> --- a/src/rtdk/internal.h
> +++ b/src/rtdk/internal.h
> @@ -23,6 +23,7 @@
>  #include 
>  
>  void __rt_print_init(void);
> +void __rt_print_exit(void);
>  
>  void __real_free(void *ptr);
>  void *__real_malloc(size_t size);
> diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
> index c6b5c55..dae7d7b 100644
> --- a/src/rtdk/rt_print.c
> +++ b/src/rtdk/rt_print.c
> @@ -455,7 +455,7 @@ static void spawn_printer_thread(void)
>   pthread_attr_t thattr;
>  
>   pthread_attr_init(&thattr);
> - pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
> + pthread_attr_setstacksize(&thattr, 32768);

Mmh... maybe rather $something +PTHREAD_STACK_MIN?

>   pthread_create(&printer_thread, &thattr, printer_loop, NULL);
>  }
>  
> @@ -464,6 +464,15 @@ static void forked_child_init(void)
>   struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
>   struct print_buffer **pbuffer = &first_buffer;
>  
> + if (my_buffer) {
> + /* Any content of my_buffer should be printed by our parent,
> +not us. */
> + memset(my_buffer->ring, 0, my_buffer->size);
> +
> + my_buffer->read_pos  = 0;
> + my_buffer->write_pos = 0;
> + }
> +

Ack.

>   /* re-init to avoid finding it locked by some parent thread */
>   pthread_mutex_init(&buffer_lock, NULL);
>  
> @@ -518,3 +527,13 @@ void __rt_print_init(void)
>   spawn_printer_thread();
>   pthread_atfork(NULL, NULL, forked_child_init);
>  }
> +
> +void __rt_print_exit(void)
> +{
> + if (buffers) {
> + /* Flush the buffers. Do not call print_buffers here
> +  * since we do not know if our stack is big enough. */
> + nanosleep(&print_period, NULL);
> + nanosleep(&print_period, NULL);
> + }
> +}

IIRC, that's what cleanup_buffer is supposed to do, triggered by the
pthread key destruction. Can you explain why it failed in your scenario.

Jan



signature.asc
Description: OpenPGP digital signature
___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core