diff mbox series

[V4,5/6] syscalls: Don't pass struct timespec to tst_syscall()

Message ID 9562fdf4debd759439ee7f468008177003db9513.1592457867.git.viresh.kumar@linaro.org
State Accepted
Headers show
Series None | expand

Commit Message

Viresh Kumar June 18, 2020, 5:25 a.m. UTC
There are compatibility issues here as we are calling the direct
syscalls (with tst_syscall()) with the "struct timespec" (which is a
libc definition). Over that, an architecture may not define
__NR_clock_getres (for example) and so we must have the fallback version
in place.

This updates the tst_clock_*() routines in core libraries and adds
support for different syscall variants.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V4: Properly use return value and errno.

 lib/tst_clocks.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 90 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis June 18, 2020, 11:06 a.m. UTC | #1
Hi!
Pushed, thanks.
Li Wang July 3, 2020, 9:55 a.m. UTC | #2
Hi Viresh,
Seems this patch involved a new regression:(.

Viresh Kumar <viresh.kumar@linaro.org> wrote:

...
>
> +typedef int (*mysyscall)(clockid_t clk_id, void *ts);
> +
> +int syscall_supported_by_kernel(mysyscall func)
> +{
> +       int ret;
> +
> +       ret = func(0, NULL);

+       if (ret == -1 && errno == ENOSYS)
> +               return 0;
> +
> +       return 1;
> +}
> ... }
>
>  int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
>  {
> -       return tst_syscall(__NR_clock_gettime, clk_id, ts);
> +       struct tst_ts tts = { 0, };
> +       static mysyscall func;
> +       int ret;
> +
> +#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
> +       if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
>

To invoke sys_clock_gettime64 here makes no chance to choose the correct
syscall version since tst_syscall() will exit directly when getting ENOSYS.

We got many tests TCONF like the mmap18 did as below:
-------------------
# uname -rm
5.8.0-rc2+ aarch64
# ./mmap18
tst_test.c:1247: INFO: Timeout per run is 0h 05m 00s
../include/tst_timer.h:214: CONF: syscall(403) __NR_clock_gettime64 not
supported

the function call trace:
-----------------------------
testrun()
get_time_ms
...
tst_clock_gettime
syscall_supported_by_kernel
sys_clock_gettime64
tst_syscall(__NR_clock_gettime64, ...)


---- syscalls/regen.sh -----
#define tst_syscall(NR, ...) ({ \\
        int tst_ret; \\
        if (NR == __LTP__NR_INVALID_SYSCALL) { \\
                errno = ENOSYS; \\
                tst_ret = -1; \\
        } else { \\
                tst_ret = syscall(NR, ##__VA_ARGS__); \\
        } \\
        if (tst_ret == -1 && errno == ENOSYS) { \\
                tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \\
        } \\
        tst_ret; \\
})



> +               func = sys_clock_gettime64;
> +               tts.type = TST_KERN_TIMESPEC;
> +       }
> +#endif
> +
> +       if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
> +               func = sys_clock_gettime;
> +               tts.type = TST_KERN_OLD_TIMESPEC;
> +       }
> +
> +       if (!func) {
> +               tst_res(TCONF, "clock_gettime() not available");
> +               errno = ENOSYS;
> +               return -1;
> +       }
> +
> +       ret = func(clk_id, tst_ts_get(&tts));
> +       ts->tv_sec = tst_ts_get_sec(tts);
> +       ts->tv_nsec = tst_ts_get_nsec(tts);
> +       return ret;
>  }
>


Regards,
Li Wang
Harish July 3, 2020, 12:26 p.m. UTC | #3
Hi,

+1. I am also facing the same issue with many similar tests.

# uname -rm
4.18.0-211.el8.ppc64le ppc64le

Regards,
Harish

