2 Copyright (C) 2010-2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #define _(str) gettext(str)
30 #include <NVCtrl/NVCtrl.h>
31 #include <NVCtrl/NVCtrlLib.h>
38 Returns the temperature (Celcius) of a NVidia GPU.
40 static int get_temp(struct psensor *sensor)
45 res = XNVCTRLQueryTargetAttribute(display,
46 NV_CTRL_TARGET_TYPE_GPU,
49 NV_CTRL_GPU_CORE_TEMPERATURE,
55 fprintf(stderr, _("ERROR: failed to retrieve nvidia temperature\n"));
59 static struct psensor *create_sensor(int id, int values_len)
65 sprintf(name, "GPU%d", id);
67 sid = malloc(strlen("nvidia") + 1 + strlen(name) + 1);
68 sprintf(sid, "nvidia %s", name);
70 s = psensor_create(sid, strdup(name),
71 SENSOR_TYPE_NVIDIA_TEMP, values_len);
79 Opens connection to X server and returns the number
82 Return 0 if no NVidia gpus or cannot get information.
88 display = XOpenDisplay(NULL);
92 _("ERROR: Cannot open connection to X Server\n"));
96 if (XNVCTRLQueryExtension(display, &evt, &err) &&
97 XNVCTRLQueryTargetCount(display, NV_CTRL_TARGET_TYPE_GPU, &n))
100 fprintf(stderr, _("ERROR: Cannot retrieve NVidia information\n"));
105 void nvidia_psensor_list_update(struct psensor **sensors)
107 struct psensor **ss, *s;
113 if (s->type == SENSOR_TYPE_NVIDIA_TEMP)
114 psensor_set_current_value(s, get_temp(s));
120 struct psensor **nvidia_psensor_list_add(struct psensor **sensors,
124 struct psensor **tmp, **ss, *s;
129 for (i = 0; i < n; i++) {
130 s = create_sensor(i, values_len);
132 tmp = psensor_list_add(ss, s);
143 void nvidia_cleanup()
146 XCloseDisplay(display);