VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/system-posix.cpp@ 537

Last change on this file since 537 was 537, checked in by vboxsync, 18 years ago

Make runtime build on FreeBSD.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/* $Id: system-posix.cpp 537 2007-02-02 06:08:57Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - System, POSIX.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/system.h>
27#include <iprt/assert.h>
28
29#include <unistd.h>
30#include <sys/sysctl.h>
31
32
33/**
34 * Gets the number of logical (not physical) processors in the system.
35 *
36 * @returns Number of logical processors in the system.
37 */
38RTR3DECL(unsigned) RTSystemProcessorGetCount(void)
39{
40 int cCpus; NOREF(cCpus);
41
42 /*
43 * The sysconf way (linux and others).
44 */
45#ifdef _SC_NPROCESSORS_ONLN
46 cCpus = sysconf(_SC_NPROCESSORS_ONLN);
47 if (cCpus >= 1)
48 return cCpus;
49#endif
50
51 /*
52 * The BSD 4.4 way.
53 */
54#if defined(CTL_HW) && defined(HW_NCPU)
55 int aiMib[2];
56 aiMib[0] = CTL_HW;
57 aiMib[1] = HW_NCPU;
58 cCpus = -1;
59 size_t cb = sizeof(cCpus);
60 int rc = sysctl(aiMib, ELEMENTS(aiMib), &cCpus, &cb, NULL, 0);
61 if (rc != -1 && cCpus >= 1)
62 return cCpus;
63#endif
64 return 1;
65}
66
67
68/**
69 * Gets the active logical processor mask.
70 *
71 * @returns Active logical processor mask. (bit 0 == logical cpu 0)
72 */
73RTR3DECL(uint64_t) RTSystemProcessorGetActiveMask(void)
74{
75 int cCpus = RTSystemProcessorGetCount();
76 return ((uint64_t)1 << cCpus) - 1;
77}
78
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette