Shared Memory Queue Setup

PolySync provides a shared memory API that enables very fast read/write speeds to host-local data. In Linux, this is an implementation similar to POSIX message queues.

Some PolySync nodes such as the dynamic driver are able to publish data to a shared memory queue where another application can access the data.

The shared memory queue must be created before nodes can write data to it.

Calculating shared memory size

The shared memory queue must be able to store up to five copies of whatever data buffer is being pushed into the queue.

To calculate the required shared memory segment size for image data, use the following calculation.

To store up to 5 image frames with size 640x480x3, you would set the sysctl settings to match: - 5 frames x 640 image height x 480 image width x 3 channels per pixel = 4608000 bytes

Configuring shared memory segment

To persistently set the buffer size to 4608000, append the following lines to the /etc/sysctl.d/10-polysync.conf file.

  • kernel.msgmax=4608000
  • kernel.msgmnb=4608000

The next time the machine boots the shared memory segment will be created. To force the system to load this configuration for the current boot-cycle issue the command sudo sysctl -p /etc/sysctl.d/10-polysync.conf.

To temporarily set the buffer sizes use the sysctl tool:

$ sysctl -w kernel.msgmax=4608000
$ sysctl -w kernel.msgmnb=4608000

Troubleshooting a dynamic driver

If the queue size is insufficient, the dynamic driver interface will indicate with the following error and debug messages:

$ polysync-core-dynamic-driver -n 5 
2016-09-22 12:36:52.09s DEBUG  [video-device-] - build version 2.0.7-1470511976
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - created participant - GUID: 0x0006000572AD58D2 d(1688873259063506)
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - message types visible to this node: 42
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - transition to state: INIT - timestamp: 1474573013356533
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - initializing replay clock
2016-09-22 12:36:53.09s ERROR  [video-device-1688873259063506] - failed to set queue size - Operation not permitted
2016-09-22 12:36:53.09s ERROR  [video-device-1688873259063506] - failed to create shared memory queue with key: 4 - size: 6144000 bytes - check Shared Memory API documentation for system resource configurations
2016-09-22 12:36:53.09s ERROR  [video-device-1688873259063506] - failed to validate interface - check sensor connection if connected, SDF and system configurations, and manager node status
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - activate fault - dtc_code: 308
2016-09-22 12:36:53.09s DEBUG  [video-device-1688873259063506] - transition to state: ERROR - timestamp: 1474573013607427
2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to set queue size - Operation not permitted
2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to create shared memory queue with key: 4 - size: 6144000 bytes - check Shared Memory API documentation for system resource configurations
2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to set queue size - Operation not permitted
2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to create shared memory queue with key: 4 - size: 6144000 bytes - check Shared Memory API documentation for system resource configurations
^C2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to set queue size - Operation not permitted
2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to create shared memory queue with key: 4 - size: 6144000 bytes - check Shared Memory API documentation for system resource configurations
2016-09-22 12:36:54.09s DEBUG  [video-device-1688873259063506] - exit signaled - terminating
2016-09-22 12:36:54.09s DEBUG  [video-device-1688873259063506] - releasing replay clock
2016-09-22 12:36:56.09s DEBUG  [video-device-1688873259063506] - last node registered on the host - deleting shared memory

Within the error and debug messages, there’s a line that indicates specifically how large the queue must be:

2016-09-22 12:36:54.09s ERROR  [video-device-1688873259063506] - failed to create shared memory queue with key: 4 - size: 6144000 bytes - check Shared Memory API documentation for system resource configurations

Use this size─in this case 6144000─to increase the local hosts shared memory queue size:

sysctl -w kernel.msgmax=6144000
sysctl -w kernel.msgmnb=6144000