netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND v3 net-next 0/7] Remove the "dsa_to_port in a loop" antipattern
@ 2021-10-20 17:49 Vladimir Oltean
  2021-10-20 17:49 ` [PATCH RESEND v3 net-next 1/7] net: dsa: introduce helpers for iterating through ports using dp Vladimir Oltean
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Vladimir Oltean @ 2021-10-20 17:49 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Florian Fainelli, Andrew Lunn, Vivien Didelot, Vladimir Oltean

I noticed that v3 was dropped with "Changes requested" without actually
requesting any change:
https://patchwork.kernel.org/project/netdevbpf/list/?series=565665&state=*
I suppose it has to do with the simultaneous build errors in mlx5, so
I'm just resending now that those are fixed.

v1->v2: more patches
v2->v3: less patches

As opposed to previous series, I would now like to first refactor the
DSA core, since that sees fewer patches than drivers, and make the
helpers available. Since the refactoring is fairly noisy, I don't want
to force it on driver maintainers right away, patches can be submitted
independently.

The original cover letter is below:

The DSA core and drivers currently iterate too much through the port
list of a switch. For example, this snippet:

	for (port = 0; port < ds->num_ports; port++) {
		if (!dsa_is_cpu_port(ds, port))
			continue;

		ds->ops->change_tag_protocol(ds, port, tag_ops->proto);
	}

iterates through ds->num_ports once, and then calls dsa_is_cpu_port to
filter out the other types of ports. But that function has a hidden call
to dsa_to_port() in it, which contains:

	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds == ds && dp->index == p)
			return dp;

where the only thing we wanted to know in the first place was whether
dp->type == DSA_PORT_TYPE_CPU or not.

So it seems that the problem is that we are not iterating with the right
variable. We have an "int port" but in fact need a "struct dsa_port *dp".

This has started being an issue since this patch series:
https://patchwork.ozlabs.org/project/netdev/cover/20191020031941.3805884-1-vivien.didelot@gmail.com/

The currently proposed set of changes iterates like this:

	dsa_switch_for_each_cpu_port(cpu_dp, ds)
		err = ds->ops->change_tag_protocol(ds, cpu_dp->index,
						   tag_ops->proto);

which iterates directly over ds->dst->ports, which is a list of struct
dsa_port *dp. This makes it much easier and more efficient to check
dp->type.

As a nice side effect, with the proposed driver API, driver writers are
now encouraged to use more efficient patterns, and not only due to less
iterations through the port list. For example, something like this:

	for (port = 0; port < ds->num_ports; port++)
		do_something();

probably does not need to do_something() for the ports that are disabled
in the device tree. But adding extra code for that would look like this:

	for (port = 0; port < ds->num_ports; port++) {
		if (!dsa_is_unused_port(ds, port))
			continue;

		do_something();
	}

and therefore, it is understandable that some driver writers may decide
to not bother. This patch series introduces a "dsa_switch_for_each_available_port"
macro which comes at no extra cost in terms of lines of code / number of
braces to the driver writer, but it has the "dsa_is_unused_port" check
embedded within it.


Vladimir Oltean (7):
  net: dsa: introduce helpers for iterating through ports using dp
  net: dsa: remove the "dsa_to_port in a loop" antipattern from the core
  net: dsa: do not open-code dsa_switch_for_each_port
  net: dsa: remove gratuitous use of dsa_is_{user,dsa,cpu}_port
  net: dsa: convert cross-chip notifiers to iterate using dp
  net: dsa: tag_sja1105: do not open-code dsa_switch_for_each_port
  net: dsa: tag_8021q: make dsa_8021q_{rx,tx}_vid take dp as argument

 drivers/net/dsa/sja1105/sja1105_vl.c |   3 +-
 include/linux/dsa/8021q.h            |   5 +-
 include/net/dsa.h                    |  35 +++++-
 net/dsa/dsa.c                        |  22 ++--
 net/dsa/dsa2.c                       |  57 ++++-----
 net/dsa/port.c                       |  21 ++--
 net/dsa/slave.c                      |   2 +-
 net/dsa/switch.c                     | 169 ++++++++++++++-------------
 net/dsa/tag_8021q.c                  | 113 +++++++++---------
 net/dsa/tag_ocelot_8021q.c           |   2 +-
 net/dsa/tag_sja1105.c                |   9 +-
 11 files changed, 224 insertions(+), 214 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-21 11:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-20 17:49 [PATCH RESEND v3 net-next 0/7] Remove the "dsa_to_port in a loop" antipattern Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 1/7] net: dsa: introduce helpers for iterating through ports using dp Vladimir Oltean
2021-10-20 23:10   ` Florian Fainelli
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 2/7] net: dsa: remove the "dsa_to_port in a loop" antipattern from the core Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 3/7] net: dsa: do not open-code dsa_switch_for_each_port Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 4/7] net: dsa: remove gratuitous use of dsa_is_{user,dsa,cpu}_port Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 5/7] net: dsa: convert cross-chip notifiers to iterate using dp Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 6/7] net: dsa: tag_sja1105: do not open-code dsa_switch_for_each_port Vladimir Oltean
2021-10-20 17:49 ` [PATCH RESEND v3 net-next 7/7] net: dsa: tag_8021q: make dsa_8021q_{rx,tx}_vid take dp as argument Vladimir Oltean
2021-10-21 11:50 ` [PATCH RESEND v3 net-next 0/7] Remove the "dsa_to_port in a loop" antipattern patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).