From: Lukas Wunner <lukas@wunner.de>
To: Hans Zhang <18255117159@163.com>
Cc: bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com,
kwilczynski@kernel.org, mani@kernel.org,
ilpo.jarvinen@linux.intel.com, jingoohan1@gmail.com,
robh@kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] PCI/bwctrl: Replace legacy speed conversion with shared macro
Date: Sat, 16 Aug 2025 22:13:15 +0200 [thread overview]
Message-ID: <aKDmW6l6uxZGr1Wl@wunner.de> (raw)
In-Reply-To: <20250816154633.338653-4-18255117159@163.com>
On Sat, Aug 16, 2025 at 11:46:33PM +0800, Hans Zhang wrote:
> Remove obsolete pci_bus_speed2lnkctl2() function and utilize the common
> PCIE_SPEED2LNKCTL2_TLS() macro instead.
[...]
> +++ b/drivers/pci/pcie/bwctrl.c
> @@ -53,23 +53,6 @@ static bool pcie_valid_speed(enum pci_bus_speed speed)
> return (speed >= PCIE_SPEED_2_5GT) && (speed <= PCIE_SPEED_64_0GT);
> }
>
> -static u16 pci_bus_speed2lnkctl2(enum pci_bus_speed speed)
> -{
> - static const u8 speed_conv[] = {
> - [PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT,
> - [PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT,
> - [PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT,
> - [PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT,
> - [PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT,
> - [PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT,
> - };
> -
> - if (WARN_ON_ONCE(!pcie_valid_speed(speed)))
> - return 0;
> -
> - return speed_conv[speed];
> -}
> -
> static inline u16 pcie_supported_speeds2target_speed(u8 supported_speeds)
> {
> return __fls(supported_speeds);
> @@ -91,7 +74,7 @@ static u16 pcie_bwctrl_select_speed(struct pci_dev *port, enum pci_bus_speed spe
> u8 desired_speeds, supported_speeds;
> struct pci_dev *dev;
>
> - desired_speeds = GENMASK(pci_bus_speed2lnkctl2(speed_req),
> + desired_speeds = GENMASK(PCIE_SPEED2LNKCTL2_TLS(speed_req),
> __fls(PCI_EXP_LNKCAP2_SLS_2_5GB));
No, that's not good. The function you're removing above,
pci_bus_speed2lnkctl2(), uses an array to look up the speed.
That's an O(1) operation, it doesn't get any more efficient
than that. It was a deliberate design decision to do this
when the bandwidth controller was created.
Whereas the function you're using instead uses a series
of ternary operators. That's no longer an O(1) operation,
the compiler translates it into a series of conditional
branches, so essentially an O(n) lookup (where n is the
number of speeds). So it's less efficient and less elegant.
Please come up with an approach that doesn't make this
worse than before.
Thanks,
Lukas
next prev parent reply other threads:[~2025-08-16 20:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-16 15:46 [PATCH v3 0/3] PCIe: Refactor link speed configuration with unified macro Hans Zhang
2025-08-16 15:46 ` [PATCH v3 1/3] PCI: Add PCIE_SPEED2LNKCTL2_TLS conversion macro Hans Zhang
2025-08-16 15:46 ` [PATCH v3 2/3] PCI: dwc: Simplify link speed configuration with macro Hans Zhang
2025-08-16 15:46 ` [PATCH v3 3/3] PCI/bwctrl: Replace legacy speed conversion with shared macro Hans Zhang
2025-08-16 20:13 ` Lukas Wunner [this message]
2025-08-17 15:02 ` Hans Zhang
2025-08-18 5:21 ` Manivannan Sadhasivam
2025-08-18 12:07 ` Hans Zhang
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=aKDmW6l6uxZGr1Wl@wunner.de \
--to=lukas@wunner.de \
--cc=18255117159@163.com \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jingoohan1@gmail.com \
--cc=kw@linux.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
/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®