Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[1d97c1]: nouveau-pm / monitor_downclocking.c Maximize Restore History

Download this file

monitor_downclocking.c    228 lines (190 with data), 8.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* Copyright 2009 Emil Velikov
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <sys/time.h>
#include <X11/Xlib.h>
#include "NVCtrl.h"
#include "NVCtrlLib.h"
#define NOUVEAU_TIME_WAIT 180
inline void
read_card_specific_registers(void)
{}
inline void
read_fanspeed(Display *dpy,int *pData, int len)
{
/* XXX: add fanspeedcheck etc. */
/* look at NVCtrl.h line 2560 - 2611 */
#if 0
static int fanspeed;
if (read_fanspeed != fanspeed) {
read_fanspeed = fanspeed;
fprintf(stderr, info);
}
#endif
}
inline void
read_bus_rate(Display *dpy)
{
static int bus_rate;
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_BUS_RATE, &bus_rate);
fprintf(stderr, "NV_CTRL_BUS_RATE = %d\n", bus_rate);
}
inline void
check_bus_type(Display *dpy)
{
static int bus_type;
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_BUS_TYPE, &bus_type);
// fprintf(stderr, "NV_CTRL_BUS_TYPE = %d\n", bus_type);
fprintf(stderr, "NV_CTRL_BUS_TYPE = ");
switch(bus_type)
{
case NV_CTRL_BUS_TYPE_AGP: fprintf(stderr, "AGP\n"); break;
case NV_CTRL_BUS_TYPE_PCI: fprintf(stderr, "PCI\n"); break;
case NV_CTRL_BUS_TYPE_PCI_EXPRESS: fprintf(stderr, "PCI-Express\n"); break;
case NV_CTRL_BUS_TYPE_INTEGRATED: fprintf(stderr, "Integrated\n"); break;
}
read_bus_rate(dpy);
}
void check_temp(Display *dpy)
{
int i, ret;
ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0, NV_CTRL_GPU_CORE_TEMPERATURE, &i);
fprintf(stderr, "%sNV_CTRL_GPU_CORE_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
/* ------------------------------------------------------------------------------*/
ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0, NV_CTRL_GPU_CORE_THRESHOLD, &i);
fprintf(stderr, "%sNV_CTRL_GPU_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD, &i);
fprintf(stderr, "%sNV_CTRL_GPU_DEFAULT_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0, NV_CTRL_GPU_MAX_CORE_THRESHOLD, &i);
fprintf(stderr, "%sNV_CTRL_GPU_MAX_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
/* ------------------------------------------------------------------------------*/
ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0, NV_CTRL_AMBIENT_TEMPERATURE, &i);
fprintf(stderr, "%sNV_CTRL_AMBIENT_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
}
void check_fans(Display *dpy, int *pData, int len)
{
int ret;
/* NV-CONTROL version 1.20 and above have the nessesary bits */
ret = XNVCTRLQueryTargetBinaryData (dpy, NV_CTRL_TARGET_TYPE_GPU, 0, 0,
NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU,
(unsigned char **)(&pData), &len);
fprintf(stderr, "%sNV_COOLER_COUNT = %d\n", ret ? "" : "Failed ", ret ? pData[0]:0 );
read_fanspeed(dpy,pData,len);
}
int main(void)
{
unsigned long start_time, get_time;
struct timeval tv;
Display *dpy;
int old_hz, new_hz, old_mode, new_mode, def_2d;
int i;
char *str;
int *pData = 0, len = 0;
fprintf(stderr, "Getting system time\n");
gettimeofday(&tv, NULL);
start_time = tv.tv_sec;
fprintf(stderr, "Done\n");
dpy = XOpenDisplay(NULL);
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0,NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE , &i);
if ( i != NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE_ENABLED ) {
fprintf(stderr, "ERROR - Driver not in Adaptive state\n");
return 2;
}
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
0,NV_CTRL_GPU_POWER_MIZER_MODE , &i);
if ( i != NV_CTRL_GPU_POWER_MIZER_MODE_ADAPTIVE ) {
fprintf(stderr, "ERROR - PowerMizer mode is not Adaptive.\n");
return 3;
}
fprintf(stderr, "Start of downclock monitoring\n");
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_NUM_GPU_ERRORS_RECOVERED, &i);
fprintf(stderr, "NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
XNVCTRLQueryTargetStringAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_STRING_PERFORMANCE_MODES, &str);
fprintf(stderr, "NV_CTRL_STRING_PERFORMANCE_MODES = %s\n", str);
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL, &old_mode);
fprintf(stderr, "NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", old_mode);
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS, &def_2d);
fprintf(stderr, "NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
def_2d, ((def_2d & 0xFFFF0000) >> 16), (def_2d & 0xFFFF));
/* XXX: compare with the default ones, but inside the program use these
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_2D_CLOCK_FREQS, &def_2d);
fprintf(stderr, "NV_CTRL_GPU_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
def_2d, ((def_2d & 0xFFFF0000) >> 16), (def_2d & 0xFFFF));
*/
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_CURRENT_CLOCK_FREQS, &old_hz);
fprintf(stderr, "NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
old_hz, ((old_hz & 0xFFFF0000) >> 16), (old_hz & 0xFFFF));
check_fans(dpy, pData, len);
check_bus_type(dpy);
read_card_specific_registers();
// In case of integrated videocard, manualy edit the following line
// def_2d = 0;
do
{
gettimeofday(&tv, NULL);
get_time = tv.tv_sec;
if ((start_time + NOUVEAU_TIME_WAIT) < get_time ) {
fprintf(stderr, "ERROR - Timeout\n");
XCloseDisplay(dpy);
return 4;
}
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_CURRENT_CLOCK_FREQS, &new_hz);
if (new_hz != old_hz) {
old_hz = new_hz;
fprintf(stderr, "Changed NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
new_hz, ((new_hz & 0xFFFF0000) >> 16), (new_hz & 0xFFFF));
read_bus_rate(dpy);
read_fanspeed(dpy,pData,len);
read_card_specific_registers();
}
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL, &new_mode);
if (new_mode != old_mode) {
old_mode = new_mode;
fprintf(stderr, "Changed NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", new_mode);
}
} while ( new_hz != def_2d );
fprintf(stderr, "Downclock monitoring finished\n");
check_temp(dpy);
XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
0, NV_CTRL_NUM_GPU_ERRORS_RECOVERED, &i);
fprintf(stderr, "Total NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
fprintf(stderr, "All done !!!\n");
XCloseDisplay(dpy);
return 0;
}