2014-01-09 00:24:24

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allocate prefetch mmio resource first when possible

[+cc Yinghai]

On Wed, Jan 8, 2014 at 11:17 AM, threeTigers Lin
<[email protected]> wrote:
> From f7a37ed1c61b5939ccef810e28b25ecf3bfa9077 Mon Sep 17 00:00:00 2001
> From: linmuhui <[email protected]>
> Date: Thu, 9 Jan 2014 01:03:12 +0800
> Subject: [PATCH] PCI: Allocate prefetch mmio resource first when possible

This patch is not in the standard format and does not apply cleanly.
See Documentation/SubmittingPatches.

> Hi Bjorn,
>
> PCI bus resources will be set up at pci_bridge_check_ranges() or
> pci_read_bridge_bases(). In both cases, we can find that the PCI bus'
> non-pref mmio will be assigned to bus->resource[1] and pref mmio will be
> assigned to bus->resource[2]. So, in the scenario that we need to allocate
> pref resources from PCI bus such as hotplug operation, the bus' non-pref
> mmio will be quickly eaten up first if we try to allocate bus resources in
> the order from bus->resource[0] to bus->resource[PCI_BRIDGE_RESOURCE_NUM -
> 1] in the function pci_bus_alloc_resource(), even though there is enough
> pref mmio resource of the bus. This may lead to the later requester who want
> to allocate non-pref mmio cannot allocate the resource from the bus. So, I
> think the order of allocating PCI bus resources in function
> pci_bus_alloc_resource() should be changed to try pref mmio first when
> possible.

Don't we do this already? The code in __pci_assign_resource() looks
like it should prefer an exact prefetching match.

If that code doesn't work, we should fix it there. I don't want to
fiddle with pci_bus_for_each_resource() for this -- that's a really
arcane place to hide such a fix.

Bjorn

> Signed-off-by: Lin Muhui <[email protected]>
> ---
> include/linux/pci.h | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 1084a15..238df8f 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1064,7 +1064,8 @@ void pci_bus_remove_resources(struct pci_bus *bus);
>
> #define pci_bus_for_each_resource(bus, res, i) \
> for (i = 0; \
> - (res = pci_bus_resource_n(bus, i)) || i <
> PCI_BRIDGE_RESOURCE_NUM; \
> + (res = pci_bus_resource_n(bus, (i < PCI_BRIDGE_RESOURCE_NUM ?
> (PCI_BRIDGE_RESOURCE_NUM - 1 - i) : i)))\
> + || i < PCI_BRIDGE_RESOURCE_NUM; \
> i++)
>
> int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
> --
> 1.7.1
>


2014-01-09 20:44:16

by Yinghai Lu

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allocate prefetch mmio resource first when possible

On Wed, Jan 8, 2014 at 4:24 PM, Bjorn Helgaas <[email protected]> wrote:
> [+cc Yinghai]
>
> On Wed, Jan 8, 2014 at 11:17 AM, threeTigers Lin
> <[email protected]> wrote:
>> From f7a37ed1c61b5939ccef810e28b25ecf3bfa9077 Mon Sep 17 00:00:00 2001
>> From: linmuhui <[email protected]>
>> Date: Thu, 9 Jan 2014 01:03:12 +0800
>> Subject: [PATCH] PCI: Allocate prefetch mmio resource first when possible
>
> This patch is not in the standard format and does not apply cleanly.
> See Documentation/SubmittingPatches.
>
>> Hi Bjorn,
>>
>> PCI bus resources will be set up at pci_bridge_check_ranges() or
>> pci_read_bridge_bases(). In both cases, we can find that the PCI bus'
>> non-pref mmio will be assigned to bus->resource[1] and pref mmio will be
>> assigned to bus->resource[2]. So, in the scenario that we need to allocate
>> pref resources from PCI bus such as hotplug operation, the bus' non-pref
>> mmio will be quickly eaten up first if we try to allocate bus resources in
>> the order from bus->resource[0] to bus->resource[PCI_BRIDGE_RESOURCE_NUM -
>> 1] in the function pci_bus_alloc_resource(), even though there is enough
>> pref mmio resource of the bus. This may lead to the later requester who want
>> to allocate non-pref mmio cannot allocate the resource from the bus. So, I
>> think the order of allocating PCI bus resources in function
>> pci_bus_alloc_resource() should be changed to try pref mmio first when
>> possible.
>
> Don't we do this already? The code in __pci_assign_resource() looks
> like it should prefer an exact prefetching match.
>
> If that code doesn't work, we should fix it there. I don't want to
> fiddle with pci_bus_for_each_resource() for this -- that's a really
> arcane place to hide such a fix.

Looks like he was trying to do sorting work like we try to do with
root bus resource before, but with new patches in pci/resource, we do
NOT need to do that anymore.

Hi, Lin,

Can you check linus/master + pci/next + pci/resource

and

http://patchwork.ozlabs.org/patch/303740/
PCI: Try best to allocate pref mmio 64bit above 4g

would fix the problem in your setup?

Thanks

Yinghai