Can printf() be made SMP safe?

Sebastian Huber sebastian.huber at embedded-brains.de
Fri May 14 05:56:42 UTC 2021


On 14/05/2021 03:09, Dave DeGroote wrote:
> I'm still beating my head against this so I wrote a simple RTEMS only 
> test to narrow it down and the problem is still occurring. Sometimes it 
> crashes, hangs, or runs fine, depending on the number of RTEMS objects 
> created (it sometimes works with fewer objects and fails with more).

If it crashes depending on the number of object, then this still looks 
like a general memory corruption which depends on the memory layout.

Which RTEMS version do you use? Did enabling RTEMS_DEBUG help to get 
more information.

I checked your example program on another target and it works fine. I 
didn't see anything obviously wrong in the example.

> 
> 
> - The code starts two tasks with printf() loops.
> 
> - To start, the printf()'s do not overlap - this always works
> 
> - The code then switches to fast overlapping printf()'s where it fails 
> (depending on the #of objects).
> 
> 
> The compile command, code, and results are below.
> 
> 
> Thanks for any help or insight!
> 
> 
> 
> 
> Compile command (gcc version 7.2.0 (Cobham Gaisler RCC 1.3-rc7) ):
> 
> sparc-gaisler-rtems5-gcc -Wall -g -O2 -Werror -mcpu=leon3 -mfix-gr712rc 
> -qbsp=gr712rc_smp -o smp_test smp_test.c
> 
> 
> 
> 
> Results: fails with 20 semaphores:
> 
> |gncsim||@gncsim||:~/grmon-pro-||3.0||.||9||/linux/bin64$ sudo ./grmon 
> -ftdi -log /tmp/grmon-log.log -e ||"load 
> ~/lander/flat_sat/DaveD/smp_test; run"||-u|
> |||GRMON LEON debug monitor v3.||0.9| |64||-bit pro version|
> ||
> |||Copyright (C) ||2018| |Cobham Gaisler - All rights reserved.|
> |||For latest updates, go to http:||//www.gaisler.com/|
> |||Comments or bug-reports to support||@gaisler||.com|
> |JTAG chain (||1||): GR712RC|
> |Device ID: ||0x712|
> |||GRLIB build version: ||3696|
> |||Detected system:     GR712RC|
> |||Detected frequency: ||80| |MHz|
> ||
> |||Component Vendor|
> |||LEON3FT SPARC V8 Processor           Cobham Gaisler|
>    <... snip ...>
> ||
> |||Timer Unit with Latches              Cobham Gaisler|
> ||
> |||Use command ||'info sys'| |to print a detailed report of attached cores|
> |||40000000| |.text ||191||.7kB / ||191||.7kB [===============>] ||100||%|
> |||4002FED0 .rtemsroset                 96B              
> [===============>] ||100||%|
> |||40031F40 .data ||5||.6kB / ||5||.6kB [===============>] ||100||%|
> |||Total size: ||197||.38kB (||774||.38kbit/s)|
> |||Entry point ||0x40000000|
> |||Image /home/gncsim/lander/flat_sat/DaveD/smp_test loaded|
> |t1a:||0| |<||0||>|
> |t2a:||1| |[||0||]|
> |t1a:||0| |<||1||>|
> |t2a:||1| |[||1||]|
> |t1a:||0| |<||2||>|
> |t2a:||1| |[||2||]|
> |t2b:||1| |[||0||]|
> |t1b:||0| |<||0||>|
> |t2b:||1| |[||1||]|
> ||
> |||CPU ||0||: Unknown watchpoint hit|
> |||0x400217b4||: ba100015  mov  %l5, %i5  <_vfprintf_r+||316||>|
> |||CPU ||1||: IU exception (tt = ||0x2B||, data store error)|
> |||0x40011818||: ||96100001| |mov %g1, %o3  
> <_Thread_queue_Queue_enqueue+||108||>|
> ||
> |grmon3> bt cpu0|
> ||
> |||%pc %sp|
> |||#||0| |0x400217b4| |0x4003eb60| |<_vfprintf_r+||0x13c||>|
> |||#||1| |0x4001e1ec| |0x4003ed38| |<printf+||0x2c||>|
> |||#||2| |0x40001334| |0x4003eda0| |<task1+||0x68||>|
> |||#||3| |0x40010084| |0x4003ee00| |<_Thread_Entry_adaptor_numeric+||0x8||>|
> |||#||4| |0x4000ea8c| |0x4003ee60| |<_Thread_Handler+||0x60||>|
> |||#||5| |0x4000ea2c| |0x4003eec0| |<_Thread_Handler+||0||>|
> ||
> |grmon3> bt cpu1|
> ||
> |||%pc %sp|
> |||#||0| |0x40011818| |0x4003fae0| |<_Thread_queue_Queue_enqueue+||0x6c||>|
> |||#||1| |0x40010c00| |0x4003fb40| |<_Thread_queue_Enqueue+||0x80||>|
> |||#||2| |0x4002ce60| |0x4003fba8| |<clock_nanosleep.part.||4||+||0x134||>|
> |||#||3| |0x4002cf34| |0x4003fcd8| |<nanosleep+||0x10||>|
> |||#||4| |0x400214c4| |0x4003fd38| |<usleep+||0x48||>|
> |||#||5| |0x400013dc| |0x4003fda8| |<task2+||0x70||>|
> |||#||6| |0x40010084| |0x4003fe08| |<_Thread_Entry_adaptor_numeric+||0x8||>|
> |||#||7| |0x4000ea8c| |0x4003fe68| |<_Thread_Handler+||0x60||>|
> |||#||8| |0x4000ea2c| |0x4003fec8| |<_Thread_Handler+||0||>|
> ||
> |grmon3>|

There seems to be a data store error in usleep(). This function uses a 
global object: _Nanosleep_Pseudo_queue. I would check the state of this 
object during crash.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the users mailing list