1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
5 *
6 * $Id: os_cpu.c,v 12.17 2008/01/08 20:58:43 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13#ifdef HAVE_SYSTEM_INCLUDE_FILES
14#if defined(HAVE_PSTAT_GETDYNAMIC)
15#include <sys/pstat.h>
16#endif
17#endif
18
19/*
20 * __os_cpu_count --
21 *	Return the number of CPUs.
22 *
23 * PUBLIC: u_int32_t __os_cpu_count __P((void));
24 */
25u_int32_t
26__os_cpu_count()
27{
28#if defined(HAVE_PSTAT_GETDYNAMIC)
29	/*
30	 * HP/UX.
31	 */
32	struct pst_dynamic psd;
33
34	return ((u_int32_t)pstat_getdynamic(&psd,
35	    sizeof(psd), (size_t)1, 0) == -1 ? 1 : psd.psd_proc_cnt);
36#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
37	/*
38	 * Solaris, Linux.
39	 */
40	long nproc;
41
42	nproc = sysconf(_SC_NPROCESSORS_ONLN);
43	return ((u_int32_t)(nproc > 1 ? nproc : 1));
44#else
45	return (1);
46#endif
47}
48