VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/* $Id: system-posix.cpp 1 1970-01-01 00:00:00Z 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 /*
41 * The sysconf way (linux and others).
42 */
43#ifdef _SC_NPROCESSORS_ONLN
44 int cCpus = sysconf(_SC_NPROCESSORS_ONLN);
45 if (cCpus >= 1)
46 return cCpus;
47#endif
48
49 /*
50 * The BSD 4.4 way.
51 */
52#if defined(CTL_HW) && defined(HW_NCPU)
53 int aiMib[2];
54 aiMib[0] = CTL_HW;
55 aiMib[1] = HW_NCPU;
56 int cCpus = -1;
57 size_t cb = sizeof(cCpus);
58 int rc = sysctl(aiMib, ELEMENTS(aiMib), &cCpus, &cb, NULL, 0);
59 if (rc != -1 && cCpus >= 1)
60 return cCpus;
61#endif
62 return 1;
63}
64
65
66/**
67 * Gets the active logical processor mask.
68 *
69 * @returns Active logical processor mask. (bit 0 == logical cpu 0)
70 */
71RTR3DECL(uint64_t) RTSystemProcessorGetActiveMask(void)
72{
73 int cCpus = RTSystemProcessorGetCount();
74 return ((uint64_t)1 << cCpus) - 1;
75}
76
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