From: "Khor, Isaac Shi Yan" <isaac.shi.yan.k...@intel.com> Users may need to use different socket priorities for ptp4l traffic for the purpose of traffic shaping. An example is to route ptp4l traffic through a specific Linux egress qdisc.
- Update raw.c open_socket() to accept a socket_priority parameter - Update ptp4l.c to accept a '-c' command line argument to configure its egress socket priority - Add the socket_priority option to config.c and the default.cfg config file. The option defaults to 0. CC: "Wong, Vincent Por Yin" <vincent.por.yin.w...@intel.com> CC: "Ong, Boon Leong" <boon.leong....@intel.com> Signed-off-by: Khor, Isaac Shi Yan <isaac.shi.yan.k...@intel.com> --- This patch adds an option to configure the socket priority of sockets used by ptp4l. This is to support cases where a user may want to route ptp4l traffic to specific egress qdiscs. For example, in a network-heavy workload, a user may want to route ptp4l traffic to a specific egress queue that has priority over other outbound traffic. The configuration is introduced as the 'socket_priority' option in the configuration file and the '-c' command line argument, and must be between 0 and 15, inclusive. Only the IEEE 802.3 raw transport type is modified to support this option. The UDS and IPv4/6 types have not been modified. Feedback on both the placement of the configuration option, the setsockopt() syscall, and other areas are welcome and appreciated. config.c | 1 + configs/default.cfg | 1 + ptp4l.c | 10 ++++++++-- raw.c | 17 ++++++++++++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config.c b/config.c index 93ea5da..3346081 100644 --- a/config.c +++ b/config.c @@ -305,6 +305,7 @@ struct config_item config_tab[] = { GLOB_ITEM_STR("userDescription", ""), GLOB_ITEM_INT("utc_offset", CURRENT_UTC_OFFSET, 0, INT_MAX), GLOB_ITEM_INT("verbose", 0, 0, 1), + GLOB_ITEM_INT("socket_priority", 0, 0, 15), }; static struct unicast_master_table *current_uc_mtab; diff --git a/configs/default.cfg b/configs/default.cfg index e23dfd7..c52dc37 100644 --- a/configs/default.cfg +++ b/configs/default.cfg @@ -4,6 +4,7 @@ # twoStepFlag 1 slaveOnly 0 +socket_priority 0 priority1 128 priority2 128 domainNumber 0 diff --git a/ptp4l.c b/ptp4l.c index 84661c5..ffdf989 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -59,6 +59,7 @@ static void usage(char *progname) " -p [dev] Clock device to use, default auto\n" " (ignored for SOFTWARE/LEGACY HW time stamping)\n" " -s slave only mode (overrides configuration file)\n" + " -c [num] set socket priority (must be between 0 and 15)\n" " -l [num] set the logging level to 'num'\n" " -m print messages to stdout\n" " -q do not print messages to the syslog\n" @@ -70,9 +71,9 @@ static void usage(char *progname) int main(int argc, char *argv[]) { + int c, err = -1, index, print_level, socket_priority = 0; char *config = NULL, *req_phc = NULL, *progname; enum clock_type type = CLOCK_TYPE_ORDINARY; - int c, err = -1, index, print_level; struct clock *clock = NULL; struct option *opts; struct config *cfg; @@ -89,7 +90,7 @@ int main(int argc, char *argv[]) /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt_long(argc, argv, "AEP246HSLf:i:p:sl:mqvh", + while (EOF != (c = getopt_long(argc, argv, "AEP246HSLf:i:p:sc:l:mqvh", opts, &index))) { switch (c) { case 0: @@ -150,6 +151,11 @@ int main(int argc, char *argv[]) goto out; } break; + case 'c': + if (get_arg_val_i(c, optarg, &socket_priority, 0, 15)) + goto out; + config_set_int(cfg, "socket_priority", socket_priority); + break; case 'l': if (get_arg_val_i(c, optarg, &print_level, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX)) diff --git a/raw.c b/raw.c index 8dc50bc..eebd10f 100644 --- a/raw.c +++ b/raw.c @@ -150,7 +150,7 @@ static int raw_close(struct transport *t, struct fdarray *fda) } static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac, - unsigned char *p2p_dst_mac) + unsigned char *p2p_dst_mac, int socket_priority) { struct sockaddr_ll addr; int fd, index; @@ -176,6 +176,13 @@ static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac, pr_err("setsockopt SO_BINDTODEVICE failed: %m"); goto no_option; } + + if (socket_priority > 0 && + setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_err("setsockopt SO_PRIORITY failed: %m"); + goto no_option; + } if (raw_configure(fd, event, index, ptp_dst_mac, p2p_dst_mac, 1)) goto no_option; @@ -207,6 +214,7 @@ static int raw_open(struct transport *t, struct interface *iface, unsigned char p2p_dst_mac[MAC_LEN]; int efd, gfd; char *str, *name; + int socket_priority; name = iface->ts_label; str = config_get_string(t->cfg, name, "ptp_dst_mac"); @@ -219,17 +227,20 @@ static int raw_open(struct transport *t, struct interface *iface, pr_err("invalid p2p_dst_mac %s", str); return -1; } + + socket_priority = config_get_int(t->cfg, "global", "socket_priority"); + mac_to_addr(&raw->ptp_addr, ptp_dst_mac); mac_to_addr(&raw->p2p_addr, p2p_dst_mac); if (sk_interface_macaddr(name, &raw->src_addr)) goto no_mac; - efd = open_socket(name, 1, ptp_dst_mac, p2p_dst_mac); + efd = open_socket(name, 1, ptp_dst_mac, p2p_dst_mac, socket_priority); if (efd < 0) goto no_event; - gfd = open_socket(name, 0, ptp_dst_mac, p2p_dst_mac); + gfd = open_socket(name, 0, ptp_dst_mac, p2p_dst_mac, socket_priority); if (gfd < 0) goto no_general; -- 2.17.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel