[Glibc-bsd-commits] r4882 - trunk/glibc-ports/kfreebsd/fbtl
Petr Salinger
ps-guest at alioth.debian.org
Thu Aug 8 15:56:03 UTC 2013
Author: ps-guest
Date: 2013-08-08 15:56:03 +0000 (Thu, 08 Aug 2013)
New Revision: 4882
Added:
trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_getaffinity.c
trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_setaffinity.c
trunk/glibc-ports/kfreebsd/fbtl/pthread_getaffinity.c
trunk/glibc-ports/kfreebsd/fbtl/pthread_setaffinity.c
Log:
pthread affinity - should be added with 2.18 upload
Added: trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_getaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_getaffinity.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_getaffinity.c 2013-08-08 15:56:03 UTC (rev 4882)
@@ -0,0 +1,73 @@
+/* Copyright (C) 2003-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthreadP.h>
+#include <string.h>
+#include <sysdep.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+
+int
+__pthread_attr_getaffinity_new (const pthread_attr_t *attr, size_t cpusetsize,
+ cpu_set_t *cpuset)
+{
+ const struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (const struct pthread_attr *) attr;
+
+ if (iattr->cpuset != NULL)
+ {
+ /* Check whether there are any bits set beyond the limits
+ the user requested. */
+ for (size_t cnt = cpusetsize; cnt < iattr->cpusetsize; ++cnt)
+ if (((char *) iattr->cpuset)[cnt] != 0)
+ return EINVAL;
+
+ /* Copy over the cpuset from the thread attribute object. Limit the copy
+ to the minimum of the source and destination sizes to prevent a buffer
+ overrun. If the destination is larger, fill the remaining space with
+ zeroes. */
+ void *p = mempcpy (cpuset, iattr->cpuset,
+ MIN (iattr->cpusetsize, cpusetsize));
+ if (cpusetsize > iattr->cpusetsize)
+ memset (p, '\0', cpusetsize - iattr->cpusetsize);
+ }
+ else
+ /* We have no information. */
+ memset (cpuset, -1, cpusetsize);
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_attr_getaffinity_new,
+ pthread_attr_getaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_attr_getaffinity_old (const pthread_attr_t *attr, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_attr_getaffinity_new (attr, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_attr_getaffinity_old,
+ pthread_attr_getaffinity_np, GLIBC_2_3_3);
+#endif
Added: trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_setaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_setaffinity.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_attr_setaffinity.c 2013-08-08 15:56:03 UTC (rev 4882)
@@ -0,0 +1,80 @@
+/* Copyright (C) 2003-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+
+
+int
+__pthread_attr_setaffinity_new (pthread_attr_t *attr, size_t cpusetsize,
+ const cpu_set_t *cpuset)
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ if (cpuset == NULL || cpusetsize == 0)
+ {
+ free (iattr->cpuset);
+ iattr->cpuset = NULL;
+ iattr->cpusetsize = 0;
+ }
+ else
+ {
+ int ret = check_cpuset_attr (cpuset, cpusetsize);
+
+ if (ret)
+ return ret;
+
+ if (iattr->cpusetsize != cpusetsize)
+ {
+ void *newp = (cpu_set_t *) realloc (iattr->cpuset, cpusetsize);
+ if (newp == NULL)
+ return ENOMEM;
+
+ iattr->cpuset = newp;
+ iattr->cpusetsize = cpusetsize;
+ }
+
+ memcpy (iattr->cpuset, cpuset, cpusetsize);
+ }
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_attr_setaffinity_new,
+ pthread_attr_setaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_attr_setaffinity_old (pthread_attr_t *attr, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_attr_setaffinity_new (attr, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_attr_setaffinity_old,
+ pthread_attr_setaffinity_np, GLIBC_2_3_3);
+#endif
Added: trunk/glibc-ports/kfreebsd/fbtl/pthread_getaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_getaffinity.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_getaffinity.c 2013-08-08 15:56:03 UTC (rev 4882)
@@ -0,0 +1,66 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <limits.h>
+#include <pthreadP.h>
+#include <string.h>
+#include <sysdep.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+#include "../cpuset-kern.h"
+
+int
+__pthread_getaffinity_new (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset)
+{
+ const struct pthread *pd = (const struct pthread *) th;
+ int64_t id = pd->tid;
+ int res;
+
+ if (cpusetsize > sizeof(cpu_set_t))
+ {
+ /* Clean the rest of the memory the kernel won't do. */
+ memset ((char *) cpuset + sizeof(cpu_set_t), '\0', cpusetsize - sizeof(cpu_set_t));
+
+ cpusetsize = sizeof(cpu_set_t);
+ }
+
+ res = INLINE_SYSCALL (cpuset_getaffinity, 5, CPU_LEVEL_WHICH,
+ CPU_WHICH_TID, id, cpusetsize, cpuset);
+
+ if (res == 0)
+ return 0;
+
+ if (errno == ERANGE)
+ {
+ return EINVAL;
+ }
+
+ return errno;
+}
+strong_alias (__pthread_getaffinity_new, __pthread_getaffinity_np)
+versioned_symbol (libpthread, __pthread_getaffinity_new,
+ pthread_getaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+/* The old interface have not been really exposed */
+compat_symbol (libpthread, __pthread_getaffinity_new, pthread_getaffinity_np,
+ GLIBC_2_3_3);
+#endif
Added: trunk/glibc-ports/kfreebsd/fbtl/pthread_setaffinity.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_setaffinity.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_setaffinity.c 2013-08-08 15:56:03 UTC (rev 4882)
@@ -0,0 +1,69 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <pthreadP.h>
+#include <sysdep.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+#include "../cpuset-kern.h"
+
+
+size_t __kernel_cpumask_size attribute_hidden;
+
+/* Determine the current affinity. As a side affect we learn
+ about the size of the cpumask_t in the kernel. */
+int
+__determine_cpumask_size (pid_t tid)
+{
+ /* not yet dynamical */
+ __kernel_cpumask_size = sizeof(cpu_set_t);
+ return 0;
+}
+
+int
+__pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
+ const cpu_set_t *cpuset)
+{
+ const struct pthread *pd = (const struct pthread *) th;
+ int64_t id = pd->tid;
+ int res;
+
+ res = INLINE_SYSCALL (cpuset_setaffinity, 5, CPU_LEVEL_WHICH,
+ CPU_WHICH_TID, id, cpusetsize, cpuset);
+
+ if (res == 0)
+ return 0;
+
+ if ((errno == ERANGE) || (errno == EDEADLK))
+ {
+ return EINVAL;
+ }
+
+ return errno;
+}
+versioned_symbol (libpthread, __pthread_setaffinity_new,
+ pthread_setaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+/* The old interface have not been really exposed */
+compat_symbol (libpthread, __pthread_setaffinity_new, pthread_setaffinity_np,
+ GLIBC_2_3_3);
+#endif
More information about the Glibc-bsd-commits
mailing list