diff mbox series

[v15,1/7] net: split off __napi_busy_poll from napi_busy_poll

Message ID 20230608163839.2891748-2-shr@devkernel.io (mailing list archive)
State New
Headers show
Series io_uring: add napi busy polling support | expand

Commit Message

Stefan Roesch June 8, 2023, 4:38 p.m. UTC
This splits off the key part of the napi_busy_poll function into its own
function __napi_busy_poll. The new function has an additional rcu
parameter. This new parameter can be used when the caller is already
holding the rcu read lock.

This is done in preparation for an additional napi_busy_poll() function,
that doesn't take the rcu_read_lock(). The new function is introduced
in the next patch.

Signed-off-by: Stefan Roesch <shr@devkernel.io>
---
 net/core/dev.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

kernel test robot June 8, 2023, 7:33 p.m. UTC | #1
Hi Stefan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on f026be0e1e881e3395c3d5418ffc8c2a2203c3f3]

url:    https://github.com/intel-lab-lkp/linux/commits/Stefan-Roesch/net-split-off-__napi_busy_poll-from-napi_busy_poll/20230609-010104
base:   f026be0e1e881e3395c3d5418ffc8c2a2203c3f3
patch link:    https://lore.kernel.org/r/20230608163839.2891748-2-shr%40devkernel.io
patch subject: [PATCH v15 1/7] net: split off __napi_busy_poll from napi_busy_poll
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230609/202306090341.ShxjwRn1-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git checkout f026be0e1e881e3395c3d5418ffc8c2a2203c3f3
        b4 shazam https://lore.kernel.org/r/20230608163839.2891748-2-shr@devkernel.io
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=alpha olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash net/core/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306090341.ShxjwRn1-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> net/core/dev.c:6182:6: warning: no previous prototype for '__napi_busy_loop' [-Wmissing-prototypes]
    6182 | void __napi_busy_loop(unsigned int napi_id,
         |      ^~~~~~~~~~~~~~~~


vim +/__napi_busy_loop +6182 net/core/dev.c

  6181	
> 6182	void __napi_busy_loop(unsigned int napi_id,
  6183			      bool (*loop_end)(void *, unsigned long),
  6184			      void *loop_end_arg, bool prefer_busy_poll, u16 budget,
  6185			      bool rcu)
  6186	{
  6187		unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
  6188		int (*napi_poll)(struct napi_struct *napi, int budget);
  6189		void *have_poll_lock = NULL;
  6190		struct napi_struct *napi;
  6191	
  6192	restart:
  6193		napi_poll = NULL;
  6194	
  6195		if (!rcu)
  6196			rcu_read_lock();
  6197	
  6198		napi = napi_by_id(napi_id);
  6199		if (!napi)
  6200			goto out;
  6201	
  6202		preempt_disable();
  6203		for (;;) {
  6204			int work = 0;
  6205	
  6206			local_bh_disable();
  6207			if (!napi_poll) {
  6208				unsigned long val = READ_ONCE(napi->state);
  6209	
  6210				/* If multiple threads are competing for this napi,
  6211				 * we avoid dirtying napi->state as much as we can.
  6212				 */
  6213				if (val & (NAPIF_STATE_DISABLE | NAPIF_STATE_SCHED |
  6214					   NAPIF_STATE_IN_BUSY_POLL)) {
  6215					if (prefer_busy_poll)
  6216						set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
  6217					goto count;
  6218				}
  6219				if (cmpxchg(&napi->state, val,
  6220					    val | NAPIF_STATE_IN_BUSY_POLL |
  6221						  NAPIF_STATE_SCHED) != val) {
  6222					if (prefer_busy_poll)
  6223						set_bit(NAPI_STATE_PREFER_BUSY_POLL, &napi->state);
  6224					goto count;
  6225				}
  6226				have_poll_lock = netpoll_poll_lock(napi);
  6227				napi_poll = napi->poll;
  6228			}
  6229			work = napi_poll(napi, budget);
  6230			trace_napi_poll(napi, work, budget);
  6231			gro_normal_list(napi);
  6232	count:
  6233			if (work > 0)
  6234				__NET_ADD_STATS(dev_net(napi->dev),
  6235						LINUX_MIB_BUSYPOLLRXPACKETS, work);
  6236			local_bh_enable();
  6237	
  6238			if (!loop_end || loop_end(loop_end_arg, start_time))
  6239				break;
  6240	
  6241			if (unlikely(need_resched())) {
  6242				if (rcu)
  6243					break;
  6244				if (napi_poll)
  6245					busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
  6246				preempt_enable();
  6247				rcu_read_unlock();
  6248				cond_resched();
  6249				if (loop_end(loop_end_arg, start_time))
  6250					return;
  6251				goto restart;
  6252			}
  6253			cpu_relax();
  6254		}
  6255		if (napi_poll)
  6256			busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
  6257		preempt_enable();
  6258	out:
  6259		if (!rcu)
  6260			rcu_read_unlock();
  6261	}
  6262
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index b3c13e041935..ae90265f4020 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6179,9 +6179,10 @@  static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool
 	local_bh_enable();
 }
 
-void napi_busy_loop(unsigned int napi_id,
-		    bool (*loop_end)(void *, unsigned long),
-		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
+void __napi_busy_loop(unsigned int napi_id,
+		      bool (*loop_end)(void *, unsigned long),
+		      void *loop_end_arg, bool prefer_busy_poll, u16 budget,
+		      bool rcu)
 {
 	unsigned long start_time = loop_end ? busy_loop_current_time() : 0;
 	int (*napi_poll)(struct napi_struct *napi, int budget);
@@ -6191,7 +6192,8 @@  void napi_busy_loop(unsigned int napi_id,
 restart:
 	napi_poll = NULL;
 
-	rcu_read_lock();
+	if (!rcu)
+		rcu_read_lock();
 
 	napi = napi_by_id(napi_id);
 	if (!napi)
@@ -6237,6 +6239,8 @@  void napi_busy_loop(unsigned int napi_id,
 			break;
 
 		if (unlikely(need_resched())) {
+			if (rcu)
+				break;
 			if (napi_poll)
 				busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
 			preempt_enable();
@@ -6252,7 +6256,16 @@  void napi_busy_loop(unsigned int napi_id,
 		busy_poll_stop(napi, have_poll_lock, prefer_busy_poll, budget);
 	preempt_enable();
 out:
-	rcu_read_unlock();
+	if (!rcu)
+		rcu_read_unlock();
+}
+
+void napi_busy_loop(unsigned int napi_id,
+		    bool (*loop_end)(void *, unsigned long),
+		    void *loop_end_arg, bool prefer_busy_poll, u16 budget)
+{
+	__napi_busy_loop(napi_id, loop_end, loop_end_arg, prefer_busy_poll,
+			 budget, false);
 }
 EXPORT_SYMBOL(napi_busy_loop);