-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson 06 Time management: Add module_time.c and Makefile #110
base: Dmitriy.Ganshin
Are you sure you want to change the base?
Conversation
Signed-off-by: Dmitriy Ganshin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide PR description and changes.
if (delay) | ||
mod_timer(&timer, jiffies + msecs_to_jiffies(delay * HZ)); | ||
else | ||
del_timer(&timer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once deleted how would it be inited back?
What if user consequently adjust spam times to 10 sec, 0, 5 sec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the delay is less than 1 then the timer will be stopped.
The timer will be turned on again after the delay is set to be greater than or equal to 1.
99 if (tmp) {
100 pr_info("delay: %ld\n", delay);
101 timer_update();
The spam period of the message can only be set to an integer value, because the delay is an integer value. 0.5 s can not be installed, you can from 1c
class_remove_file(attr_class, &class_attr_previous_ads); | ||
class_destroy(attr_class); | ||
|
||
del_timer(&timer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
del_timer(&timer);
What if timer is already deleted by timer_update ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will delete the already deleted timerю
I can add the timer_pedding () function to check if the timer is running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Could you please provide the log of such behavior?
- Start timer with some interval
- Adjust interval to zero
- rmmod the driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insmod module_time.ko
echo "1" > /sys/class/time_module/spam
echo "0" > /sys/class/time_module/spam
rmmod module_time.ko
dmesg
[ 3090.780090] mymodule: module loaded
[ 3090.780090] Create:
[ 3090.780090] /sys/class/time_module/
[ 3096.150538] delay setting:
[ 3096.150922] delay: 1
[ 3097.184634] uptime module 6 s.
[ 3098.208571] uptime module 7 s.
[ 3099.232588] uptime module 8 s.
[ 3100.256579] uptime module 9 s.
[ 3101.280518] uptime module 10 s.
[ 3102.304590] uptime module 11 s.
[ 3103.328536] uptime module 12 s.
[ 3104.352584] uptime module 13 s.
[ 3105.376513] uptime module 14 s.
[ 3106.400605] uptime module 15 s.
[ 3106.729052] delay setting:
[ 3106.729264] delay: 0
[ 3112.811275] mymodule: module exited
[ 3112.811275] Remove:
[ 3112.811275] /sys/class/time_module/
Please add PR description |
|
Implemented a kernel module with an API in sysfs.
The module creates the time_module class in / sys / class /. The module provides 3 attributes:
previous(ro) - returns the relative time (in seconds) elapsed from the previous reading
revious_abs(ro) - returns the absolute time of the previous reading;
spam(rw) - periodically printed message how much time has elapsed since the module was started, period can be customized.