The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/posix4/p1003_1b.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1996, 1997, 1998
    3  *      HD Associates, Inc.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by HD Associates, Inc
   16  * 4. Neither the name of the author nor the names of any co-contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  */
   32 
   33 /* p1003_1b: Real Time common code.
   34  */
   35 
   36 #include <sys/cdefs.h>
   37 __FBSDID("$FreeBSD: releng/6.4/sys/posix4/p1003_1b.c 160952 2006-08-03 12:50:21Z davidxu $");
   38 
   39 #include "opt_posix.h"
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/kernel.h>
   44 #include <sys/lock.h>
   45 #include <sys/module.h>
   46 #include <sys/mutex.h>
   47 #include <sys/proc.h>
   48 #include <sys/syscallsubr.h>
   49 #include <sys/sysctl.h>
   50 #include <sys/sysent.h>
   51 #include <sys/syslog.h>
   52 #include <sys/sysproto.h>
   53 
   54 #include <posix4/posix4.h>
   55 
   56 MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
   57 
   58 /* The system calls return ENOSYS if an entry is called that is
   59  * not run-time supported.  I am also logging since some programs
   60  * start to use this when they shouldn't.  That will be removed if annoying.
   61  */
   62 int
   63 syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
   64 {
   65         log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
   66                         td->td_proc->p_comm, td->td_proc->p_pid, s);
   67 
   68         /* a " return nosys(p, uap); " here causes a core dump.
   69          */
   70 
   71         return ENOSYS;
   72 }
   73 
   74 #if !defined(_KPOSIX_PRIORITY_SCHEDULING)
   75 
   76 /* Not configured but loadable via a module:
   77  */
   78 
   79 static int sched_attach(void)
   80 {
   81         return 0;
   82 }
   83 
   84 SYSCALL_NOT_PRESENT_GEN(sched_setparam)
   85 SYSCALL_NOT_PRESENT_GEN(sched_getparam)
   86 SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
   87 SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
   88 SYSCALL_NOT_PRESENT_GEN(sched_yield)
   89 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
   90 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
   91 SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
   92 
   93 #else
   94 
   95 /* Configured in kernel version:
   96  */
   97 static struct ksched *ksched;
   98 
   99 static int sched_attach(void)
  100 {
  101         int ret = ksched_attach(&ksched);
  102 
  103         if (ret == 0)
  104                 p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
  105 
  106         return ret;
  107 }
  108 
  109 /* 
  110  * MPSAFE
  111  */
  112 int sched_setparam(struct thread *td,
  113         struct sched_setparam_args *uap)
  114 {
  115         struct thread *targettd;
  116         struct proc *targetp;
  117         int e;
  118         struct sched_param sched_param;
  119 
  120         e = copyin(uap->param, &sched_param, sizeof(sched_param));
  121         if (e)
  122                 return (e);
  123 
  124         mtx_lock(&Giant);
  125         if (uap->pid == 0) {
  126                 targetp = td->td_proc;
  127                 targettd = td;
  128                 PROC_LOCK(targetp);
  129         } else {
  130                 targetp = pfind(uap->pid);
  131                 if (targetp == NULL) {
  132                         e = ESRCH;
  133                         goto done2;
  134                 }
  135                 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
  136         }
  137 
  138         e = p_cansched(td, targetp);
  139         PROC_UNLOCK(targetp);
  140         if (e == 0) {
  141                 e = ksched_setparam(&td->td_retval[0], ksched, targettd,
  142                         (const struct sched_param *)&sched_param);
  143         }
  144 done2:
  145         mtx_unlock(&Giant);
  146         return (e);
  147 }
  148 
  149 /* 
  150  * MPSAFE
  151  */
  152 int sched_getparam(struct thread *td,
  153         struct sched_getparam_args *uap)
  154 {
  155         int e;
  156         struct sched_param sched_param;
  157         struct thread *targettd;
  158         struct proc *targetp;
  159 
  160         mtx_lock(&Giant);
  161         if (uap->pid == 0) {
  162                 targetp = td->td_proc;
  163                 targettd = td;
  164                 PROC_LOCK(targetp);
  165         } else {
  166                 targetp = pfind(uap->pid);
  167                 if (targetp == NULL) {
  168                         e = ESRCH;
  169                         goto done2;
  170                 }
  171                 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
  172         }
  173 
  174         e = p_cansee(td, targetp);
  175         PROC_UNLOCK(targetp);
  176         if (e)
  177                 goto done2;
  178 
  179         e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
  180         if (e == 0)
  181                 e = copyout(&sched_param, uap->param, sizeof(sched_param));
  182 done2:
  183         mtx_unlock(&Giant);
  184         return (e);
  185 }
  186 
  187 /* 
  188  * MPSAFE
  189  */
  190 int sched_setscheduler(struct thread *td,
  191         struct sched_setscheduler_args *uap)
  192 {
  193         int e;
  194         struct sched_param sched_param;
  195         struct thread *targettd;
  196         struct proc *targetp;
  197 
  198         /* Don't allow non root user to set a scheduler policy */
  199         if (suser(td) != 0)
  200                 return (EPERM);
  201 
  202         e = copyin(uap->param, &sched_param, sizeof(sched_param));
  203         if (e)
  204                 return (e);
  205 
  206         mtx_lock(&Giant);
  207         if (uap->pid == 0) {
  208                 targetp = td->td_proc;
  209                 targettd = td;
  210                 PROC_LOCK(targetp);
  211         } else {
  212                 targetp = pfind(uap->pid);
  213                 if (targetp == NULL) {
  214                         e = ESRCH;
  215                         goto done2;
  216                 }
  217                 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
  218         }
  219 
  220         e = p_cansched(td, targetp);
  221         PROC_UNLOCK(targetp);
  222         if (e == 0) {
  223                 e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
  224                         uap->policy, (const struct sched_param *)&sched_param);
  225         }
  226 done2:
  227         mtx_unlock(&Giant);
  228         return (e);
  229 }
  230 
  231 /* 
  232  * MPSAFE
  233  */
  234 int sched_getscheduler(struct thread *td,
  235         struct sched_getscheduler_args *uap)
  236 {
  237         int e;
  238         struct thread *targettd;
  239         struct proc *targetp;
  240 
  241         mtx_lock(&Giant);
  242         if (uap->pid == 0) {
  243                 targetp = td->td_proc;
  244                 targettd = td;
  245                 PROC_LOCK(targetp);
  246         } else {
  247                 targetp = pfind(uap->pid);
  248                 if (targetp == NULL) {
  249                         e = ESRCH;
  250                         goto done2;
  251                 }
  252                 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
  253         }
  254 
  255         e = p_cansee(td, targetp);
  256         PROC_UNLOCK(targetp);
  257         if (e == 0)
  258                 e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
  259 
  260 done2:
  261         mtx_unlock(&Giant);
  262         return (e);
  263 }
  264 
  265 /* 
  266  * MPSAFE
  267  */
  268 int sched_yield(struct thread *td,
  269         struct sched_yield_args *uap)
  270 {
  271         int error;
  272 
  273         mtx_lock(&Giant);
  274         error = ksched_yield(&td->td_retval[0], ksched);
  275         mtx_unlock(&Giant);
  276         return (error);
  277 }
  278 
  279 /* 
  280  * MPSAFE
  281  */
  282 int sched_get_priority_max(struct thread *td,
  283         struct sched_get_priority_max_args *uap)
  284 {
  285         int error;
  286 
  287         mtx_lock(&Giant);
  288         error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
  289         mtx_unlock(&Giant);
  290         return (error);
  291 }
  292 
  293 /* 
  294  * MPSAFE
  295  */
  296 int sched_get_priority_min(struct thread *td,
  297         struct sched_get_priority_min_args *uap)
  298 {
  299         int error;
  300 
  301         mtx_lock(&Giant);
  302         error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
  303         mtx_unlock(&Giant);
  304         return (error);
  305 }
  306 
  307 /* 
  308  * MPSAFE
  309  */
  310 int sched_rr_get_interval(struct thread *td,
  311         struct sched_rr_get_interval_args *uap)
  312 {
  313         struct timespec timespec;
  314         int error;
  315 
  316         error = kern_sched_rr_get_interval(td, uap->pid, &timespec);
  317         if (error == 0)
  318                 error = copyout(&timespec, uap->interval, sizeof(timespec));
  319         return (error);
  320 }
  321 
  322 int kern_sched_rr_get_interval(struct thread *td, pid_t pid,
  323     struct timespec *ts)
  324 {
  325         int e;
  326         struct thread *targettd;
  327         struct proc *targetp;
  328 
  329         mtx_lock(&Giant);
  330         if (pid == 0) {
  331                 targettd = td;
  332                 targetp = td->td_proc;
  333                 PROC_LOCK(targetp);
  334         } else {
  335                 targetp = pfind(pid);
  336                 if (targetp == NULL) {
  337                         mtx_unlock(&Giant);
  338                         return (ESRCH);
  339                 }
  340                 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
  341         }
  342 
  343         e = p_cansee(td, targetp);
  344         if (e == 0)
  345                 e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
  346                         ts);
  347         PROC_UNLOCK(targetp);
  348         mtx_unlock(&Giant);
  349         return (e);
  350 }
  351 
  352 #endif
  353 
  354 static void p31binit(void *notused)
  355 {
  356         (void) sched_attach();
  357         p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
  358 }
  359 
  360 SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);

Cache object: 9edbc496fcaed1e7e5b909dfe61fe3e9


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.