+ double v;
+ int id;
+
+ id = get_nvidia_id(sensor);
+
+ 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,
+ id);
+ psensor_set_current_value(sensor, v);
+}
+
+static int check_sensor(int id, int type)
+{
+ return get_value(id, type) != UNKNOWN_DBL_VALUE;
+}
+
+static char *i2str(int i)
+{
+ char *str;
+ size_t n;
+
+ /* second +1 to avoid issue about the conversion of a double
+ * to a lower int */
+ n = 1 + (ceil(log10(INT_MAX)) + 1) + 1;
+
+ str = malloc(n);
+ snprintf(str, n, "%d", i);
+
+ return str;
+}
+
+static struct psensor *create_nvidia_sensor(int id, int subtype, int value_len)
+{
+ char *pname, *name, *strnid, *sid;
+ const char *stype;
+ int type;
+ size_t n;
+ struct psensor *s;
+ double v;
+
+ type = SENSOR_TYPE_NVCTRL | subtype;
+
+ if (!check_sensor(id, type))
+ return NULL;
+
+ pname = get_product_name(id, type);
+ strnid = i2str(id);
+ stype = get_nvidia_type_str(type);
+
+ n = strlen(pname) + 1 + strlen(strnid) + 1 + strlen(stype) + 1;
+ name = malloc(n);
+ sprintf(name, "%s %s %s", pname, strnid, stype);
+
+ sid = malloc(strlen(PROVIDER_NAME) + 1 + strlen(name) + 1);
+ sprintf(sid, "%s %s", PROVIDER_NAME, name);
+
+ s = psensor_create(sid, name, pname, type, value_len);
+ 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;
+}
+
+static int init(void)
+{
+ int evt, err;