From: "Pali Rohár" <pali@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Martin Mares" <mj@ucw.cz>, "Bjorn Helgaas" <helgaas@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v2] lspci: Show Slot Power Limit values above EFh
Date: Wed, 24 Nov 2021 13:46:11 +0100 [thread overview]
Message-ID: <20211124124611.wi6u77pnparg2563@pali> (raw)
In-Reply-To: <YYABw84admN1+8Ly@casper.infradead.org>
On Monday 01 November 2021 15:03:31 Matthew Wilcox wrote:
> On Mon, Nov 01, 2021 at 03:47:40PM +0100, Pali Rohár wrote:
> > PCI Express Base Specification rev. 3.0 has the following definition for
> > the Slot Power Limit Value:
> >
> > =======================================================================
> > When the Slot Power Limit Scale field equals 00b (1.0x) and Slot Power
> > Limit Value exceeds EFh, the following alternative encodings are used:
> > F0h = 250 W Slot Power Limit
> > F1h = 275 W Slot Power Limit
> > F2h = 300 W Slot Power Limit
> > F3h to FFh = Reserved for Slot Power Limit values above 300 W
> > =======================================================================
> >
> > Replace function power_limit() by show_power_limit() which also prints
> > power limit value. Show reserved value as string ">300W" and omit usage of
> > floating point variables as it is not needed.
>
> I don't understand why you want to avoid the use of floating point here?
Because library does not use floating point. So I thought that it is a
good idea to not use it neither for printing power limit.
I can change it, just I wanted to hear project / library preference.
> > +++ b/ls-caps.c
> > @@ -656,10 +656,27 @@ static int exp_downstream_port(int type)
> > type == PCI_EXP_TYPE_PCIE_BRIDGE; /* PCI/PCI-X to PCIe Bridge */
> > }
> >
> > -static float power_limit(int value, int scale)
> > +static void show_power_limit(int value, int scale)
> > {
> > - static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
> > - return value * scales[scale];
> > + static const int scales[4] = { 1000, 100, 10, 1 };
> > + static const int scale0_values[3] = { 250, 275, 300 };
> > + if (scale == 0 && value >= 0xF0) {
> > + /* F3h to FFh = Reserved for Slot Power Limit values above 300 W */
> > + if (value >= 0xF3) {
> > + printf(">300W");
> > + return;
> > + }
> > + value = scale0_values[value - 0xF0];
> > + }
> > + value *= scales[scale];
> > + printf("%d", value / 1000);
> > + if (value % 10)
> > + printf(".%03d", value % 1000);
> > + else if (value % 100)
> > + printf(".%02d", (value / 10) % 100);
> > + else if (value % 1000)
> > + printf(".%d", (value / 100) % 10);
> > + printf("W");
>
> Wouldn't this be clearer if written as:
>
> static void show_power_limit(int value, int scale)
> {
> static const float scales[4] = { 1.0, 0.1, 0.01, 0.001 };
> static const int scale0_values[3] = { 250, 275, 300 };
>
> if (scale == 0 && value >= 0xF0) {
> /* F3h to FFh = Reserved for Slot Power Limit values above 300 W */
> if (value >= 0xF3) {
> printf(">300W");
> return;
> }
> value = scale0_values[value - 0xF0];
> }
> printf("%.3fW", value * scales[scale]);
> }
>
next prev parent reply other threads:[~2021-11-24 13:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-03 11:48 lspci: Slot Power Limit values above EFh Pali Rohár
2021-04-03 15:48 ` Matthew Wilcox
2021-11-01 14:47 ` [PATCH v2] lspci: Show " Pali Rohár
2021-11-01 15:03 ` Matthew Wilcox
2021-11-24 12:46 ` Pali Rohár [this message]
2021-12-26 22:07 ` Martin Mareš
2021-12-26 22:41 ` [PATCH v3 pciutils] " Pali Rohár
2021-12-26 22:43 ` Martin Mareš
2021-12-26 23:34 ` [PATCH v4 " Pali Rohár
2021-12-26 23:55 ` Martin Mareš
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=20211124124611.wi6u77pnparg2563@pali \
--to=pali@kernel.org \
--cc=helgaas@kernel.org \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=mj@ucw.cz \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).