From: Wei Yang <weiyang@linux.vnet.ibm.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
Ram Pai <linuxram@us.ibm.com>,
Gavin Shan <shangw@linux.vnet.ibm.com>
Subject: Re: [PATCH 1/4] PCI: optimize pci_bus_get_depth() by enumerating on pci bus hierachy
Date: Wed, 10 Jul 2013 09:36:06 +0800 [thread overview]
Message-ID: <20130710013606.GB6671@weiyang.vnet.ibm.com> (raw)
In-Reply-To: <CAErSpo4XqeY5XH3qpc2sKuec8BakUAQkjZKB9X3eKg2uFi6L6g@mail.gmail.com>
On Tue, Jul 09, 2013 at 01:27:42PM -0600, Bjorn Helgaas wrote:
>On Mon, Jul 8, 2013 at 8:38 PM, Wei Yang <weiyang@linux.vnet.ibm.com> wrote:
>> On Mon, Jul 08, 2013 at 02:46:17PM -0600, Bjorn Helgaas wrote:
>>>On Mon, Jul 1, 2013 at 9:10 AM, Wei Yang <weiyang@linux.vnet.ibm.com> wrote:
>>>> Normally, on one pci bus there would be more devices than pci buses. When
>>>> calculating the depth of pci bus, it would be more time efficient by
>>>> enumerating through the child buses instead of the child devices.
>>>>
>>>> Also by doing so, the code seems more self explaining. Previously, it go
>>>> through the pci devices and check whether a bridge introduce a child bus or
>>>> not, which needs more background knowledge to understand it.
>>>>
>>>> This patch caculating the depth by enumerating on pci bus hierachy in an
>>>> iterative way.
>>>
>>>Your code does have the advantage of not being recursive, but the
>>>original code is significantly shorter and, in my opinion, much more
>>>readable. This is not in a performance path, so I don't see any
>>>advantage in optimizing.
>>
>> Thanks for your comments~
>>
>> Yes, this doesn't benefit a lot on the performance.
>>
>> The benefit of this code is not only the recursive approach, but on
>> calculating the depth of pci bus tree by iterating on pci bus tree instead of
>> the pci device tree.
>>
>> In my mind, there is less pci bus structrue than the pci device structure, and
>> hope the code would be more self explaining for the audience by going through
>> the pci bus tree to calculate the pci bus tree depth.
>>
>> My original code looks like below. Do you think this one is more friendly to
>> the audience?
>
>Yes.
Thanks for your comment.
If you agree, I will re-sent the patch with this recursive version.
>
>> @@ -1300,21 +1300,19 @@ static void pci_bus_dump_resources(struct pci_bus *bus)
>> static int __init pci_bus_get_depth(struct pci_bus *bus)
>> {
>> int depth = 0;
>> - struct pci_dev *dev;
>> + struct pci_bus *child_bus;
>>
>> - list_for_each_entry(dev, &bus->devices, bus_list) {
>> + list_for_each_entry(child_bus, &bus->children, node){
>> int ret;
>> - struct pci_bus *b = dev->subordinate;
>> - if (!b)
>> - continue;
>>
>> - ret = pci_bus_get_depth(b);
>> + ret = pci_bus_get_depth(child_bus);
>> if (ret + 1 > depth)
>> depth = ret + 1;
>> }
>>
>> return depth;
>> }
>>
>> And yes again, this change will not bring much improvement for the performance.
>> If this is not good, just ignore the code. :-)
>>
>>>
>>>> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>>>> Reviewed-by: Gavin Shan <shangw@linux.vnet.ibm.com>
>>>> Reviewed-by: Ram Pai <linuxram@us.ibm.com>
>>>> Reviewed-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
>>>> Reviewed-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>
>>>> ---
>>>> drivers/pci/setup-bus.c | 43 ++++++++++++++++++++++++++++++++-----------
>>>> 1 files changed, 32 insertions(+), 11 deletions(-)
>>>>
>>>> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
>>>> index 16abaaa..b333f73 100644
>>>> --- a/drivers/pci/setup-bus.c
>>>> +++ b/drivers/pci/setup-bus.c
>>>> @@ -1299,22 +1299,43 @@ static void pci_bus_dump_resources(struct pci_bus *bus)
>>>>
>>>> static int __init pci_bus_get_depth(struct pci_bus *bus)
>>>> {
>>>> - int depth = 0;
>>>> - struct pci_dev *dev;
>>>> + int max_depth, depth;
>>>> + struct pci_bus *parent, *curr;
>>>> + struct list_head *node;
>>>>
>>>> - list_for_each_entry(dev, &bus->devices, bus_list) {
>>>> - int ret;
>>>> - struct pci_bus *b = dev->subordinate;
>>>> - if (!b)
>>>> - continue;
>>>> + /* no child? */
>>>> + if (list_empty(&bus->children))
>>>> + return 0;
>>>>
>>>> - ret = pci_bus_get_depth(b);
>>>> - if (ret + 1 > depth)
>>>> - depth = ret + 1;
>>>> + node = bus->children.next;
>>>> + parent = bus;
>>>> + max_depth = depth = 1;
>>>> +
>>>> + while (parent) {
>>>> + /* hit the head, go back to parent level */
>>>> + if (node == &parent->children) {
>>>> + node = parent->node.next;
>>>> + parent = parent->parent;
>>>> + depth--;
>>>> + continue;
>>>> + }
>>>> + curr = list_entry(node, struct pci_bus, node);
>>>> + /* depth first */
>>>> + if (!list_empty(&curr->children)) {
>>>> + node = curr->children.next;
>>>> + parent = curr;
>>>> + depth++;
>>>> + if (max_depth < depth)
>>>> + max_depth = depth;
>>>> + }
>>>> + /* no child, go to the sibling */
>>>> + else
>>>> + node = curr->node.next;
>>>> }
>>>>
>>>> - return depth;
>>>> + return max_depth;
>>>> }
>>>> +
>>>> static int __init pci_get_max_depth(void)
>>>> {
>>>> int depth = 0;
>>>> --
>>>> 1.7.5.4
>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>> --
>> Richard Yang
>> Help you, Help me
>>
--
Richard Yang
Help you, Help me
next prev parent reply other threads:[~2013-07-10 1:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-01 15:10 [PATCH 0/4] optimization/fix/cleanup in pci_assign_unassigned_resources Wei Yang
2013-07-01 15:10 ` [PATCH 1/4] PCI: optimize pci_bus_get_depth() by enumerating on pci bus hierachy Wei Yang
2013-07-08 20:46 ` Bjorn Helgaas
2013-07-09 2:38 ` Wei Yang
2013-07-09 19:27 ` Bjorn Helgaas
2013-07-10 1:36 ` Wei Yang [this message]
2013-07-01 15:10 ` [PATCH 2/4] PCI: add comment for pbus_size_mem() parameter Wei Yang
2013-07-01 15:10 ` [PATCH 3/4] PCI: trivial cleanup in pbus_size_io() Wei Yang
2013-07-01 15:10 ` [PATCH 4/4] PCI: fix the io resource alignment calculation " Wei Yang
2013-07-08 21:15 ` Bjorn Helgaas
2013-07-09 3:20 ` Wei Yang
2013-07-09 17:38 ` Bjorn Helgaas
2013-07-10 1:34 ` Wei Yang
2013-07-19 3:10 ` Wei Yang
2013-07-25 21:22 ` Bjorn Helgaas
[not found] ` <20130701231040.GA8174@shangw.(null)>
[not found] ` <20130701231540.GA15263@shangw.(null)>
2013-07-02 1:51 ` [PATCH 0/4] optimization/fix/cleanup in pci_assign_unassigned_resources Wei Yang
2013-07-04 1:15 ` Wei Yang
-- strict thread matches above, loose matches on Subject: below --
2013-08-02 9:31 Wei Yang
2013-08-02 9:31 ` [PATCH 1/4] PCI: optimize pci_bus_get_depth() by enumerating on pci bus hierachy Wei Yang
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=20130710013606.GB6671@weiyang.vnet.ibm.com \
--to=weiyang@linux.vnet.ibm.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=linuxram@us.ibm.com \
--cc=shangw@linux.vnet.ibm.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).