From: Ivan Vecera <ivecera@redhat.com>
To: intel-wired-lan@lists.osuosl.org
Cc: Jesse Brandeburg <jesse.brandeburg@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org,
Jacob Keller <jacob.e.keller@intel.com>,
Wojciech Drewek <wojciech.drewek@intel.com>,
Simon Horman <horms@kernel.org>,
mschmidt@redhat.com, netdev@vger.kernel.org
Subject: Re: [PATCH v4 2/5] i40e: Introduce and use macros for iterating VSIs and VEBs
Date: Fri, 24 Nov 2023 15:52:47 +0100 [thread overview]
Message-ID: <838b7b9b-a937-4f6c-9239-93e40fe0a97b@redhat.com> (raw)
In-Reply-To: <20231122101545.28819-3-ivecera@redhat.com>
On 22. 11. 23 11:15, Ivan Vecera wrote:
> Introduce i40e_for_each_vsi() and i40e_for_each_veb() helper
> macros and use them to iterate relevant arrays.
>
> Replace pattern:
> for (i = 0; i < pf->num_alloc_vsi; i++)
> by:
> i40e_for_each_vsi(pf, i, vsi)
>
> and pattern:
> for (i = 0; i < I40E_MAX_VEB; i++)
> by
> i40e_for_each_veb(pf, i, veb)
>
> These macros also check if array item pf->vsi[i] or pf->veb[i]
> are not NULL and skip such items so we can remove redundant
> checks from loop bodies.
>
> Reviewed-by: Wojciech Drewek<wojciech.drewek@intel.com>
> Signed-off-by: Ivan Vecera<ivecera@redhat.com>
> ---
> drivers/net/ethernet/intel/i40e/i40e.h | 56 ++-
> drivers/net/ethernet/intel/i40e/i40e_dcb_nl.c | 10 +-
> .../net/ethernet/intel/i40e/i40e_debugfs.c | 54 +--
> drivers/net/ethernet/intel/i40e/i40e_main.c | 389 ++++++++----------
> 4 files changed, 264 insertions(+), 245 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
> index f1627ab211cd..1e9266de270b 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e.h
> +++ b/drivers/net/ethernet/intel/i40e/i40e.h
> @@ -686,6 +686,54 @@ struct i40e_pf {
> struct list_head ddp_old_prof;
> };
>
> +/**
> + * __i40e_pf_next_vsi - get next valid VSI
> + * @pf: pointer to the PF struct
> + * @idx: pointer to start position number
> + *
> + * Find and return next non-NULL VSI pointer in pf->vsi array and
> + * updates idx position. Returns NULL if no VSI is found.
> + **/
> +static __always_inline struct i40e_vsi *
> +__i40e_pf_next_vsi(struct i40e_pf *pf, int *idx)
> +{
> + while (*idx < pf->num_alloc_vsi) {
> + if (pf->vsi[*idx])
> + return pf->vsi[(*idx)++];
> + (*idx)++;
> + }
> + return NULL;
> +}
> +
> +#define i40e_pf_for_each_vsi(_pf, _i, _vsi) \
> + for (_i = 0, _vsi = __i40e_pf_next_vsi(_pf, &_i); \
> + _vsi; \
> + _vsi = __i40e_pf_next_vsi(_pf, &_i))
> +
It would be safer to update idx to index of returned vsi in
__i40e_pf_next_vsi() so
(pf->vsi[i] == vsi) in i40e_pf_for_each_vsi(pf, i, vsi) loop.
Will fix this in v5.
Thanks,
Ivan
next prev parent reply other threads:[~2023-11-24 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 10:15 [PATCH iwl-next v4 0/5] i40e: Simplify VSI and VEB handling Ivan Vecera
2023-11-22 10:15 ` [PATCH v4 1/5] i40e: Use existing helper to find flow director VSI Ivan Vecera
2023-11-22 10:15 ` [PATCH v4 2/5] i40e: Introduce and use macros for iterating VSIs and VEBs Ivan Vecera
2023-11-24 14:52 ` Ivan Vecera [this message]
2023-11-22 10:15 ` [PATCH v4 3/5] i40e: Add helpers to find VSI and VEB by SEID and use them Ivan Vecera
2023-11-22 10:15 ` [PATCH v4 4/5] i40e: Fix broken support for floating VEBs Ivan Vecera
2023-11-22 10:15 ` [PATCH v4 5/5] i40e: Remove VEB recursion Ivan Vecera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=838b7b9b-a937-4f6c-9239-93e40fe0a97b@redhat.com \
--to=ivecera@redhat.com \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jacob.e.keller@intel.com \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wojciech.drewek@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®