All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Herbert <tom@herbertland.com>
To: netdev@vger.kernel.org
Cc: Tom Herbert <tom@herbertland.com>
Subject: [RFC PATCH 06/11] net: Function to check against maximum number for RPS queues
Date: Wed, 24 Jun 2020 10:17:45 -0700	[thread overview]
Message-ID: <20200624171749.11927-7-tom@herbertland.com> (raw)
In-Reply-To: <20200624171749.11927-1-tom@herbertland.com>

Add rps_check_max_queues function which checks is the input number
is greater than rps_max_num_queues. If it is then set max_num_queues
to the value and recreating the sock_flow_table to update the
queue masks used in table entries.
---
 include/linux/netdevice.h  | 10 ++++++++
 net/core/sysctl_net_core.c | 48 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d528aa61fea3..48ba1c1fc644 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -804,6 +804,16 @@ static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
 	}
 }
 
+int __rps_check_max_queues(unsigned int idx);
+
+static inline int rps_check_max_queues(unsigned int idx)
+{
+	if (idx < rps_max_num_queues)
+		return 0;
+
+	return __rps_check_max_queues(idx);
+}
+
 #ifdef CONFIG_RFS_ACCEL
 bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
 			 u16 filter_id);
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index d09471f29d89..743c46148135 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -127,6 +127,54 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
 
 	return ret;
 }
+
+int __rps_check_max_queues(unsigned int idx)
+{
+	unsigned int old;
+	size_t size;
+	int ret = 0;
+
+	/* Assume maximum queues should be a least the number of CPUs.
+	 * This avoids too much thrashing of the sock flow table at
+	 * initialization.
+	 */
+	if (idx < nr_cpu_ids && nr_cpu_ids < RPS_MAX_QID)
+		idx = nr_cpu_ids;
+
+	if (idx > RPS_MAX_QID)
+		return -EINVAL;
+
+	mutex_lock(&sock_flow_mutex);
+
+	old = rps_max_num_queues;
+	rps_max_num_queues = idx;
+
+	/* No need to reallocate table since nothing is changing */
+
+	if (roundup_pow_of_two(old) != roundup_pow_of_two(idx)) {
+		struct rps_sock_flow_table *sock_table;
+
+		sock_table = rcu_dereference_protected(rps_sock_flow_table,
+						       lockdep_is_held(&sock_flow_mutex));
+		size = sock_table ? sock_table->mask + 1 : 0;
+
+		/* Force creation of a new rps_sock_flow_table. It's
+		 * the same size as the existing table, but we expunge
+		 * any stale queue entries that would refer to the old
+		 * queue mask.
+		 */
+		ret = rps_create_sock_flow_table(size, size,
+						 sock_table, true);
+		if (ret)
+			rps_max_num_queues = old;
+	}
+
+	mutex_unlock(&sock_flow_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL(__rps_check_max_queues);
+
 #endif /* CONFIG_RPS */
 
 #ifdef CONFIG_NET_FLOW_LIMIT
-- 
2.25.1


  parent reply	other threads:[~2020-06-24 17:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 17:17 [RFC PATCH 00/11] ptq: Per Thread Queues Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 01/11] cgroup: Export cgroup_{procs,threads}_start and cgroup_procs_next Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 02/11] net: Create netqueue.h and define NO_QUEUE Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 03/11] arfs: Create set_arfs_queue Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 04/11] net-sysfs: Create rps_create_sock_flow_table Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 05/11] net: Infrastructure for per queue aRFS Tom Herbert
2020-06-28  8:55   ` kernel test robot
2020-06-24 17:17 ` Tom Herbert [this message]
2020-06-24 17:17 ` [RFC PATCH 07/11] net: Introduce global queues Tom Herbert
2020-06-24 23:00   ` kernel test robot
2020-06-24 23:58   ` kernel test robot
2020-06-25  0:23   ` kernel test robot
2020-06-30 21:06   ` Jonathan Lemon
2020-06-24 17:17 ` [RFC PATCH 08/11] ptq: Per Thread Queues Tom Herbert
2020-06-24 21:20   ` kernel test robot
2020-06-25  1:50   ` [RFC PATCH] ptq: null_pcdesc can be static kernel test robot
2020-06-25  7:26   ` [RFC PATCH 08/11] ptq: Per Thread Queues kernel test robot
2020-06-24 17:17 ` [RFC PATCH 09/11] ptq: Hook up transmit side of Per Queue Threads Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 10/11] ptq: Hook up receive " Tom Herbert
2020-06-24 17:17 ` [RFC PATCH 11/11] doc: Documentation for Per Thread Queues Tom Herbert
2020-06-25  2:20   ` kernel test robot
2020-06-25 23:00   ` Jacob Keller
2020-06-29  6:28   ` Saeed Mahameed
2020-06-29 15:10     ` Tom Herbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200624171749.11927-7-tom@herbertland.com \
    --to=tom@herbertland.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.