Question

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.

Was it helpful?

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.

OTHER TIPS

Add a timer with add_timer() in the write callback of the device driver and make sure to del_timer() or del_timer_sync() in the read callback.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top