On 7/3/20 3:25 PM, Li Wang wrote:
> Hi Viresh,
> Seems this patch involved a new regression:(.
>
> Viresh Kumar <viresh.kumar@linaro.org 
> <mailto:viresh.kumar@linaro.org>> wrote:
>
>     ...
>
>     +typedef int (*mysyscall)(clockid_t clk_id, void *ts);
>     +
>     +int syscall_supported_by_kernel(mysyscall func)
>     +{
>     +       int ret;
>     +
>     +       ret = func(0, NULL); 
>
>     +       if (ret == -1 && errno == ENOSYS)
>     +               return 0;
>     +
>     +       return 1;
>     +}
>     ... }
>
>      int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
>      {
>     -       return tst_syscall(__NR_clock_gettime, clk_id, ts);
>     +       struct tst_ts tts = { 0, };
>     +       static mysyscall func;
>     +       int ret;
>     +
>     +#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
>     +       if (!func &&
>     syscall_supported_by_kernel(sys_clock_gettime64)) {
>
>
> To invoke sys_clock_gettime64 here makes no chance to choose the 
> correct syscall version since tst_syscall() will exit directly when 
> getting ENOSYS.
>
> We got many tests TCONF like the mmap18 did as below:
> -------------------
> # uname -rm
> 5.8.0-rc2+ aarch64
> # ./mmap18
> tst_test.c:1247: INFO: Timeout per run is 0h 05m 00s
> ../include/tst_timer.h:214: CONF: syscall(403) __NR_clock_gettime64 
> not supported
>
> the function call trace:
> -----------------------------
> testrun()
> get_time_ms
> ...
> tst_clock_gettime
> syscall_supported_by_kernel
> sys_clock_gettime64
> tst_syscall(__NR_clock_gettime64, ...)
>
>
> ---- syscalls/regen.sh -----
> #define tst_syscall(NR, ...) ({ \\
>         int tst_ret; \\
>         if (NR == __LTP__NR_INVALID_SYSCALL) { \\
>                 errno = ENOSYS; \\
>                 tst_ret = -1; \\
>         } else { \\
>                 tst_ret = syscall(NR, ##__VA_ARGS__); \\
>         } \\
>         if (tst_ret == -1 && errno == ENOSYS) { \\
>                 tst_brk(TCONF, "syscall(%d) " #NR " not supported", 
> NR); \\
>         } \\
>         tst_ret; \\
> })
>
>     +               func = sys_clock_gettime64;
>     +               tts.type = TST_KERN_TIMESPEC;
>     +       }
>     +#endif
>     +
>     +       if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
>     +               func = sys_clock_gettime;
>     +               tts.type = TST_KERN_OLD_TIMESPEC;
>     +       }
>     +
>     +       if (!func) {
>     +               tst_res(TCONF, "clock_gettime() not available");
>     +               errno = ENOSYS;
>     +               return -1;
>     +       }
>     +
>     +       ret = func(clk_id, tst_ts_get(&tts));
>     +       ts->tv_sec = tst_ts_get_sec(tts);
>     +       ts->tv_nsec = tst_ts_get_nsec(tts);
>     +       return ret;
>      }
>
>
> Regards,
> Li Wang
>
Cyril Hrubis July 3, 2020, 12:59 p.m. UTC | #4
Hi!
I guess that we need:

diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index bc0bef273..c0727a34c 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -14,11 +14,11 @@
 
 typedef int (*mysyscall)(clockid_t clk_id, void *ts);
 
-int syscall_supported_by_kernel(mysyscall func)
+int syscall_supported_by_kernel(long sysnr)
 {
 	int ret;
 
-	ret = func(0, NULL);
+	ret = syscall(sysnr, func(0, NULL);
 	if (ret == -1 && errno == ENOSYS)
 		return 0;
 
@@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct timespec *res)
 	int ret;
 
 #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
-	if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_getres64)) {
 		func = sys_clock_getres64;
 		tts.type = TST_KERN_TIMESPEC;
 	}
 #endif
 
-	if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
 		func = sys_clock_getres;
 		tts.type = TST_KERN_OLD_TIMESPEC;
 	}
