X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=src%2Flib%2Famd.c;h=72a807e6306435a871c54d4ed498ad4e81ac31ba;hp=02fcc03aba05d755aedf1c73a1dddacc42f60cdf;hb=3361fda8735c65887a859c9faf287cb105ae6bc8;hpb=1438bc505641cd98fe3af323fb2329c3284e157f diff --git a/src/lib/amd.c b/src/lib/amd.c index 02fcc03..72a807e 100644 --- a/src/lib/amd.c +++ b/src/lib/amd.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2010-2011 thgreasi@gmail.com, jeanfi@gmail.com - * Copyright (C) 2010-2013 jeanfi@gmail.com + * Copyright (C) 2012-2014 jeanfi@gmail.com * * GPU usage is a contribution of MestreLion * @@ -34,7 +34,7 @@ #include -#include "psensor.h" +#include typedef int (*ADL_MAIN_CONTROL_CREATE)(ADL_MAIN_MALLOC_CALLBACK, int); typedef int (*ADL_MAIN_CONTROL_DESTROY)(); @@ -69,19 +69,18 @@ static void *getprocaddress(void *plibrary, const char *name) return dlsym(plibrary, name); } -/* - Returns the temperature (Celcius) of an AMD/ATI GPU. -*/ +/* Returns the temperature (Celsius) of an AMD/ATI GPU. */ static double get_temp(struct psensor *sensor) { ADLTemperature v; v.iSize = sizeof(ADLTemperature); v.iTemperature = -273; - if (ADL_OK == adl_od5_temperature_get(sensor->amd_id, 0, &v)) + + if (adl_od5_temperature_get(sensor->amd_id, 0, &v) == ADL_OK) return v.iTemperature/1000; - else - return UNKNOWN_DBL_VALUE; + + return UNKNOWN_DBL_VALUE; } static double get_fanspeed(struct psensor *sensor) @@ -91,10 +90,11 @@ static double get_fanspeed(struct psensor *sensor) v.iSize = sizeof(ADLFanSpeedValue); v.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM; v.iFanSpeed = -1; - if (ADL_OK == adl_od5_fanspeed_get(sensor->amd_id, 0, &v)) + + if (adl_od5_fanspeed_get(sensor->amd_id, 0, &v) == ADL_OK) return v.iFanSpeed; - else - return UNKNOWN_DBL_VALUE; + + return UNKNOWN_DBL_VALUE; } static double get_usage(struct psensor *sensor) @@ -102,10 +102,11 @@ static double get_usage(struct psensor *sensor) ADLPMActivity v; v.iSize = sizeof(ADLPMActivity); - if (ADL_OK == adl_od5_currentactivity_get(sensor->amd_id, &v)) + + if (adl_od5_currentactivity_get(sensor->amd_id, &v) == ADL_OK) return v.iActivityPercent; - else - return UNKNOWN_DBL_VALUE; + + return UNKNOWN_DBL_VALUE; } static struct psensor *create_sensor(int id, int type, int values_len) @@ -132,7 +133,7 @@ static struct psensor *create_sensor(int id, int type, int values_len) /* GPU Usage (Activity/Load %) */ case 2: sprintf(name, "AMD GPU%d Usage", id); - sensor_type |= SENSOR_TYPE_GPU | SENSOR_TYPE_USAGE; + sensor_type |= SENSOR_TYPE_GPU | SENSOR_TYPE_PERCENT; break; } @@ -151,11 +152,11 @@ static struct psensor *create_sensor(int id, int type, int values_len) } /* - Returns the number of active AMD/ATI GPU adapters - - Return 0 if no AMD/ATI GPUs or cannot get information. -*/ -static int init() + * Returns the number of active AMD/ATI GPU adapters + * + * Return 0 if no AMD/ATI GPUs or cannot get information. + */ +static int init(void) { LPAdapterInfo lpadapterinfo; int i, inumberadapters, inumberadaptersactive, lpstatus, iadapterindex; @@ -199,17 +200,17 @@ static int init() } /* - 1 in 2nd parameter means retrieve adapter information only - for adapters that are physically present and enabled in the - system + * 1 in 2nd parameter means retrieve adapter information only + * for adapters that are physically present and enabled in the + * system */ - if (ADL_OK != adl_main_control_create(adl_main_memory_alloc, 1)) { + if (adl_main_control_create(adl_main_memory_alloc, 1) != ADL_OK) { log_err(_("AMD: failed to initialize ADL.")); return 0; } adl_main_control_done = 1; - if (ADL_OK != adl_adapter_numberofadapters_get(&inumberadapters)) { + if (adl_adapter_numberofadapters_get(&inumberadapters) != ADL_OK) { log_err(_("AMD: cannot get the number of adapters.")); return 0; } @@ -227,7 +228,7 @@ static int init() iadapterindex = lpadapterinfo[i].iAdapterIndex; - if (ADL_OK != adl_adapter_active_get(iadapterindex, &lpstatus)) + if (adl_adapter_active_get(iadapterindex, &lpstatus) != ADL_OK) continue; if (lpstatus != ADL_TRUE) continue; @@ -270,7 +271,7 @@ void amd_psensor_list_update(struct psensor **sensors) psensor_set_current_value(s, get_temp(s)); else if (s->type & SENSOR_TYPE_RPM) psensor_set_current_value(s, get_fanspeed(s)); - else if (s->type & SENSOR_TYPE_USAGE) + else if (s->type & SENSOR_TYPE_PERCENT) psensor_set_current_value(s, get_usage(s)); } @@ -279,31 +280,22 @@ void amd_psensor_list_update(struct psensor **sensors) } /* Entry point for AMD sensors */ -struct psensor * * -amd_psensor_list_add(struct psensor **sensors, int values_len) +void amd_psensor_list_append(struct psensor ***sensors, int values_len) { int i, j, n; - struct psensor **tmp, **ss, *s; + struct psensor *s; n = init(); - ss = sensors; for (i = 0; i < n; i++) /* Each GPU Adapter has 3 sensors: temp, fan speed and usage */ for (j = 0; j < 3; j++) { s = create_sensor(i, j, values_len); - tmp = psensor_list_add(ss, s); - - if (ss != tmp) - free(ss); - - ss = tmp; + psensor_list_append(sensors, s); } - - return ss; } -void amd_cleanup() +void amd_cleanup(void) { if (hdll) { if (adl_main_control_done)