Skip to contentSkip to conversation

net/core: add optional threading for rps backlog processing

RFC Superseded Felix Fietkau 2 participants 2 messages Feb 16, 2023 – Feb 17, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 net/core: add optional threading for rps backlog processing

When dealing with few flows or an imbalance on CPU utilization, static RPS CPU assignment can be too inflexible. Add support for enabling threaded NAPI for RPS backlog processing in order to allow the scheduler to better balance processing. This helps better spread the load across idle CPUs.

---
 include/linux/netdevice.h  |  1 +
 net/core/dev.c             | 60 ++++++++++++++++++++++++++++++++++----
 net/core/sysctl_net_core.c | 27 +++++++++++++++++
 3 files changed, 83 insertions(+), 5 deletions(-)
include/linux/netdevice.h +1 -0
index d9cdbc047b49..9ee2162c907e 100644
@@ -522,6 +522,7 @@ static inline bool napi_complete(struct napi_struct *n)
 }
 
 int dev_set_threaded(struct net_device *dev, bool threaded);
+int rps_set_threaded(bool threaded);
 
 /**
  *	napi_disable - prevent NAPI from scheduling
net/core/dev.c +55 -5

87 lines not on this page · raw message

net/core/sysctl_net_core.c +27 -0
index 7130e6d9e263..438957535e74 100644
@@ -30,6 +30,7 @@ static int int_3600 = 3600;
 static int min_sndbuf = SOCK_MIN_SNDBUF;
 static int min_rcvbuf = SOCK_MIN_RCVBUF;
 static int max_skb_frags = MAX_SKB_FRAGS;
+static int rps_threaded;
 
 static int net_msg_warn;	/* Unused, but still a sysctl */
 
@@ -163,6 +164,23 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
 
 	return ret;
 }
+
+static int rps_threaded_sysctl(struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
+{
+	static DEFINE_MUTEX(rps_threaded_mutex);
+	int ret;
+
+	mutex_lock(&rps_threaded_mutex);
+
+	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+	if (write && !ret)
+		ret = rps_set_threaded(rps_threaded);
+
+	mutex_unlock(&rps_threaded_mutex);
+
+	return ret;
+}
 #endif /* CONFIG_RPS */
 
 #ifdef CONFIG_NET_FLOW_LIMIT
@@ -513,6 +531,15 @@ static struct ctl_table net_core_table[] = {
 		.mode		= 0644,
 		.proc_handler	= rps_default_mask_sysctl
 	},
+	{
+		.procname	= "rps_threaded",
+		.data		= &rps_threaded,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= rps_threaded_sysctl,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
 #endif
 #ifdef CONFIG_NET_FLOW_LIMIT
 	{
Signature · 1 line
2.39.0
#1 lore raw
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…

Hi Felix,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net-next/master]
[also build test ERROR on next-20230216]
[cannot apply to horms-ipvs/master net/master linus/master v6.2-rc8] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Felix-Fietkau/net-core-add-optional-threading-for-rps-backlog-processing/20230217-014318
patch link:    https://lore.kernel.org/r/20230216174154.89956-1-nbd%40nbd.name
patch subject: [RFC] net/core: add optional threading for rps backlog processing
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20230217/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/cfa45a2d0fa5797acfd823432640693fa2b0cde5
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Felix-Fietkau/net-core-add-optional-threading-for-rps-backlog-processing/20230217-014318
        git checkout cfa45a2d0fa5797acfd823432640693fa2b0cde5
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash net/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

net/core/dev.c: In function 'rps_set_threaded':

>> net/core/dev.c:6394:17: error: implicit declaration of function 'rps_lock'; did you mean 'rht_lock'? [-Werror=implicit-function-declaration]
    6394 |                 rps_lock(sd);
         |                 ^~~~~~~~
         |                 rht_lock
>> net/core/dev.c:6399:17: error: implicit declaration of function 'rps_unlock'; did you mean 'rht_unlock'? [-Werror=implicit-function-declaration]
    6399 |                 rps_unlock(sd);
         |                 ^~~~~~~~~~
         |                 rht_unlock

cc1: some warnings being treated as errors

vim +6394 net/core/dev.c

6357
6358 #ifdef CONFIG_RPS
6359 int rps_set_threaded(bool threaded)
6360 {
6361 static bool rps_threaded;
6362 int err = 0;
6363 int i;
6364
6365 if (rps_threaded == threaded)
6366 return 0;
6367
6368 for_each_possible_cpu(i) {
6369 struct softnet_data *sd = &per_cpu(softnet_data, i);
6370 struct napi_struct *n = &sd->backlog;
6371
6372 n->thread = kthread_run(napi_threaded_poll, n, "napi/rps-%d", i);
6373 if (IS_ERR(n->thread)) {
6374 err = PTR_ERR(n->thread);
6375 pr_err("kthread_run failed with err %d\n", err);
6376 n->thread = NULL;
6377 threaded = false;
6378 break;
6379 }
6380
6381 }
6382
6383 rps_threaded = threaded;
6384
6385 /* Make sure kthread is created before THREADED bit
6386 * is set.
6387 */
6388 smp_mb__before_atomic();
6389
6390 for_each_possible_cpu(i) {
6391 struct softnet_data *sd = &per_cpu(softnet_data, i);
6392 struct napi_struct *n = &sd->backlog;
6393

> 6394			rps_lock(sd);
  6395			if (threaded)
  6396				n->state |= NAPIF_STATE_THREADED;
  6397			else
  6398				n->state &= ~NAPIF_STATE_THREADED;
> 6399			rps_unlock(sd);

6400 }
6401
6402 return err;
6403 }
6404 #endif
6405

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests