Skip to content
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

Open
wants to merge 1 commit into
base: Dmitriy.Ganshin
Choose a base branch
from

Conversation

d-ganshin
Copy link

@d-ganshin d-ganshin commented Nov 26, 2018

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.

Copy link
Contributor

@DevyatovAndrey DevyatovAndrey left a 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);
Copy link
Contributor

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?

Copy link
Author

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);
Copy link
Contributor

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 ?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

@d-ganshin d-ganshin Dec 5, 2018

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/

@DevyatovAndrey DevyatovAndrey added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Nov 28, 2018
@d-ganshin d-ganshin added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Dec 4, 2018
@DevyatovAndrey DevyatovAndrey added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Dec 5, 2018
@d-ganshin d-ganshin added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Dec 5, 2018
@DevyatovAndrey
Copy link
Contributor

Please add PR description

@d-ganshin
Copy link
Author

Please add PR description
added PR description

@DevyatovAndrey DevyatovAndrey added OK The PR has been reviewed and (at least generally) accepted (set by reviewer). and removed ready labels Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OK The PR has been reviewed and (at least generally) accepted (set by reviewer).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants