[LTP] [PATCH v1] Correctly check setitimer params in setitimer01

Li Wang liwang@redhat.com
Fri Nov 4 07:48:53 CET 2022


Hi Andrea,

Andrea Cervesato via ltp <ltp@lists.linux.it> wrote:

Last test rewrite didn't consider the right expected boundaries when
> setitimer syscall was tested. We also introduced counter times as
> multiple of clock resolution, to avoid kernel rounding during setitimer
> counter increase.
>

Good catch, but I'm afraid this can not solve the problem thoroughly.
According failure log on "ITIMER_VIRTUAL/PROF" with running this patch.:

setitimer01.c:64: TINFO: tc->which = ITIMER_VIRTUAL
setitimer01.c:69: TPASS: sys_setitimer(tc->which, value, NULL) passed
setitimer01.c:72: TPASS: sys_setitimer(tc->which, value, ovalue) passed
setitimer01.c:76: TINFO: tv_sec=0, tv_usec=31000
setitimer01.c:79: TFAIL: Ending counters are out of range
setitimer01.c:88: TPASS: Child received signal: SIGVTALRM

setitimer01.c:64: TINFO: tc->which = ITIMER_PROF
setitimer01.c:69: TPASS: sys_setitimer(tc->which, value, NULL) passed
setitimer01.c:72: TPASS: sys_setitimer(tc->which, value, ovalue) passed
setitimer01.c:76: TINFO: tv_sec=0, tv_usec=31000
setitimer01.c:79: TFAIL: Ending counters are out of range
setitimer01.c:88: TPASS: Child received signal: SIGPROF

It seems the tv_usec always increase 1000us, I highly suspect
this increase comes from kernel function set_cpu_itimer() that
explicitly add TICK_NSEC when 'nval' is larger than zero:

$ cat kernel/time/itimer.c -n
   ...
   168 static void set_cpu_itimer(struct task_struct *tsk, unsigned int
clock_id,
   169                 const struct itimerspec64 *const value,
   170                 struct itimerspec64 *const ovalue)
   171 {
                   ...
   182          if (oval || nval) {
   183                  if (nval > 0)
   184                          nval += TICK_NSEC;
   185                  set_process_cpu_timer(tsk, clock_id, &nval, &oval);
   186          }
   187          ...
   198 }

To verify my guess, I do a modification based on your patch and
then easily get the result in pass.

--- a/testcases/kernel/syscalls/setitimer/setitimer01.c
+++ b/testcases/kernel/syscalls/setitimer/setitimer01.c
@@ -76,7 +76,7 @@ static void verify_setitimer(unsigned int i)
                        ovalue->it_value.tv_sec,
                        ovalue->it_value.tv_usec);

-               if (ovalue->it_value.tv_sec != 0 ||
ovalue->it_value.tv_usec > usec)
+               if (ovalue->it_value.tv_sec != 0 ||
ovalue->it_value.tv_usec - time_step > usec)
                        tst_res(TFAIL, "Ending counters are out of range");

                for (;;)
@@ -98,8 +98,8 @@ static void setup(void)
        SAFE_CLOCK_GETRES(CLOCK_MONOTONIC, &res);

        time_step = res.tv_nsec / 1000;
-       if (time_step < 10000)
-               time_step = 10000;
+       if (time_step < 1000)
+               time_step = 1000;

        tst_res(TINFO, "clock resolution: %luns, time step: %luus",
                res.tv_nsec,


But after trying this with my RasberryPi4, it fails again with an increase
4000us each time. So it might related to the system use different time
resolutions. When I shift to use `CLOCK_MONOTONIC_COARSE`
then test gets passed on all my platforms.

Any comments?


----------CLOCK_MONOTONIC-------------
setitimer01.c:65: TINFO: tc->which = ITIMER_VIRTUAL
setitimer01.c:70: TPASS: sys_setitimer(tc->which, value, NULL) passed
setitimer01.c:73: TPASS: sys_setitimer(tc->which, value, ovalue) passed
setitimer01.c:77: TINFO: tv_sec=0, tv_usec=7000
setitimer01.c:80: TFAIL: Ending counters are out of range

-----------CLOCK_MONOTONIC_COARSE-------
setitimer01.c:65: TINFO: tc->which = ITIMER_VIRTUAL
setitimer01.c:70: TPASS: sys_setitimer(tc->which, value, NULL) passed
setitimer01.c:73: TPASS: sys_setitimer(tc->which, value, ovalue) passed
setitimer01.c:77: TINFO: tv_sec=0, tv_usec=16000
setitimer01.c:89: TPASS: Child received signal: SIGVTALRM

# lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  1
Core(s) per cluster: 4
Socket(s):           -
Cluster(s):          1
Vendor ID:           ARM
Model:               3
Model name:          Cortex-A72
Stepping:            r0p3
CPU max MHz:         1500.0000
CPU min MHz:         600.0000
BogoMIPS:            108.00
Flags:               fp asimd evtstrm crc32 cpuid

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20221104/fffd661c/attachment-0001.htm>


More information about the ltp mailing list