From patchwork Wed Feb 6 00:01:03 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: 1037279 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 43vM6s2BV8z9s7T for ; Wed, 6 Feb 2019 11:01:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbfBFABY (ORCPT ); Tue, 5 Feb 2019 19:01:24 -0500 Received: from mga09.intel.com ([134.134.136.24]:8499 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbfBFABO (ORCPT ); Tue, 5 Feb 2019 19:01:14 -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="113999009" 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 3/6] ethtool: introduce new ioctl for per-queue settings Date: Tue, 5 Feb 2019 16:01:03 -0800 Message-Id: <20190206000106.24364-3-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 Introduce a new ioctl for setting per-queue parameters. Users can apply commands to specific queues by setting SUB_COMMAND and queue_mask with the following ethtool command: ethtool --set-perqueue-command DEVNAME [queue_mask %x] SUB_COMMAND If queue_mask is not set, the SUB_COMMAND will be applied to all queues. SUB_COMMANDs for per-queue settings will be implemented in following patches. Based on patch by Kan Liang Signed-off-by: Nicholas Nunley Signed-off-by: Jeff Kirsher --- ethtool.8.in | 20 ++++++++++ ethtool.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/ethtool.8.in b/ethtool.8.in index 5a26cff..0aaca2c 100644 --- a/ethtool.8.in +++ b/ethtool.8.in @@ -391,6 +391,14 @@ ethtool \- query or control network driver and hardware settings .I devname .B encoding .BR auto | off | rs | baser \ [...] +.HP +.B ethtool \-\-set\-perqueue\-command +.I devname +.RB [ queue_mask +.IR %x ] +.I sub_command +.RB ... + . . .\" Adjust lines (i.e. full justification) and hyphenate. .ad @@ -1135,6 +1143,18 @@ RS Force RS-FEC encoding BaseR Force BaseR encoding .TE .RE +.TP +.B \-\-set\-perqueue\-command +Sets sub command to specific queues. +.RS 4 +.TP +.B queue_mask %x +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. +.RE .SH BUGS Not supported (in part or whole) on all network drivers. .SH AUTHOR diff --git a/ethtool.c b/ethtool.c index af266c5..4dc725c 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5048,6 +5048,8 @@ static int do_sfec(struct cmd_context *ctx) return 0; } +static int do_perqueue(struct cmd_context *ctx); + #ifndef TEST_ETHTOOL int send_ioctl(struct cmd_context *ctx, void *cmd) { @@ -5243,6 +5245,8 @@ static const struct option { { "--show-fec", 1, do_gfec, "Show FEC settings"}, { "--set-fec", 1, do_sfec, "Set FEC settings", " [ encoding auto|off|rs|baser [...]]\n"}, + { "--set-perqueue-command", 1, do_perqueue, "Set per queue command", + " [queue_mask %x] SUB_COMMAND\n"}, { "-h|--help", 0, show_usage, "Show this help" }, { "--version", 0, do_version, "Show version number" }, {} @@ -5294,6 +5298,103 @@ static int find_option(int argc, char **argp) return -1; } +static int set_queue_mask(u32 *queue_mask, char *str) +{ + int len = strlen(str); + int index = __KERNEL_DIV_ROUND_UP(len * 4, 32); + char tmp[9]; + char *end = str + len; + int i, num; + __u32 mask; + int n_queues = 0; + + if (len > MAX_NUM_QUEUE) + return -EINVAL; + + for (i = 0; i < index; i++) { + num = end - str; + + if (num >= 8) { + end -= 8; + num = 8; + } else { + end = str; + } + strncpy(tmp, end, num); + tmp[num] = '\0'; + + queue_mask[i] = strtoul(tmp, NULL, 16); + + mask = queue_mask[i]; + while (mask > 0) { + if (mask & 0x1) + n_queues++; + mask = mask >> 1; + } + } + + return n_queues; +} + +#define MAX(x, y) (x > y ? x : y) + +static int find_max_num_queues(struct cmd_context *ctx) +{ + struct ethtool_channels echannels; + + echannels.cmd = ETHTOOL_GCHANNELS; + if (send_ioctl(ctx, &echannels)) + return -1; + + return MAX(MAX(echannels.rx_count, echannels.tx_count), + echannels.combined_count); +} + +static int do_perqueue(struct cmd_context *ctx) +{ + __u32 queue_mask[__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32)] = {0}; + int i, n_queues = 0; + + if (ctx->argc == 0) + exit_bad_args(); + + /* + * The sub commands will be applied to + * all queues if no queue_mask set + */ + if (strncmp(*ctx->argp, "queue_mask", 10)) { + n_queues = find_max_num_queues(ctx); + if (n_queues < 0) { + perror("Cannot get number of queues"); + return -EFAULT; + } + for (i = 0; i < n_queues / 32; i++) + queue_mask[i] = ~0; + queue_mask[i] = (1 << (n_queues - i * 32)) - 1; + fprintf(stdout, + "The sub commands will be applied to all %d queues\n", + n_queues); + } else { + ctx->argc--; + ctx->argp++; + n_queues = set_queue_mask(queue_mask, *ctx->argp); + if (n_queues < 0) { + perror("Invalid queue mask"); + return n_queues; + } + ctx->argc--; + ctx->argp++; + } + + i = find_option(ctx->argc, ctx->argp); + if (i < 0) + exit_bad_args(); + + /* no sub_command support yet */ + + return 0; +} + int main(int argc, char **argp) { int (*func)(struct cmd_context *);