<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Andrea,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 7, 2022 at 7:03 PM Andrea Cervesato via ltp <<a href="mailto:ltp@lists.linux.it" target="_blank">ltp@lists.linux.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We use CLOCK_MONOTONIC_COARSE as our time resolution for checking<br>
setitimer counter boundaries.<br>
<br>
Signed-off-by: Andrea Cervesato <<a href="mailto:andrea.cervesato@suse.com" target="_blank">andrea.cervesato@suse.com</a>><br>
---<br>
Switching to CLOCK_MONOTONIC_COARSE for setitimer time resolution.<br>
<br>
 .../kernel/syscalls/setitimer/setitimer01.c   | 33 +++++++++++--------<br>
 1 file changed, 19 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/setitimer/setitimer01.c b/testcases/kernel/syscalls/setitimer/setitimer01.c<br>
index eb62f02c6..5c880c6ef 100644<br>
--- a/testcases/kernel/syscalls/setitimer/setitimer01.c<br>
+++ b/testcases/kernel/syscalls/setitimer/setitimer01.c<br>
@@ -8,7 +8,7 @@<br>
 /*\<br>
  * [Description]<br>
  *<br>
- * Spawn a child and verify that setitimer() syscall passes, and it ends up<br>
+ * Spawn a child, verify that setitimer() syscall passes and it ends up<br>
  * counting inside expected boundaries. Then verify from the parent that our<br>
  * syscall sent the correct signal to the child.<br>
  */<br>
@@ -22,7 +22,8 @@<br>
 #include "tst_safe_clocks.h"<br>
<br>
 static struct itimerval *value, *ovalue;<br>
-static unsigned long time_step;<br>
+static long time_step;<br>
+static long time_count;<br>
<br>
 static struct tcase {<br>
        int which;<br>
@@ -56,7 +57,6 @@ static void verify_setitimer(unsigned int i)<br>
 {<br>
        pid_t pid;<br>
        int status;<br>
-       int usec = 3 * time_step;<br>
        struct tcase *tc = &tcases[i];<br>
<br>
        pid = SAFE_FORK();<br>
@@ -66,7 +66,7 @@ static void verify_setitimer(unsigned int i)<br>
<br>
                tst_no_corefile(0);<br>
<br>
-               set_setitimer_value(usec, 0);<br>
+               set_setitimer_value(time_count, 0);<br>
                TST_EXP_PASS(sys_setitimer(tc->which, value, NULL));<br>
<br>
                set_setitimer_value(5 * time_step, 7 * time_step);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Maybe we can use 'time_count' instead of 'time_step' as well.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
@@ -76,7 +76,7 @@ static void verify_setitimer(unsigned int i)<br>
                        ovalue->it_value.tv_sec,<br>
                        ovalue->it_value.tv_usec);<br>
<br>
-               if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_usec > usec)<br>
+               if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_usec > time_count + time_step)<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">This is not correct for 'ITIMER_REAL', kernel does _not_</div><div class="gmail_default" style="font-size:small">add that one jiffy when using high resolution. I'd suggest</div><div class="gmail_default" style="font-size:small">taking reference to Martin's code in the last email thread.</div><br></div><div><div class="gmail_default" style="font-size:small">And, I also think we'd better insert code comments here to</div><div class="gmail_default" style="font-size:small">briefly declare why need to add the time_step for the result </div><div class="gmail_default" style="font-size:small">(of ITIMER_VIRTUAL/ITIMER_PROF) comparison, otherwise, </div><div class="gmail_default" style="font-size:small">people who are not familiar with this test will be confused.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                        tst_res(TFAIL, "Ending counters are out of range");<br>
<br>
                for (;;)<br>
@@ -93,24 +93,29 @@ static void verify_setitimer(unsigned int i)<br>
<br>
 static void setup(void)<br>
 {<br>
-       struct timespec res;<br>
+       struct timespec time_res;<br>
<br>
-       SAFE_CLOCK_GETRES(CLOCK_MONOTONIC, &res);<br>
+       SAFE_CLOCK_GETRES(CLOCK_MONOTONIC_COARSE, &time_res);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">And here require code comments on why we choose to</div><div class="gmail_default" style="font-size:small">use CLOCK_MONOTONIC_COARSE.</div></div><div class="gmail_default" style="font-size:small"><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-       time_step = res.tv_nsec / 1000;<br>
-       if (time_step < 10000)<br>
-               time_step = 10000;<br>
+       time_step = time_res.tv_nsec / 1000;<br>
+       if (time_step <= 0)<br>
+               time_step = 1000;<br>
<br>
-       tst_res(TINFO, "clock resolution: %luns, time step: %luus",<br>
-               res.tv_nsec,<br>
-               time_step);<br>
+       time_count = 3 * time_step;<br>
+<br>
+       tst_res(TINFO, "clock resolution: %luns, "<br>
+               "time step: %luus, "<br>
+               "time count: %luus",<br>
+               time_res.tv_nsec,<br>
+               time_step,<br>
+               time_count);<br>
 }<br>
<br>
 static struct tst_test test = {<br>
        .tcnt = ARRAY_SIZE(tcases),<br>
        .forks_child = 1,<br>
-       .test = verify_setitimer,<br>
        .setup = setup,<br>
+       .test = verify_setitimer,<br>
        .bufs = (struct tst_buffers[]) {<br>
                {&value,  .size = sizeof(struct itimerval)},<br>
                {&ovalue, .size = sizeof(struct itimerval)},<br>
-- <br>
2.35.3<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>