git: 187715a42023 - main - linux(4): Implement clock_getres_time64 system call.

Dmitry Chagin dchagin at FreeBSD.org
Sun Jun 6 14:21:30 UTC 2021


The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=187715a420237e1ed94dd5aef158eada7dcdc559

commit 187715a420237e1ed94dd5aef158eada7dcdc559
Author:     Dmitry Chagin <dchagin at FreeBSD.org>
AuthorDate: 2021-06-07 02:21:32 +0000
Commit:     Dmitry Chagin <dchagin at FreeBSD.org>
CommitDate: 2021-06-07 02:21:32 +0000

    linux(4): Implement clock_getres_time64 system call.
    
    MFC after:      2 weeks
---
 sys/amd64/linux32/linux32_dummy_machdep.c |  1 -
 sys/amd64/linux32/syscalls.master         |  5 +-
 sys/compat/linux/linux_time.c             | 92 +++++++++++++++++++++++--------
 sys/i386/linux/linux_dummy_machdep.c      |  1 -
 sys/i386/linux/syscalls.master            |  5 +-
 5 files changed, 76 insertions(+), 28 deletions(-)

diff --git a/sys/amd64/linux32/linux32_dummy_machdep.c b/sys/amd64/linux32/linux32_dummy_machdep.c
index 022fbcbdd0c6..3f8dfe711dba 100644
--- a/sys/amd64/linux32/linux32_dummy_machdep.c
+++ b/sys/amd64/linux32/linux32_dummy_machdep.c
@@ -68,7 +68,6 @@ DUMMY(mq_getsetattr);
 DUMMY(arch_prctl);
 /* Linux 5.0: */
 DUMMY(clock_adjtime64);
-DUMMY(clock_getres_time64);
 DUMMY(clock_nanosleep_time64);
 DUMMY(timer_gettime64);
 DUMMY(timer_settime64);
diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master
index 924fbce9eac7..27034c0216ff 100644
--- a/sys/amd64/linux32/syscalls.master
+++ b/sys/amd64/linux32/syscalls.master
@@ -2356,7 +2356,10 @@
 		int linux_clock_adjtime64(void);
 	}
 406	AUE_NULL	STD {
-		int linux_clock_getres_time64(void);
+		int linux_clock_getres_time64(
+		    clockid_t which,
+		    struct l_timespec64 *tp
+		);
 	}
 407	AUE_NULL	STD {
 		int linux_clock_nanosleep_time64(void);
diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c
index 65bb4e9b754f..43db8871a0d8 100644
--- a/sys/compat/linux/linux_time.c
+++ b/sys/compat/linux/linux_time.c
@@ -94,10 +94,13 @@ LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, copyin_error, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime64, conversion_error, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime64, copyin_error, "int");
 #endif
-LIN_SDT_PROBE_DEFINE0(time, linux_clock_getres, nullcall);
-LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, conversion_error, "int");
-LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, getres_error, "int");
+LIN_SDT_PROBE_DEFINE0(time, linux_common_clock_getres, nullcall);
+LIN_SDT_PROBE_DEFINE1(time, linux_common_clock_getres, conversion_error, "int");
+LIN_SDT_PROBE_DEFINE1(time, linux_common_clock_getres, getres_error, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int");
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres_time64, copyout_error, "int");
+#endif
 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int");
@@ -111,6 +114,8 @@ static int	linux_common_clock_gettime(struct thread *, clockid_t,
 		    struct timespec *);
 static int	linux_common_clock_settime(struct thread *, clockid_t,
 		    struct timespec *);
+static int	linux_common_clock_getres(struct thread *, clockid_t,
+		    struct timespec *);
 
 int
 native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
@@ -486,23 +491,22 @@ linux_clock_settime64(struct thread *td, struct linux_clock_settime64_args *args
 }
 #endif
 
-int
-linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
+static int
+linux_common_clock_getres(struct thread *td, clockid_t which,
+    struct timespec *ts)
 {
 	struct proc *p;
-	struct timespec ts;
-	struct l_timespec lts;
 	int error, clockwhich;
 	clockid_t nwhich;
 	pid_t pid;
 	lwpid_t tid;
 
-	error = linux_to_native_clockid(&nwhich, args->which);
+	error = linux_to_native_clockid(&nwhich, which);
 	if (error != 0) {
 		linux_msg(curthread,
-		    "unsupported clock_getres clockid %d", args->which);
-		LIN_SDT_PROBE1(time, linux_clock_getres, conversion_error,
-		    error);
+		    "unsupported clock_getres clockid %d", which);
+		LIN_SDT_PROBE1(time, linux_common_clock_getres,
+		    conversion_error, error);
 		return (error);
 	}
 
@@ -510,10 +514,10 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
 	 * Check user supplied clock id in case of per-process
 	 * or thread-specific cpu-time clock.
 	 */
