Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 May 2015 14:45:58 +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: r283379 - in head/sys: amd64/linux32 compat/linux i386/linux
Message-ID:  <201505241445.t4OEjwFW029435@svn.freebsd.org>

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

Log:
  Implement a Linux version of sched_getparam() && sched_setparam().
  Temporarily use the first thread in proc.
  
  Differential Revision:	https://reviews.freebsd.org/D1036
  Reviewed by:	trasz

Modified:
  head/sys/amd64/linux32/syscalls.master
  head/sys/compat/linux/linux_misc.c
  head/sys/i386/linux/syscalls.master

Modified: head/sys/amd64/linux32/syscalls.master
==============================================================================
--- head/sys/amd64/linux32/syscalls.master	Sun May 24 14:44:57 2015	(r283378)
+++ head/sys/amd64/linux32/syscalls.master	Sun May 24 14:45:57 2015	(r283379)
@@ -267,10 +267,10 @@
 151	AUE_MUNLOCK	NOPROTO	{ int munlock(const void *addr, size_t len); }
 152	AUE_MLOCKALL	NOPROTO	{ int mlockall(int how); }
 153	AUE_MUNLOCKALL	NOPROTO	{ int munlockall(void); }
-154	AUE_SCHED_SETPARAM	NOPROTO	{ int sched_setparam(pid_t pid, \
-				    const struct sched_param *param); }
-155	AUE_SCHED_GETPARAM	NOPROTO	{ int sched_getparam(pid_t pid, \
-				    struct sched_param *param); }
+154	AUE_SCHED_SETPARAM	STD	{ int linux_sched_setparam(l_pid_t pid, \
+				    struct l_sched_param *param); }
+155	AUE_SCHED_GETPARAM	STD	{ int linux_sched_getparam(l_pid_t pid, \
+				    struct l_sched_param *param); }
 156	AUE_SCHED_SETSCHEDULER	STD { int linux_sched_setscheduler( \
 				    l_pid_t pid, l_int policy, \
 				    struct l_sched_param *param); }

Modified: head/sys/compat/linux/linux_misc.c
==============================================================================
--- head/sys/compat/linux/linux_misc.c	Sun May 24 14:44:57 2015	(r283378)
+++ head/sys/compat/linux/linux_misc.c	Sun May 24 14:45:57 2015	(r283379)
@@ -1873,6 +1873,78 @@ linux_prctl(struct thread *td, struct li
 	return (error);
 }
 
+int
+linux_sched_setparam(struct thread *td,
+    struct linux_sched_setparam_args *uap)
+{
+	struct sched_param sched_param;
+	struct thread *tdt;
+	struct proc *p;
+	int error;
+
+#ifdef DEBUG
+	if (ldebug(sched_setparam))
+		printf(ARGS(sched_setparam, "%d, *"), uap->pid);
+#endif
+
+	error = copyin(uap->param, &sched_param, sizeof(sched_param));
+	if (error)
+		return (error);
+
+	if (uap->pid == 0) {
+		tdt = td;
+		p = tdt->td_proc;
+		PROC_LOCK(p);
+	} else {
+		p = pfind(uap->pid);
+		if (p == NULL)
+			return (ESRCH);
+		/*
+		 * XXX. Scheduling parameters are in fact per-thread
+		 * attributes in Linux. Temporarily use the first
+		 * thread in proc. The same for get_param().
+		 */
+		tdt = FIRST_THREAD_IN_PROC(p);
+	}
+
+	error = kern_sched_setparam(td, tdt, &sched_param);
+	PROC_UNLOCK(p);
+	return (error);
+}
+
+int
+linux_sched_getparam(struct thread *td,
+    struct linux_sched_getparam_args *uap)
+{
+	struct sched_param sched_param;
+	struct thread *tdt;
+	struct proc *p;
+	int error;
+
+#ifdef DEBUG
+	if (ldebug(sched_getparam))
+		printf(ARGS(sched_getparam, "%d, *"), uap->pid);
+#endif
+
+	if (uap->pid == 0) {
+		tdt = td;
+		p = tdt->td_proc;
+		PROC_LOCK(p);
+	} else {
+		p = pfind(uap->pid);
+		if (p == NULL)
+			return (ESRCH);
+		tdt = FIRST_THREAD_IN_PROC(p);
+	}
+
+	error = kern_sched_getparam(td, tdt, &sched_param);
+	PROC_UNLOCK(p);
+	if (error == 0)
+		error = copyout(&sched_param, uap->param,
+		    sizeof(sched_param));
+	return (error);
+}
+
 /*
  * Get affinity of a process.
  */

Modified: head/sys/i386/linux/syscalls.master
==============================================================================
--- head/sys/i386/linux/syscalls.master	Sun May 24 14:44:57 2015	(r283378)
+++ head/sys/i386/linux/syscalls.master	Sun May 24 14:45:57 2015	(r283379)
@@ -269,10 +269,10 @@
 151	AUE_MUNLOCK	NOPROTO	{ int munlock(const void *addr, size_t len); }
 152	AUE_MLOCKALL	NOPROTO	{ int mlockall(int how); }
 153	AUE_MUNLOCKALL	NOPROTO	{ int munlockall(void); }
-154	AUE_SCHED_SETPARAM	NOPROTO	{ int sched_setparam(pid_t pid, \
-				    const struct sched_param *param); }
-155	AUE_SCHED_GETPARAM	NOPROTO	{ int sched_getparam(pid_t pid, \
-				    struct sched_param *param); }
+154	AUE_SCHED_SETPARAM	STD	{ int linux_sched_setparam(l_pid_t pid, \
+				    struct l_sched_param *param); }
+155	AUE_SCHED_GETPARAM	STD	{ int linux_sched_getparam(l_pid_t pid, \
+				    struct l_sched_param *param); }
 156	AUE_SCHED_SETSCHEDULER	STD { int linux_sched_setscheduler( \
 				    l_pid_t pid, l_int policy, \
 				    struct l_sched_param *param); }



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