[Glibc-bsd-commits] r4766 - trunk/kfreebsd-9/debian/patches

Petr Salinger ps-guest at alioth.debian.org
Fri Jul 19 12:34:34 UTC 2013


Author: ps-guest
Date: 2013-07-19 12:34:33 +0000 (Fri, 19 Jul 2013)
New Revision: 4766

Added:
   trunk/kfreebsd-9/debian/patches/000_clock_getcpuclockid2.diff
Log:
backport of clock_getcpuclockid2(), we still need some upstream fix


Added: trunk/kfreebsd-9/debian/patches/000_clock_getcpuclockid2.diff
===================================================================
--- trunk/kfreebsd-9/debian/patches/000_clock_getcpuclockid2.diff	                        (rev 0)
+++ trunk/kfreebsd-9/debian/patches/000_clock_getcpuclockid2.diff	2013-07-19 12:34:33 UTC (rev 4766)
@@ -0,0 +1,460 @@
+backport clock_getcpuclockid2 syscall into kfreebsd-9
+#716746
+
+To properly provide CLOCK_THREAD_CPUTIME_ID, CLOCK_PROCESS_CPUTIME_ID
+and clock_id's created by clock_getcpuclockid() and 
+pthread_getcpuclockid(), we need this kernel support.
+
+MFC r239347 - http://www.freebsd.org/cgi/query-pr.cgi?pr=168417
+MFC r253325 - http://www.freebsd.org/cgi/query-pr.cgi?pr=180496
+and regenerate files from syscalls.master's
+
+It still remains to solve compat32 problem by upstream,
+see http://www.freebsd.org/cgi/query-pr.cgi?pr=180652
+
+
+--- a/sys/compat/freebsd32/syscalls.master
++++ b/sys/compat/freebsd32/syscalls.master
+@@ -453,7 +453,8 @@
+ 244	AUE_NULL	UNIMPL	nosys
+ 245	AUE_NULL	UNIMPL	nosys
+ 246	AUE_NULL	UNIMPL	nosys
+-247	AUE_NULL	UNIMPL	nosys
++247	AUE_NULL	NOPROTO	{ int clock_getcpuclockid2(id_t id,\
++					int which, clockid_t *clock_id); }
+ 248	AUE_NULL	UNIMPL	ntp_gettime
+ 249	AUE_NULL	UNIMPL	nosys
+ ; syscall numbers initially used in OpenBSD
+--- a/sys/compat/freebsd32/freebsd32_systrace_args.c
++++ b/sys/compat/freebsd32/freebsd32_systrace_args.c
+@@ -1203,6 +1203,15 @@
+ 		*n_args = 2;
+ 		break;
+ 	}
++	/* clock_getcpuclockid2 */
++	case 247: {
++		struct clock_getcpuclockid2_args *p = params;
++		iarg[0] = p->id; /* id_t */
++		iarg[1] = p->which; /* int */
++		uarg[2] = (intptr_t) p->clock_id; /* clockid_t * */
++		*n_args = 3;
++		break;
++	}
+ 	/* minherit */
+ 	case 250: {
+ 		struct minherit_args *p = params;
+@@ -4938,6 +4947,22 @@
+ 			break;
+ 		default:
+ 			break;
++		};
++		break;
++	/* clock_getcpuclockid2 */
++	case 247:
++		switch(ndx) {
++		case 0:
++			p = "id_t";
++			break;
++		case 1:
++			p = "int";
++			break;
++		case 2:
++			p = "clockid_t *";
++			break;
++		default:
++			break;
+ 		};
+ 		break;
+ 	/* minherit */
+--- a/sys/compat/freebsd32/freebsd32_syscalls.c
++++ b/sys/compat/freebsd32/freebsd32_syscalls.c
+@@ -257,7 +257,7 @@
+ 	"#244",			/* 244 = nosys */
+ 	"#245",			/* 245 = nosys */
+ 	"#246",			/* 246 = nosys */
+-	"#247",			/* 247 = nosys */
++	"clock_getcpuclockid2",			/* 247 = clock_getcpuclockid2 */
+ 	"#248",			/* 248 = ntp_gettime */
+ 	"#249",			/* 249 = nosys */
+ 	"minherit",			/* 250 = minherit */
+--- a/sys/compat/freebsd32/freebsd32_syscall.h
++++ b/sys/compat/freebsd32/freebsd32_syscall.h
+@@ -207,6 +207,7 @@
+ #define	FREEBSD32_SYS_freebsd32_clock_settime	233
+ #define	FREEBSD32_SYS_freebsd32_clock_getres	234
+ #define	FREEBSD32_SYS_freebsd32_nanosleep	240
++#define	FREEBSD32_SYS_clock_getcpuclockid2	247
+ #define	FREEBSD32_SYS_minherit	250
+ #define	FREEBSD32_SYS_rfork	251
+ #define	FREEBSD32_SYS_openbsd_poll	252
+--- a/sys/compat/freebsd32/freebsd32_sysent.c
++++ b/sys/compat/freebsd32/freebsd32_sysent.c
+@@ -294,7 +294,7 @@
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 244 = nosys */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 245 = nosys */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 246 = nosys */
+-	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 247 = nosys */
++	{ AS(clock_getcpuclockid2_args), (sy_call_t *)sys_clock_getcpuclockid2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 247 = clock_getcpuclockid2 */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 248 = ntp_gettime */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 249 = nosys */
+ 	{ AS(minherit_args), (sy_call_t *)sys_minherit, AUE_MINHERIT, NULL, 0, 0, 0, SY_THR_STATIC },	/* 250 = minherit */
+--- a/sys/sys/syscall.mk
++++ b/sys/sys/syscall.mk
+@@ -168,6 +168,7 @@
+ 	ktimer_gettime.o \
+ 	ktimer_getoverrun.o \
+ 	nanosleep.o \
++	clock_getcpuclockid2.o \
+ 	ntp_gettime.o \
+ 	minherit.o \
+ 	rfork.o \
+--- a/sys/sys/syscall.h
++++ b/sys/sys/syscall.h
+@@ -216,6 +216,7 @@
+ #define	SYS_ktimer_gettime	238
+ #define	SYS_ktimer_getoverrun	239
+ #define	SYS_nanosleep	240
++#define	SYS_clock_getcpuclockid2	247
+ #define	SYS_ntp_gettime	248
+ #define	SYS_minherit	250
+ #define	SYS_rfork	251
+--- a/sys/sys/time.h
++++ b/sys/sys/time.h
+@@ -266,6 +266,7 @@
+ #define CLOCK_MONOTONIC_FAST	12	/* FreeBSD-specific. */
+ #define CLOCK_SECOND	13		/* FreeBSD-specific. */
+ #define CLOCK_THREAD_CPUTIME_ID	14
++#define CLOCK_PROCESS_CPUTIME_ID	15
+ #endif
+ 
+ #ifndef TIMER_ABSTIME
+@@ -273,6 +274,11 @@
+ #define TIMER_ABSTIME	0x1	/* absolute timer */
+ #endif
+ 
++#if __BSD_VISIBLE
++#define	CPUCLOCK_WHICH_PID	0
++#define	CPUCLOCK_WHICH_TID	1
++#endif
++
+ #ifdef _KERNEL
+ 
+ /*
+@@ -344,6 +350,7 @@
+ 
+ #if __BSD_VISIBLE
+ int	adjtime(const struct timeval *, struct timeval *);
++int	clock_getcpuclockid2(id_t, int, clockid_t *);
+ int	futimes(int, const struct timeval *);
+ int	futimesat(int, const char *, const struct timeval [2]);
+ int	lutimes(const char *, const struct timeval *);
+--- a/sys/sys/sysproto.h
++++ b/sys/sys/sysproto.h
+@@ -726,6 +726,11 @@
+ 	char rqtp_l_[PADL_(const struct timespec *)]; const struct timespec * rqtp; char rqtp_r_[PADR_(const struct timespec *)];
+ 	char rmtp_l_[PADL_(struct timespec *)]; struct timespec * rmtp; char rmtp_r_[PADR_(struct timespec *)];
+ };
++struct clock_getcpuclockid2_args {
++	char id_l_[PADL_(id_t)]; id_t id; char id_r_[PADR_(id_t)];
++	char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)];
++	char clock_id_l_[PADL_(clockid_t *)]; clockid_t * clock_id; char clock_id_r_[PADR_(clockid_t *)];
++};
+ struct ntp_gettime_args {
+ 	char ntvp_l_[PADL_(struct ntptimeval *)]; struct ntptimeval * ntvp; char ntvp_r_[PADR_(struct ntptimeval *)];
+ };
+@@ -1894,6 +1899,7 @@
+ int	sys_ktimer_gettime(struct thread *, struct ktimer_gettime_args *);
+ int	sys_ktimer_getoverrun(struct thread *, struct ktimer_getoverrun_args *);
+ int	sys_nanosleep(struct thread *, struct nanosleep_args *);
++int	sys_clock_getcpuclockid2(struct thread *, struct clock_getcpuclockid2_args *);
+ int	sys_ntp_gettime(struct thread *, struct ntp_gettime_args *);
+ int	sys_minherit(struct thread *, struct minherit_args *);
+ int	sys_rfork(struct thread *, struct rfork_args *);
+@@ -2581,6 +2587,7 @@
+ #define	SYS_AUE_ktimer_gettime	AUE_NULL
+ #define	SYS_AUE_ktimer_getoverrun	AUE_NULL
+ #define	SYS_AUE_nanosleep	AUE_NULL
++#define	SYS_AUE_clock_getcpuclockid2	AUE_NULL
+ #define	SYS_AUE_ntp_gettime	AUE_NULL
+ #define	SYS_AUE_minherit	AUE_MINHERIT
+ #define	SYS_AUE_rfork	AUE_RFORK
+--- a/sys/sys/unistd.h
++++ b/sys/sys/unistd.h
+@@ -53,7 +53,7 @@
+ #define	_POSIX_ASYNCHRONOUS_IO		0
+ #define	_POSIX_CHOWN_RESTRICTED		1
+ #define	_POSIX_CLOCK_SELECTION		(-1)
+-#define	_POSIX_CPUTIME			(-1)
++#define	_POSIX_CPUTIME			200112L
+ #define	_POSIX_FSYNC			200112L
+ #define	_POSIX_IPV6			0
+ #define	_POSIX_JOB_CONTROL		1
+--- a/sys/kern/syscalls.c
++++ b/sys/kern/syscalls.c
+@@ -254,7 +254,7 @@
+ 	"#244",			/* 244 = nosys */
+ 	"#245",			/* 245 = nosys */
+ 	"#246",			/* 246 = nosys */
+-	"#247",			/* 247 = nosys */
++	"clock_getcpuclockid2",			/* 247 = clock_getcpuclockid2 */
+ 	"ntp_gettime",			/* 248 = ntp_gettime */
+ 	"#249",			/* 249 = nosys */
+ 	"minherit",			/* 250 = minherit */
+--- a/sys/kern/kern_time.c
++++ b/sys/kern/kern_time.c
+@@ -58,6 +58,12 @@
+ #include <vm/vm_extern.h>
+ 
+ #define MAX_CLOCKS 	(CLOCK_MONOTONIC+1)
++#define CPUCLOCK_BIT		0x80000000
++#define CPUCLOCK_PROCESS_BIT	0x40000000
++#define CPUCLOCK_ID_MASK	(~(CPUCLOCK_BIT|CPUCLOCK_PROCESS_BIT))
++#define MAKE_THREAD_CPUCLOCK(tid)	(CPUCLOCK_BIT|(tid))
++#define MAKE_PROCESS_CPUCLOCK(pid)	\
++	(CPUCLOCK_BIT|CPUCLOCK_PROCESS_BIT|(pid))
+ 
+ static struct kclock	posix_clocks[MAX_CLOCKS];
+ static uma_zone_t	itimer_zone = NULL;
+@@ -165,6 +171,52 @@
+ }
+ 
+ #ifndef _SYS_SYSPROTO_H_
++struct clock_getcpuclockid2_args {
++	id_t id;
++	int which,
++	clockid_t *clock_id;
++};
++#endif
++/* ARGSUSED */
++int
++sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_args *uap)
++{
++	clockid_t clk_id;
++	struct proc *p;
++	pid_t pid;
++	lwpid_t tid;
++	int error;
++
++	switch(uap->which) {
++	case CPUCLOCK_WHICH_PID:
++		if (uap->id != 0) {
++			p = pfind(uap->id);
++			if (p == NULL)
++				return (ESRCH);
++			error = p_cansee(td, p);
++			PROC_UNLOCK(p);
++			if (error)
++				return (error);
++			pid = uap->id;
++		} else {
++			pid = td->td_proc->p_pid;
++		}
++		clk_id = MAKE_PROCESS_CPUCLOCK(pid);
++		break;
++	case CPUCLOCK_WHICH_TID:
++		if (uap->id == 0)
++			tid = td->td_tid;
++		else
++			tid = uap->id;
++		clk_id = MAKE_THREAD_CPUCLOCK(tid);
++		break;
++	default:
++		return (EINVAL);
++	}
++	return (copyout(&clk_id, uap->clock_id, sizeof(clockid_t)));
++}
++
++#ifndef _SYS_SYSPROTO_H_
+ struct clock_gettime_args {
+ 	clockid_t clock_id;
+ 	struct	timespec *tp;
+@@ -184,12 +236,80 @@
+ 	return (error);
+ }
+ 
++static inline void
++cputick2timespec(uint64_t runtime, struct timespec *ats)
++{
++	runtime = cputick2usec(runtime);
++	ats->tv_sec = runtime / 1000000;
++	ats->tv_nsec = runtime % 1000000 * 1000;
++}
++
++static void
++get_thread_cputime(struct thread *targettd, struct timespec *ats)
++{
++	uint64_t runtime, curtime, switchtime;
++
++	if (targettd == NULL) { /* current thread */
++		critical_enter();
++		switchtime = PCPU_GET(switchtime);
++		curtime = cpu_ticks();
++		runtime = curthread->td_runtime;
++		critical_exit();
++		runtime += curtime - switchtime;
++	} else {
++		thread_lock(targettd);
++		runtime = targettd->td_runtime;
++		thread_unlock(targettd);
++	}
++	cputick2timespec(runtime, ats);
++}
++
++static void
++get_process_cputime(struct proc *targetp, struct timespec *ats)
++{
++	uint64_t runtime;
++	struct rusage ru;
++
++	PROC_SLOCK(targetp);
++	rufetch(targetp, &ru);
++	runtime = targetp->p_rux.rux_runtime;
++	PROC_SUNLOCK(targetp);
++	cputick2timespec(runtime, ats);
++}
++
++static int
++get_cputime(struct thread *td, clockid_t clock_id, struct timespec *ats)
++{
++	struct proc *p, *p2;
++	struct thread *td2;
++	lwpid_t tid;
++	pid_t pid;
++	int error;
++
++	p = td->td_proc;
++	if ((clock_id & CPUCLOCK_PROCESS_BIT) == 0) {
++		tid = clock_id & CPUCLOCK_ID_MASK;
++		td2 = tdfind(tid, p->p_pid);
++		if (td2 == NULL)
++			return (EINVAL);
++		get_thread_cputime(td2, ats);
++		PROC_UNLOCK(td2->td_proc);
++	} else {
++		pid = clock_id & CPUCLOCK_ID_MASK;
++		error = pget(pid, PGET_CANSEE, &p2);
++		if (error != 0)
++			return (EINVAL);
++		get_process_cputime(p2, ats);
++		PROC_UNLOCK(p2);
++	}
++	return (0);
++}
++
+ int
+ kern_clock_gettime(struct thread *td, clockid_t clock_id, struct timespec *ats)
+ {
+ 	struct timeval sys, user;
+ 	struct proc *p;
+-	uint64_t runtime, curtime, switchtime;
+ 
+ 	p = td->td_proc;
+ 	switch (clock_id) {
+@@ -232,17 +352,17 @@
+ 		ats->tv_nsec = 0;
+ 		break;
+ 	case CLOCK_THREAD_CPUTIME_ID:
+-		critical_enter();
+-		switchtime = PCPU_GET(switchtime);
+-		curtime = cpu_ticks();
+-		runtime = td->td_runtime;
+-		critical_exit();
+-		runtime = cputick2usec(runtime + curtime - switchtime);
+-		ats->tv_sec = runtime / 1000000;
+-		ats->tv_nsec = runtime % 1000000 * 1000;
++		get_thread_cputime(NULL, ats);
++		break;
++	case CLOCK_PROCESS_CPUTIME_ID:
++		PROC_LOCK(p);
++		get_process_cputime(p, ats);
++		PROC_UNLOCK(p);
+ 		break;
+ 	default:
+-		return (EINVAL);
++		if ((int)clock_id >= 0)
++			return (EINVAL);
++		return (get_cputime(td, clock_id, ats));
+ 	}
+ 	return (0);
+ }
+@@ -336,12 +456,16 @@
+ 		ts->tv_nsec = 0;
+ 		break;
+ 	case CLOCK_THREAD_CPUTIME_ID:
++	case CLOCK_PROCESS_CPUTIME_ID:
++	cputime:
+ 		/* sync with cputick2usec */
+ 		ts->tv_nsec = 1000000 / cpu_tickrate();
+ 		if (ts->tv_nsec == 0)
+ 			ts->tv_nsec = 1000;
+ 		break;
+ 	default:
++		if ((int)clock_id < 0)
++			goto cputime;
+ 		return (EINVAL);
+ 	}
+ 	return (0);
+--- a/sys/kern/init_sysent.c
++++ b/sys/kern/init_sysent.c
+@@ -281,7 +281,7 @@
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 244 = nosys */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 245 = nosys */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 246 = nosys */
+-	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 247 = nosys */
++	{ AS(clock_getcpuclockid2_args), (sy_call_t *)sys_clock_getcpuclockid2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 247 = clock_getcpuclockid2 */
+ 	{ AS(ntp_gettime_args), (sy_call_t *)sys_ntp_gettime, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC },	/* 248 = ntp_gettime */
+ 	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 249 = nosys */
+ 	{ AS(minherit_args), (sy_call_t *)sys_minherit, AUE_MINHERIT, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC },	/* 250 = minherit */
+--- a/sys/kern/syscalls.master
++++ b/sys/kern/syscalls.master
+@@ -462,7 +462,8 @@
+ 244	AUE_NULL	UNIMPL	nosys
+ 245	AUE_NULL	UNIMPL	nosys
+ 246	AUE_NULL	UNIMPL	nosys
+-247	AUE_NULL	UNIMPL	nosys
++247	AUE_NULL	STD	{ int clock_getcpuclockid2(id_t id,\
++				    int which, clockid_t *clock_id); }
+ 248	AUE_NULL	STD	{ int ntp_gettime(struct ntptimeval *ntvp); }
+ 249	AUE_NULL	UNIMPL	nosys
+ ; syscall numbers initially used in OpenBSD
+--- a/sys/kern/systrace_args.c
++++ b/sys/kern/systrace_args.c
+@@ -1337,6 +1337,15 @@
+ 		*n_args = 2;
+ 		break;
+ 	}
++	/* clock_getcpuclockid2 */
++	case 247: {
++		struct clock_getcpuclockid2_args *p = params;
++		iarg[0] = p->id; /* id_t */
++		iarg[1] = p->which; /* int */
++		uarg[2] = (intptr_t) p->clock_id; /* clockid_t * */
++		*n_args = 3;
++		break;
++	}
+ 	/* ntp_gettime */
+ 	case 248: {
+ 		struct ntp_gettime_args *p = params;
+@@ -5379,6 +5388,22 @@
+ 			break;
+ 		default:
+ 			break;
++		};
++		break;
++	/* clock_getcpuclockid2 */
++	case 247:
++		switch(ndx) {
++		case 0:
++			p = "id_t";
++			break;
++		case 1:
++			p = "int";
++			break;
++		case 2:
++			p = "clockid_t *";
++			break;
++		default:
++			break;
+ 		};
+ 		break;
+ 	/* ntp_gettime */




More information about the Glibc-bsd-commits mailing list