-
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
Lesson06: Implement kernel module for test kernel time functions and timers #87
base: Oleg.Khokhlov
Are you sure you want to change the base?
Conversation
Signed-off-by: Oleg.Khokhlov <[email protected]>
Signed-off-by: Oleg.Khokhlov <[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 fix mentioned issues
06-TimeManagement/omod6_kern_time.c
Outdated
int n; | ||
|
||
n = sscanf(buf, "%d %s", &interval, LogMessage); | ||
pr_info("omod6 store (%d, \'%s\')\n", interval, LogMessage); |
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.
@OlegH-ua
As far as I can see, the message passed to store method was "Hello from timer", but then it prints only "Hello":
"omod6 store (5000, 'Hello')"
IMO it's better to divide setting of timer period and message into two sys/proc files
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.
You are right, this piece of code is really not perfect. And even non-safe.
06-TimeManagement/omod6_kern_time.c
Outdated
interval * HZ / 1000; | ||
//if (timer_pending(&MyTimer)) { | ||
// mod_timer_pending(&MyTimer, expired); | ||
//} else { |
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.
What is the purpose of these lines commented out?
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.
- I had to do some experiments and kernel code inspection to clarify the behavior of timers and timer functions. A lot of lecture information about timers was unclear, obsolete and non-actual.
- That commented code has been left to accentuate that used functions was tested and recognized as excessive. Everything works perfect without them. But it works with them, too.
sprintf(strchr(buf, 0), "%u module call\n", ModCallCount); | ||
sprintf(strchr(buf, 0), "%u sec from last call\n", dT); | ||
sprintf(strchr(buf, 0), "%u sec curr abs time from Epoch (year:%d)\n", TS, 1970+TS/(3600*24*365)); | ||
sprintf(strchr(buf, 0), "%u sec prev call abs time from Epoch\n", LastCallTimeSec); |
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.
1542096137 sec curr abs time from Epoch (year:2018)
IMO it's better to format absolute time stamp as human readable string aka YY.MM.DD hh:mm:ss
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.
Good idea. I had been thinking about it when I was written the code but I decided that it's extraneous. Maybe you can recomend proper kernel function to convert epoch timestamp to struct time ?
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.
I see you've managed to format the epoch time. Good job!
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.
Could you please squash the two commits? The intermediate state after the first commit is actually not needed.
sprintf(strchr(buf, 0), "%u module call\n", ModCallCount); | ||
sprintf(strchr(buf, 0), "%u sec from last call\n", dT); | ||
sprintf(strchr(buf, 0), "%u sec curr abs time from Epoch (year:%d)\n", TS, 1970+TS/(3600*24*365)); | ||
sprintf(strchr(buf, 0), "%u sec prev call abs time from Epoch\n", LastCallTimeSec); |
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.
I see you've managed to format the epoch time. Good job!
if (cp) { | ||
while (*cp == ' ') | ||
cp++; | ||
for (n = 0; n < sizeof(LogMessage) - 1; n++) { |
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.
What would be if user enter the wrong/garbage string? Have you tested this case?
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.
No, I haven't tested this case. But as for this code, it's made a priory safe by design. It copies only limited number of chars into message string and is protected against strange ascii codes, e.g. CR/LF, ESC, etc. Which are unwanted in system log. All other ascii chars are OK. This method of string copying was selected after I realized that the 'store' function gets the string from user space which is ended this '\n'. It was a piece of bad news for me.
Last two commits was squashed using git rebase -i HEAD~1 and forcepush. please check it up. |
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.
@OlegH-ua
Please get rid off all unnesessary comments and dead code.
Thank you!
06-TimeManagement/omod6_kern_time.c
Outdated
//--- commented code is not needed - timer works without it --- | ||
//if (timer_pending(&MyTimer)) { | ||
// mod_timer_pending(&MyTimer, expired); | ||
//} else { |
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.
It's not clear still - what is the purpose of commented chunks of code, if that code is not needed?
Any PR aims to add some useful code/comments into the project. But not dead code commented out.
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.
(almost) everything to make you happy ;-)
Signed-off-by: Oleg.Khokhlov <[email protected]>
No description provided.