Commit 6ecab67e authored by Joanne Hugé's avatar Joanne Hugé

Update ptp4l, add ETF HW offloading, add ptptime

Add -s and -o options in run-ptp
Add option to use no profile
Add latency threshold for XDP tracing
Add hardware offloading option for ETF
Add option to choose interface in wrapper scripts
Add ptptime program
parent d9a21ee7
...@@ -6,6 +6,7 @@ clockres/build/clockres ...@@ -6,6 +6,7 @@ clockres/build/clockres
clockres/build/clockres_arm clockres/build/clockres_arm
packet-exchange/build/server packet-exchange/build/server
packet-exchange/build/client packet-exchange/build/client
ptptime/build/ptptime
img-kernel-utils/full-img-debian img-kernel-utils/full-img-debian
img-kernel-utils/full-img-olimex img-kernel-utils/full-img-olimex
......
PROG = ptptime
SRCDIR = ../src
SRCS = main.c
OBJS = $(SRCS:%.c=%.o)
ifeq ($(DEBUG),)
CFLAGS = -O2
else
CFLAGS = -Og -g -Wall -Wextra
endif
CFLAGS += -MD -MP
CFLAGS += -I $(SRCDIR)
CFLAGS += -std=gnu99
LLIBS = -pthread
vpath %.c $(SRCDIR)
$(PROG): $(OBJS)
$(CC) $(LDFLAGS) $(LDIRS) $^ $(LLIBS) -o $@
-include $(subst .c,.d,$(SRCS))
clean:
$(RM) $(OBJS) $(PROG) $(subst .c,.d,$(SRCS))
.PHONY: clean
/*
* Get PTP time
*
* Large portions taken from cyclictest
*
*/
#define _GNU_SOURCE
#include <errno.h>
#include <error.h>
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#define NSEC_PER_SEC UINT64_C(1000000000)
// Structs
typedef struct thread_param {
int interval;
int priority;
} thread_param_t;
// Static functions
static void process_options(int argc, char *argv[]);
static void add_ns(struct timespec *t, uint64_t ns);
static uint64_t ts_to_uint(struct timespec t);
// Static variables
static thread_param_t thread_params;
static uint64_t ptptime;
static void help(char *argv[]) {
printf(
"Usage: %s [-h] [-i USEC]\n"
" -h Show help\n"
" -i USEC Wake up the real time thread every "
"USEC "
"microseconds (Default: 10ms)\n"
"\n",
argv[0]);
}
/*
* Real-time thread: Sends packets at a regular intervall
*/
static void *packet_sending_thread(void *p) {
(void)p;
struct timespec next, ptptime_ts;
cpu_set_t mask;
// Set thread CPU affinity
CPU_ZERO(&mask);
CPU_SET(1, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
error(EXIT_FAILURE, errno,
"Could not set CPU affinity to CPU #1\n");
clock_gettime(CLOCK_MONOTONIC, &next);
// Packet sending loop
for (;;) {
clock_gettime(CLOCK_REALTIME, &ptptime_ts);
ptptime = ts_to_uint(ptptime_ts);
add_ns(&next, thread_params.interval);
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL);
}
return NULL;
}
/*
* Main thread, has non-real time priority
* Handles the IO and creates the real time thread
*/
int main(int argc, char *argv[]) {
pthread_t thread;
struct sched_param param;
pthread_attr_t attr;
// Default configuration values
thread_params.interval = 100000 * 1000;
thread_params.priority = 99;
/* Lock all current and future pages from preventing of being paged to
* swap */
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
perror("mlockall failed");
/* exit(-1) or do error handling */
}
// Process bash options
process_options(argc, argv);
/* Initialize pthread attributes (default values) */
if (pthread_attr_init(&attr)) {
fprintf(stderr, "init pthread attributes failed\n");
exit(EXIT_FAILURE);
}
/* Set a specific stack size */
if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN)) {
fprintf(stderr, "pthread setstacksize failed\n");
exit(EXIT_FAILURE);
}
/* Set scheduler policy and priority of pthread */
if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
fprintf(stderr, "pthread setschedpolicy failed\n");
exit(EXIT_FAILURE);
}
param.sched_priority = thread_params.priority;
if (pthread_attr_setschedparam(&attr, &param)) {
fprintf(stderr, "pthread setschedparam failed\n");
exit(EXIT_FAILURE);
}
/* Use scheduling parameters of attr */
if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
fprintf(stderr, "pthread setinheritsched failed\n");
exit(EXIT_FAILURE);
}
// Create the real time thread
if (pthread_create(&thread, &attr, packet_sending_thread, NULL))
error(EXIT_FAILURE, errno,
"Couldn't create packet sending thread");
// Verbose loop
for (;;) {
usleep(1000);
printf("%9" PRIu64 ": \n", ptptime);
printf("\033[%dA", 1);
}
exit(EXIT_SUCCESS);
}
// Process bash options
static void process_options(int argc, char *argv[]) {
int network_if_specified = 0;
for (;;) {
int c = getopt(argc, argv, "hi:");
if (c == -1) break;
switch (c) {
case 'h':
help(argv);
exit(EXIT_SUCCESS);
break;
case 'i':
thread_params.interval = atoi(optarg) * 1000;
break;
}
}
}
static void add_ns(struct timespec *t, uint64_t ns) {
t->tv_nsec += ns;
while ((unsigned int)t->tv_nsec >= NSEC_PER_SEC) {
t->tv_sec += 1;
t->tv_nsec -= NSEC_PER_SEC;
}
}
static uint64_t ts_to_uint(struct timespec t) {
return t.tv_sec * NSEC_PER_SEC + t.tv_nsec;
}
#!/bin/bash #!/bin/bash
usage() { usage() {
echo "Usage: $0 -e delta|-p" 1>&2; echo "Usage: $0 [-I if] -e delta -H|-p" 1>&2;
exit 1; exit 1;
} }
while getopts "e:p" opt; do tc_opts=""
interface="eth0"
while getopts "he:pHI:" opt; do
case "${opt}" in case "${opt}" in
h )
usage
;;
e ) e )
delta=${OPTARG} delta=${OPTARG}
use_etf=1 use_etf=1
...@@ -14,6 +20,12 @@ while getopts "e:p" opt; do ...@@ -14,6 +20,12 @@ while getopts "e:p" opt; do
p ) p )
use_pfast=1 use_pfast=1
;; ;;
I )
interface="${OPTARG}"
;;
H )
tc_opts+=" offload on"
;;
* ) * )
usage usage
;; ;;
...@@ -30,12 +42,12 @@ fi ...@@ -30,12 +42,12 @@ fi
if [ -n "${use_etf}" ]; then if [ -n "${use_etf}" ]; then
echo "Creating ETF qdisc with delta $delta" echo "Creating ETF qdisc with delta $delta"
tc qdisc del root dev eth0; tc qdisc del root dev $interface;
tc qdisc add dev eth0 parent root handle 100 prio bands 2 priomap 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1; tc qdisc add dev $interface parent root handle 100 prio bands 2 priomap 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1;
tc qdisc add dev eth0 parent 100:1 etf clockid CLOCK_TAI delta $delta; tc qdisc add dev $interface parent 100:1 etf clockid CLOCK_TAI delta $delta $tc_opts;
tc qdisc show dev eth0; tc qdisc show dev $interface;
elif [ -n "${use_pfast}" ]; then elif [ -n "${use_pfast}" ]; then
echo "Creating pfast qdisc" echo "Creating pfast qdisc"
tc qdisc del root dev eth0; tc qdisc del root dev $interface;
tc qdisc show; tc qdisc show;
fi fi
...@@ -5,8 +5,8 @@ script_dir=$(dirname $(realpath $0)) ...@@ -5,8 +5,8 @@ script_dir=$(dirname $(realpath $0))
usage() { usage() {
cat << ENDUSAGE cat << ENDUSAGE
Usage: $0 QDISC_OPT [CLIENT_OPTS] BOARD Usage: $0 QDISC_OPT [CLIENT_OPTS] BOARD
QDISC_OPTS: (-e delta [-o etf_offset] | -p) QDISC_OPTS: (-e delta [-o etf_offset] -H | -p)
CLIENT_OPTS: -bgt -i INTERVAL -d TX_BUF_LEN [TRACE_OPTS] CLIENT_OPTS: -bgt -i INTERVAL -I if -d TX_BUF_LEN [TRACE_OPTS]
TRACE_OPTS: [-T -P TRACER -E EVENTS -B SIZE] TRACE_OPTS: [-T -P TRACER -E EVENTS -B SIZE]
default tracer opts: irq, sched, net_dev_start_xmit, default tracer opts: irq, sched, net_dev_start_xmit,
net_dev_xmit, net_dev_xmit_timeout net_dev_xmit, net_dev_xmit_timeout
...@@ -20,13 +20,14 @@ ENDUSAGE ...@@ -20,13 +20,14 @@ ENDUSAGE
interval=100000 interval=100000
# Default options # Default options
client_options="-a -p 99 -f eth0" interface="eth0"
client_options="-a -p 99"
qdisc_options="" qdisc_options=""
etf_offset=500 etf_offset=500
tracecmd_events="-e irq -e sched -e net_dev_start_xmit -e net_dev_xmit -e net_dev_xmit_timeout" tracecmd_events="-e irq -e sched -e net_dev_start_xmit -e net_dev_xmit -e net_dev_xmit_timeout"
tracecmd_opts="" tracecmd_opts=""
while getopts "bd:e:o:ghi:ptB:E:P:T" opt; do while getopts "bd:e:o:ghi:ptB:E:I:HP:T" opt; do
case "${opt}" in case "${opt}" in
b ) b )
client_options+=" -b" client_options+=" -b"
...@@ -68,6 +69,12 @@ while getopts "bd:e:o:ghi:ptB:E:P:T" opt; do ...@@ -68,6 +69,12 @@ while getopts "bd:e:o:ghi:ptB:E:P:T" opt; do
E ) E )
tracecmd_events=${OPTARG} tracecmd_events=${OPTARG}
;; ;;
I )
interface="${OPTARG}"
;;
H )
qdisc_options+=" -H"
;;
P ) P )
tracecmd_opts+=" -p ${OPTARG}" tracecmd_opts+=" -p ${OPTARG}"
;; ;;
...@@ -87,6 +94,9 @@ if [ -z "$1" ]; then ...@@ -87,6 +94,9 @@ if [ -z "$1" ]; then
usage usage
fi fi
client_options+=" -f $interface"
qdisc_options+=" -I $interface"
board_name=$1 board_name=$1
if [ $board_name != "emerald" ] && [ $board_name != "onyx" ] && [ $board_name != "slate" ]; then if [ $board_name != "emerald" ] && [ $board_name != "onyx" ] && [ $board_name != "slate" ]; then
......
...@@ -4,24 +4,24 @@ linuxptp_dir=/home/oli/linuxptp ...@@ -4,24 +4,24 @@ linuxptp_dir=/home/oli/linuxptp
telecom_profile="G.8265.1.cfg" telecom_profile="G.8265.1.cfg"
gPTP_profile="gPTP.cfg" gPTP_profile="gPTP.cfg"
profile=$telecom_profile profile_name="telecom"
opts=""
usage() { usage() {
echo "Usage: $0 [-p telecom|gPTP|OTHER]" 1>&2; echo "Usage: $0 [-p telecom|gPTP|OTHER -s -o OPTS]" 1>&2;
exit 1; exit 1;
} }
while getopts "p:q:" opt; do while getopts "o:p:s" opt; do
case "${opt}" in case "${opt}" in
o )
opts+=${OPTARG}
;;
p ) p )
input_profile=${OPTARG} profile_name=${OPTARG}
if [ $input_profile == "telecom" ]; then ;;
profile=$telecom_profile s )
elif [ $input_profile == "gPTP" ]; then opts+=" -s "
profile=$gPTP_profile
else
profile=$input_profile
fi
;; ;;
* ) * )
usage usage
...@@ -31,5 +31,16 @@ done ...@@ -31,5 +31,16 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
echo "ptp4l -i eth0 -f $linuxptp_dir/configs/$profile --step_threshold=1 -m -S &> ~/ptp4l_log &"; if [ $profile_name == "none" ]; then
ptp4l -i eth0 -f $linuxptp_dir/configs/$profile --step_threshold=1 -m -S &> ~/ptp4l_log & opts+=""
elif [ $profile_name == "telecom" ]; then
opts+=" -f $linuxptp_dir/configs/$telecom_profile "
elif [ $profile_name == "gPTP" ]; then
opts=" -f $linuxptp_dir/configs/$gPTP_profile "
else
opts=" -f $profile_name "
fi
killall ptp4l;
echo "ptp4l $opts -i eth0 --step_threshold=1 -m -S &> ~/ptp4l_log &";
ptp4l $opts -i eth0 --step_threshold=1 -m -S &> ~/ptp4l_log &
...@@ -8,10 +8,10 @@ usage() { ...@@ -8,10 +8,10 @@ usage() {
} }
usage() { usage() {
cat << ENDUSAGE cat << ENDUSAGE
Usage: $0 SERVER | TCPDUMP [TRACE_OPTS] Usage: $0 [-I if] SERVER | TCPDUMP [TRACE_OPTS]
SERVER: [-bt] [(-x | -X) POLL] [-g INTERVAL] SERVER: [-bt] [(-x | -X) POLL] [-g INTERVAL]
TCPDUMP: -d NB_PACKETS [-i INTERVAL] TCPDUMP: -d NB_PACKETS [-i INTERVAL]
TRACE_OPTS: (-T LATENCY_THRESHOLD -G) | -E TRACE_OPTS: (-T LATENCY_THRESHOLD -G) | -E LATENCY_THRESHOLD
ENDUSAGE ENDUSAGE
1>&2; 1>&2;
...@@ -19,12 +19,13 @@ ENDUSAGE ...@@ -19,12 +19,13 @@ ENDUSAGE
} }
# Default options # Default options
server_options="-a -p 99 -f eth0" interface="eth0"
server_options="-a -p 99"
make_opts="" make_opts=""
ip="10.100.21." ip="10.100.21."
tcpdump_interval=1000000 tcpdump_interval=1000000
while getopts "b:htx:X:d:i:g:T:GE" opt; do while getopts "b:htx:X:d:i:g:I:T:GE:" opt; do
case "${opt}" in case "${opt}" in
b ) b )
use_rtt=1 use_rtt=1
...@@ -53,6 +54,9 @@ while getopts "b:htx:X:d:i:g:T:GE" opt; do ...@@ -53,6 +54,9 @@ while getopts "b:htx:X:d:i:g:T:GE" opt; do
server_options+=" -x ${OPTARG}" server_options+=" -x ${OPTARG}"
make_opts=" -e WITH_XDP=1" make_opts=" -e WITH_XDP=1"
;; ;;
I )
interface+="${OPTARG}"
;;
X ) X )
server_options+=" -x ${OPTARG}" server_options+=" -x ${OPTARG}"
make_opts=" -e WITH_GIT_XDP=1" make_opts=" -e WITH_GIT_XDP=1"
...@@ -65,6 +69,7 @@ while getopts "b:htx:X:d:i:g:T:GE" opt; do ...@@ -65,6 +69,7 @@ while getopts "b:htx:X:d:i:g:T:GE" opt; do
;; ;;
E ) E )
enable_xdp_events=1 enable_xdp_events=1
server_options+=" -T ${OPTARG}"
;; ;;
* ) * )
usage usage
...@@ -74,6 +79,7 @@ done ...@@ -74,6 +79,7 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
server_options+=" -f $interface"
if [ -n "${use_rtt}" ]; then if [ -n "${use_rtt}" ]; then
if [ $board_name != "emerald" ] && [ $board_name != "onyx" ] && [ $board_name != "slate" ]; then if [ $board_name != "emerald" ] && [ $board_name != "onyx" ] && [ $board_name != "slate" ]; then
...@@ -91,8 +97,8 @@ fi ...@@ -91,8 +97,8 @@ fi
if [ -n "${use_tcpdump}" ]; then if [ -n "${use_tcpdump}" ]; then
echo "tcpdump -c $nb_packets -i eth0 -w tmp.pcap -tt --time-stamp-precision=nano udp port 50000"; echo "tcpdump -c $nb_packets -i $interface -w tmp.pcap -tt --time-stamp-precision=nano udp port 50000";
tcpdump -c $nb_packets -i eth0 -w server_stats_tmp.pcap -tt --time-stamp-precision=nano udp port 50000; tcpdump -c $nb_packets -i $interface -w server_stats_tmp.pcap -tt --time-stamp-precision=nano udp port 50000;
echo "tshark -r tmp.pcap --disable-protocol dcp-etsi --disable-protocol dcp-pft -t e -E separator=, -T fields -e frame.number -e frame.time_epoch -e data.data > tmp.out"; echo "tshark -r tmp.pcap --disable-protocol dcp-etsi --disable-protocol dcp-pft -t e -E separator=, -T fields -e frame.number -e frame.time_epoch -e data.data > tmp.out";
tshark -r server_stats_tmp.pcap --disable-protocol dcp-etsi --disable-protocol dcp-pft -t e -E separator=, -T fields -e frame.number -e frame.time_epoch -e data.data > server_stats_tmp.out; tshark -r server_stats_tmp.pcap --disable-protocol dcp-etsi --disable-protocol dcp-pft -t e -E separator=, -T fields -e frame.number -e frame.time_epoch -e data.data > server_stats_tmp.out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment