1

my team is writing software interacting with a Linux kernel module. We write to sysfs to manage the module. Recently, we've been battling a problem in which the module occasionally does not behave as expected.

One of my colleagues noticed that if we put a sleep between subsequent writes to sysfs, the problem does not occur. This probably means that after the first write the module needs some time to do some additional processing, and our code should wait until it's done before performing the second write.

I really don't want to put a random sleep in the code. However, we have virtually no experience with kernel space. Is there a way to detect that the kernel module is busy doing the additional processing? To track activity of the module? Especially a programmatic way, that we could use instead of sleep-ing some predefined interval?

Unfortunately, my NDA prevents me from going into details about which module and which sysfs files we interact with.

user44168
  • 365
  • 1
  • 4
  • 13
  • "Is there a way to detect that a kernel module is busy processing a sysfs write?" - Unless the module itself or its subsystem provides the meens for that, it is unlikely you may detect this. Moreover, as far as I understand your problem, it is not about "kernel module is busy processing a sysfs write": The `write` function has already returned to the caller, so the module finishes sysfs writing before the subsequent "write" request. But the module does *some other work*, and you may only guess what this work is and when it will be finished. – Tsyvarev Sep 04 '18 at 13:57
  • I've edited the question according to your comment. – user44168 Sep 04 '18 at 14:24
  • 1
    Sounds like your kernel module needs a command queue to properly synchronize tasks given to it via sysfs writes. If it's not an in-house developed module of yours but in fact a publically accessible vanilla one, I see no reason why an NDA prevents you from talking about it and I suggest you talk to your boss to get clearance to provide us with more detail. If you can't you're stuck with reading kernel source code and probably building your own debugging kernel with a bunch of debug and stack trace prints in it. As this question stands right now, we're probably doing more guessing than you are. – Cobra_Fast Sep 04 '18 at 15:19

0 Answers0