Howto:Activate multi core support for OSG

From FlightGear wiki
Jump to navigation Jump to search

OSG threading support allows rendering-related computations (e.g., culling) to be offloaded to different threads.[1]

Selecting threading modes

There is a property named /sim/rendering/multithreading-mode that can be set by using the --prop:/sim/rendering/multithreading-mode=... parameter. This affects directly the osgviewer threading mode, supported values are:

  • AutomaticSelection
  • CullDrawThreadPerContext
  • DrawThreadPerContext (recommended)
  • CullThreadPerCameraDrawThreadPerContext

In the launcher, you can click the "Settings" tab and paste --prop:/sim/rendering/multithreading-mode=... in the "Additional Settings" section. For example, you could paste --prop:/sim/rendering/multithreading-mode=DrawThreadPerContext.

If FG crashes, you can try running OSG_NOTIFY_LEVEL=WARN ./fgfs (or OSG_NOTIFY_LEVEL=INFO ./fgfs) to show logs from OpenSceneGraph.

Comparison of CPU usage

Before enabling multi-core support for OSG:

$ ps -T -o pid,tid,comm,stat,psr,pcpu,pmem,wchan,cmd -p $(pgrep -d, fgfs)
    PID     TID COMMAND         STAT PSR %CPU %MEM WCHAN  CMD
   7706    7706 fgfs            RLl    0 92.1 13.0 -      /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7762 QXcbEventQueue  SLl   14  0.0 13.0 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7787 fgfs:disk$0     SNLl   0  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7788 fgfs:sh0        SLl   18  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7829 Qt bearer threa SLl   16  0.0 13.0 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7830 QDBusConnection SLl    2  0.0 13.0 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7989 fgfs:disk$0     SNLl  17  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7990 fgfs:sh0        SLl   12  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7991 fgfs:traceq0    SNLl  17  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    7992 fgfs:gdrv0      SLl    5 14.3 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8008 fgfs            SLl    9  0.3 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8010 fgfs            SLl   15  0.0 13.0 ep_pol /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8011 fgfs            SLl   14  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8012 fgfs            SLl   16  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8013 fgfs            SLl   15  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8014 fgfs            SLl   16  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8015 fgfs            SLl    1  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8020 threaded-ml     SLl   13  0.4 13.0 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8021 fgfs            SLl   15  0.6 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8022 fgfs            SLl   19  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8023 fgfs            SLl   13  0.0 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8025 fgfs            SLl    6 10.1 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8026 fgfs            SLl    7  6.4 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8027 fgfs            SLl    5  6.6 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   7706    8028 fgfs            SLl    6  9.2 13.0 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -

After adding the --prop:/sim/rendering/multithreading-mode=DrawThreadPerContext parameter:

$ ps -T -o pid,tid,comm,stat,psr,pcpu,pmem,wchan,cmd -p $(pgrep -d, fgfs)
    PID     TID COMMAND         STAT PSR %CPU %MEM WCHAN  CMD
   8447    8447 fgfs            RLl   10 25.2  8.9 -      /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8454 QXcbEventQueue  SLl   12  0.0  8.9 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8456 fgfs:disk$0     SNLl  13  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8457 fgfs:sh0        SLl   16  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8464 Qt bearer threa SLl    6  0.0  8.9 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8465 QDBusConnection SLl    0  0.0  8.9 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8470 Thread (pooled) SLl   16  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8471 Thread (pooled) SLl   10  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8472 Thread (pooled) SLl   14  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8473 Thread (pooled) SLl    9  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8474 Thread (pooled) SLl    3  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8475 Thread (pooled) SLl   12  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8476 Thread (pooled) SLl    0  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8477 Thread (pooled) SLl   16  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8478 Thread (pooled) SLl   13  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8479 Thread (pooled) SLl    8  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8480 Thread (pooled) SLl    6  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8481 Thread (pooled) SLl   11  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8482 Thread (pooled) SLl    2  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8483 Thread (pooled) SLl    5  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8484 Thread (pooled) SLl   17  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8485 Thread (pooled) SLl    7  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8486 Thread (pooled) SLl   11  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8487 Thread (pooled) SLl   18  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8488 Thread (pooled) SLl   15  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8489 Thread (pooled) SLl   19  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8494 fgfs:disk$0     SNLl  15  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8495 fgfs:sh0        SLl   15  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8496 fgfs:traceq0    SNLl  15  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8497 fgfs:gdrv0      SLl   10  0.8  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8534 fgfs            SLl   11 13.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8539 fgfs            SLl   17  0.0  8.9 ep_pol /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8540 fgfs            SLl   19  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8541 fgfs            SLl   14  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8542 fgfs            SLl   19  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8543 fgfs            SLl   14  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8544 fgfs            SLl    1  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8549 threaded-ml     SLl   18  0.2  8.9 poll_s /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8550 fgfs            SLl   19  0.4  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8551 fgfs            SLl   12  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8552 fgfs            SLl    8  0.1  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8559 fgfs            RLl    5 76.4  8.9 -      /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8560 fgfs            SLl   10 28.6  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8561 fgfs            SLl    0 72.1  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8562 fgfs            SLl    2 22.9  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -
   8447    8565 fgfs            SLl   19  0.0  8.9 futex_ /mnt/f/Env/flightgear/linux/usr/bin/fgfs -

It can be seen that the CPU usage of the main thread has decreased.

Related content

References