Cpu Affinity and the sfptpd Threading Model

Enhanced PTP User Guide (UG1602)

Document ID
Release Date
1.0 English

sfptpd is a multi-threaded application. The singular task of the main sfptpd process is to spawn a number of child processes which carry out the sfptpd processing tasks. The main sfptpd thread does no further work and, once started, will ignore attempts to affinitize to another CPU core.

At startup the following command will ensure that sfptpd and its child threads will run on CPU core 1.

# taskset -C 1 ./sfptpd -i <interface> -fconfig/ptp_slave.cfg

Thereafter attempts to move the sfptpd process to a different thread will fail because the main thread is doing no work, so takes not notice of affinity changes.

But the child/worker threads can be directed to other CPU cores while sfptpd is running. It is strongly recommended that all workers are affinitized to the same CPU core.

The following example (ptpthreads) script can be used as a simple shell script to identify sfptpd worker threads and affinitize all to a specific CPU core:

# usage:   ptpthreads 2

SFPTPD_PIDS=$(ps -T -p $(pidof sfptpd) | grep -v SPID | awk '{print $2}')
for i in ${SFPTPD_PIDS[@]}; do
  taskset -c -p $DESIRED_CPU $i;

# Confirm changes for sfptpd threads which are busy:
ps -Leo cpuid,lastcpu,pid | grep $(pidof sfptpd)