-	if (args->which < 0) {
+	if (which < 0) {
 		switch (nwhich) {
 		case CLOCK_THREAD_CPUTIME_ID:
-			tid = LINUX_CPUCLOCK_ID(args->which);
+			tid = LINUX_CPUCLOCK_ID(which);
 			if (tid != 0) {
 				p = td->td_proc;
 				if (linux_tdfind(td, tid, p->p_pid) == NULL)
@@ -522,7 +526,7 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
 			}
 			break;
 		case CLOCK_PROCESS_CPUTIME_ID:
-			pid = LINUX_CPUCLOCK_ID(args->which);
+			pid = LINUX_CPUCLOCK_ID(which);
 			if (pid != 0) {
 				error = pget(pid, PGET_CANSEE, &p);
 				if (error != 0)
@@ -533,15 +537,15 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
 		}
 	}
 
-	if (args->tp == NULL) {
-		LIN_SDT_PROBE0(time, linux_clock_getres, nullcall);
+	if (ts == NULL) {
+		LIN_SDT_PROBE0(time, linux_common_clock_getres, nullcall);
 		return (0);
 	}
 
 	switch (nwhich) {
 	case CLOCK_THREAD_CPUTIME_ID:
 	case CLOCK_PROCESS_CPUTIME_ID:
-		clockwhich = LINUX_CPUCLOCK_WHICH(args->which);
+		clockwhich = LINUX_CPUCLOCK_WHICH(which);
 		/*
 		 * In both cases (when the clock id obtained by a call to
 		 * clock_getcpuclockid() or using the clock
@@ -550,9 +554,9 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
 		 *
 		 * See Linux posix_cpu_clock_getres() implementation.
 		 */
-		if (args->which > 0 || clockwhich == LINUX_CPUCLOCK_SCHED) {
-			ts.tv_sec = 0;
-			ts.tv_nsec = 1;
+		if (which > 0 || clockwhich == LINUX_CPUCLOCK_SCHED) {
+			ts->tv_sec = 0;
+			ts->tv_nsec = 1;
 			goto out;
 		}
 
@@ -571,22 +575,62 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
 	default:
 		break;
 	}
-	error = kern_clock_getres(td, nwhich, &ts);
+	error = kern_clock_getres(td, nwhich, ts);
 	if (error != 0) {
-		LIN_SDT_PROBE1(time, linux_clock_getres, getres_error, error);
+		LIN_SDT_PROBE1(time, linux_common_clock_getres,
+		    getres_error, error);
 		return (error);
 	}
 
 out:
+	return (error);
+}
+
+int
+linux_clock_getres(struct thread *td,
+    struct linux_clock_getres_args *args)
+{
+	struct timespec ts;
+	struct l_timespec lts;
+	int error;
+
+	error = linux_common_clock_getres(td, args->which, &ts);
+	if (error != 0 || args->tp == NULL)
+		return (error);
+
 	error = native_to_linux_timespec(&lts, &ts);
 	if (error != 0)
 		return (error);
-	error = copyout(&lts, args->tp, sizeof lts);
+	error = copyout(&lts, args->tp, sizeof(lts));
 	if (error != 0)
-		LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error);
+		LIN_SDT_PROBE1(time, linux_clock_getres,
+		    copyout_error, error);
+	return (error);
+}
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_clock_getres_time64(struct thread *td,
+    struct linux_clock_getres_time64_args *args)
+{
+	struct timespec ts;
+	struct l_timespec64 lts;
+	int error;
+
+	error = linux_common_clock_getres(td, args->which, &ts);
+	if (error != 0 || args->tp == NULL)
+		return (error);
 
+	error = native_to_linux_timespec64(&lts, &ts);
+	if (error != 0)
+		return (error);
+	error = copyout(&lts, args->tp, sizeof(lts));
+	if (error != 0)
+		LIN_SDT_PROBE1(time, linux_clock_getres_time64,
+		    copyout_error, error);
 	return (error);
 }
+#endif
 
 int
 linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
diff --git a/sys/i386/linux/linux_dummy_machdep.c b/sys/i386/linux/linux_dummy_machdep.c
index 762dc177b1b0..6e4c9c66edcb 100644
--- a/sys/i386/linux/linux_dummy_machdep.c
+++ b/sys/i386/linux/linux_dummy_machdep.c
@@ -70,7 +70,6 @@ DUMMY(vm86old);
 DUMMY(arch_prctl);
 /* Linux 5.0: */
 DUMMY(clock_adjtime64);
-DUMMY(clock_getres_time64);
 DUMMY(clock_nanosleep_time64);
 DUMMY(timer_gettime64);
 DUMMY(timer_settime64);
diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master
index a8b41605b743..0876a039ea05 100644
--- a/sys/i386/linux/syscalls.master
+++ b/sys/i386/linux/syscalls.master
@@ -2374,7 +2374,10 @@
 		int linux_clock_adjtime64(void);
 	}
 406	AUE_NULL	STD {
-		int linux_clock_getres_time64(void);
+		int linux_clock_getres_time64(
+		    clockid_t which,
+		    struct l_timespec64 *tp
+		);
 	}
 407	AUE_NULL	STD {
 		int linux_clock_nanosleep_time64(void);


More information about the dev-commits-src-all mailing list