1 | /* $Id: mp-solaris.cpp 11205 2008-08-07 13:58:16Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Multiprocessor, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.215389.xyz. 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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #define LOG_GROUP RTLOGGROUP_DEFAULT
|
---|
36 | #include <unistd.h>
|
---|
37 | #include <stdio.h>
|
---|
38 | #include <errno.h>
|
---|
39 | #include <kstat.h>
|
---|
40 |
|
---|
41 | #include <iprt/mp.h>
|
---|
42 | #include <iprt/cpuset.h>
|
---|
43 | #include <iprt/assert.h>
|
---|
44 | #include <iprt/string.h>
|
---|
45 | #include <iprt/alloc.h>
|
---|
46 | #include <iprt/log.h>
|
---|
47 |
|
---|
48 | static kstat_ctl_t *g_kc;
|
---|
49 | static kstat_t **g_cpuInfo;
|
---|
50 | static RTCPUID g_nCPUs;
|
---|
51 |
|
---|
52 | void rtLookupCpuInfoStats()
|
---|
53 | {
|
---|
54 | g_kc = kstat_open();
|
---|
55 | if (!g_kc)
|
---|
56 | {
|
---|
57 | Log(("kstat_open() -> %d\n", errno));
|
---|
58 | return;
|
---|
59 | }
|
---|
60 |
|
---|
61 | g_nCPUs = RTMpGetCount();
|
---|
62 | g_cpuInfo = (kstat_t**)RTMemAlloc(g_nCPUs * sizeof(kstat_t*));
|
---|
63 | if (!g_cpuInfo)
|
---|
64 | {
|
---|
65 | Log(("RTMemAlloc() -> NULL\n"));
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | RTCPUID i = 0;
|
---|
70 | kstat_t *ksp;
|
---|
71 | for (ksp = g_kc->kc_chain; ksp != NULL; ksp = ksp->ks_next)
|
---|
72 | {
|
---|
73 | if (strcmp(ksp->ks_module, "cpu_info") == 0)
|
---|
74 | {
|
---|
75 | g_cpuInfo[i++] = ksp;
|
---|
76 | }
|
---|
77 | Assert(i <= g_nCPUs);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | static uint64_t rtMpGetFrequency(RTCPUID idCpu, char *statName)
|
---|
82 | {
|
---|
83 | if (!g_kc)
|
---|
84 | rtLookupCpuInfoStats();
|
---|
85 |
|
---|
86 | if (idCpu < g_nCPUs && g_cpuInfo[idCpu])
|
---|
87 | if (kstat_read(g_kc, g_cpuInfo[idCpu], 0) != -1)
|
---|
88 | {
|
---|
89 | kstat_named_t *kn;
|
---|
90 | kn = (kstat_named_t *)kstat_data_lookup(g_cpuInfo[idCpu], statName);
|
---|
91 | if (kn)
|
---|
92 | return kn->value.ul;
|
---|
93 | else
|
---|
94 | Log(("kstat_data_lookup(%s) -> %d\n", statName, errno));
|
---|
95 | }
|
---|
96 | else
|
---|
97 | Log(("kstat_read() -> %d\n", errno));
|
---|
98 | else
|
---|
99 | Log(("invalid idCpu: %d\n", idCpu));
|
---|
100 |
|
---|
101 | return 0;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu)
|
---|
106 | {
|
---|
107 | return rtMpGetFrequency(idCpu, "current_clock_Hz") / 1000000;
|
---|
108 | }
|
---|
109 |
|
---|
110 | RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu)
|
---|
111 | {
|
---|
112 | return rtMpGetFrequency(idCpu, "clock_MHz");
|
---|
113 | }
|
---|