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/kern/kern_numa.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) 2015, Adrian Chadd <adrian@FreeBSD.org>
    3  * 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 unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   25  *
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: releng/11.2/sys/kern/kern_numa.c 285387 2015-07-11 15:21:37Z adrian $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/sysproto.h>
   34 #include <sys/jail.h>
   35 #include <sys/kernel.h>
   36 #include <sys/lock.h>
   37 #include <sys/malloc.h>
   38 #include <sys/mutex.h>
   39 #include <sys/priv.h>
   40 #include <sys/proc.h>
   41 #include <sys/refcount.h>
   42 #include <sys/sched.h>
   43 #include <sys/smp.h>
   44 #include <sys/syscallsubr.h>
   45 #include <sys/cpuset.h>
   46 #include <sys/sx.h>
   47 #include <sys/queue.h>
   48 #include <sys/libkern.h>
   49 #include <sys/limits.h>
   50 #include <sys/bus.h>
   51 #include <sys/interrupt.h>
   52 
   53 #include <vm/uma.h>
   54 #include <vm/vm.h>
   55 #include <vm/vm_page.h>
   56 #include <vm/vm_param.h>
   57 #include <vm/vm_phys.h>
   58 #include <vm/vm_domain.h>
   59 
   60 int
   61 sys_numa_setaffinity(struct thread *td, struct numa_setaffinity_args *uap)
   62 {
   63         int error;
   64         struct vm_domain_policy vp;
   65         struct thread *ttd;
   66         struct proc *p;
   67         struct cpuset *set;
   68 
   69         set = NULL;
   70         p = NULL;
   71 
   72         /*
   73          * Copy in just the policy information into the policy
   74          * struct.  Userland only supplies vm_domain_policy_entry.
   75          */
   76         error = copyin(uap->policy, &vp.p, sizeof(vp.p));
   77         if (error)
   78                 goto out;
   79 
   80         /*
   81          * Ensure the seq number is zero - otherwise seq.h
   82          * may get very confused.
   83          */
   84         vp.seq = 0;
   85 
   86         /*
   87          * Validate policy.
   88          */
   89         if (vm_domain_policy_validate(&vp) != 0) {
   90                 error = EINVAL;
   91                 goto out;
   92         }
   93 
   94         /*
   95          * Go find the desired proc/tid for this operation.
   96          */
   97         error = cpuset_which(uap->which, uap->id, &p,
   98             &ttd, &set);
   99         if (error)
  100                 goto out;
  101 
  102         /* Only handle CPU_WHICH_TID and CPU_WHICH_PID */
  103         /*
  104          * XXX if cpuset_which is called with WHICH_CPUSET and NULL cpuset,
  105          * it'll return ESRCH.  We should just return EINVAL.
  106          */
  107         switch (uap->which) {
  108         case CPU_WHICH_TID:
  109                 vm_domain_policy_copy(&ttd->td_vm_dom_policy, &vp);
  110                 break;
  111         case CPU_WHICH_PID:
  112                 vm_domain_policy_copy(&p->p_vm_dom_policy, &vp);
  113                 break;
  114         default:
  115                 error = EINVAL;
  116                 break;
  117         }
  118 
  119         PROC_UNLOCK(p);
  120 out:
  121         if (set)
  122                 cpuset_rel(set);
  123         return (error);
  124 }
  125 
  126 int
  127 sys_numa_getaffinity(struct thread *td, struct numa_getaffinity_args *uap)
  128 {
  129         int error;
  130         struct vm_domain_policy vp;
  131         struct thread *ttd;
  132         struct proc *p;
  133         struct cpuset *set;
  134 
  135         set = NULL;
  136         p = NULL;
  137 
  138         error = cpuset_which(uap->which, uap->id, &p,
  139             &ttd, &set);
  140         if (error)
  141                 goto out;
  142 
  143         /* Only handle CPU_WHICH_TID and CPU_WHICH_PID */
  144         /*
  145          * XXX if cpuset_which is called with WHICH_CPUSET and NULL cpuset,
  146          * it'll return ESRCH.  We should just return EINVAL.
  147          */
  148         switch (uap->which) {
  149         case CPU_WHICH_TID:
  150                 vm_domain_policy_localcopy(&vp, &ttd->td_vm_dom_policy);
  151                 break;
  152         case CPU_WHICH_PID:
  153                 vm_domain_policy_localcopy(&vp, &p->p_vm_dom_policy);
  154                 break;
  155         default:
  156                 error = EINVAL;
  157                 break;
  158         }
  159         if (p)
  160                 PROC_UNLOCK(p);
  161         /*
  162          * Copy out only the vm_domain_policy_entry part.
  163          */
  164         if (error == 0)
  165                 error = copyout(&vp.p, uap->policy, sizeof(vp.p));
  166 out:
  167         if (set)
  168                 cpuset_rel(set);
  169         return (error);
  170 }

Cache object: 3cd5e8a2634ab6fbddb160de7cf759d8


[ 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.