/* * Copyright (c) 2015 Cyril Hrubis * * This program is free software; you can redistribute it and/or modify * it under the terms in version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* * This code was extracted form the sched_setparam testcases. */ #include #ifdef BSD # include # include # include #endif #ifdef HPUX # include # include #endif static int get_ncpu(void) { int ncpu = -1; /* This syscall is not POSIX but it should work on many system */ #ifdef _SC_NPROCESSORS_ONLN ncpu = sysconf(_SC_NPROCESSORS_ONLN); #else # ifdef BSD int mib[2]; size_t len = sizeof(ncpu); mib[0] = CTL_HW; mib[1] = HW_NCPU; sysctl(mib, 2, &ncpu, &len, NULL, 0); # endif # ifdef HPUX struct pst_dynamic psd; pstat_getdynamic(&psd, sizeof(psd), 1, 0); ncpu = (int)psd.psd_proc_cnt; # endif #endif /* _SC_NPROCESSORS_ONLN */ return ncpu; }