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

Lesson06: Implement kernel module for test kernel time functions and timers #87

Open
wants to merge 3 commits into
base: Oleg.Khokhlov
Choose a base branch
from

Conversation

OlegH-ua
Copy link

No description provided.

@OlegH-ua OlegH-ua requested a review from an1kh November 13, 2018 08:54
@OlegH-ua OlegH-ua added the ready label Nov 13, 2018
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 fix mentioned issues

int n;

n = sscanf(buf, "%d %s", &interval, LogMessage);
pr_info("omod6 store (%d, \'%s\')\n", interval, LogMessage);
Copy link
Contributor

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

Copy link
Author

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.

interval * HZ / 1000;
//if (timer_pending(&MyTimer)) {
// mod_timer_pending(&MyTimer, expired);
//} else {
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Copy link
Author

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 ?

Copy link
Contributor

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!

@DevyatovAndrey DevyatovAndrey added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Nov 13, 2018
@OlegH-ua OlegH-ua added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Nov 13, 2018
@OlegH-ua OlegH-ua requested review from DevyatovAndrey and removed request for an1kh November 13, 2018 19:56
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.

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

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

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?

Copy link
Author

@OlegH-ua OlegH-ua Nov 14, 2018

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.

@DevyatovAndrey DevyatovAndrey added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Nov 14, 2018
@OlegH-ua
Copy link
Author

Last two commits was squashed using git rebase -i HEAD~1 and forcepush. please check it up.

@OlegH-ua OlegH-ua added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Nov 14, 2018
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.

@OlegH-ua
Please get rid off all unnesessary comments and dead code.
Thank you!

//--- commented code is not needed - timer works without it ---
//if (timer_pending(&MyTimer)) {
// mod_timer_pending(&MyTimer, expired);
//} else {
Copy link
Contributor

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.

Copy link
Author

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 ;-)

@DevyatovAndrey DevyatovAndrey added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Nov 15, 2018
@OlegH-ua OlegH-ua added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants