From 08934db58c851ab43cf63d2db1aa57aaa5620370 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 3 Jun 2016 16:08:32 +0200 Subject: [PATCH 1/3] Add NvAPI_GPU_GetPerfPoliciesInfo() and NvAPI_GPU_GetPerfPoliciesStatus() for later use --- include/ext_nvapi.h | 62 +++++++++++++++++++++++++++------------------ src/ext_nvapi.c | 38 +++++++++++++++++++-------- 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/include/ext_nvapi.h b/include/ext_nvapi.h index 7cf2b4095..f38cba2ec 100644 --- a/include/ext_nvapi.h +++ b/include/ext_nvapi.h @@ -183,28 +183,42 @@ typedef enum _NvAPI_Status NVAPI_FIRMWARE_REVISION_NOT_SUPPORTED = -200, // The device's firmware is not supported. } NvAPI_Status; - -//! Used in NvAPI_GPU_GetPerfDecreaseInfo. -//! Bit masks for knowing the exact reason for performance decrease -typedef enum _NVAPI_GPU_PERF_DECREASE +typedef struct { - NV_GPU_PERF_DECREASE_NONE = 0, //!< No Slowdown detected - NV_GPU_PERF_DECREASE_REASON_THERMAL_PROTECTION = 0x00000001, //!< Thermal slowdown/shutdown/POR thermal protection - NV_GPU_PERF_DECREASE_REASON_POWER_CONTROL = 0x00000002, //!< Power capping / pstate cap - NV_GPU_PERF_DECREASE_REASON_AC_BATT = 0x00000004, //!< AC->BATT event - NV_GPU_PERF_DECREASE_REASON_API_TRIGGERED = 0x00000008, //!< API triggered slowdown - NV_GPU_PERF_DECREASE_REASON_INSUFFICIENT_POWER = 0x00000010, //!< Power connector missing - NV_GPU_PERF_DECREASE_REASON_UNKNOWN = 0x80000000, //!< Unknown reason -} NVAPI_GPU_PERF_DECREASE; + // total size (of memset) is always: 76 = 0x4c + NvU32 version; -NVAPI_INTERFACE NvAPI_QueryInterface(uint offset); -NVAPI_INTERFACE NvAPI_Initialize(); -NVAPI_INTERFACE NvAPI_Unload(); -NVAPI_INTERFACE NvAPI_GetErrorMessage(NvAPI_Status nr,NvAPI_ShortString szDesc); -NVAPI_INTERFACE NvAPI_EnumPhysicalGPUs(NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount); + NvU32 a; + NvU32 info_value; -NVAPI_INTERFACE NvAPI_GPU_GetPerfDecreaseInfo(NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pPerfDecrInfo); + unsigned char x[64]; + +} NV_GPU_PERF_POLICIES_INFO_PARAMS_V1; + +typedef struct +{ + // total size (of memset) is always: 1360 = 0x550 + + NvU32 version; + NvU32 info_value; + + NvU32 a; + NvU32 b; + + NvU32 throttle; + + unsigned char x[1340]; + +} NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1; + +NVAPI_INTERFACE NvAPI_QueryInterface (uint offset); +NVAPI_INTERFACE NvAPI_Initialize (); +NVAPI_INTERFACE NvAPI_Unload (); +NVAPI_INTERFACE NvAPI_GetErrorMessage (NvAPI_Status nr,NvAPI_ShortString szDesc); +NVAPI_INTERFACE NvAPI_EnumPhysicalGPUs (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount); +NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesInfo (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info); +NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesStatus (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status); #ifdef __nvapi_success #undef __success @@ -269,8 +283,8 @@ typedef int (*NVAPI_INITIALIZE) (void); typedef int (*NVAPI_UNLOAD) (void); typedef int (*NVAPI_GETERRORMESSAGE) (NvAPI_Status, NvAPI_ShortString); typedef int (*NVAPI_ENUMPHYSICALGPUS) (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *); - -typedef int (*NVAPI_GPU_GETPERFDECREASEINFO) (NvPhysicalGpuHandle, NvU32 *); +typedef int (*NVAPI_GPU_GETPERFPOLICIESINFO) (NvPhysicalGpuHandle, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *); +typedef int (*NVAPI_GPU_GETPERFPOLICIESSTATUS) (NvPhysicalGpuHandle, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *); typedef struct { @@ -281,8 +295,8 @@ typedef struct NVAPI_UNLOAD NvAPI_Unload; NVAPI_GETERRORMESSAGE NvAPI_GetErrorMessage; NVAPI_ENUMPHYSICALGPUS NvAPI_EnumPhysicalGPUs; - - NVAPI_GPU_GETPERFDECREASEINFO NvAPI_GPU_GetPerfDecreaseInfo; + NVAPI_GPU_GETPERFPOLICIESINFO NvAPI_GPU_GetPerfPoliciesInfo; + NVAPI_GPU_GETPERFPOLICIESSTATUS NvAPI_GPU_GetPerfPoliciesStatus; } hm_nvapi_lib_t; @@ -296,8 +310,8 @@ int hm_NvAPI_Initialize (NVAPI_PTR *nvapi); int hm_NvAPI_Unload (NVAPI_PTR *nvapi); int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status nr, NvAPI_ShortString szDesc); int hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount); - -int hm_NvAPI_GPU_GetPerfDecreaseInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pPerfDecrInfo); +int hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info); +int hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status); #endif // HAVE_HWMON diff --git a/src/ext_nvapi.c b/src/ext_nvapi.c index 1e2f16c91..38326380d 100644 --- a/src/ext_nvapi.c +++ b/src/ext_nvapi.c @@ -31,13 +31,13 @@ int nvapi_init (NVAPI_PTR *nvapi) return (-1); } - HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0) - - HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfDecreaseInfo, NVAPI_GPU_GETPERFDECREASEINFO, nvapi_QueryInterface, 0x7F7F4600, NVAPI, 0) + HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0) return 0; } @@ -116,11 +116,11 @@ int hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle return NvAPI_rc; } -int hm_NvAPI_GPU_GetPerfDecreaseInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pPerfDecrInfo) +int hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info) { if (!nvapi) return (-1); - NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfDecreaseInfo (hPhysicalGpu, pPerfDecrInfo); + NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesInfo (hPhysicalGpu, perfPolicies_info); if (NvAPI_rc != NVAPI_OK) { @@ -128,7 +128,25 @@ int hm_NvAPI_GPU_GetPerfDecreaseInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhy hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfDecreaseInfo()", NvAPI_rc, string); + log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesInfo()", NvAPI_rc, string); + } + + return NvAPI_rc; +} + +int hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status) +{ + if (!nvapi) return (-1); + + NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesStatus (hPhysicalGpu, perfPolicies_status); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesStatus()", NvAPI_rc, string); } return NvAPI_rc; From 3e30b62bf68b8fce6a8cf417d6729771819df467 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 3 Jun 2016 16:20:59 +0200 Subject: [PATCH 2/3] Remove some ugly code from nvapi.h --- include/ext_nvapi.h | 83 +++------------------------------------------ 1 file changed, 4 insertions(+), 79 deletions(-) diff --git a/include/ext_nvapi.h b/include/ext_nvapi.h index f38cba2ec..0d9439efc 100644 --- a/include/ext_nvapi.h +++ b/include/ext_nvapi.h @@ -12,36 +12,13 @@ #include -/* +/** * Declarations from nvapi.h and subheaders - **/ - -#ifndef __success - #define __nvapi_success - #define __success(epxr) -#endif - -//#define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl -#define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status - -/* - * Definitions from nvapi_lite_common.h */ -// mac os 32-bit still needs this -#if (defined(macintosh) || defined(__APPLE__)) && !defined(__LP64__) -typedef signed long NvS32; /* -2147483648 to 2147483647 */ -#else -typedef signed int NvS32; /* -2147483648 to 2147483647 */ -#endif +#define NVAPI_INTERFACE extern NvAPI_Status -// mac os 32-bit still needs this -#if ( (defined(macintosh) && defined(__LP64__) && (__NVAPI_RESERVED0__)) || \ - (!defined(macintosh) && defined(__NVAPI_RESERVED0__)) ) -typedef unsigned int NvU32; /* 0 to 4294967295 */ -#else -typedef unsigned long NvU32; /* 0 to 4294967295 */ -#endif +typedef unsigned long NvU32; #define NV_DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name @@ -56,10 +33,8 @@ typedef char NvAPI_LongString[NVAPI_LONG_STRING_MAX]; typedef char NvAPI_ShortString[NVAPI_SHORT_STRING_MAX]; #define MAKE_NVAPI_VERSION(typeName,ver) (NvU32)(sizeof(typeName) | ((ver)<<16)) -#define GET_NVAPI_VERSION(ver) (NvU32)((ver)>>16) -#define GET_NVAPI_SIZE(ver) (NvU32)((ver) & 0xffff) -#define NVAPI_MAX_PHYSICAL_GPUS 64 +#define NVAPI_MAX_PHYSICAL_GPUS 64 typedef enum _NvAPI_Status { @@ -220,60 +195,10 @@ NVAPI_INTERFACE NvAPI_EnumPhysicalGPUs (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MA NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesInfo (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info); NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesStatus (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status); -#ifdef __nvapi_success - #undef __success - #undef __nvapi_success -#endif - /* * End of declarations from nvapi.h and subheaders **/ -// Just annotations (they do nothing special) - -#ifndef __success -#define __success(x) -#endif -#ifndef __in -#define __in -#endif -#ifndef __out -#define __out -#endif -#ifndef __in_ecount -#define __in_ecount(x) -#endif -#ifndef __out_ecount -#define __out_ecount(x) -#endif -#ifndef __in_opt -#define __in_opt -#endif -#ifndef __out_opt -#define __out_opt -#endif -#ifndef __inout -#define __inout -#endif -#ifndef __inout_opt -#define __inout_opt -#endif -#ifndef __inout_ecount -#define __inout_ecount(x) -#endif -#ifndef __inout_ecount_full -#define __inout_ecount_full(x) -#endif -#ifndef __inout_ecount_part_opt -#define __inout_ecount_part_opt(x,y) -#endif -#ifndef __inout_ecount_full_opt -#define __inout_ecount_full_opt(x,y) -#endif -#ifndef __out_ecount_full_opt -#define __out_ecount_full_opt(x) -#endif - typedef NvPhysicalGpuHandle HM_ADAPTER_NVAPI; #include From 2e706edc18a41006b768bb5ff155a367b25c4610 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 3 Jun 2016 16:26:05 +0200 Subject: [PATCH 3/3] Do not show *throttle* in status display if the reason is unknown --- include/ext_nvml.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ src/shared.c | 2 ++ 2 files changed, 59 insertions(+) diff --git a/include/ext_nvml.h b/include/ext_nvml.h index 538942ffb..b33e2abc7 100644 --- a/include/ext_nvml.h +++ b/include/ext_nvml.h @@ -103,6 +103,63 @@ typedef enum nvmlGom_enum //!< high bandwidth double precision } nvmlGpuOperationMode_t; +/***************************************************************************************************/ +/** @addtogroup nvmlClocksThrottleReasons + * @{ + */ +/***************************************************************************************************/ + +/** Nothing is running on the GPU and the clocks are dropping to Idle state + * \note This limiter may be removed in a later release + */ +#define nvmlClocksThrottleReasonGpuIdle 0x0000000000000001LL + +/** GPU clocks are limited by current setting of applications clocks + * + * @see nvmlDeviceSetApplicationsClocks + * @see nvmlDeviceGetApplicationsClock + */ +#define nvmlClocksThrottleReasonApplicationsClocksSetting 0x0000000000000002LL + +/** + * @deprecated Renamed to \ref nvmlClocksThrottleReasonApplicationsClocksSetting + * as the name describes the situation more accurately. + */ +#define nvmlClocksThrottleReasonUserDefinedClocks nvmlClocksThrottleReasonApplicationsClocksSetting + +/** SW Power Scaling algorithm is reducing the clocks below requested clocks + * + * @see nvmlDeviceGetPowerUsage + * @see nvmlDeviceSetPowerManagementLimit + * @see nvmlDeviceGetPowerManagementLimit + */ +#define nvmlClocksThrottleReasonSwPowerCap 0x0000000000000004LL + +/** HW Slowdown (reducing the core clocks by a factor of 2 or more) is engaged + * + * This is an indicator of: + * - temperature being too high + * - External Power Brake Assertion is triggered (e.g. by the system power supply) + * - Power draw is too high and Fast Trigger protection is reducing the clocks + * - May be also reported during PState or clock change + * - This behavior may be removed in a later release. + * + * @see nvmlDeviceGetTemperature + * @see nvmlDeviceGetTemperatureThreshold + * @see nvmlDeviceGetPowerUsage + */ +#define nvmlClocksThrottleReasonHwSlowdown 0x0000000000000008LL + +/** Some other unspecified factor is reducing the clocks */ +#define nvmlClocksThrottleReasonUnknown 0x8000000000000000LL + +/** Bit mask representing no clocks throttling + * + * Clocks are as high as possible. + * */ +#define nvmlClocksThrottleReasonNone 0x0000000000000000LL + + /* * End of declarations from nvml.h **/ diff --git a/src/shared.c b/src/shared.c index fafa6ed9c..d723abb24 100644 --- a/src/shared.c +++ b/src/shared.c @@ -3396,6 +3396,8 @@ int hm_get_throttle_with_device_id (const uint device_id) clocksThrottleReasons &= supportedThrottleReasons; + clocksThrottleReasons &= ~nvmlClocksThrottleReasonUnknown; + return (clocksThrottleReasons > 0); }