Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 May 2015 14:44:07 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r283377 - in head/sys: kern sys
Message-ID:  <201505241444.t4OEi7Ic029040@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sun May 24 14:44:06 2015
New Revision: 283377
URL: https://svnweb.freebsd.org/changeset/base/283377

Log:
  In preparation for switching linuxulator to the use the native 1:1
  threads split sys_sched_getparam(), sys_sched_setparam(),
  sys_sched_getscheduler(), sys_sched_setscheduler() to their kern_*
  counterparts and add targettd parameter to allow specify the target
  thread directly by callee.
  
  Differential Revision:	https://reviews.freebsd.org/D1034
  Reviewed by:	trasz

Modified:
  head/sys/kern/p1003_1b.c
  head/sys/sys/syscallsubr.h

Modified: head/sys/kern/p1003_1b.c
==============================================================================
--- head/sys/kern/p1003_1b.c	Sun May 24 14:43:06 2015	(r283376)
+++ head/sys/kern/p1003_1b.c	Sun May 24 14:44:06 2015	(r283377)
@@ -130,16 +130,29 @@ sys_sched_setparam(struct thread *td, st
 		targettd = FIRST_THREAD_IN_PROC(targetp);
 	}
 
-	e = p_cansched(td, targetp);
-	if (e == 0) {
-		e = ksched_setparam(ksched, targettd,
-			(const struct sched_param *)&sched_param);
-	}
+	e = kern_sched_setparam(td, targettd, &sched_param);
 	PROC_UNLOCK(targetp);
 	return (e);
 }
 
 int
+kern_sched_setparam(struct thread *td, struct thread *targettd,
+    struct sched_param *param)
+{
+	struct proc *targetp;
+	int error;
+
+	targetp = targettd->td_proc;
+	PROC_LOCK_ASSERT(targetp, MA_OWNED);
+
+	error = p_cansched(td, targetp);
+	if (error == 0)
+		error = ksched_setparam(ksched, targettd,
+		    (const struct sched_param *)param);
+	return (error);
+}
+
+int
 sys_sched_getparam(struct thread *td, struct sched_getparam_args *uap)
 {
 	int e;
@@ -159,10 +172,7 @@ sys_sched_getparam(struct thread *td, st
 		targettd = FIRST_THREAD_IN_PROC(targetp);
 	}
 
-	e = p_cansee(td, targetp);
-	if (e == 0) {
-		e = ksched_getparam(ksched, targettd, &sched_param);
-	}
+	e = kern_sched_getparam(td, targettd, &sched_param);
 	PROC_UNLOCK(targetp);
 	if (e == 0)
 		e = copyout(&sched_param, uap->param, sizeof(sched_param));
@@ -170,6 +180,22 @@ sys_sched_getparam(struct thread *td, st
 }
 
 int
+kern_sched_getparam(struct thread *td, struct thread *targettd,
+    struct sched_param *param)
+{
+	struct proc *targetp;
+	int error;
+
+	targetp = targettd->td_proc;
+	PROC_LOCK_ASSERT(targetp, MA_OWNED);
+
+	error = p_cansee(td, targetp);
+	if (error == 0)
+		error = ksched_getparam(ksched, targettd, param);
+	return (error);
+}
+
+int
 sys_sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
 {
 	int e;
@@ -177,11 +203,6 @@ sys_sched_setscheduler(struct thread *td
 	struct thread *targettd;
 	struct proc *targetp;
 
-	/* Don't allow non root user to set a scheduler policy. */
-	e = priv_check(td, PRIV_SCHED_SET);
-	if (e)
-		return (e);
-
 	e = copyin(uap->param, &sched_param, sizeof(sched_param));
 	if (e)
 		return (e);
@@ -197,16 +218,35 @@ sys_sched_setscheduler(struct thread *td
 		targettd = FIRST_THREAD_IN_PROC(targetp);
 	}
 
-	e = p_cansched(td, targetp);
-	if (e == 0) {
-		e = ksched_setscheduler(ksched, targettd,
-			uap->policy, (const struct sched_param *)&sched_param);
-	}
+	e = kern_sched_setscheduler(td, targettd, uap->policy,
+	    &sched_param);
 	PROC_UNLOCK(targetp);
 	return (e);
 }
 
 int
+kern_sched_setscheduler(struct thread *td, struct thread *targettd,
+    int policy, struct sched_param *param)
+{
+	struct proc *targetp;
+	int error;
+
+	targetp = targettd->td_proc;
+	PROC_LOCK_ASSERT(targetp, MA_OWNED);
+
+	/* Don't allow non root user to set a scheduler policy. */
+	error = priv_check(td, PRIV_SCHED_SET);
+	if (error)
+		return (error);
+
+	error = p_cansched(td, targetp);
+	if (error == 0)
+		error = ksched_setscheduler(ksched, targettd, policy,
+		    (const struct sched_param *)param);
+	return (error);
+}
+
+int
 sys_sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
 {
 	int e, policy;
@@ -224,17 +264,31 @@ sys_sched_getscheduler(struct thread *td
 		targettd = FIRST_THREAD_IN_PROC(targetp);
 	}
 
-	e = p_cansee(td, targetp);
-	if (e == 0) {
-		e = ksched_getscheduler(ksched, targettd, &policy);
-		td->td_retval[0] = policy;
-	}
+	e = kern_sched_getscheduler(td, targettd, &policy);
 	PROC_UNLOCK(targetp);
+	if (e == 0)
+		td->td_retval[0] = policy;
 
 	return (e);
 }
 
 int
+kern_sched_getscheduler(struct thread *td, struct thread *targettd,
+    int *policy)
+{
+	struct proc *targetp;
+	int error;
+
+	targetp = targettd->td_proc;
+	PROC_LOCK_ASSERT(targetp, MA_OWNED);
+
+	error = p_cansee(td, targetp);
+	if (error == 0)
+		error = ksched_getscheduler(ksched, targettd, policy);
+	return (error);
+}
+
+int
 sys_sched_yield(struct thread *td, struct sched_yield_args *uap)
 {
 

Modified: head/sys/sys/syscallsubr.h
==============================================================================
--- head/sys/sys/syscallsubr.h	Sun May 24 14:43:06 2015	(r283376)
+++ head/sys/sys/syscallsubr.h	Sun May 24 14:44:06 2015	(r283377)
@@ -55,6 +55,7 @@ struct sendfile_args;
 struct sockaddr;
 struct stat;
 struct thr_param;
+struct sched_param;
 struct __wrusage;
 
 int	kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg,
@@ -169,6 +170,14 @@ int	kern_renameat(struct thread *td, int
 	    char *new, enum uio_seg pathseg);
 int	kern_rmdirat(struct thread *td, int fd, char *path,
 	    enum uio_seg pathseg);
+int	kern_sched_getparam(struct thread *td, struct thread *targettd,
+	    struct sched_param *param);
+int	kern_sched_getscheduler(struct thread *td, struct thread *targettd,
+	    int *policy);
+int	kern_sched_setparam(struct thread *td, struct thread *targettd,
+	    struct sched_param *param);
+int	kern_sched_setscheduler(struct thread *td, struct thread *targettd,
+	    int policy, struct sched_param *param);
 int	kern_sched_rr_get_interval(struct thread *td, pid_t pid,
 	    struct timespec *ts);
 int	kern_sched_rr_get_interval_td(struct thread *td, struct thread *targettd,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505241444.t4OEi7Ic029040>