@@ -62,13 +62,13 @@ int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
 	int ret;
 
 #if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
-	if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_gettime64)) {
 		func = sys_clock_gettime64;
 		tts.type = TST_KERN_TIMESPEC;
 	}
 #endif
 
-	if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_gettime)) {
 		func = sys_clock_gettime;
 		tts.type = TST_KERN_OLD_TIMESPEC;
 	}
@@ -91,13 +91,13 @@ int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
 	static mysyscall func;
 
 #if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
-	if (!func && syscall_supported_by_kernel(sys_clock_settime64)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_settime64)) {
 		func = sys_clock_settime64;
 		tts.type = TST_KERN_TIMESPEC;
 	}
 #endif
 
-	if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
+	if (!func && syscall_supported_by_kernel(__NR_clock_settime)) {
 		func = sys_clock_settime;
 		tts.type = TST_KERN_OLD_TIMESPEC;
 	}
Li Wang July 4, 2020, 7:14 a.m. UTC | #5
Hi Cyril,

On Fri, Jul 3, 2020 at 8:59 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> I guess that we need:
>

This method works for me, plz could you correct some typos as below.


>
> diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
> index bc0bef273..c0727a34c 100644
> --- a/lib/tst_clocks.c
> +++ b/lib/tst_clocks.c
> @@ -14,11 +14,11 @@
>
>  typedef int (*mysyscall)(clockid_t clk_id, void *ts);
>
> -int syscall_supported_by_kernel(mysyscall func)
> +int syscall_supported_by_kernel(long sysnr)
>  {
>         int ret;
>
> -       ret = func(0, NULL);
> +       ret = syscall(sysnr, func(0, NULL);
>

This line should be: ret = syscall(sysnr, 0, NULL);


>         if (ret == -1 && errno == ENOSYS)
>                 return 0;
>
> @@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct timespec
> *res)
>         int ret;
>
>  #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
> -       if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_getres64)) {


if (!func && syscall_supported_by_kernel(__NR_clock_getres_time64 )) {


>

                func = sys_clock_getres64;
>                 tts.type = TST_KERN_TIMESPEC;
>         }
>  #endif
>
> -       if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
>                 func = sys_clock_getres;
>                 tts.type = TST_KERN_OLD_TIMESPEC;
>         }
> @@ -62,13 +62,13 @@ int tst_clock_gettime(clockid_t clk_id, struct
> timespec *ts)
>         int ret;
>
>  #if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
> -       if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_gettime64)) {
>                 func = sys_clock_gettime64;
>                 tts.type = TST_KERN_TIMESPEC;
>         }
>  #endif
>
> -       if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_gettime)) {
>                 func = sys_clock_gettime;
>                 tts.type = TST_KERN_OLD_TIMESPEC;
>         }
> @@ -91,13 +91,13 @@ int tst_clock_settime(clockid_t clk_id, struct
> timespec *ts)
>         static mysyscall func;
>
>  #if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
> -       if (!func && syscall_supported_by_kernel(sys_clock_settime64)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_settime64)) {
>                 func = sys_clock_settime64;
>                 tts.type = TST_KERN_TIMESPEC;
>         }
>  #endif
>
> -       if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
> +       if (!func && syscall_supported_by_kernel(__NR_clock_settime)) {
>                 func = sys_clock_settime;
>                 tts.type = TST_KERN_OLD_TIMESPEC;
>         }
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
>
Viresh Kumar July 6, 2020, 2:21 a.m. UTC | #6
On 03-07-20, 14:59, Cyril Hrubis wrote:
> Hi!
> I guess that we need:
> 
> diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
> index bc0bef273..c0727a34c 100644
> --- a/lib/tst_clocks.c
> +++ b/lib/tst_clocks.c
> @@ -14,11 +14,11 @@
>  
>  typedef int (*mysyscall)(clockid_t clk_id, void *ts);
>  
> -int syscall_supported_by_kernel(mysyscall func)
> +int syscall_supported_by_kernel(long sysnr)
>  {
>  	int ret;
>  
> -	ret = func(0, NULL);
> +	ret = syscall(sysnr, func(0, NULL);
>  	if (ret == -1 && errno == ENOSYS)
>  		return 0;
>  
> @@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct timespec *res)
>  	int ret;
>  
>  #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
> -	if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_getres64)) {
>  		func = sys_clock_getres64;
>  		tts.type = TST_KERN_TIMESPEC;
>  	}
>  #endif
>  
> -	if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
>  		func = sys_clock_getres;
>  		tts.type = TST_KERN_OLD_TIMESPEC;
>  	}
> @@ -62,13 +62,13 @@ int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
>  	int ret;
>  
>  #if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
> -	if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_gettime64)) {
>  		func = sys_clock_gettime64;
>  		tts.type = TST_KERN_TIMESPEC;
>  	}
>  #endif
>  
> -	if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_gettime)) {
>  		func = sys_clock_gettime;
>  		tts.type = TST_KERN_OLD_TIMESPEC;
>  	}
> @@ -91,13 +91,13 @@ int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
>  	static mysyscall func;
>  
>  #if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
> -	if (!func && syscall_supported_by_kernel(sys_clock_settime64)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_settime64)) {
>  		func = sys_clock_settime64;
>  		tts.type = TST_KERN_TIMESPEC;
>  	}
>  #endif
>  
> -	if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
> +	if (!func && syscall_supported_by_kernel(__NR_clock_settime)) {
>  		func = sys_clock_settime;
>  		tts.type = TST_KERN_OLD_TIMESPEC;
>  	}

