Re: [PATCH 1/2] net: Assert proper context while calling napi_schedule()

Jakub Kicinski
2025-02-14T22:10:12Z

On Fri, 14 Feb 2025 08:43:28 -0800 Breno Leitao wrote:
> diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
> index 42f247cbdceec..cd56904a39049 100644
> --- a/drivers/net/netdevsim/netdev.c
> +++ b/drivers/net/netdevsim/netdev.c
> @@ -87,7 +87,7 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
> if (unlikely(nsim_forward_skb(peer_dev, skb, rq) == NET_RX_DROP))
> goto out_drop_cnt;
>
> - napi_schedule(&rq->napi);
> + hrtimer_start(&rq->napi_timer, ns_to_ktime(5), HRTIMER_MODE_REL);

ns -> us

We want to leave the timer be in case it's already scheduled.
Otherwise we'll keep postponing forever under load.
Double check that hrtime_start() does not reset the time if already
pending. Maybe hrtimer_start_range_ns(..., 0, us_to_ktime(5), ...)
would work?

> rcu_read_unlock();
> u64_stats_update_begin(&ns->syncp);
> @@ -426,6 +426,25 @@ static int nsim_init_napi(struct netdevsim *ns)
> return err;
> }
>
> +static enum hrtimer_restart nsim_napi_schedule(struct hrtimer *timer)
> +{
> + struct nsim_rq *rq;
> +
> + rq = container_of(timer, struct nsim_rq, napi_timer);
> + napi_schedule(&rq->napi);
> + /* TODO: Should HRTIMER_RESTART be returned if napi_schedule returns
> + * false?
> + */

I think not, ignore the return value

> + return HRTIMER_NORESTART;
> +}