linux-kernellinux-device-drivertimer-jobs

How to implement timer expire function in sysfs of driver.?


Scenario: Suppose if I am doing echo 1 > sysfs_entry - It will start doing some I/O operation until I do echo 0 > sysfs_entry. Here, I wanted to implement timer in sysfs_entry so that it should stop I/O operation after t seconds , even if I do not give echo 0 > sysfs_entry.

PS: I do not want to use busy wait methods.

Preferred: deferred/delayed work

Please somebody help me to resolve this scenario.


Solution

  • You can use add_timer() and del_timer() API for this. Event queue might also work (depends on context). For more details, please read Chapter 7 «Time, Delays, and Deferred Work» of Linux Device Drivers (aka LDD) book that is available free of charge right here. The Timer API is described on page 198.