intget_used_gpu_utilization(int*userutil,int*sysprocnum){structtimevalcur;size_tmicrosec;inti;unsignedintinfcount;nvmlProcessInfo_v1_tinfos[SHARED_REGION_MAX_PROCESS_NUM];unsignedintnvmlCounts;CHECK_NVML_API(nvmlDeviceGetCount(&nvmlCounts));lock_shrreg();intdevi,cudadev;for(devi=0;devi<nvmlCounts;devi++){uint64_tsum=0;infcount=SHARED_REGION_MAX_PROCESS_NUM;shrreg_proc_slot_t*proc;cudadev=nvml_to_cuda_map((unsignedint)(devi));if(cudadev<0)continue;userutil[cudadev]=0;nvmlDevice_tdevice;CHECK_NVML_API(nvmlDeviceGetHandleByIndex(cudadev,&device));//Get Memory for container
nvmlReturn_tres=nvmlDeviceGetComputeRunningProcesses(device,&infcount,infos);if(res==NVML_SUCCESS){for(i=0;i<infcount;i++){proc=find_proc_by_hostpid(infos[i].pid);if(proc!=NULL){// 这里是显存用量
proc->monitorused[cudadev]=infos[i].usedGpuMemory;}}}// Get SM util for container
gettimeofday(&cur,NULL);microsec=(cur.tv_sec-1)*1000UL*1000UL+cur.tv_usec;nvmlProcessUtilizationSample_tprocesses_sample[SHARED_REGION_MAX_PROCESS_NUM];unsignedintprocesses_num=SHARED_REGION_MAX_PROCESS_NUM;res=nvmlDeviceGetProcessUtilization(device,processes_sample,&processes_num,microsec);if(res==NVML_SUCCESS){for(i=0;i<processes_num;i++){proc=find_proc_by_hostpid(processes_sample[i].pid);if(proc!=NULL){sum+=processes_sample[i].smUtil;// 这里是sm 使用率
proc->device_util[cudadev].sm_util=processes_sample[i].smUtil;}}}if(sum<0)sum=0;userutil[cudadev]=sum;}unlock_shrreg();return0;}