在 2024/10/22 23:44, Bjorn Helgaas 写道:
[+cc Greg]
On Fri, Oct 18, 2024 at 01:47:28PM +0800, Guixin Liu wrote:
PCI driver will traverse pci device list in pci_seq_start in every
sequential file reading, use xarry to store all pci devices to
accelerate finding the start.
/* iterator */
static void *pci_seq_start(struct seq_file *m, loff_t *pos)
{
- struct pci_dev *dev = NULL;
+ struct pci_dev *dev;
loff_t n = *pos;
- for_each_pci_dev(dev) {
- if (!n--)
- break;
- }
Maybe another approach would be to use pci_get_device() directly
instead of for_each_pci_dev().
pci_get_device() takes a "from" starting point, so instead of keeping
track of the index "n", you could keep track of the current pci_dev.
You mean let struct seq_file to keep the pci_dev? Well, we also need keep
the pci_dev which held by seq_file in klist_devices, because finding
next rely on
it, this make things complicated.
In addition, in pci_seq_start(), the pos may not increased one by one, so
we dont know how many times we should skip to find the pci_dev which number
is *pos.
Best Regards,
Guixin Liu