Skip to content

Commit 898f801

Browse files
nbd168davem330
authored andcommitted
net: extract napi poll functionality to __napi_poll()
This commit introduces a new function __napi_poll() which does the main logic of the existing napi_poll() function, and will be called by other functions in later commits. This idea and implementation is done by Felix Fietkau <nbd@nbd.name> and is proposed as part of the patch to move napi work to work_queue context. This commit by itself is a code restructure. Signed-off-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Wei Wang <weiwan@google.com> Reviewed-by: Alexander Duyck <alexanderduyck@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4feffea commit 898f801

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

net/core/dev.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6776,15 +6776,10 @@ void __netif_napi_del(struct napi_struct *napi)
67766776
}
67776777
EXPORT_SYMBOL(__netif_napi_del);
67786778

6779-
static int napi_poll(struct napi_struct *n, struct list_head *repoll)
6779+
static int __napi_poll(struct napi_struct *n, bool *repoll)
67806780
{
6781-
void *have;
67826781
int work, weight;
67836782

6784-
list_del_init(&n->poll_list);
6785-
6786-
have = netpoll_poll_lock(n);
6787-
67886783
weight = n->weight;
67896784

67906785
/* This NAPI_STATE_SCHED test is for avoiding a race
@@ -6804,7 +6799,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
68046799
n->poll, work, weight);
68056800

68066801
if (likely(work < weight))
6807-
goto out_unlock;
6802+
return work;
68086803

68096804
/* Drivers must not modify the NAPI state if they
68106805
* consume the entire weight. In such cases this code
@@ -6813,7 +6808,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
68136808
*/
68146809
if (unlikely(napi_disable_pending(n))) {
68156810
napi_complete(n);
6816-
goto out_unlock;
6811+
return work;
68176812
}
68186813

68196814
/* The NAPI context has more processing work, but busy-polling
@@ -6826,7 +6821,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
68266821
*/
68276822
napi_schedule(n);
68286823
}
6829-
goto out_unlock;
6824+
return work;
68306825
}
68316826

68326827
if (n->gro_bitmask) {
@@ -6844,12 +6839,29 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
68446839
if (unlikely(!list_empty(&n->poll_list))) {
68456840
pr_warn_once("%s: Budget exhausted after napi rescheduled\n",
68466841
n->dev ? n->dev->name : "backlog");
6847-
goto out_unlock;
6842+
return work;
68486843
}
68496844

6850-
list_add_tail(&n->poll_list, repoll);
6845+
*repoll = true;
6846+
6847+
return work;
6848+
}
6849+
6850+
static int napi_poll(struct napi_struct *n, struct list_head *repoll)
6851+
{
6852+
bool do_repoll = false;
6853+
void *have;
6854+
int work;
6855+
6856+
list_del_init(&n->poll_list);
6857+
6858+
have = netpoll_poll_lock(n);
6859+
6860+
work = __napi_poll(n, &do_repoll);
6861+
6862+
if (do_repoll)
6863+
list_add_tail(&n->poll_list, repoll);
68516864

6852-
out_unlock:
68536865
netpoll_poll_unlock(have);
68546866

68556867
return work;

0 commit comments

Comments
 (0)