Thanks, this will do.
Harish July 6, 2020, 8:44 a.m. UTC | #7
Hi,

I tried the suggested patch, but was unsuccessful in running the test. 
Here is my diff.

diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index bc0bef273..7b465b1f6 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -14,11 +14,11 @@

  typedef int (*mysyscall)(clockid_t clk_id, void *ts);

-int syscall_supported_by_kernel(mysyscall func)
+int syscall_supported_by_kernel(long sysnr)
  {
      int ret;

-    ret = func(0, NULL);
+    ret = syscall(sysnr, 0, NULL);
      if (ret == -1 && errno == ENOSYS)
          return 0;

@@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct 
timespec *res)
      int ret;

  #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
-    if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_getres_time64)) {
          func = sys_clock_getres64;
          tts.type = TST_KERN_TIMESPEC;
      }
  #endif

-    if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
          func = sys_clock_getres;
          tts.type = TST_KERN_OLD_TIMESPEC;
      }
@@ -62,13 +62,13 @@ int tst_clock_gettime(clockid_t clk_id, struct 
timespec *ts)
      int ret;

  #if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
-    if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_gettime64)) {
          func = sys_clock_gettime64;
          tts.type = TST_KERN_TIMESPEC;
      }
  #endif

-    if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_gettime)) {
          func = sys_clock_gettime;
          tts.type = TST_KERN_OLD_TIMESPEC;
      }
@@ -91,13 +91,13 @@ int tst_clock_settime(clockid_t clk_id, struct 
timespec *ts)
      static mysyscall func;

  #if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
-    if (!func && syscall_supported_by_kernel(sys_clock_settime64)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_settime64)) {
          func = sys_clock_settime64;
          tts.type = TST_KERN_TIMESPEC;
      }
  #endif

-    if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
+    if (!func && syscall_supported_by_kernel(__NR_clock_settime)) {
          func = sys_clock_settime;
          tts.type = TST_KERN_OLD_TIMESPEC;
      }


$ ./runltp -s max_map_count
...
...
Running tests.......
<<<test_start>>>
tag=max_map_count stime=1594019344
cmdline="max_map_count -i 10"
contacts=""
analysis=exit
<<<test_output>>>
incrementing stop
tst_test.c:1247: INFO: Timeout per run is 0h 05m 00s
../include/tst_timer.h:214: CONF: syscall(403) __NR_clock_gettime64 not 
supported

