1 | /* $Id: mp-freebsd.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Multiprocessor, FreeBSD.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #define LOG_GROUP RTLOGGROUP_DEFAULT
|
---|
31 | #include <unistd.h>
|
---|
32 | #include <stdio.h>
|
---|
33 | #include <errno.h>
|
---|
34 | #include <sys/sysctl.h>
|
---|
35 |
|
---|
36 | #include <iprt/mp.h>
|
---|
37 | #include <iprt/cpuset.h>
|
---|
38 | #include <iprt/assert.h>
|
---|
39 | #include <iprt/string.h>
|
---|
40 | #include <iprt/alloc.h>
|
---|
41 | #include <iprt/log.h>
|
---|
42 | #include <iprt/once.h>
|
---|
43 | #include <iprt/critsect.h>
|
---|
44 |
|
---|
45 |
|
---|
46 | RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu)
|
---|
47 | {
|
---|
48 | int uFreqCurr = 0;
|
---|
49 | size_t cbParameter = sizeof(uFreqCurr);
|
---|
50 |
|
---|
51 | /* CPU's have a common frequency. */
|
---|
52 | int rc = sysctlbyname("dev.cpu.0.freq", &uFreqCurr, &cbParameter, NULL, NULL);
|
---|
53 | if (rc)
|
---|
54 | return 0;
|
---|
55 |
|
---|
56 | return (uint32_t)uFreqCurr;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu)
|
---|
61 | {
|
---|
62 | char szFreqLevels[20]; /* Should be enough to get the highest level which is always the first. */
|
---|
63 | size_t cbFreqLevels = sizeof(szFreqLevels);
|
---|
64 |
|
---|
65 | memset(szFreqLevels, 0, sizeof(szFreqLevels));
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * CPU 0 has the freq levels entry. ENOMEM is ok as we don't need all supported
|
---|
69 | * levels but only the first one.
|
---|
70 | */
|
---|
71 | int rc = sysctlbyname("dev.cpu.0.freq_levels", szFreqLevels, &cbFreqLevels, NULL, NULL);
|
---|
72 | if ( (rc && (errno != ENOMEM))
|
---|
73 | || (cbFreqLevels == 0))
|
---|
74 | return 0;
|
---|
75 |
|
---|
76 | /* Clear everything starting from the '/' */
|
---|
77 | unsigned i = 0;
|
---|
78 |
|
---|
79 | do
|
---|
80 | {
|
---|
81 | if (szFreqLevels[i] == '/')
|
---|
82 | {
|
---|
83 | memset(&szFreqLevels[i], 0, sizeof(szFreqLevels) - i);
|
---|
84 | break;
|
---|
85 | }
|
---|
86 | i++;
|
---|
87 | } while (i < sizeof(szFreqLevels));
|
---|
88 |
|
---|
89 | /* Returns 0 on failure. */
|
---|
90 | return RTStrToUInt32(szFreqLevels);
|
---|
91 | }
|
---|
92 |
|
---|
93 | RTDECL(RTCPUID) RTMpGetOnlineCount(void)
|
---|
94 | {
|
---|
95 | /*
|
---|
96 | * FreeBSD has sysconf.
|
---|
97 | */
|
---|
98 | return sysconf(_SC_NPROCESSORS_ONLN);
|
---|
99 | }
|
---|
100 |
|
---|