Skip to content

Commit 6e332df

Browse files
refactormyselfbjorn-helgaas
authored andcommitted
PCI/ASPM: Stop caching device L0s, L1 acceptable exit latencies
Previously we calculated the device's acceptable L0s and L1 exit latencies in pcie_aspm_cap_init() and cached them in struct pcie_link_state. These values are only used in pcie_aspm_check_latency() where they are compared with the actual exit latencies of the link. This path is used when removing or changing the D state of the device, so it's relatively low frequency. To reduce the amount of per-link data we store, remove the acceptable[] arrays from struct pcie_link_state and calculate them directly from the already-cached Device Capabilities register when needed. [bhelgaas: use endpoint->devcap instead of reading it again] Link: https://lore.kernel.org/r/20211119193732.12343-4-refactormyself@gmail.com Signed-off-by: Saheed O. Bolarinwa <refactormyself@gmail.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 222578d commit 6e332df

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

drivers/pci/pcie/aspm.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ struct pcie_link_state {
6565
u32 clkpm_enabled:1; /* Current Clock PM state */
6666
u32 clkpm_default:1; /* Default Clock PM state by BIOS */
6767
u32 clkpm_disable:1; /* Clock PM disabled */
68-
69-
/*
70-
* Endpoint acceptable latencies. A pcie downstream port only
71-
* has one slot under it, so at most there are 8 functions.
72-
*/
73-
struct aspm_latency acceptable[8];
7468
};
7569

7670
static int aspm_disabled, aspm_force;
@@ -389,7 +383,8 @@ static void encode_l12_threshold(u32 threshold_us, u32 *scale, u32 *value)
389383

390384
static void pcie_aspm_check_latency(struct pci_dev *endpoint)
391385
{
392-
u32 latency, lnkcap_up, lnkcap_dw, l1_switch_latency = 0;
386+
u32 latency, encoding, lnkcap_up, lnkcap_dw;
387+
u32 l1_switch_latency = 0;
393388
struct aspm_latency latency_up, latency_dw;
394389
struct aspm_latency *acceptable;
395390
struct pcie_link_state *link;
@@ -400,7 +395,14 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint)
400395
return;
401396

402397
link = endpoint->bus->self->link_state;
403-
acceptable = &link->acceptable[PCI_FUNC(endpoint->devfn)];
398+
399+
/* Calculate endpoint L0s acceptable latency */
400+
encoding = (endpoint->devcap & PCI_EXP_DEVCAP_L0S) >> 6;
401+
acceptable->l0s = calc_l0s_acceptable(encoding);
402+
403+
/* Calculate endpoint L1 acceptable latency */
404+
encoding = (endpoint->devcap & PCI_EXP_DEVCAP_L1) >> 9;
405+
acceptable->l1 = calc_l1_acceptable(encoding);
404406

405407
while (link) {
406408
struct pci_dev *dev = pci_function_0(link->pdev->subordinate);
@@ -666,22 +668,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
666668

667669
/* Get and check endpoint acceptable latencies */
668670
list_for_each_entry(child, &linkbus->devices, bus_list) {
669-
u32 reg32, encoding;
670-
struct aspm_latency *acceptable =
671-
&link->acceptable[PCI_FUNC(child->devfn)];
672671

673672
if (pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT &&
674673
pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END)
675674
continue;
676675

677-
pcie_capability_read_dword(child, PCI_EXP_DEVCAP, &reg32);
678-
/* Calculate endpoint L0s acceptable latency */
679-
encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
680-
acceptable->l0s = calc_l0s_acceptable(encoding);
681-
/* Calculate endpoint L1 acceptable latency */
682-
encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9;
683-
acceptable->l1 = calc_l1_acceptable(encoding);
684-
685676
pcie_aspm_check_latency(child);
686677
}
687678
}

0 commit comments

Comments
 (0)