X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fnvidia.c;h=c88e7cff163e6a805f44cb66bdd86e1ea1ca9506;hb=573a01a68ca7cfc7c0afc6c128737dd05dd11625;hp=807aec02246c06cfd49165ce5de50513625325b3;hpb=eb18851dd8472699e39d9488786396d201245160;p=psensor.git diff --git a/src/lib/nvidia.c b/src/lib/nvidia.c index 807aec0..c88e7cf 100644 --- a/src/lib/nvidia.c +++ b/src/lib/nvidia.c @@ -38,6 +38,16 @@ static Display *display; 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; @@ -220,15 +230,18 @@ static double get_value(int id, int type) 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, - sensor->nvidia_id); + id); psensor_set_current_value(sensor, v); } @@ -243,7 +256,8 @@ static char *i2str(int i) 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); @@ -259,6 +273,7 @@ static struct psensor *create_nvidia_sensor(int id, int subtype, int value_len) int type; size_t n; struct psensor *s; + double v; type = SENSOR_TYPE_NVCTRL | subtype; @@ -277,7 +292,15 @@ 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); - 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);