Author: trasz
Date: Sun Mar 19 15:15:34 2017
New Revision: 315555
URL: https://svnweb.freebsd.org/changeset/base/315555

Log:
  MFC r313281:
  
  Add kern_cpuset_getaffinity() and kern_cpuset_getaffinity(),
  and use it in compats instead of their sys_*() counterparts.
  
  Sponsored by: DARPA, AFRL

Modified:
  stable/11/sys/compat/freebsd32/freebsd32_misc.c
  stable/11/sys/compat/linux/linux_misc.c
  stable/11/sys/kern/kern_cpuset.c
  stable/11/sys/sys/syscallsubr.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32_misc.c     Sun Mar 19 15:07:30 
2017        (r315554)
+++ stable/11/sys/compat/freebsd32/freebsd32_misc.c     Sun Mar 19 15:15:34 
2017        (r315555)
@@ -2544,30 +2544,18 @@ int
 freebsd32_cpuset_getaffinity(struct thread *td,
     struct freebsd32_cpuset_getaffinity_args *uap)
 {
-       struct cpuset_getaffinity_args ap;
 
-       ap.level = uap->level;
-       ap.which = uap->which;
-       ap.id = PAIR32TO64(id_t,uap->id);
-       ap.cpusetsize = uap->cpusetsize;
-       ap.mask = uap->mask;
-
-       return (sys_cpuset_getaffinity(td, &ap));
+       return (kern_cpuset_getaffinity(td, uap->level, uap->which,
+           PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
 }
 
 int
 freebsd32_cpuset_setaffinity(struct thread *td,
     struct freebsd32_cpuset_setaffinity_args *uap)
 {
-       struct cpuset_setaffinity_args ap;
-
-       ap.level = uap->level;
-       ap.which = uap->which;
-       ap.id = PAIR32TO64(id_t,uap->id);
-       ap.cpusetsize = uap->cpusetsize;
-       ap.mask = uap->mask;
 
-       return (sys_cpuset_setaffinity(td, &ap));
+       return (kern_cpuset_setaffinity(td, uap->level, uap->which,
+           PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
 }
 
 int

Modified: stable/11/sys/compat/linux/linux_misc.c
==============================================================================
--- stable/11/sys/compat/linux/linux_misc.c     Sun Mar 19 15:07:30 2017        
(r315554)
+++ stable/11/sys/compat/linux/linux_misc.c     Sun Mar 19 15:15:34 2017        
(r315555)
@@ -2095,7 +2095,6 @@ linux_sched_getaffinity(struct thread *t
 {
        int error;
        struct thread *tdt;
-       struct cpuset_getaffinity_args cga;
 
 #ifdef DEBUG
        if (ldebug(sched_getaffinity))
@@ -2110,13 +2109,10 @@ linux_sched_getaffinity(struct thread *t
                return (ESRCH);
 
        PROC_UNLOCK(tdt->td_proc);
-       cga.level = CPU_LEVEL_WHICH;
-       cga.which = CPU_WHICH_TID;
-       cga.id = tdt->td_tid;
-       cga.cpusetsize = sizeof(cpuset_t);
-       cga.mask = (cpuset_t *) args->user_mask_ptr;
 
-       if ((error = sys_cpuset_getaffinity(td, &cga)) == 0)
+       error = kern_cpuset_getaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
+           tdt->td_tid, sizeof(cpuset_t), (cpuset_t *)args->user_mask_ptr);
+       if (error == 0)
                td->td_retval[0] = sizeof(cpuset_t);
 
        return (error);
@@ -2129,7 +2125,6 @@ int
 linux_sched_setaffinity(struct thread *td,
     struct linux_sched_setaffinity_args *args)
 {
-       struct cpuset_setaffinity_args csa;
        struct thread *tdt;
 
 #ifdef DEBUG
@@ -2145,13 +2140,9 @@ linux_sched_setaffinity(struct thread *t
                return (ESRCH);
 
        PROC_UNLOCK(tdt->td_proc);
-       csa.level = CPU_LEVEL_WHICH;
-       csa.which = CPU_WHICH_TID;
-       csa.id = tdt->td_tid;
-       csa.cpusetsize = sizeof(cpuset_t);
-       csa.mask = (cpuset_t *) args->user_mask_ptr;
 
-       return (sys_cpuset_setaffinity(td, &csa));
+       return (kern_cpuset_setaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
+           tdt->td_tid, sizeof(cpuset_t), (cpuset_t *) args->user_mask_ptr));
 }
 
 struct linux_rlimit64 {

Modified: stable/11/sys/kern/kern_cpuset.c
==============================================================================
--- stable/11/sys/kern/kern_cpuset.c    Sun Mar 19 15:07:30 2017        
(r315554)
+++ stable/11/sys/kern/kern_cpuset.c    Sun Mar 19 15:15:34 2017        
(r315555)
@@ -1078,6 +1078,15 @@ struct cpuset_getaffinity_args {
 int
 sys_cpuset_getaffinity(struct thread *td, struct cpuset_getaffinity_args *uap)
 {
+
+       return (kern_cpuset_getaffinity(td, uap->level, uap->which,
+           uap->id, uap->cpusetsize, uap->mask));
+}
+
+int
+kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which,
+    id_t id, size_t cpusetsize, cpuset_t *maskp)
+{
        struct thread *ttd;
        struct cpuset *nset;
        struct cpuset *set;
@@ -1086,18 +1095,17 @@ sys_cpuset_getaffinity(struct thread *td
        int error;
        size_t size;
 
-       if (uap->cpusetsize < sizeof(cpuset_t) ||
-           uap->cpusetsize > CPU_MAXSIZE / NBBY)
+       if (cpusetsize < sizeof(cpuset_t) || cpusetsize > CPU_MAXSIZE / NBBY)
                return (ERANGE);
-       size = uap->cpusetsize;
+       size = cpusetsize;
        mask = malloc(size, M_TEMP, M_WAITOK | M_ZERO);
-       error = cpuset_which(uap->which, uap->id, &p, &ttd, &set);
+       error = cpuset_which(which, id, &p, &ttd, &set);
        if (error)
                goto out;
-       switch (uap->level) {
+       switch (level) {
        case CPU_LEVEL_ROOT:
        case CPU_LEVEL_CPUSET:
-               switch (uap->which) {
+               switch (which) {
                case CPU_WHICH_TID:
                case CPU_WHICH_PID:
                        thread_lock(ttd);
@@ -1112,7 +1120,7 @@ sys_cpuset_getaffinity(struct thread *td
                        error = EINVAL;
                        goto out;
                }
-               if (uap->level == CPU_LEVEL_ROOT)
+               if (level == CPU_LEVEL_ROOT)
                        nset = cpuset_refroot(set);
                else
                        nset = cpuset_refbase(set);
@@ -1120,7 +1128,7 @@ sys_cpuset_getaffinity(struct thread *td
                cpuset_rel(nset);
                break;
        case CPU_LEVEL_WHICH:
-               switch (uap->which) {
+               switch (which) {
                case CPU_WHICH_TID:
                        thread_lock(ttd);
                        CPU_COPY(&ttd->td_cpuset->cs_mask, mask);
@@ -1138,13 +1146,13 @@ sys_cpuset_getaffinity(struct thread *td
                        CPU_COPY(&set->cs_mask, mask);
                        break;
                case CPU_WHICH_IRQ:
-                       error = intr_getaffinity(uap->id, mask);
+                       error = intr_getaffinity(id, mask);
                        break;
                case CPU_WHICH_DOMAIN:
-                       if (uap->id < 0 || uap->id >= MAXMEMDOM)
+                       if (id < 0 || id >= MAXMEMDOM)
                                error = ESRCH;
                        else
-                               CPU_COPY(&cpuset_domain[uap->id], mask);
+                               CPU_COPY(&cpuset_domain[id], mask);
                        break;
                }
                break;
@@ -1157,7 +1165,7 @@ sys_cpuset_getaffinity(struct thread *td
        if (p)
                PROC_UNLOCK(p);
        if (error == 0)
-               error = copyout(mask, uap->mask, size);
+               error = copyout(mask, maskp, size);
 out:
        free(mask, M_TEMP);
        return (error);
@@ -1175,6 +1183,15 @@ struct cpuset_setaffinity_args {
 int
 sys_cpuset_setaffinity(struct thread *td, struct cpuset_setaffinity_args *uap)
 {
+
+       return (kern_cpuset_setaffinity(td, uap->level, uap->which,
+           uap->id, uap->cpusetsize, uap->mask));
+}
+
+int
+kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which,
+    id_t id, size_t cpusetsize, const cpuset_t *maskp)
+{
        struct cpuset *nset;
        struct cpuset *set;
        struct thread *ttd;
@@ -1182,22 +1199,21 @@ sys_cpuset_setaffinity(struct thread *td
        cpuset_t *mask;
        int error;
 
-       if (uap->cpusetsize < sizeof(cpuset_t) ||
-           uap->cpusetsize > CPU_MAXSIZE / NBBY)
+       if (cpusetsize < sizeof(cpuset_t) || cpusetsize > CPU_MAXSIZE / NBBY)
                return (ERANGE);
-       mask = malloc(uap->cpusetsize, M_TEMP, M_WAITOK | M_ZERO);
-       error = copyin(uap->mask, mask, uap->cpusetsize);
+       mask = malloc(cpusetsize, M_TEMP, M_WAITOK | M_ZERO);
+       error = copyin(maskp, mask, cpusetsize);
        if (error)
                goto out;
        /*
         * Verify that no high bits are set.
         */
-       if (uap->cpusetsize > sizeof(cpuset_t)) {
+       if (cpusetsize > sizeof(cpuset_t)) {
                char *end;
                char *cp;
 
                end = cp = (char *)&mask->__bits;
-               end += uap->cpusetsize;
+               end += cpusetsize;
                cp += sizeof(cpuset_t);
                while (cp != end)
                        if (*cp++ != 0) {
@@ -1206,13 +1222,13 @@ sys_cpuset_setaffinity(struct thread *td
                        }
 
        }
-       switch (uap->level) {
+       switch (level) {
        case CPU_LEVEL_ROOT:
        case CPU_LEVEL_CPUSET:
-               error = cpuset_which(uap->which, uap->id, &p, &ttd, &set);
+               error = cpuset_which(which, id, &p, &ttd, &set);
                if (error)
                        break;
-               switch (uap->which) {
+               switch (which) {
                case CPU_WHICH_TID:
                case CPU_WHICH_PID:
                        thread_lock(ttd);
@@ -1228,7 +1244,7 @@ sys_cpuset_setaffinity(struct thread *td
                        error = EINVAL;
                        goto out;
                }
-               if (uap->level == CPU_LEVEL_ROOT)
+               if (level == CPU_LEVEL_ROOT)
                        nset = cpuset_refroot(set);
                else
                        nset = cpuset_refbase(set);
@@ -1237,24 +1253,23 @@ sys_cpuset_setaffinity(struct thread *td
                cpuset_rel(set);
                break;
        case CPU_LEVEL_WHICH:
-               switch (uap->which) {
+               switch (which) {
                case CPU_WHICH_TID:
-                       error = cpuset_setthread(uap->id, mask);
+                       error = cpuset_setthread(id, mask);
                        break;
                case CPU_WHICH_PID:
-                       error = cpuset_setproc(uap->id, NULL, mask);
+                       error = cpuset_setproc(id, NULL, mask);
                        break;
                case CPU_WHICH_CPUSET:
                case CPU_WHICH_JAIL:
-                       error = cpuset_which(uap->which, uap->id, &p,
-                           &ttd, &set);
+                       error = cpuset_which(which, id, &p, &ttd, &set);
                        if (error == 0) {
                                error = cpuset_modify(set, mask);
                                cpuset_rel(set);
                        }
                        break;
                case CPU_WHICH_IRQ:
-                       error = intr_setaffinity(uap->id, mask);
+                       error = intr_setaffinity(id, mask);
                        break;
                default:
                        error = EINVAL;

Modified: stable/11/sys/sys/syscallsubr.h
==============================================================================
--- stable/11/sys/sys/syscallsubr.h     Sun Mar 19 15:07:30 2017        
(r315554)
+++ stable/11/sys/sys/syscallsubr.h     Sun Mar 19 15:15:34 2017        
(r315555)
@@ -33,6 +33,7 @@
 #include <sys/socket.h>
 #include <sys/mac.h>
 #include <sys/mount.h>
+#include <sys/_cpuset.h>
 
 struct file;
 struct filecaps;
@@ -87,6 +88,11 @@ int  kern_clock_settime(struct thread *td
 int    kern_close(struct thread *td, int fd);
 int    kern_connectat(struct thread *td, int dirfd, int fd,
            struct sockaddr *sa);
+int    kern_cpuset_getaffinity(struct thread *td, cpulevel_t level,
+           cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *maskp);
+int    kern_cpuset_setaffinity(struct thread *td, cpulevel_t level,
+           cpuwhich_t which, id_t id, size_t cpusetsize,
+           const cpuset_t *maskp);
 int    kern_cpuset_getid(struct thread *td, cpulevel_t level,
            cpuwhich_t which, id_t id, cpusetid_t *setid);
 int    kern_cpuset_setid(struct thread *td, cpuwhich_t which,
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to