From 36def60bfaad9b0f2b1142b2f2de0d0044553eba Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 28 May 2016 16:49:23 +0200 Subject: [PATCH] Added NVML support for querying current engine clock and current memory clock --- include/ext_nvml.h | 9 +++++++++ src/ext_nvml.c | 20 ++++++++++++++++++++ src/shared.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/include/ext_nvml.h b/include/ext_nvml.h index 3b4edfc..68fd324 100644 --- a/include/ext_nvml.h +++ b/include/ext_nvml.h @@ -52,6 +52,12 @@ typedef enum nvmlReturn_enum { NVML_ERROR_UNKNOWN = 999 // An internal driver error occurred } nvmlReturn_t; +typedef enum nvmlClockType_enum { + NVML_CLOCK_GRAPHICS = 0, + NVML_CLOCK_SM = 1, + NVML_CLOCK_MEM = 2 +} nvmlClockType_t; + /* * End of declarations from nvml.h **/ @@ -69,6 +75,7 @@ typedef nvmlReturn_t (*NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatu typedef nvmlReturn_t (*NVML_DEVICE_GET_FAN_SPEED) (nvmlDevice_t, unsigned int *); typedef nvmlReturn_t (*NVML_DEVICE_GET_POWER_USAGE) (nvmlDevice_t, unsigned int *); typedef nvmlReturn_t (*NVML_DEVICE_GET_UTILIZATION_RATES) (nvmlDevice_t, nvmlUtilization_t *); +typedef nvmlReturn_t (*NVML_DEVICE_GET_CLOCKINFO) (nvmlDevice_t, nvmlClockType_t, unsigned int *); typedef struct { @@ -83,6 +90,7 @@ typedef struct NVML_DEVICE_GET_FAN_SPEED nvmlDeviceGetFanSpeed; NVML_DEVICE_GET_POWER_USAGE nvmlDeviceGetPowerUsage; NVML_DEVICE_GET_UTILIZATION_RATES nvmlDeviceGetUtilizationRates; + NVML_DEVICE_GET_CLOCKINFO nvmlDeviceGetClockInfo; } hm_nvml_lib_t; @@ -100,6 +108,7 @@ nvmlReturn_t hm_NVML_nvmlDeviceGetTemperature (NVML_PTR *nvml, nvmlDevice_t devi nvmlReturn_t hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *speed); nvmlReturn_t hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR *nvml, nvmlDevice_t device, unsigned int *power); nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, nvmlDevice_t device, nvmlUtilization_t *utilization); +nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); #endif // HAVE_HWMON && HAVE_NVML diff --git a/src/ext_nvml.c b/src/ext_nvml.c index 4eb02eb..2a66214 100644 --- a/src/ext_nvml.c +++ b/src/ext_nvml.c @@ -32,6 +32,7 @@ int nvml_init (NVML_PTR *nvml) HC_LOAD_FUNC(nvml, nvmlDeviceGetFanSpeed, NVML_DEVICE_GET_FAN_SPEED, NVML, 0) HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerUsage, NVML_DEVICE_GET_POWER_USAGE, NVML, 0) HC_LOAD_FUNC(nvml, nvmlDeviceGetUtilizationRates, NVML_DEVICE_GET_UTILIZATION_RATES, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetClockInfo, NVML_DEVICE_GET_CLOCKINFO, NVML, 0) return 0; } @@ -198,3 +199,22 @@ nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, nvmlDevice_t return nvml_rc; } + +nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock) +{ + if (!nvml) return -1; + + nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetClockInfo (device, type, clock); + + if (nvml_rc != NVML_SUCCESS) + { + *clock = -1; + + //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string); + } + + return nvml_rc; +} + diff --git a/src/shared.c b/src/shared.c index 4fb97de..baa830d 100644 --- a/src/shared.c +++ b/src/shared.c @@ -3251,6 +3251,23 @@ int hm_get_memoryspeed_with_device_id (const uint device_id) } #endif // HAVE_ADL + #if defined(HAVE_NVML) || defined(HAVE_NVAPI) + if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + { + #if defined(LINUX) && defined(HAVE_NVML) + unsigned int clock; + + hm_NVML_nvmlDeviceGetClockInfo (data.hm_nv, data.hm_device[device_id].adapter_index.nv, NVML_CLOCK_MEM, &clock); + + return clock; + #endif + + #if defined(WIN) && defined(HAVE_NVAPI) + + #endif + } + #endif // HAVE_NVML || HAVE_NVAPI + return -1; } @@ -3274,6 +3291,23 @@ int hm_get_corespeed_with_device_id (const uint device_id) } #endif // HAVE_ADL + #if defined(HAVE_NVML) || defined(HAVE_NVAPI) + if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + { + #if defined(LINUX) && defined(HAVE_NVML) + unsigned int clock; + + hm_NVML_nvmlDeviceGetClockInfo (data.hm_nv, data.hm_device[device_id].adapter_index.nv, NVML_CLOCK_SM, &clock); + + return clock; + #endif + + #if defined(WIN) && defined(HAVE_NVAPI) + + #endif + } + #endif // HAVE_NVML || HAVE_NVAPI + return -1; } -- 2.25.1