Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device_utilization_desc_of_container 数据采集始终为0 #32

Open
MouseSun846 opened this issue Oct 30, 2024 · 0 comments
Open

Device_utilization_desc_of_container 数据采集始终为0 #32

MouseSun846 opened this issue Oct 30, 2024 · 0 comments

Comments

@MouseSun846
Copy link

image

Device_utilization_desc_of_container 数据采集始终为0, 调试libvgpu 发现找不到hostpid
image

代码修改如下

int get_used_gpu_utilization(int *userutil,int *sysprocnum) {
    struct timeval cur;
    size_t microsec;

    int i,sum=0;
    unsigned int infcount;
    size_t summonitor=0;
    nvmlProcessInfo_v1_t infos[SHARED_REGION_MAX_PROCESS_NUM];

    unsigned int nvmlCounts;
    CHECK_NVML_API(nvmlDeviceGetCount(&nvmlCounts));

    int devi,cudadev;
    for (devi=0;devi<nvmlCounts;devi++){
      sum=0;
      summonitor=0;
      shrreg_proc_slot_t *proc;
      cudadev = nvml_to_cuda_map((unsigned int)(devi));
      if (cudadev<0)
        continue;
      nvmlDevice_t device;
      char uuid[NVML_DEVICE_UUID_BUFFER_SIZE];
      CHECK_NVML_API(nvmlDeviceGetHandleByIndex(cudadev, &device));
        // Get device UUID
     CHECK_NVML_API(nvmlDeviceGetUUID(device, uuid, NVML_DEVICE_UUID_BUFFER_SIZE));
      nvmlReturn_t res = nvmlDeviceGetComputeRunningProcesses(device,&infcount,infos);
      if (res==NVML_ERROR_INSUFFICIENT_SIZE){
        continue;
      }
      gettimeofday(&cur,NULL);
      microsec = (cur.tv_sec - 1) * 1000UL * 1000UL + cur.tv_usec;
      nvmlProcessUtilizationSample_t processes_sample[SHARED_REGION_MAX_PROCESS_NUM];
      unsigned int processes_num = SHARED_REGION_MAX_PROCESS_NUM;
      res = nvmlDeviceGetProcessUtilization(device,processes_sample,&processes_num,microsec);
      LOG_DEBUG("processes_num=%d\n",processes_num);
      LOG_DEBUG("Device UUID: %s\n", uuid);
      LOG_DEBUG("nvmlDeviceGetProcessUtilization res: %d\n", res);
      if ((res==NVML_ERROR_INSUFFICIENT_SIZE) || (res==NVML_ERROR_NOT_FOUND)){
        userutil[cudadev] = 0;
        for (i=0; i<infcount; i++){
          proc = find_proc_by_hostpid(infos[i].pid);
          if (proc != NULL){
              LOG_DEBUG("pid=%u monitor=%lld\n",infos[i].pid,infos[i].usedGpuMemory);
              summonitor += infos[i].usedGpuMemory;
          }
          set_gpu_device_memory_monitor(infos[i].pid,cudadev,summonitor);
          set_gpu_device_sm_utilization(infos[i].pid,cudadev,0);
        } 
        continue;
      }
      for (i=0; i<processes_num; i++){
          //if (processes_sample[i].timeStamp >= microsec){
          proc = find_proc_by_hostpid(processes_sample[i].pid);
          if (proc != NULL){
              //LOG_WARN("pid=%u num=%d\n",processes_sample[i].pid,processes_num);
              //proc = find_proc_by_hostpid(processes_sample[i].pid);
              //if (proc!=NULL) {
              //    printf("inner pid=%u\n",proc->pid);
              sum += processes_sample[i].smUtil;
              summonitor += infos[i].usedGpuMemory;
              LOG_DEBUG("monitorused=%lld %d %d %d",infos[i].usedGpuMemory,proc->hostpid,proc->pid,pidfound);
              LOG_DEBUG("smutil=%u %u %u\n",processes_sample[i].smUtil,processes_sample[i].encUtil,processes_sample[i].decUtil);
              //}
          } else {
            LOG_DEBUG("find_proc_by_hostpid proc is null.\n")
          }

          set_gpu_device_memory_monitor(processes_sample[i].pid,cudadev,summonitor);
          set_gpu_device_sm_utilization(processes_sample[i].pid,cudadev,processes_sample[i].smUtil);
      }
      if (sum < 0)
        sum = 0;
      LOG_DEBUG("sum=%d\n", sum);
      userutil[cudadev] = sum;
    }
    return 0;
}

请问是配置不正确吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant