Improved the CPU load sensors. The values displayed for the load per core and the total load should now be more accurate.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2011
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.ComponentModel;
40 using System.Runtime.InteropServices;
43 namespace OpenHardwareMonitor.Hardware {
45 internal static class FirmwareTable {
47 public static byte[] GetTable(Provider provider, string table) {
48 int id = table[3] << 24 | table[2] << 16 | table[1] << 8 | table[0];
49 return GetTable(provider, id);
52 public static byte[] GetTable(Provider provider, int table) {
56 size = NativeMethods.GetSystemFirmwareTable(provider, table,
58 } catch (DllNotFoundException) { return null; }
59 catch (EntryPointNotFoundException) { return null; }
64 IntPtr nativeBuffer = Marshal.AllocHGlobal(size);
65 NativeMethods.GetSystemFirmwareTable(provider, table, nativeBuffer, size);
67 if (Marshal.GetLastWin32Error() != 0)
70 byte[] buffer = new byte[size];
71 Marshal.Copy(nativeBuffer, buffer, 0, size);
72 Marshal.FreeHGlobal(nativeBuffer);
77 public static string[] EnumerateTables(Provider provider) {
80 size = NativeMethods.EnumSystemFirmwareTables(
81 provider, IntPtr.Zero, 0);
82 } catch (DllNotFoundException) { return null; }
83 catch (EntryPointNotFoundException) { return null; }
85 IntPtr nativeBuffer = Marshal.AllocHGlobal(size);
86 NativeMethods.EnumSystemFirmwareTables(
87 provider, nativeBuffer, size);
88 byte[] buffer = new byte[size];
89 Marshal.Copy(nativeBuffer, buffer, 0, size);
90 Marshal.FreeHGlobal(nativeBuffer);
92 string[] result = new string[size / 4];
93 for (int i = 0; i < result.Length; i++)
94 result[i] = Encoding.ASCII.GetString(buffer, 4 * i, 4);
99 public enum Provider : int {
100 ACPI = (byte)'A' << 24 | (byte)'C' << 16 | (byte)'P' << 8 | (byte)'I',
101 FIRM = (byte)'F' << 24 | (byte)'I' << 16 | (byte)'R' << 8 | (byte)'M',
102 RSMB = (byte)'R' << 24 | (byte)'S' << 16 | (byte)'M' << 8 | (byte)'B'
105 private static class NativeMethods {
106 private const string KERNEL = "kernel32.dll";
108 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
109 SetLastError = true)]
110 public static extern int EnumSystemFirmwareTables(
111 Provider firmwareTableProviderSignature,
112 IntPtr firmwareTableBuffer, int bufferSize);
114 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
115 SetLastError = true)]
116 public static extern int GetSystemFirmwareTable(
117 Provider firmwareTableProviderSignature,
118 int firmwareTableID, IntPtr firmwareTableBuffer, int bufferSize);