1

The essence of my question is almost painfully simple:

  • Given my current hardware, would the design of Linux sysfs allow me to expect that the device at /sys/devices/pci0000:00/0000:00:14.0/usb1/1-6 will always be the same device at that same location every time that I boot?

I'm 99% certain that the answer is "yes", but getting an expert to quickly weigh in seems prudent, to make sure I don't do anything stupid.

The inverse way to ask my question would be:

  • Is there any non-determinism in how the kernel enumerates pci and usb hardware at boot? (Assume the hardware is always fixed in advance of the boot.)

Supporting details:

Kernel in use on this hardware is 5.4.0-58-generic

This PCI and USB connection is all inside of the custom device enclosure, and is part of the "permanent" hardware design. There is no possibility of "hot-plugging" or unplugging or any end-user intervention with regard to changing/reconfiguring these connections.

The actual device that I care about, located at usb1/1-6, is an stm32f103 microcontroller, in case that matters. (I suspect it does not matter.)

The hardware design is fixed, and made by someone other than myself. I am writing software (mostly high-level GUI software) that runs on this device. As you can probably guess, my kernel knowledge is a bit weak.

As I said, I'm fairly convinced that the structure of the path /sys/devices/pci0000:00/0000:00:14.0/usb1/1-6 is derived entirely from the real-world structure of the hardware, but am looking for confirmation.

I've been reading about sysfs (such as here: https://www.kernel.org/doc/html/latest/admin-guide/sysfs-rules.html), but I still feel a lack of stumbling into any single unambiguous sentence which would resolve my uncertainty.

pestophagous
  • 4,069
  • 3
  • 33
  • 42
  • to whomever voted to close: Linux kernel API(s) and their nuances are quite relevant to programmers working on linux. Please consider this to be a kernel API question. I doubt the kernel mailing list would appreciate my "trifle" of a question, so I am counting on my friendly linux-programmers-in-arms here at StackOverflow. – pestophagous Jan 08 '21 at 19:35
  • 1
    If you change the hardware, then the assigned PCI numbering changes because it is enumerated by firmware at boot time. – stark Jan 11 '21 at 14:24
  • @stark thank you for your help. I can confirm that a change in the hardware will change the PCI numbering. That still leaves an open doubt: if I do **not** change the hardware, is there anything else about the kernel code itself that might result in a (for me, "unwanted") numbering change? Any kind of race condition or non-determinism? I don't want to assume that just because I have booted 100 times and things look the same... I don't want to "assume" the 101st boot is guaranteed to be the same. I'd like to find some documentation or commentary that reassures me. – pestophagous Jan 11 '21 at 16:10
  • 2
    I know from personal experience that updating the platform firmware can change the numbering. This has nothing to do with the kernel. It just uses what its given. – stark Jan 11 '21 at 16:14
  • @stark thank you. that definitely helps me build a better mental model of this. when you say "updating the platform firmware", would "platform" correspond to the `stm32f103` micro in my scenario? – pestophagous Jan 11 '21 at 16:17
  • @stark or does platform firmware mean motherboard firmware? – pestophagous Jan 11 '21 at 16:18
  • Firmware means the code in flash or ROM that initializes the system and runs either Linux or runs the bootloader that runs Linux. – stark Jan 11 '21 at 16:22
  • @stark so if the kernel "just uses what it is given", then do you feel confident endorsing the idea that if all things are held constant (the hardware, the BIOS, the kernel version), then "just booting linux" does not bring with it any non-determinism in the numbering? (totally fine if you lack the confidence to assert that at this time. Erring on the side of caution is best.) – pestophagous Jan 11 '21 at 16:34
  • 1
    For PCIe yes, not sure about USB. See https://superuser.com/q/488833/127177 – stark Jan 11 '21 at 16:45

0 Answers0