-
Notifications
You must be signed in to change notification settings - Fork 615
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
Enhanced Timer Handling and Testing for One Shot Timer #2562
base: criu-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ static inline int timeval_valid(struct timeval *tv) | |
|
||
static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) | ||
{ | ||
if (ie->isec == 0 && ie->iusec == 0) { | ||
if (ie->isec == 0 && ie->iusec == 0 && ie->vsec == 0 && ie->vusec == 0) { | ||
memzero_p(val); | ||
return 0; | ||
} | ||
|
@@ -29,17 +29,8 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) | |
return -1; | ||
} | ||
|
||
if (ie->vsec == 0 && ie->vusec == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code handles the case when the timer is armed, but it_value is set to 0:
|
||
/* | ||
* Remaining time was too short. Set it to | ||
* interval to make the timer armed and work. | ||
*/ | ||
val->it_value.tv_sec = ie->isec; | ||
val->it_value.tv_usec = ie->iusec; | ||
} else { | ||
val->it_value.tv_sec = ie->vsec; | ||
val->it_value.tv_usec = ie->vusec; | ||
} | ||
val->it_value.tv_sec = ie->vsec; | ||
val->it_value.tv_usec = ie->vusec; | ||
|
||
if (!timeval_valid(&val->it_value)) { | ||
pr_err("Invalid timer value\n"); | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -33,21 +33,17 @@ static void timer_tick(int sig) | |||
} | ||||
} | ||||
|
||||
static void setup_timers(void) | ||||
static void setup_timers(const struct itimerval *tv) | ||||
{ | ||||
int i; | ||||
struct itimerval tv = { | ||||
.it_interval = { .tv_sec = 0, .tv_usec = 100000 }, | ||||
.it_value = { .tv_sec = 0, .tv_usec = 100 }, | ||||
}; | ||||
|
||||
for (i = 0; i < NUM_TIMERS; i++) { | ||||
if (signal(timer_tests[i].signal, timer_tick) == SIG_ERR) { | ||||
pr_perror("can't set signal handler %d", i); | ||||
exit(1); | ||||
} | ||||
|
||||
if (setitimer(timer_tests[i].timer_type, &tv, NULL) < 0) { | ||||
if (setitimer(timer_tests[i].timer_type, tv, NULL) < 0) { | ||||
pr_perror("can't set timer %d", i); | ||||
exit(1); | ||||
} | ||||
|
@@ -77,13 +73,27 @@ static void check_timers(void) | |||
|
||||
int main(int argc, char **argv) | ||||
{ | ||||
test_init(argc, argv); | ||||
const struct itimerval tv = { | ||||
.it_interval = { .tv_sec = 0, .tv_usec = 100000 }, | ||||
.it_value = { .tv_sec = 0, .tv_usec = 100 }, | ||||
}; | ||||
const struct itimerval oneshot_tv = { | ||||
.it_interval = { .tv_sec = 0, .tv_usec = 0 }, | ||||
.it_value = { .tv_sec = 1, .tv_usec = 100 }, | ||||
}; | ||||
const struct itimerval tvs[2] = { | ||||
tv, | ||||
oneshot_tv, | ||||
}; | ||||
|
||||
setup_timers(); | ||||
test_init(argc, argv); | ||||
for (int i = 0; i < 2; i++) { | ||||
setup_timers(&tvs[i]); | ||||
|
||||
test_daemon(); | ||||
test_waitsig(); | ||||
test_daemon(); | ||||
test_waitsig(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will not work. test_waitsig does its job when it is called first time. If you call it second time, it returns immediately: Line 365 in 27a5b9a
I suggest to add a new test. Here is my version of it: avagin@c02e313 It fails without the your fix and it passes with it:
|
||||
|
||||
check_timers(); | ||||
check_timers(); | ||||
} | ||||
return 0; | ||||
} |
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.
nit: The limit on the length of lines is 80 columns and this is a strongly preferred limit.
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.
actually, you need to check just it_value.tv_sec and it_value.tv_usec:
If this two fields are zero, setitimer disarms the timer.