Linux 内核 net_device_ops 是否被调用者序列化

Are the Linux kernel net_device_ops serialized by the caller or not

我试图查明 Linux net_device_ops 是否被调用者序列化,或者实现这些操作的驱动程序是否必须处理序列化(或者它们可以同时调用) .

例如,可以在驱动程序完成当前 ndo_start_xmit 调用之前再次调用 ndo_start_xmit 相同的驱动程序实例(例如在不同的 CPU)吗?

我搜索了其他 net_device 驱动程序是如何执行此操作的,但看起来他们假设 ndo_start_xmit 序列化是由调用者完成的(如果我错了请纠正我)。

但是我也搜索了调用者是否使用自旋锁或其他锁机制,但我没有找到。如果存在这样的(调用者)锁定机制,请指出执行此操作的代码。

在大多数情况下,调用者应该负责序列化,net_device_ops 通常实现为无锁。但是,可能您仍然可能会发现某些驱动程序在内部net_device_ops为他们的internal 目的 - 例如,驱动程序可能需要在任一回调中访问其 own 全局 data/counters。

ndo_start_xmit,确实,这可能是一个相当 eloquent 的例子,可以观察锁定可能存在的位置。在这种情况下,确实,上层调用者持有锁。您可能会发现查看驱动程序提供的 corresponding place within dev_queue_xmit() kernel function. As you see, lock is acquired there prior calling dev_hard_start_xmit() function which in turn calls xmit_one() function. It's easy to track it further, namely, you may observe netdev_start_xmit() code 调用 ndo_start_xmit 很有帮助。

另外,Linux Device Drivers, 3rd Edition 一书可能值得一读,即段落 17.5.1section 17.5。希望对您有所帮助。