Skip to content

Lesson 06 Time management: Add module_time.c and Makefile - #110

Open
d-ganshin wants to merge 1 commit into
Kernel-GL-HRK:Dmitriy.Ganshinfrom
d-ganshin:lesson_6
Open

d-ganshin wants to merge 1 commit into
Kernel-GL-HRK:Dmitriy.Ganshinfrom
d-ganshin:lesson_6

Conversation

@d-ganshin

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

Copy link
Copy Markdown

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.

Signed-off-by: Dmitriy Ganshin <d.hanshyn@gmail.com>

@DevyatovAndrey DevyatovAndrey left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@d-ganshin d-ganshin Dec 5, 2018

Copy link
Copy Markdown
Author

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
Copy Markdown
Contributor

Please add PR description

@d-ganshin

Copy link
Copy Markdown
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