@@ -652,9 +652,6 @@ static void gpuinfo_amdgpu_populate_static_info(struct gpu_info *_gpu_info) {
652652}
653653
654654static void gpuinfo_amdgpu_refresh_dynamic_info (struct gpu_info * _gpu_info ) {
655- struct timespec t_query_start , t_query_end ;
656- clock_gettime (CLOCK_MONOTONIC , & t_query_start );
657-
658655 struct gpu_info_amdgpu * gpu_info = container_of (_gpu_info , struct gpu_info_amdgpu , base );
659656 struct gpuinfo_dynamic_info * dynamic_info = & gpu_info -> base .dynamic_info ;
660657 bool info_query_success = false;
@@ -666,12 +663,6 @@ static void gpuinfo_amdgpu_refresh_dynamic_info(struct gpu_info *_gpu_info) {
666663 if (libdrm_amdgpu_handle && _amdgpu_query_gpu_info )
667664 info_query_success = !_amdgpu_query_gpu_info (gpu_info -> amdgpu_device , & info );
668665
669- clock_gettime (CLOCK_MONOTONIC , & t_query_end );
670- double elapsed_q =
671- (t_query_end .tv_sec - t_query_start .tv_sec ) * 1000.0 + (t_query_end .tv_nsec - t_query_start .tv_nsec ) / 1000000.0 ;
672- if (elapsed_q > 5.0 )
673- fprintf (stderr , "[DEBUG] AMD _amdgpu_query_gpu_info took %.2f ms\n" , elapsed_q );
674-
675666 // GPU current speed
676667 if (libdrm_amdgpu_handle && _amdgpu_query_sensor_info )
677668 last_libdrm_return_status =
@@ -714,15 +705,9 @@ static void gpuinfo_amdgpu_refresh_dynamic_info(struct gpu_info *_gpu_info) {
714705
715706 // Memory usage
716707 struct drm_amdgpu_memory_info memory_info ;
717- clock_gettime (CLOCK_MONOTONIC , & t_query_start );
718708 if (libdrm_amdgpu_handle && _amdgpu_query_info )
719709 last_libdrm_return_status =
720710 _amdgpu_query_info (gpu_info -> amdgpu_device , AMDGPU_INFO_MEMORY , sizeof (memory_info ), & memory_info );
721- clock_gettime (CLOCK_MONOTONIC , & t_query_end );
722- elapsed_q =
723- (t_query_end .tv_sec - t_query_start .tv_sec ) * 1000.0 + (t_query_end .tv_nsec - t_query_start .tv_nsec ) / 1000000.0 ;
724- if (elapsed_q > 5.0 )
725- fprintf (stderr , "[DEBUG] AMD _amdgpu_query_info(AMDGPU_INFO_MEMORY) took %.2f ms\n" , elapsed_q );
726711 else
727712 last_libdrm_return_status = 1 ;
728713 if (!last_libdrm_return_status ) {
@@ -754,13 +739,7 @@ static void gpuinfo_amdgpu_refresh_dynamic_info(struct gpu_info *_gpu_info) {
754739
755740 // Fan speed
756741 unsigned currentFanSpeed ;
757- clock_gettime (CLOCK_MONOTONIC , & t_query_start );
758742 int patternsMatched = rewindAndReadPattern (gpu_info -> fanSpeedFILE , "%u" , & currentFanSpeed );
759- clock_gettime (CLOCK_MONOTONIC , & t_query_end );
760- elapsed_q =
761- (t_query_end .tv_sec - t_query_start .tv_sec ) * 1000.0 + (t_query_end .tv_nsec - t_query_start .tv_nsec ) / 1000000.0 ;
762- if (elapsed_q > 5.0 )
763- fprintf (stderr , "[DEBUG] AMD rewindAndReadPattern(fanSpeedFILE) took %.2f ms\n" , elapsed_q );
764743 if (patternsMatched == 1 ) {
765744 SET_GPUINFO_DYNAMIC (dynamic_info , fan_speed , currentFanSpeed * 100 / gpu_info -> maxFanValue );
766745 }
@@ -789,19 +768,13 @@ static void gpuinfo_amdgpu_refresh_dynamic_info(struct gpu_info *_gpu_info) {
789768 // to function without hanging for 1,000ms+ on launch, we skip reading this file
790769 // purely on the very first polling cycle.
791770 if (gpu_info -> PCIeBW && GPUINFO_DYNAMIC_FIELD_VALID (dynamic_info , used_memory )) {
792- // We confirm this is not the first cycle by checking if used_memory and
793- // memory thresholds have successfully been evaluated in prior polling cycles
794- // before we allow the PCIe bandwidth kernel lock .
771+ // According to https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/pm/amdgpu_pm.c, under the pcie_bw
772+ // section, we should be able to read the number of packets received and sent by the GPU and get the maximum payload
773+ // size during the last second. This is untested but should work when the file is populated by the driver .
795774 uint64_t received , transmitted ;
796775 int maxPayloadSize ;
797- clock_gettime (CLOCK_MONOTONIC , & t_query_start );
798776 int NreadPatterns =
799777 rewindAndReadPattern (gpu_info -> PCIeBW , "%" SCNu64 " %" SCNu64 " %i" , & received , & transmitted , & maxPayloadSize );
800- clock_gettime (CLOCK_MONOTONIC , & t_query_end );
801- elapsed_q = (t_query_end .tv_sec - t_query_start .tv_sec ) * 1000.0 +
802- (t_query_end .tv_nsec - t_query_start .tv_nsec ) / 1000000.0 ;
803- if (elapsed_q > 5.0 )
804- fprintf (stderr , "[DEBUG] AMD rewindAndReadPattern(PCIeBW) took %.2f ms\n" , elapsed_q );
805778 if (NreadPatterns == 3 ) {
806779 received *= maxPayloadSize ;
807780 transmitted *= maxPayloadSize ;
@@ -816,13 +789,7 @@ static void gpuinfo_amdgpu_refresh_dynamic_info(struct gpu_info *_gpu_info) {
816789 if (gpu_info -> powerCap ) {
817790 // The power cap in microwatts
818791 unsigned powerCap ;
819- clock_gettime (CLOCK_MONOTONIC , & t_query_start );
820792 int NreadPatterns = rewindAndReadPattern (gpu_info -> powerCap , "%u" , & powerCap );
821- clock_gettime (CLOCK_MONOTONIC , & t_query_end );
822- elapsed_q = (t_query_end .tv_sec - t_query_start .tv_sec ) * 1000.0 +
823- (t_query_end .tv_nsec - t_query_start .tv_nsec ) / 1000000.0 ;
824- if (elapsed_q > 5.0 )
825- fprintf (stderr , "[DEBUG] AMD rewindAndReadPattern(powerCap) took %.2f ms\n" , elapsed_q );
826793 if (NreadPatterns == 1 ) {
827794 SET_GPUINFO_DYNAMIC (dynamic_info , power_draw_max , powerCap / 1000 );
828795 }
0 commit comments