From patchwork Wed Mar 7 01:16:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesus Sanchez-Palencia X-Patchwork-Id: 882349 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zwwl96KNJz9sYh for ; Wed, 7 Mar 2018 12:18:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933280AbeCGBSj (ORCPT ); Tue, 6 Mar 2018 20:18:39 -0500 Received: from mga06.intel.com ([134.134.136.31]:44575 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932801AbeCGBSi (ORCPT ); Tue, 6 Mar 2018 20:18:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2018 17:18:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,433,1515484800"; d="scan'208";a="35180077" Received: from darjeeling.jf.intel.com ([10.24.15.164]) by fmsmga004.fm.intel.com with ESMTP; 06 Mar 2018 17:18:37 -0800 From: Jesus Sanchez-Palencia To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, Jesus Sanchez-Palencia Subject: [RFC v3 iproute2 1/3] include: Add ptp_clock.h to linux uapi Date: Tue, 6 Mar 2018 17:16:06 -0800 Message-Id: <20180307011608.24186-1-jesus.sanchez-palencia@intel.com> X-Mailer: git-send-email 2.16.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This header will be used by the new tc-tbs qdisc. It was copied from kernel tag 4.16.0-rc2. Signed-off-by: Jesus Sanchez-Palencia --- include/uapi/linux/ptp_clock.h | 147 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 include/uapi/linux/ptp_clock.h diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h new file mode 100644 index 00000000..3039bf6a --- /dev/null +++ b/include/uapi/linux/ptp_clock.h @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * PTP 1588 clock support - user space interface + * + * Copyright (C) 2010 OMICRON electronics GmbH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef _PTP_CLOCK_H_ +#define _PTP_CLOCK_H_ + +#include +#include + +/* PTP_xxx bits, for the flags field within the request structures. */ +#define PTP_ENABLE_FEATURE (1<<0) +#define PTP_RISING_EDGE (1<<1) +#define PTP_FALLING_EDGE (1<<2) + +/* + * struct ptp_clock_time - represents a time value + * + * The sign of the seconds field applies to the whole value. The + * nanoseconds field is always unsigned. The reserved field is + * included for sub-nanosecond resolution, should the demand for + * this ever appear. + * + */ +struct ptp_clock_time { + __s64 sec; /* seconds */ + __u32 nsec; /* nanoseconds */ + __u32 reserved; +}; + +struct ptp_clock_caps { + int max_adj; /* Maximum frequency adjustment in parts per billon. */ + int n_alarm; /* Number of programmable alarms. */ + int n_ext_ts; /* Number of external time stamp channels. */ + int n_per_out; /* Number of programmable periodic signals. */ + int pps; /* Whether the clock supports a PPS callback. */ + int n_pins; /* Number of input/output pins. */ + /* Whether the clock supports precise system-device cross timestamps */ + int cross_timestamping; + int rsv[13]; /* Reserved for future use. */ +}; + +struct ptp_extts_request { + unsigned int index; /* Which channel to configure. */ + unsigned int flags; /* Bit field for PTP_xxx flags. */ + unsigned int rsv[2]; /* Reserved for future use. */ +}; + +struct ptp_perout_request { + struct ptp_clock_time start; /* Absolute start time. */ + struct ptp_clock_time period; /* Desired period, zero means disable. */ + unsigned int index; /* Which channel to configure. */ + unsigned int flags; /* Reserved for future use. */ + unsigned int rsv[4]; /* Reserved for future use. */ +}; + +#define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */ + +struct ptp_sys_offset { + unsigned int n_samples; /* Desired number of measurements. */ + unsigned int rsv[3]; /* Reserved for future use. */ + /* + * Array of interleaved system/phc time stamps. The kernel + * will provide 2*n_samples + 1 time stamps, with the last + * one as a system time stamp. + */ + struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; +}; + +struct ptp_sys_offset_precise { + struct ptp_clock_time device; + struct ptp_clock_time sys_realtime; + struct ptp_clock_time sys_monoraw; + unsigned int rsv[4]; /* Reserved for future use. */ +}; + +enum ptp_pin_function { + PTP_PF_NONE, + PTP_PF_EXTTS, + PTP_PF_PEROUT, + PTP_PF_PHYSYNC, +}; + +struct ptp_pin_desc { + /* + * Hardware specific human readable pin name. This field is + * set by the kernel during the PTP_PIN_GETFUNC ioctl and is + * ignored for the PTP_PIN_SETFUNC ioctl. + */ + char name[64]; + /* + * Pin index in the range of zero to ptp_clock_caps.n_pins - 1. + */ + unsigned int index; + /* + * Which of the PTP_PF_xxx functions to use on this pin. + */ + unsigned int func; + /* + * The specific channel to use for this function. + * This corresponds to the 'index' field of the + * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls. + */ + unsigned int chan; + /* + * Reserved for future use. + */ + unsigned int rsv[5]; +}; + +#define PTP_CLK_MAGIC '=' + +#define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) +#define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) +#define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) +#define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) +#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) +#define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) +#define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) +#define PTP_SYS_OFFSET_PRECISE \ + _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise) + +struct ptp_extts_event { + struct ptp_clock_time t; /* Time event occured. */ + unsigned int index; /* Which channel produced the event. */ + unsigned int flags; /* Reserved for future use. */ + unsigned int rsv[2]; /* Reserved for future use. */ +}; + +#endif From patchwork Wed Mar 7 01:16:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesus Sanchez-Palencia X-Patchwork-Id: 882348 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zwwl639Gfz9sYh for ; Wed, 7 Mar 2018 12:18:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933438AbeCGBSk (ORCPT ); Tue, 6 Mar 2018 20:18:40 -0500 Received: from mga06.intel.com ([134.134.136.31]:44575 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932906AbeCGBSj (ORCPT ); Tue, 6 Mar 2018 20:18:39 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2018 17:18:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,433,1515484800"; d="scan'208";a="35180081" Received: from darjeeling.jf.intel.com ([10.24.15.164]) by fmsmga004.fm.intel.com with ESMTP; 06 Mar 2018 17:18:37 -0800 From: Jesus Sanchez-Palencia To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, Jesus Sanchez-Palencia Subject: [RFC v3 iproute2 2/3] uapi pkt_sched: Add tbs info - DO NOT COMMIT Date: Tue, 6 Mar 2018 17:16:07 -0800 Message-Id: <20180307011608.24186-2-jesus.sanchez-palencia@intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307011608.24186-1-jesus.sanchez-palencia@intel.com> References: <20180307011608.24186-1-jesus.sanchez-palencia@intel.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This should come from the next uapi headers update. Sending it now just as a convenience so anyone can build tc with tbs support. Signed-off-by: Jesus Sanchez-Palencia --- include/uapi/linux/pkt_sched.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index 37b5096a..92af9fa4 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -934,4 +934,22 @@ enum { #define TCA_CBS_MAX (__TCA_CBS_MAX - 1) + +/* TBS */ +struct tc_tbs_qopt { + __s32 delta; + __s32 clockid; + __u32 flags; +#define TC_TBS_SORTING_ON BIT(0) +#define TC_TBS_OFFLOAD_ON BIT(1) +}; + +enum { + TCA_TBS_UNSPEC, + TCA_TBS_PARMS, + __TCA_TBS_MAX, +}; + +#define TCA_TBS_MAX (__TCA_TBS_MAX - 1) + #endif From patchwork Wed Mar 7 01:16:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesus Sanchez-Palencia X-Patchwork-Id: 882350 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zwwlC5FRBz9sYh for ; Wed, 7 Mar 2018 12:18:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933521AbeCGBSp (ORCPT ); Tue, 6 Mar 2018 20:18:45 -0500 Received: from mga06.intel.com ([134.134.136.31]:44575 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933264AbeCGBSj (ORCPT ); Tue, 6 Mar 2018 20:18:39 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2018 17:18:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,433,1515484800"; d="scan'208";a="35180084" Received: from darjeeling.jf.intel.com ([10.24.15.164]) by fmsmga004.fm.intel.com with ESMTP; 06 Mar 2018 17:18:38 -0800 From: Jesus Sanchez-Palencia To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, Vinicius Costa Gomes , Jesus Sanchez-Palencia Subject: [RFC v3 iproute2 3/3] tc: Add support for the TBS Qdisc Date: Tue, 6 Mar 2018 17:16:08 -0800 Message-Id: <20180307011608.24186-3-jesus.sanchez-palencia@intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307011608.24186-1-jesus.sanchez-palencia@intel.com> References: <20180307011608.24186-1-jesus.sanchez-palencia@intel.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vinicius Costa Gomes The Time Based Scheduler (TBS) queueing discipline allows precise control of the transmission time of packets. The syntax is: tc qdisc add dev DEV parent NODE tbs delta clockid [offload] [sorting] Signed-off-by: Vinicius Costa Gomes Signed-off-by: Jesus Sanchez-Palencia --- tc/Makefile | 1 + tc/q_tbs.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 tc/q_tbs.c diff --git a/tc/Makefile b/tc/Makefile index 3716dd6a..3c87b0dc 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -71,6 +71,7 @@ TCMODULES += q_clsact.o TCMODULES += e_bpf.o TCMODULES += f_matchall.o TCMODULES += q_cbs.o +TCMODULES += q_tbs.o TCSO := ifeq ($(TC_CONFIG_ATM),y) diff --git a/tc/q_tbs.c b/tc/q_tbs.c new file mode 100644 index 00000000..b0823dc9 --- /dev/null +++ b/tc/q_tbs.c @@ -0,0 +1,200 @@ +/* + * q_tbs.c TBS. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Authors: Vinicius Costa Gomes + * Jesus Sanchez-Palencia + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +/* clockid is invalid if bits 0, 1, 2 are set as described by posix-timers.h */ +#define CLOCKID_INVALID (BIT(0) | BIT(1) | BIT(2)) +#define PTP_MAX_DEV_PATH 16 + +/* fd to clockid helpers. Copied from posix-timers.h. */ +#define CLOCKFD 3 +static inline clockid_t make_process_cpuclock(const unsigned int pid, + const clockid_t clock) +{ + return ((~pid) << 3) | clock; +} + +static inline clockid_t fd_to_clockid(const int fd) +{ + return make_process_cpuclock((unsigned int) fd, CLOCKFD); +} + +static void explain(void) +{ + fprintf(stderr, "Usage: ... tbs delta NANOS clockid CLOCKID [offload] [sorting]\n"); + fprintf(stderr, "CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI) or \ + a dynamic clock (i.e. /dev/ptp0).\n"); +} + +static void explain1(const char *arg, const char *val) +{ + fprintf(stderr, "tbs: illegal value for \"%s\": \"%s\"\n", arg, val); +} + +static void explain_clockid(const char *val) +{ + fprintf(stderr, "tbs: illegal value for \"clockid\": \"%s\".\n", val); + fprintf(stderr, "It must be a valid SYS-V id (i.e. CLOCK_TAI) or "\ + "dynamic clock (i.e. /dev/ptp0).\n"); +} + +static int get_clockid(__s32 *val, const char *arg) +{ + const struct static_clockid { + const char *name; + clockid_t clockid; + } clockids_sysv[] = { + { "CLOCK_REALTIME", CLOCK_REALTIME }, + { "CLOCK_TAI", CLOCK_TAI }, + { "CLOCK_BOOTTIME", CLOCK_BOOTTIME }, + { "CLOCK_MONOTONIC", CLOCK_MONOTONIC }, + { NULL } + }; + + struct ptp_clock_caps capabilities; + char ptp_path[PTP_MAX_DEV_PATH]; + const struct static_clockid *c; + int fd_ptp; + + for (c = clockids_sysv; c->name; c++) { + if (strncasecmp(c->name, arg, 25) == 0) { + *val = c->clockid; + + return 0; + } + } + + snprintf(ptp_path, sizeof(ptp_path), "%s", arg); + fd_ptp = open(ptp_path, O_RDONLY); + + /* Make sure the path provided points to a PTP chardev. */ + if (fd_ptp < 0 || ioctl(fd_ptp, PTP_CLOCK_GETCAPS, &capabilities) < 0) { + return -1; + } + + *val = fd_to_clockid(fd_ptp); + return 0; +} + + +static int tbs_parse_opt(struct qdisc_util *qu, int argc, + char **argv, struct nlmsghdr *n, const char *dev) +{ + struct tc_tbs_qopt opt = { + .clockid = CLOCKID_INVALID, + }; + struct rtattr *tail; + + while (argc > 0) { + if (matches(*argv, "offload") == 0) { + if (opt.flags & TC_TBS_OFFLOAD_ON) { + fprintf(stderr, "tbs: duplicate \"offload\" specification\n"); + return -1; + } + + opt.flags |= TC_TBS_OFFLOAD_ON; + } else if (matches(*argv, "sorting") == 0) { + if (opt.flags & TC_TBS_SORTING_ON) { + fprintf(stderr, "tbs: duplicate \"sorting\" specification\n"); + return -1; + } + + opt.flags |= TC_TBS_SORTING_ON; + } else if (matches(*argv, "delta") == 0) { + NEXT_ARG(); + if (opt.delta) { + fprintf(stderr, "tbs: duplicate \"delta\" specification\n"); + return -1; + } + if (get_s32(&opt.delta, *argv, 0)) { + explain1("delta", *argv); + return -1; + } + } else if (matches(*argv, "clockid") == 0) { + NEXT_ARG(); + if (opt.clockid != CLOCKID_INVALID) { + fprintf(stderr, "tbs: duplicate \"clockid\" specification\n"); + return -1; + } + if (get_clockid(&opt.clockid, *argv)) { + explain_clockid(*argv); + return -1; + } + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "tbs: unknown parameter \"%s\"\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + addattr_l(n, 2024, TCA_TBS_PARMS, &opt, sizeof(opt)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int tbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_TBS_MAX+1]; + struct tc_tbs_qopt *qopt; + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_TBS_MAX, opt); + + if (tb[TCA_TBS_PARMS] == NULL) + return -1; + + qopt = RTA_DATA(tb[TCA_TBS_PARMS]); + if (RTA_PAYLOAD(tb[TCA_TBS_PARMS]) < sizeof(*qopt)) + return -1; + + fprintf(f, "clockid "); + if (qopt->clockid == CLOCKID_INVALID) + fprintf(f, "invalid "); + else + fprintf(f, "%d ", qopt->clockid); + + fprintf(f, "delta %d ", qopt->delta); + fprintf(f, "offload %s ", (qopt->flags & TC_TBS_OFFLOAD_ON) ? + "on" : "off"); + fprintf(f, "sorting %s", (qopt->flags & TC_TBS_SORTING_ON) ? + "on" : "off"); + + return 0; +} + +struct qdisc_util tbs_qdisc_util = { + .id = "tbs", + .parse_qopt = tbs_parse_opt, + .print_qopt = tbs_print_opt, +};