Summary:
passed   0
failed   0
skipped  1
warnings 0
<<<execution_status>>>
initiation_status="ok"
duration=0 termination_type=exited termination_id=32 corefile=no
cutime=0 cstime=0
<<<test_end>>>

Is there anything I am missing here? Thanks in advance.

Regards,
Harish

On 7/4/20 12:44 PM, Li Wang wrote:
> Hi Cyril,
>
> On Fri, Jul 3, 2020 at 8:59 PM Cyril Hrubis <chrubis@suse.cz 
> <mailto:chrubis@suse.cz>> wrote:
>
>     Hi!
>     I guess that we need:
>
>
> This method works for me, plz could you correct some typos as below.
>
>
>     diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
>     index bc0bef273..c0727a34c 100644
>     --- a/lib/tst_clocks.c
>     +++ b/lib/tst_clocks.c
>     @@ -14,11 +14,11 @@
>
>      typedef int (*mysyscall)(clockid_t clk_id, void *ts);
>
>     -int syscall_supported_by_kernel(mysyscall func)
>     +int syscall_supported_by_kernel(long sysnr)
>      {
>             int ret;
>
>     -       ret = func(0, NULL);
>     +       ret = syscall(sysnr, func(0, NULL);
>
> This line should be: ret = syscall(sysnr, 0, NULL);
>
>             if (ret == -1 && errno == ENOSYS)
>                     return 0;
>
>     @@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct
>     timespec *res)
>             int ret;
>
>      #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
>     -       if (!func &&
>     syscall_supported_by_kernel(sys_clock_getres64)) {
>     +       if (!func &&
>     syscall_supported_by_kernel(__NR_clock_getres64)) {
>
> if (!func && syscall_supported_by_kernel(__NR_clock_getres_time64 )) {
>
>                     func = sys_clock_getres64;
>                     tts.type = TST_KERN_TIMESPEC;
>             }
>      #endif
>
>     -       if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
>     +       if (!func && syscall_supported_by_kernel(__NR_clock_getres)) {
>                     func = sys_clock_getres;
>                     tts.type = TST_KERN_OLD_TIMESPEC;
>             }
>     @@ -62,13 +62,13 @@ int tst_clock_gettime(clockid_t clk_id, struct
>     timespec *ts)
>             int ret;
>
>      #if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
>     -       if (!func &&
>     syscall_supported_by_kernel(sys_clock_gettime64)) {
>     +       if (!func &&
>     syscall_supported_by_kernel(__NR_clock_gettime64)) {
>                     func = sys_clock_gettime64;
>                     tts.type = TST_KERN_TIMESPEC;
>             }
>      #endif
>
>     -       if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
>     +       if (!func &&
>     syscall_supported_by_kernel(__NR_clock_gettime)) {
>                     func = sys_clock_gettime;
>                     tts.type = TST_KERN_OLD_TIMESPEC;
>             }
>     @@ -91,13 +91,13 @@ int tst_clock_settime(clockid_t clk_id, struct
>     timespec *ts)
>             static mysyscall func;
>
>      #if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
>     -       if (!func &&
>     syscall_supported_by_kernel(sys_clock_settime64)) {
>     +       if (!func &&
>     syscall_supported_by_kernel(__NR_clock_settime64)) {
>                     func = sys_clock_settime64;
>                     tts.type = TST_KERN_TIMESPEC;
>             }
>      #endif
>
>     -       if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
>     +       if (!func &&
>     syscall_supported_by_kernel(__NR_clock_settime)) {
>                     func = sys_clock_settime;
>                     tts.type = TST_KERN_OLD_TIMESPEC;
>             }
>
>     -- 
>     Cyril Hrubis
>     chrubis@suse.cz <mailto:chrubis@suse.cz>
>
>
>
> -- 
> Regards,
> Li Wang
>
Li Wang July 6, 2020, 8:57 a.m. UTC | #8
Harish <harish@linux.ibm.com> wrote:

> Hi,
>
> I tried the suggested patch, but was unsuccessful in running the test.
> Here is my diff.
> ...
> Is there anything I am missing here? Thanks in advance.
>
Your diff version looks correct.

I doubt have you rebuild your LTP or at least rebuild the ltp-lib?
Harish July 6, 2020, 9:21 a.m. UTC | #9
On 7/6/20 2:27 PM, Li Wang wrote:
>
> Harish <harish@linux.ibm.com <mailto:harish@linux.ibm.com>> wrote:
>
>     Hi,
>
>     I tried the suggested patch, but was unsuccessful in running the
>     test. Here is my diff.
>     ...
>     Is there anything I am missing here? Thanks in advance.
>
> Your diff version looks correct.
>
> I doubt have you rebuild your LTP or at least rebuild the ltp-lib?
My bad, I did rebuild the ltp with the diff. But it required a clean 
before I do so.
I can confirm tests are running now.

Thanks.
>
> -- 
> Regards,
> Li Wang
Cyril Hrubis July 7, 2020, 9:03 a.m. UTC | #10
Hi!
> > diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
> > index bc0bef273..c0727a34c 100644
> > --- a/lib/tst_clocks.c
> > +++ b/lib/tst_clocks.c
> > @@ -14,11 +14,11 @@
> >
> >  typedef int (*mysyscall)(clockid_t clk_id, void *ts);
> >
> > -int syscall_supported_by_kernel(mysyscall func)
> > +int syscall_supported_by_kernel(long sysnr)
> >  {
> >         int ret;
> >
> > -       ret = func(0, NULL);
> > +       ret = syscall(sysnr, func(0, NULL);
> >
> 
> This line should be: ret = syscall(sysnr, 0, NULL);

This is obvious typo, sorry.

> >         if (ret == -1 && errno == ENOSYS)
> >                 return 0;
> >
> > @@ -32,13 +32,13 @@ int tst_clock_getres(clockid_t clk_id, struct timespec
> > *res)
> >         int ret;
> >
> >  #if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
> > -       if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
> > +       if (!func && syscall_supported_by_kernel(__NR_clock_getres64)) {
> 
> 
> if (!func && syscall_supported_by_kernel(__NR_clock_getres_time64 )) {

Huh, how come the syscall is called clock_getres_time64 while the rest
has only 64 appended such as clock_gettime64 and clock_settime64?

That's really strange...
Viresh Kumar July 7, 2020, 9:18 a.m. UTC | #11
On 07-07-20, 11:03, Cyril Hrubis wrote:
> Huh, how come the syscall is called clock_getres_time64 while the rest
> has only 64 appended such as clock_gettime64 and clock_settime64?
> 
> That's really strange...

That also made me wonder on how should I be naming routines.
Apparently they wanted to have "time64" in the name, if the syscall
already has "time" in it they just appended 64, else added "_time64".
Cyril Hrubis July 7, 2020, 11:49 a.m. UTC | #12
Hi!
> > Huh, how come the syscall is called clock_getres_time64 while the rest
> > has only 64 appended such as clock_gettime64 and clock_settime64?
> > 
> > That's really strange...
> 
> That also made me wonder on how should I be naming routines.
> Apparently they wanted to have "time64" in the name, if the syscall
> already has "time" in it they just appended 64, else added "_time64".

If that is the case in upstream we should follow that convence for the
functions as well...
Viresh Kumar July 8, 2020, 2:34 a.m. UTC | #13
On 07-07-20, 13:49, Cyril Hrubis wrote:
> Hi!
> > > Huh, how come the syscall is called clock_getres_time64 while the rest
> > > has only 64 appended such as clock_gettime64 and clock_settime64?
> > > 
> > > That's really strange...
> > 
> > That also made me wonder on how should I be naming routines.
> > Apparently they wanted to have "time64" in the name, if the syscall
> > already has "time" in it they just appended 64, else added "_time64".
> 
> If that is the case in upstream we should follow that convence for the
> functions as well...

That's what I tried to do in my patches normally.
diff mbox series

Patch

diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index 2eaa73b11abe..bc0bef273e52 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -7,23 +7,110 @@ 
 
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
+#include "tst_timer.h"
 #include "tst_clocks.h"
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
 
+typedef int (*mysyscall)(clockid_t clk_id, void *ts);
+
+int syscall_supported_by_kernel(mysyscall func)
+{
+	int ret;
+
+	ret = func(0, NULL);
+	if (ret == -1 && errno == ENOSYS)
+		return 0;
+
+	return 1;
+}
+
 int tst_clock_getres(clockid_t clk_id, struct timespec *res)
 {
-	return tst_syscall(__NR_clock_getres, clk_id, res);
+	static struct tst_ts tts = { 0, };
+	static mysyscall func;
+	int ret;
+
+#if (__NR_clock_getres_time64 != __LTP__NR_INVALID_SYSCALL)
+	if (!func && syscall_supported_by_kernel(sys_clock_getres64)) {
+		func = sys_clock_getres64;
+		tts.type = TST_KERN_TIMESPEC;
+	}
+#endif
+
+	if (!func && syscall_supported_by_kernel(sys_clock_getres)) {
+		func = sys_clock_getres;
+		tts.type = TST_KERN_OLD_TIMESPEC;
+	}
+
+	if (!func) {
+		tst_res(TCONF, "clock_getres() not available");
+		errno = ENOSYS;
+		return -1;
+	}
+
+	ret = func(clk_id, tst_ts_get(&tts));
+	res->tv_sec = tst_ts_get_sec(tts);
+	res->tv_nsec = tst_ts_get_nsec(tts);
+	return ret;
 }
 
 int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
 {
-	return tst_syscall(__NR_clock_gettime, clk_id, ts);
+	struct tst_ts tts = { 0, };
+	static mysyscall func;
+	int ret;
+
+#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
+	if (!func && syscall_supported_by_kernel(sys_clock_gettime64)) {
+		func = sys_clock_gettime64;
+		tts.type = TST_KERN_TIMESPEC;
+	}
+#endif
+
+	if (!func && syscall_supported_by_kernel(sys_clock_gettime)) {
+		func = sys_clock_gettime;
+		tts.type = TST_KERN_OLD_TIMESPEC;
+	}
+
+	if (!func) {
+		tst_res(TCONF, "clock_gettime() not available");
+		errno = ENOSYS;
+		return -1;
+	}
+
+	ret = func(clk_id, tst_ts_get(&tts));
+	ts->tv_sec = tst_ts_get_sec(tts);
+	ts->tv_nsec = tst_ts_get_nsec(tts);
+	return ret;
 }
 
 int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
 {
-	return tst_syscall(__NR_clock_settime, clk_id, ts);
+	struct tst_ts tts = { 0, };
+	static mysyscall func;
+
+#if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
+	if (!func && syscall_supported_by_kernel(sys_clock_settime64)) {
+		func = sys_clock_settime64;
+		tts.type = TST_KERN_TIMESPEC;
+	}
+#endif
+
+	if (!func && syscall_supported_by_kernel(sys_clock_settime)) {
+		func = sys_clock_settime;
+		tts.type = TST_KERN_OLD_TIMESPEC;
+	}
+
+	if (!func) {
+		tst_res(TCONF, "clock_settime() not available");
+		errno = ENOSYS;
+		return -1;
+	}
+
+	tst_ts_set_sec(&tts, ts->tv_sec);
+	tst_ts_set_nsec(&tts, ts->tv_nsec);
+	return func(clk_id, tst_ts_get(&tts));
 }
 
 const char *tst_clock_name(clockid_t clk_id)