Subject: Re: [PATCH net-next v11 2/4] ethtool: provide customized dim profile management

From: Simon Horman <[email-masked]>
Date: Fri, 3 May 2024 14:52:44 +0100

On Wed, May 01, 2024 at 01:31:34AM +0800, Heng Qi wrote:

...

> diff --git a/include/linux/dim.h b/include/linux/dim.h

...

> @@ -198,6 +234,32 @@ enum dim_step_result {
>  	DIM_ON_EDGE,
>  };
>  
> +/**
> + * net_dim_init_irq_moder - collect information to initialize irq moderation
> + * @dev: target network device
> + * @profile_flags: Rx or Tx profile modification capability
> + * @coal_flags: irq moderation params flags
> + * @rx_mode: CQ period mode for Rx
> + * @tx_mode: CQ period mode for Tx
> + * @rx_dim_work: Rx worker called after dim decision
> + *    void (*rx_dim_work)(struct work_struct *work);
> + *
> + * @tx_dim_work: Tx worker called after dim decision
> + *    void (*tx_dim_work)(struct work_struct *work);
> + *

Hi Heng Qi,

The above seems to result in make htmldocs issuing the following warnings:

 .../net_dim:175: ./include/linux/dim.h:244: WARNING: Inline emphasis start-string without end-string.
 .../net_dim:175: ./include/linux/dim.h:244: WARNING: Inline emphasis start-string without end-string.
 .../net_dim:175: ./include/linux/dim.h:247: WARNING: Inline emphasis start-string without end-string.
 .../net_dim:175: ./include/linux/dim.h:247: WARNING: Inline emphasis start-string without end-string.

I suggest the following alternative:

 * @rx_dim_work: Rx worker called after dim decision
 * @tx_dim_work: Tx worker called after dim decision

Exercised using Sphinx 7.2.6

...

> diff --git a/net/ethtool/coalesce.c b/net/ethtool/coalesce.c

...

> @@ -134,6 +212,12 @@ static int coalesce_fill_reply(struct sk_buff *skb,
>  	const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
>  	const struct kernel_ethtool_coalesce *kcoal = &data->kernel_coalesce;
>  	const struct ethtool_coalesce *coal = &data->coalesce;
> +#if IS_ENABLED(CONFIG_DIMLIB)
> +	struct net_device *dev = req_base->dev;
> +	struct dim_irq_moder *moder = dev->irq_moder;
> +	u8 coal_flags;
> +	int ret;
> +#endif
>  	u32 supported = data->supported_params;

It's a minor nit, but here goes: please consider using reverse xmas tree
order - longest line to shortest - for local variable declarations in
Networking code.

In this case, I appreciate that it's not strictly possible without
introducing more than one IS_ENABLED condition, which seems worse.
So, as that condition breaks the visual flow, what I suggest in this
case is having a second block of local variable declarations, like this:

	const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
	const struct kernel_ethtool_coalesce *kcoal = &data->kernel_coalesce;
	const struct ethtool_coalesce *coal = &data->coalesce;
	u32 supported = data->supported_params;                  

#if IS_ENABLED(CONFIG_DIMLIB)
	struct dim_irq_moder *moder = dev->irq_moder;
	struct net_device *dev = req_base->dev;
	u8 coal_flags;
	int ret;
#endif 

Or better still, if it can be done cleanly, moving all the IS_ENABLED()
code in this function into a separate function, with an no-op
implementation in the case that CONFIG_DIMLIB is not enabled. In general
I'd recommend that approach over sprinkling IS_ENABLED or #ifdef inside
functions. Because in my experience it tends to lead to more readable code.

In any case, the following tool is helpful for isolating
reverse xmas tree issues.

https://github.com/ecree-solarflare/xmastree

>  	if (coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS,
> @@ -192,11 +276,49 @@ static int coalesce_fill_reply(struct sk_buff *skb,
>  			     kcoal->tx_aggr_time_usecs, supported))
>  		return -EMSGSIZE;
>  
> +#if IS_ENABLED(CONFIG_DIMLIB)
> +	if (!moder)
> +		return 0;
> +
> +	coal_flags = moder->coal_flags;
> +	rcu_read_lock();
> +	if (moder->profile_flags & DIM_PROFILE_RX) {
> +		ret = coalesce_put_profile(skb, ETHTOOL_A_COALESCE_RX_PROFILE,
> +					   rcu_dereference(moder->rx_profile),
> +					   coal_flags);
> +		if (ret) {
> +			rcu_read_unlock();
> +			return ret;
> +		}
> +	}
> +
> +	if (moder->profile_flags & DIM_PROFILE_TX) {
> +		ret = coalesce_put_profile(skb, ETHTOOL_A_COALESCE_TX_PROFILE,
> +					   rcu_dereference(moder->tx_profile),
> +					   coal_flags);
> +		if (ret) {
> +			rcu_read_unlock();
> +			return ret;
> +		}
> +	}
> +	rcu_read_unlock();
> +#endif
>  	return 0;
>  }

...