linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Puranjay Mohan <puranjay12@gmail.com>,
	bhelgaas@google.com, linux-pci@vger.kernel.org
Subject: Re: [PATCH 1/2] PCI: Update BAR # and window messages
Date: Fri, 19 Nov 2021 15:43:04 -0600	[thread overview]
Message-ID: <20211119214304.GA1963177@bhelgaas> (raw)
In-Reply-To: <20211106115831.GA7452@wunner.de>

On Sat, Nov 06, 2021 at 12:58:31PM +0100, Lukas Wunner wrote:
> On Sat, Nov 06, 2021 at 04:56:05PM +0530, Puranjay Mohan wrote:
> > +		switch (i) {
> > +		case 0: return "BAR 0";
> > +		case 1: return "BAR 1";
> > +		case 2: return "BAR 2";
> > +		case 3: return "BAR 3";
> > +		case 4: return "BAR 4";
> > +		case 5: return "BAR 5";
> > +		case PCI_ROM_RESOURCE: return "ROM";
> > +		#ifdef CONFIG_PCI_IOV
> > +		case PCI_IOV_RESOURCES + 0: return "VF BAR 0";
> > +		case PCI_IOV_RESOURCES + 1: return "VF BAR 1";
> > +		case PCI_IOV_RESOURCES + 2: return "VF BAR 2";
> > +		case PCI_IOV_RESOURCES + 3: return "VF BAR 3";
> > +		case PCI_IOV_RESOURCES + 4: return "VF BAR 4";
> > +		case PCI_IOV_RESOURCES + 5: return "VF BAR 5";
> > +		#endif
> > +		}
> 
> Use a static const array of char * instead of a switch/case ladder
> to reduce LoC count and improve performance.
> 
> See pcie_to_hpx3_type[] or state_conv[] in drivers/pci/pci-acpi.c
> for an example.

I tried converting this and came up with the below.  Is that the sort
of thing you're thinking?  Gcc *does* generate slightly smaller code
for it, but Puranjay's original source code is smaller and IMO a
little easier to read.

And I just noticed that Puranjay's code nicely returns "unknown" for
BAR 2-5 of bridges, while my code below does not.  Could be fixed, of
course, but would take a little more code.

  const char *pci_resource_name(struct pci_dev *dev, int i)
  {
	  static const char *bar_name[] = {
		  "BAR 0",
		  "BAR 1",
		  "BAR 2",
		  "BAR 3",
		  "BAR 4",
		  "BAR 5",
		  "ROM",
  #ifdef CONFIG_PCI_IOV
		  "VF BAR 0",
		  "VF BAR 1",
		  "VF BAR 2",
		  "VF BAR 3",
		  "VF BAR 4",
		  "VF BAR 5",
  #endif
		  "bridge I/O window",
		  "bridge mem window",
		  "bridge mem pref window",
	  };
	  static const char *cardbus_name[] = {
		  "BAR 0",
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
  #ifdef CONFIG_PCI_IOV
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
		  "unknown",
  #endif
		  "CardBus bridge I/O 0 window",
		  "CardBus bridge I/O 1 window",
		  "CardBus bridge mem 0 window",
		  "CardBus bridge mem 1 window",
	  };

	  if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS &&
	      i < ARRAY_SIZE(cardbus_name))
		  return cardbus_name[i];
	  else if (i < ARRAY_SIZE(bar_name))
		  return bar_name[i];

	  return "unknown";
  }

  reply	other threads:[~2021-11-19 21:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06 11:26 [PATCH 0/2] PCI: Update BAR #/window messages Puranjay Mohan
2021-11-06 11:26 ` [PATCH 1/2] PCI: Update BAR # and window messages Puranjay Mohan
2021-11-06 11:58   ` Lukas Wunner
2021-11-19 21:43     ` Bjorn Helgaas [this message]
2021-11-24  4:28       ` Lukas Wunner
2021-11-06 11:26 ` [PATCH 2/2] PCI: Use resource names in PCI log messages Puranjay Mohan

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=20211119214304.GA1963177@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=puranjay12@gmail.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;
as well as URLs for NNTP newsgroup(s).