projects
/
psensor-pkg-debian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Imported Upstream version 1.2.0
[psensor-pkg-debian.git]
/
src
/
lib
/
nvidia.c
diff --git
a/src/lib/nvidia.c
b/src/lib/nvidia.c
index
b77517b
..
685f97d
100644
(file)
--- a/
src/lib/nvidia.c
+++ b/
src/lib/nvidia.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2010-201
4
jeanfi@gmail.com
+ * Copyright (C) 2010-201
6
jeanfi@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-31,12
+31,23
@@
#include <NVCtrl/NVCtrl.h>
#include <NVCtrl/NVCtrlLib.h>
#include <NVCtrl/NVCtrl.h>
#include <NVCtrl/NVCtrlLib.h>
+#include <nvidia.h>
#include <psensor.h>
#include <psensor.h>
-Display *display;
+
static
Display *display;
static const char *PROVIDER_NAME = "nvctrl";
static const char *PROVIDER_NAME = "nvctrl";
+static void set_nvidia_id(struct psensor *s, int id)
+{
+ *(int *)s->provider_data = id;
+}
+
+static int get_nvidia_id(struct psensor *s)
+{
+ return *(int *)s->provider_data;
+}
+
static char *get_product_name(int id, int type)
{
char *name;
static char *get_product_name(int id, int type)
{
char *name;
@@
-219,15
+230,18
@@
static double get_value(int id, int type)
static void update(struct psensor *sensor)
{
double v;
static void update(struct psensor *sensor)
{
double v;
+ int id;
+
+ id = get_nvidia_id(sensor);
- v = get_value(
sensor->nvidia_
id, sensor->type);
+ v = get_value(id, sensor->type);
if (v == UNKNOWN_DBL_VALUE)
log_err(_("%s: Failed to retrieve measure of type %x "
"for NVIDIA GPU %d"),
PROVIDER_NAME,
sensor->type,
if (v == UNKNOWN_DBL_VALUE)
log_err(_("%s: Failed to retrieve measure of type %x "
"for NVIDIA GPU %d"),
PROVIDER_NAME,
sensor->type,
-
sensor->nvidia_
id);
+ id);
psensor_set_current_value(sensor, v);
}
psensor_set_current_value(sensor, v);
}
@@
-242,7
+256,8
@@
static char *i2str(int i)
size_t n;
/* second +1 to avoid issue about the conversion of a double
size_t n;
/* second +1 to avoid issue about the conversion of a double
- * to a lower int */
+ * to a lower int
+ */
n = 1 + (ceil(log10(INT_MAX)) + 1) + 1;
str = malloc(n);
n = 1 + (ceil(log10(INT_MAX)) + 1) + 1;
str = malloc(n);
@@
-258,6
+273,7
@@
static struct psensor *create_nvidia_sensor(int id, int subtype, int value_len)
int type;
size_t n;
struct psensor *s;
int type;
size_t n;
struct psensor *s;
+ double v;
type = SENSOR_TYPE_NVCTRL | subtype;
type = SENSOR_TYPE_NVCTRL | subtype;
@@
-276,14
+292,22
@@
static struct psensor *create_nvidia_sensor(int id, int subtype, int value_len)
sprintf(sid, "%s %s", PROVIDER_NAME, name);
s = psensor_create(sid, name, pname, type, value_len);
sprintf(sid, "%s %s", PROVIDER_NAME, name);
s = psensor_create(sid, name, pname, type, value_len);
- s->nvidia_id = id;
+ s->provider_data = malloc(sizeof(int));
+ set_nvidia_id(s, id);
+
+ if ((type & SENSOR_TYPE_GPU) && (type & SENSOR_TYPE_TEMP)) {
+ v = get_att(NV_CTRL_TARGET_TYPE_GPU,
+ id,
+ NV_CTRL_GPU_CORE_THRESHOLD);
+ s->max = v;
+ }
free(strnid);
return s;
}
free(strnid);
return s;
}
-static int init()
+static int init(
void
)
{
int evt, err;
{
int evt, err;
@@
-372,7
+396,7
@@
void nvidia_psensor_list_append(struct psensor ***ss, int values_len)
}
}
}
}
-void nvidia_cleanup()
+void nvidia_cleanup(
void
)
{
if (display) {
XCloseDisplay(display);
{
if (display) {
XCloseDisplay(display);