From patchwork Wed Feb 6 00:01:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirsher, Jeffrey T" X-Patchwork-Id: 1037277 X-Patchwork-Delegate: linville@tuxdriver.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@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=fail (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 43vM6m23zWz9s7T for ; Wed, 6 Feb 2019 11:01:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbfBFABT (ORCPT ); Tue, 5 Feb 2019 19:01:19 -0500 Received: from mga09.intel.com ([134.134.136.24]:8500 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfBFABP (ORCPT ); Tue, 5 Feb 2019 19:01:15 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 16:01:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,337,1544515200"; d="scan'208";a="113999015" Received: from jtkirshe-desk1.jf.intel.com ([134.134.177.96]) by orsmga006.jf.intel.com with ESMTP; 05 Feb 2019 16:01:13 -0800 From: Jeff Kirsher To: linville@tuxdriver.com Cc: Nicholas Nunley , netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com, Jeff Kirsher Subject: [PATCH v2 5/6] ethtool: support per-queue sub command --coalesce Date: Tue, 5 Feb 2019 16:01:05 -0800 Message-Id: <20190206000106.24364-5-jeffrey.t.kirsher@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206000106.24364-1-jeffrey.t.kirsher@intel.com> References: <20190206000106.24364-1-jeffrey.t.kirsher@intel.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Nicholas Nunley This patch adds the ability to configure the coalesce settings from do_scoalesce on a per-queue basis. For each masked queue the current settings are read, modified, and written back to the kernel. Example: $ sudo ./ethtool --set-perqueue-command eth5 queue_mask 0x1 --coalesce rx-usecs 10 tx-usecs 5 $ sudo ./ethtool --set-perqueue-command eth5 queue_mask 0x1 --show-coalesce Queue: 0 Adaptive RX: on TX: on stats-block-usecs: 0 sample-interval: 0 pkt-rate-low: 0 pkt-rate-high: 0 rx-usecs: 10 rx-frames: 0 rx-usecs-irq: 0 rx-frames-irq: 256 tx-usecs: 5 tx-frames: 0 tx-usecs-irq: 0 tx-frames-irq: 256 rx-usecs-low: 0 rx-frame-low: 0 tx-usecs-low: 0 tx-frame-low: 0 rx-usecs-high: 0 rx-frame-high: 0 tx-usecs-high: 0 tx-frame-high: 0 Based on patch by Kan Liang Signed-off-by: Nicholas Nunley Signed-off-by: Jeff Kirsher --- ethtool.8.in | 3 ++- ethtool.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/ethtool.8.in b/ethtool.8.in index 71bb962..c7202e8 100644 --- a/ethtool.8.in +++ b/ethtool.8.in @@ -1153,7 +1153,8 @@ Sets the specific queues which the sub command is applied to. If queue_mask is not set, the sub command will be applied to all queues. .TP .B sub_command -Sets the sub command. The supported sub commands include --show-coalesce. +Sets the sub command. The supported sub commands include --show-coalesce and +--coalesce. .RE .SH BUGS Not supported (in part or whole) on all network drivers. diff --git a/ethtool.c b/ethtool.c index 9a1b83b..01bdaf1 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5269,7 +5269,7 @@ static const struct option { { "--set-fec", 1, do_sfec, "Set FEC settings", " [ encoding auto|off|rs|baser [...]]\n"}, { "--set-perqueue-command", 1, do_perqueue, "Set per queue command. " - "The supported sub commands include --show-coalesce", + "The supported sub commands include --show-coalesce, --coalesce", " [queue_mask %x] SUB_COMMAND\n"}, { "-h|--help", 0, show_usage, "Show this help" }, { "--version", 0, do_version, "Show version number" }, @@ -5397,6 +5397,53 @@ get_per_queue_coalesce(struct cmd_context *ctx, __u32 *queue_mask, int n_queues) return per_queue_opt; } +static void set_per_queue_coalesce(struct cmd_context *ctx, + struct ethtool_per_queue_op *per_queue_opt) +{ + struct ethtool_coalesce ecoal; + DECLARE_COALESCE_OPTION_VARS(); + struct cmdline_info cmdline_coalesce[] = COALESCE_CMDLINE_INFO(ecoal); + __u32 *queue_mask = per_queue_opt->queue_mask; + char *addr = (char *)per_queue_opt + sizeof(*per_queue_opt); + int gcoalesce_changed = 0; + int i; + + parse_generic_cmdline(ctx, &gcoalesce_changed, + cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce)); + + for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) { + int queue = i * 32; + __u32 mask = queue_mask[i]; + + while (mask > 0) { + if (mask & 0x1) { + int changed = 0; + + memcpy(&ecoal, addr, + sizeof(struct ethtool_coalesce)); + do_generic_set(cmdline_coalesce, + ARRAY_SIZE(cmdline_coalesce), + &changed); + if (!changed) + fprintf(stderr, + "Queue %d, no coalesce parameters changed\n", + queue); + memcpy(addr, &ecoal, + sizeof(struct ethtool_coalesce)); + addr += sizeof(struct ethtool_coalesce); + } + mask = mask >> 1; + queue++; + } + } + + per_queue_opt->cmd = ETHTOOL_PERQUEUE; + per_queue_opt->sub_command = ETHTOOL_SCOALESCE; + + if (send_ioctl(ctx, per_queue_opt)) + perror("Cannot set device per queue parameters"); +} + static int do_perqueue(struct cmd_context *ctx) { struct ethtool_per_queue_op *per_queue_opt; @@ -5447,6 +5494,17 @@ static int do_perqueue(struct cmd_context *ctx) } dump_per_queue_coalesce(per_queue_opt, queue_mask); free(per_queue_opt); + } else if (strstr(args[i].opts, "--coalesce") != NULL) { + ctx->argc--; + ctx->argp++; + per_queue_opt = get_per_queue_coalesce(ctx, queue_mask, + n_queues); + if (per_queue_opt == NULL) { + perror("Cannot get device per queue parameters"); + return -EFAULT; + } + set_per_queue_coalesce(ctx, per_queue_opt); + free(per_queue_opt); } else { perror("The subcommand is not supported yet"); return -EOPNOTSUPP;