moel@1
|
1 |
/*
|
moel@1
|
2 |
|
moel@344
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
moel@344
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
moel@344
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
moel@1
|
6 |
|
moel@428
|
7 |
Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
|
moel@344
|
8 |
|
moel@1
|
9 |
*/
|
moel@1
|
10 |
|
moel@1
|
11 |
using System;
|
moel@166
|
12 |
using System.Globalization;
|
moel@1
|
13 |
|
moel@1
|
14 |
namespace OpenHardwareMonitor.Hardware.ATI {
|
moel@166
|
15 |
internal sealed class ATIGPU : Hardware {
|
moel@1
|
16 |
|
moel@195
|
17 |
private readonly int adapterIndex;
|
moel@195
|
18 |
private readonly int busNumber;
|
moel@195
|
19 |
private readonly int deviceNumber;
|
moel@195
|
20 |
private readonly Sensor temperature;
|
moel@195
|
21 |
private readonly Sensor fan;
|
moel@195
|
22 |
private readonly Sensor coreClock;
|
moel@195
|
23 |
private readonly Sensor memoryClock;
|
moel@195
|
24 |
private readonly Sensor coreVoltage;
|
moel@195
|
25 |
private readonly Sensor coreLoad;
|
moel@247
|
26 |
private readonly Sensor controlSensor;
|
moel@428
|
27 |
private readonly Control fanControl;
|
moel@1
|
28 |
|
moel@3
|
29 |
public ATIGPU(string name, int adapterIndex, int busNumber,
|
moel@165
|
30 |
int deviceNumber, ISettings settings)
|
moel@275
|
31 |
: base(name, new Identifier("atigpu",
|
moel@275
|
32 |
adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
|
moel@3
|
33 |
{
|
moel@1
|
34 |
this.adapterIndex = adapterIndex;
|
moel@3
|
35 |
this.busNumber = busNumber;
|
moel@3
|
36 |
this.deviceNumber = deviceNumber;
|
moel@1
|
37 |
|
moel@165
|
38 |
this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
|
moel@165
|
39 |
this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
|
moel@165
|
40 |
this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
|
moel@165
|
41 |
this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
|
moel@165
|
42 |
this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
|
moel@165
|
43 |
this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
|
moel@247
|
44 |
this.controlSensor = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
|
moel@247
|
45 |
|
moel@247
|
46 |
ADLFanSpeedInfo afsi = new ADLFanSpeedInfo();
|
moel@247
|
47 |
if (ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi)
|
moel@247
|
48 |
!= ADL.ADL_OK)
|
moel@247
|
49 |
{
|
moel@247
|
50 |
afsi.MaxPercent = 100;
|
moel@247
|
51 |
afsi.MinPercent = 0;
|
moel@247
|
52 |
}
|
moel@247
|
53 |
|
moel@247
|
54 |
this.fanControl = new Control(controlSensor, settings, afsi.MinPercent,
|
moel@247
|
55 |
afsi.MaxPercent);
|
moel@247
|
56 |
this.fanControl.ControlModeChanged += ControlModeChanged;
|
moel@247
|
57 |
this.fanControl.SoftwareControlValueChanged +=
|
moel@247
|
58 |
SoftwareControlValueChanged;
|
moel@247
|
59 |
ControlModeChanged(fanControl);
|
moel@247
|
60 |
this.controlSensor.Control = fanControl;
|
moel@1
|
61 |
Update();
|
moel@1
|
62 |
}
|
moel@1
|
63 |
|
moel@247
|
64 |
private void SoftwareControlValueChanged(IControl control) {
|
moel@428
|
65 |
if (control.ControlMode == ControlMode.Software) {
|
moel@247
|
66 |
ADLFanSpeedValue adlf = new ADLFanSpeedValue();
|
moel@247
|
67 |
adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
|
moel@247
|
68 |
adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
|
moel@247
|
69 |
adlf.FanSpeed = (int)control.SoftwareValue;
|
moel@247
|
70 |
ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, ref adlf);
|
moel@247
|
71 |
}
|
moel@247
|
72 |
}
|
moel@247
|
73 |
|
moel@247
|
74 |
private void ControlModeChanged(IControl control) {
|
moel@428
|
75 |
switch (control.ControlMode) {
|
moel@428
|
76 |
case ControlMode.Undefined:
|
moel@428
|
77 |
return;
|
moel@428
|
78 |
case ControlMode.Default:
|
moel@428
|
79 |
SetDefaultFanSpeed();
|
moel@428
|
80 |
break;
|
moel@428
|
81 |
case ControlMode.Software:
|
moel@428
|
82 |
SoftwareControlValueChanged(control);
|
moel@428
|
83 |
break;
|
moel@428
|
84 |
default:
|
moel@428
|
85 |
return;
|
moel@247
|
86 |
}
|
moel@247
|
87 |
}
|
moel@247
|
88 |
|
moel@428
|
89 |
private void SetDefaultFanSpeed() {
|
moel@428
|
90 |
ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
|
moel@428
|
91 |
}
|
moel@428
|
92 |
|
moel@3
|
93 |
public int BusNumber { get { return busNumber; } }
|
moel@3
|
94 |
|
moel@3
|
95 |
public int DeviceNumber { get { return deviceNumber; } }
|
moel@3
|
96 |
|
moel@1
|
97 |
|
moel@165
|
98 |
public override HardwareType HardwareType {
|
moel@176
|
99 |
get { return HardwareType.GpuAti; }
|
moel@1
|
100 |
}
|
moel@1
|
101 |
|
moel@110
|
102 |
public override void Update() {
|
moel@1
|
103 |
ADLTemperature adlt = new ADLTemperature();
|
moel@15
|
104 |
if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
|
moel@15
|
105 |
== ADL.ADL_OK)
|
moel@15
|
106 |
{
|
moel@15
|
107 |
temperature.Value = 0.001f * adlt.Temperature;
|
moel@15
|
108 |
ActivateSensor(temperature);
|
moel@15
|
109 |
} else {
|
moel@164
|
110 |
temperature.Value = null;
|
moel@15
|
111 |
}
|
moel@1
|
112 |
|
moel@1
|
113 |
ADLFanSpeedValue adlf = new ADLFanSpeedValue();
|
moel@1
|
114 |
adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
|
moel@15
|
115 |
if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
|
moel@15
|
116 |
== ADL.ADL_OK)
|
moel@15
|
117 |
{
|
moel@15
|
118 |
fan.Value = adlf.FanSpeed;
|
moel@15
|
119 |
ActivateSensor(fan);
|
moel@15
|
120 |
} else {
|
moel@164
|
121 |
fan.Value = null;
|
moel@164
|
122 |
}
|
moel@164
|
123 |
|
moel@164
|
124 |
adlf = new ADLFanSpeedValue();
|
moel@164
|
125 |
adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
|
moel@164
|
126 |
if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
|
moel@164
|
127 |
== ADL.ADL_OK) {
|
moel@247
|
128 |
controlSensor.Value = adlf.FanSpeed;
|
moel@247
|
129 |
ActivateSensor(controlSensor);
|
moel@164
|
130 |
} else {
|
moel@247
|
131 |
controlSensor.Value = null;
|
moel@15
|
132 |
}
|
moel@1
|
133 |
|
moel@1
|
134 |
ADLPMActivity adlp = new ADLPMActivity();
|
moel@15
|
135 |
if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
|
moel@15
|
136 |
== ADL.ADL_OK)
|
moel@15
|
137 |
{
|
moel@80
|
138 |
if (adlp.EngineClock > 0) {
|
moel@80
|
139 |
coreClock.Value = 0.01f * adlp.EngineClock;
|
moel@80
|
140 |
ActivateSensor(coreClock);
|
moel@270
|
141 |
} else {
|
moel@270
|
142 |
coreClock.Value = null;
|
moel@80
|
143 |
}
|
moel@80
|
144 |
|
moel@80
|
145 |
if (adlp.MemoryClock > 0) {
|
moel@80
|
146 |
memoryClock.Value = 0.01f * adlp.MemoryClock;
|
moel@80
|
147 |
ActivateSensor(memoryClock);
|
moel@270
|
148 |
} else {
|
moel@270
|
149 |
memoryClock.Value = null;
|
moel@80
|
150 |
}
|
moel@80
|
151 |
|
moel@80
|
152 |
if (adlp.Vddc > 0) {
|
moel@80
|
153 |
coreVoltage.Value = 0.001f * adlp.Vddc;
|
moel@80
|
154 |
ActivateSensor(coreVoltage);
|
moel@270
|
155 |
} else {
|
moel@270
|
156 |
coreVoltage.Value = null;
|
moel@80
|
157 |
}
|
moel@80
|
158 |
|
moel@126
|
159 |
coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);
|
moel@24
|
160 |
ActivateSensor(coreLoad);
|
moel@15
|
161 |
} else {
|
moel@164
|
162 |
coreClock.Value = null;
|
moel@164
|
163 |
memoryClock.Value = null;
|
moel@164
|
164 |
coreVoltage.Value = null;
|
moel@164
|
165 |
coreLoad.Value = null;
|
moel@15
|
166 |
}
|
moel@1
|
167 |
}
|
moel@247
|
168 |
|
moel@298
|
169 |
public override void Close() {
|
moel@247
|
170 |
this.fanControl.ControlModeChanged -= ControlModeChanged;
|
moel@247
|
171 |
this.fanControl.SoftwareControlValueChanged -=
|
moel@247
|
172 |
SoftwareControlValueChanged;
|
moel@247
|
173 |
|
moel@428
|
174 |
if (this.fanControl.ControlMode != ControlMode.Undefined)
|
moel@428
|
175 |
SetDefaultFanSpeed();
|
moel@298
|
176 |
base.Close();
|
moel@247
|
177 |
}
|
moel@1
|
178 |
}
|
moel@1
|
179 |
}
|