2 * Copyright (C) 2010-2013 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * 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
21 #define _(str) gettext(str)
29 #include <NVCtrl/NVCtrl.h>
30 #include <NVCtrl/NVCtrlLib.h>
37 Returns the temperature (Celcius) of a NVidia GPU.
39 static int get_temp(struct psensor *sensor)
44 res = XNVCTRLQueryTargetAttribute(display,
45 NV_CTRL_TARGET_TYPE_GPU,
48 NV_CTRL_GPU_CORE_TEMPERATURE,
54 log_debug(_("NVIDIA proprietary driver not used or cannot "
55 "retrieve NVIDIA GPU temperature."));
59 static struct psensor *create_sensor(int id, int values_len)
66 sprintf(name, "GPU%d", id);
68 sid = malloc(strlen("nvidia") + 1 + strlen(name) + 1);
69 sprintf(sid, "nvidia %s", name);
71 t = SENSOR_TYPE_NVCTRL | SENSOR_TYPE_GPU | SENSOR_TYPE_TEMP;
73 s = psensor_create(sid,
85 Opens connection to X server and returns the number
88 Return 0 if no NVidia gpus or cannot get information.
94 display = XOpenDisplay(NULL);
97 log_err(_("Cannot open connection to X11 server."));
101 if (XNVCTRLQueryExtension(display, &evt, &err) &&
102 XNVCTRLQueryTargetCount(display, NV_CTRL_TARGET_TYPE_GPU, &n))
105 log_err(_("Failed to retrieve NVIDIA information."));
110 void nvidia_psensor_list_update(struct psensor **sensors)
112 struct psensor **ss, *s;
118 if (s->type & SENSOR_TYPE_NVCTRL)
119 psensor_set_current_value(s, get_temp(s));
125 struct psensor **nvidia_psensor_list_add(struct psensor **sensors,
129 struct psensor **tmp, **ss, *s;
134 for (i = 0; i < n; i++) {
135 s = create_sensor(i, values_len);
137 tmp = psensor_list_add(ss, s);
148 void nvidia_cleanup()
151 XCloseDisplay(display);