Add sched_getaffinity_np() and sched_setaffinity_np() wrappers, mainly

for compatibility purposes.
This commit is contained in:
rmind 2008-10-31 00:29:19 +00:00
parent 11582641c8
commit 9b24696c04
2 changed files with 39 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sched.h,v 1.10 2008/06/15 21:38:08 rmind Exp $ */
/* $NetBSD: sched.h,v 1.11 2008/10/31 00:29:19 rmind Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -58,13 +58,16 @@ __END_DECLS
#if defined(_NETBSD_SOURCE)
/*
* Stuff that for historical reasons is in <sched.h>, but not defined
* by any standard.
*/
__BEGIN_DECLS
/* Process affinity functions (not portable) */
int sched_getaffinity_np(pid_t, size_t, cpuset_t *);
int sched_setaffinity_np(pid_t, size_t, cpuset_t *);
/* Historical functions, not defined in standard */
pid_t clone(int (*)(void *), void *, int, void *);
pid_t __clone(int (*)(void *), void *, int, void *);
__END_DECLS
#endif /* _NETBSD_SOURCE */

View File

@ -1,4 +1,4 @@
/* $NetBSD: sched.c,v 1.1 2008/07/02 20:05:16 rmind Exp $ */
/* $NetBSD: sched.c,v 1.2 2008/10/31 00:29:19 rmind Exp $ */
/*
* Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
@ -13,21 +13,21 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: sched.c,v 1.1 2008/07/02 20:05:16 rmind Exp $");
__RCSID("$NetBSD: sched.c,v 1.2 2008/10/31 00:29:19 rmind Exp $");
#include <string.h>
#include <unistd.h>
@ -127,3 +127,21 @@ sched_rr_get_interval(pid_t pid, struct timespec *interval)
interval->tv_nsec = sysconf(_SC_SCHED_RT_TS) * 1000;
return 0;
}
/*
* Process affinity.
*/
int
sched_getaffinity_np(pid_t pid, size_t size, cpuset_t *cpuset)
{
return _sched_getaffinity(pid, P_ALL_LWPS, size, cpuset);
}
int
sched_setaffinity_np(pid_t pid, size_t size, cpuset_t *cpuset)
{
return _sched_setaffinity(pid, P_ALL_LWPS, size, cpuset);
}