2000-06-22 01:06:35 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2000-06-22 01:06:35 +00:00
|
|
|
*/
|
|
|
|
|
2001-01-06 01:10:04 +00:00
|
|
|
#include <isc/os.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYSCONF
|
|
|
|
|
2000-06-22 01:06:35 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2001-01-06 01:10:04 +00:00
|
|
|
static inline long
|
2020-02-12 13:59:18 +01:00
|
|
|
sysconf_ncpus(void)
|
|
|
|
{
|
2001-01-06 01:10:04 +00:00
|
|
|
#if defined(_SC_NPROCESSORS_ONLN)
|
|
|
|
return sysconf((_SC_NPROCESSORS_ONLN));
|
|
|
|
#elif defined(_SC_NPROC_ONLN)
|
|
|
|
return sysconf((_SC_NPROC_ONLN));
|
2001-02-11 00:52:31 +00:00
|
|
|
#else
|
2001-01-06 01:10:04 +00:00
|
|
|
return (0);
|
2001-02-11 00:52:31 +00:00
|
|
|
#endif
|
2001-01-06 01:10:04 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_SYSCONF */
|
|
|
|
|
2001-08-16 06:19:58 +00:00
|
|
|
#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sys/param.h> /* for NetBSD */
|
2001-08-16 06:19:58 +00:00
|
|
|
#include <sys/sysctl.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sys/types.h> /* for FreeBSD */
|
2001-08-16 06:19:58 +00:00
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
sysctl_ncpus(void)
|
|
|
|
{
|
|
|
|
int ncpu, result;
|
2001-08-16 06:19:58 +00:00
|
|
|
size_t len;
|
|
|
|
|
2001-11-27 01:56:32 +00:00
|
|
|
len = sizeof(ncpu);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = sysctlbyname("hw.ncpu", &ncpu, &len, 0, 0);
|
2001-08-16 06:19:58 +00:00
|
|
|
if (result != -1)
|
|
|
|
return (ncpu);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
2000-06-22 01:06:35 +00:00
|
|
|
|
|
|
|
unsigned int
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_os_ncpus(void)
|
|
|
|
{
|
2001-01-06 01:10:04 +00:00
|
|
|
long ncpus = 0;
|
2000-06-22 01:06:35 +00:00
|
|
|
|
2018-08-21 11:09:34 +02:00
|
|
|
#if defined(HAVE_SYSCONF)
|
2001-01-06 01:10:04 +00:00
|
|
|
ncpus = sysconf_ncpus();
|
2001-01-04 02:52:13 +00:00
|
|
|
#endif
|
2001-08-16 06:19:58 +00:00
|
|
|
#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
|
|
|
|
if (ncpus <= 0)
|
|
|
|
ncpus = sysctl_ncpus();
|
|
|
|
#endif
|
2000-06-22 01:06:35 +00:00
|
|
|
if (ncpus <= 0)
|
2000-06-22 02:23:39 +00:00
|
|
|
ncpus = 1;
|
|
|
|
|
|
|
|
return ((unsigned int)ncpus);
|
2000-06-22 01:06:35 +00:00
|
|
|
}
|