vbox的更動 33815 路徑 trunk/src/VBox/Runtime/r3/freebsd
- 時間撮記:
- 2010-11-5 下午09:29:08 (14 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/freebsd/mp-freebsd.cpp
r28800 r33815 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #define LOG_GROUP RTLOGGROUP_ DEFAULT30 #define LOG_GROUP RTLOGGROUP_SYSTEM 31 31 #include <unistd.h> 32 32 #include <stdio.h> … … 44 44 45 45 46 /** 47 * Internal worker that determines the max possible CPU count. 48 * 49 * @returns Max cpus. 50 */ 51 static RTCPUID rtMpFreeBsdMaxCpus(void) 52 { 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, RT_ELEMENTS(aiMib), &cCpus, &cb, NULL, 0); 59 if (rc != -1 && cCpus >= 1) 60 return cCpus; 61 AssertFailed(); 62 return 1; 63 } 64 65 66 RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu) 67 { 68 return idCpu < rtMpFreeBsdMaxCpus() ? idCpu : -1; 69 } 70 71 72 RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu) 73 { 74 return (unsigned)iCpu < rtMpFreeBsdMaxCpus() ? iCpu : NIL_RTCPUID; 75 } 76 77 78 RTDECL(RTCPUID) RTMpGetMaxCpuId(void) 79 { 80 return rtMpFreeBsdMaxCpus() - 1; 81 } 82 83 84 RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu) 85 { 86 int rc = VINF_SUCCESS; 87 char szName[32]; 88 char szDriver[10]; 89 size_t cbDriver = sizeof(szDriver); 90 91 /* 92 * FreeBSD doesn't support CPU hotplugging 93 * so every CPU which appears in the tree is also online. 94 */ 95 memset(szDriver, 0, sizeof(szDriver)); 96 memset(szName, 0, sizeof(szName)); 97 98 rc = RTStrPrintf(szName, sizeof(szName), "dev.cpu.%d.%%driver", (int)idCpu); 99 if (RT_SUCCESS(rc)) 100 { 101 int rcBsd = sysctlbyname(szName, szDriver, &cbDriver, NULL, NULL); 102 if (rcBsd == 0) 103 return true; 104 } 105 106 return false; 107 } 108 109 110 RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu) 111 { 112 return idCpu != NIL_RTCPUID 113 && idCpu < rtMpFreeBsdMaxCpus(); 114 } 115 116 117 RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet) 118 { 119 RTCpuSetEmpty(pSet); 120 RTCPUID cMax = rtMpFreeBsdMaxCpus(); 121 for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++) 122 if (RTMpIsCpuPossible(idCpu)) 123 RTCpuSetAdd(pSet, idCpu); 124 return pSet; 125 } 126 127 128 RTDECL(RTCPUID) RTMpGetCount(void) 129 { 130 return rtMpFreeBsdMaxCpus(); 131 } 132 133 134 RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet) 135 { 136 RTCpuSetEmpty(pSet); 137 RTCPUID cMax = rtMpFreeBsdMaxCpus(); 138 for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++) 139 if (RTMpIsCpuOnline(idCpu)) 140 RTCpuSetAdd(pSet, idCpu); 141 return pSet; 142 } 143 144 145 RTDECL(RTCPUID) RTMpGetOnlineCount(void) 146 { 147 /* 148 * FreeBSD has sysconf. 149 */ 150 return sysconf(_SC_NPROCESSORS_ONLN); 151 } 152 153 46 154 RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu) 47 155 { 48 156 int uFreqCurr = 0; 49 157 size_t cbParameter = sizeof(uFreqCurr); 158 159 if (!RTMpIsCpuOnline(idCpu)) 160 return 0; 50 161 51 162 /* CPU's have a common frequency. */ … … 62 173 char szFreqLevels[20]; /* Should be enough to get the highest level which is always the first. */ 63 174 size_t cbFreqLevels = sizeof(szFreqLevels); 175 176 if (!RTMpIsCpuOnline(idCpu)) 177 return 0; 64 178 65 179 memset(szFreqLevels, 0, sizeof(szFreqLevels)); … … 91 205 } 92 206 93 RTDECL(RTCPUID) RTMpGetOnlineCount(void)94 {95 /*96 * FreeBSD has sysconf.97 */98 return sysconf(_SC_NPROCESSORS_ONLN);99 }100
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器