From patchwork Wed Oct 11 00:46:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 824156 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=osuosl.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yBb0j0xkFz9t64 for ; Wed, 11 Oct 2017 11:47:17 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 924F4824DC; Wed, 11 Oct 2017 00:47:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oPbr+HJqtWDK; Wed, 11 Oct 2017 00:47:12 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 2536A82FAB; Wed, 11 Oct 2017 00:47:12 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id C71311C0FDB for ; Wed, 11 Oct 2017 00:47:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id BD54D89012 for ; Wed, 11 Oct 2017 00:47:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1k5IjUajPSZu for ; Wed, 11 Oct 2017 00:47:08 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by whitealder.osuosl.org (Postfix) with ESMTPS id 1BE1289018 for ; Wed, 11 Oct 2017 00:47:08 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2017 17:47:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,359,1503385200"; d="scan'208";a="908716152" Received: from ellie.jf.intel.com (HELO localhost.localdomain) ([10.24.13.71]) by FMSMGA003.fm.intel.com with ESMTP; 10 Oct 2017 17:47:07 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org Date: Tue, 10 Oct 2017 17:46:51 -0700 Message-Id: <20171011004652.15630-2-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171011004652.15630-1-vinicius.gomes@intel.com> References: <20171011004652.15630-1-vinicius.gomes@intel.com> Cc: rodney.cummings@ni.com, andre.guedes@intel.com, jiri@resnulli.us, ivan.briano@intel.com, richardcochran@gmail.com, henrik@austad.us, jhs@mojatatu.com, levipearson@gmail.com, boon.leong.ong@intel.com, xiyou.wangcong@gmail.com, jesus.sanchez-palencia@intel.com Subject: [Intel-wired-lan] [iproute2 net-next v2 2/3] tc: Add support for the CBS qdisc X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" The Credit Based Shaper (CBS) queueing discipline allows bandwidth reservation with sub-milisecond precision. It is defined by the 802.1Q-2014 specification (section 8.6.8.2 and Annex L). The syntax is: tc qdisc add dev DEV parent NODE cbs locredit hicredit sendslope idleslope (The order is not important) Signed-off-by: Vinicius Costa Gomes --- tc/Makefile | 1 + tc/q_cbs.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 tc/q_cbs.c diff --git a/tc/Makefile b/tc/Makefile index 777de5e6..24bd3e2e 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -69,6 +69,7 @@ TCMODULES += q_hhf.o TCMODULES += q_clsact.o TCMODULES += e_bpf.o TCMODULES += f_matchall.o +TCMODULES += q_cbs.o TCSO := ifeq ($(TC_CONFIG_ATM),y) diff --git a/tc/q_cbs.c b/tc/q_cbs.c new file mode 100644 index 00000000..e53be654 --- /dev/null +++ b/tc/q_cbs.c @@ -0,0 +1,142 @@ +/* + * q_cbs.c CBS. + * + * 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 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... cbs hicredit BYTES locredit BYTES sendslope BPS idleslope BPS\n"); + fprintf(stderr, " [offload 0|1]\n"); + +} + +static void explain1(const char *arg, const char *val) +{ + fprintf(stderr, "cbs: illegal value for \"%s\": \"%s\"\n", arg, val); +} + +static int cbs_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) +{ + struct tc_cbs_qopt opt = {}; + struct rtattr *tail; + + while (argc > 0) { + if (matches(*argv, "offload") == 0) { + NEXT_ARG(); + if (opt.offload) { + fprintf(stderr, "cbs: duplicate \"offload\" specification\n"); + return -1; + } + if (get_u8(&opt.offload, *argv, 0)) { + explain1("offload", *argv); + return -1; + } + } else if (matches(*argv, "hicredit") == 0) { + NEXT_ARG(); + if (opt.hicredit) { + fprintf(stderr, "cbs: duplicate \"hicredit\" specification\n"); + return -1; + } + if (get_s32(&opt.hicredit, *argv, 0)) { + explain1("hicredit", *argv); + return -1; + } + } else if (matches(*argv, "locredit") == 0) { + NEXT_ARG(); + if (opt.locredit) { + fprintf(stderr, "cbs: duplicate \"locredit\" specification\n"); + return -1; + } + if (get_s32(&opt.locredit, *argv, 0)) { + explain1("locredit", *argv); + return -1; + } + } else if (matches(*argv, "sendslope") == 0) { + NEXT_ARG(); + if (opt.sendslope) { + fprintf(stderr, "cbs: duplicate \"sendslope\" specification\n"); + return -1; + } + if (get_s32(&opt.sendslope, *argv, 0)) { + explain1("sendslope", *argv); + return -1; + } + } else if (matches(*argv, "idleslope") == 0) { + NEXT_ARG(); + if (opt.idleslope) { + fprintf(stderr, "cbs: duplicate \"idleslope\" specification\n"); + return -1; + } + if (get_s32(&opt.idleslope, *argv, 0)) { + explain1("idleslope", *argv); + return -1; + } + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "cbs: 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_CBS_PARMS, &opt, sizeof(opt)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int cbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CBS_MAX+1]; + struct tc_cbs_qopt *qopt; + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CBS_MAX, opt); + + if (tb[TCA_CBS_PARMS] == NULL) + return -1; + + qopt = RTA_DATA(tb[TCA_CBS_PARMS]); + if (RTA_PAYLOAD(tb[TCA_CBS_PARMS]) < sizeof(*qopt)) + return -1; + + fprintf(f, "hicredit %d ", qopt->hicredit); + fprintf(f, "locredit %d ", qopt->locredit); + fprintf(f, "sendslope %d ", qopt->sendslope); + fprintf(f, "idleslope %d ", qopt->idleslope); + fprintf(f, "offload %d ", qopt->offload); + + return 0; +} + +struct qdisc_util cbs_qdisc_util = { + .id = "cbs", + .parse_qopt = cbs_parse_opt, + .print_qopt = cbs_print_opt, +};