|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (C) 2017 Maxime Schmitt <[email protected]> |
| 4 | + * |
| 5 | + * This file is part of Nvtop. |
| 6 | + * |
| 7 | + * Nvtop is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * Nvtop is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with nvtop. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +#ifndef __EXTRACT_GPUINFO_H_ |
| 23 | +#define __EXTRACT_GPUINFO_H_ |
| 24 | + |
| 25 | +#include <stdbool.h> |
| 26 | +#include <nvml.h> |
| 27 | + |
| 28 | +struct gpu_process { |
| 29 | + unsigned int pid; // Process ID |
| 30 | + char process_name[64]; // Process Name |
| 31 | + char user_name[64]; // Process User Name |
| 32 | + unsigned long long used_memory; // Memory used by process |
| 33 | +}; |
| 34 | + |
| 35 | +struct device_info { |
| 36 | + nvmlDevice_t device_handle; // Used to query device |
| 37 | + char device_name[NVML_DEVICE_NAME_BUFFER_SIZE]; // Device Name |
| 38 | + unsigned int gpu_clock_speed; // Device clock speed in MHz |
| 39 | + unsigned int gpu_clock_speed_max; // Maximum clock speed in MHz |
| 40 | + unsigned int mem_clock_speed; // Device clock speed in MHz |
| 41 | + unsigned int mem_clock_speed_max; // Maximum clock speed in MHz |
| 42 | + unsigned int gpu_util_rate; // GPU utilization rate in % |
| 43 | + unsigned int mem_util_rate; // MEM utilization rate in % |
| 44 | + unsigned int encoder_rate; // Encoder utilization rate in % |
| 45 | + unsigned int encoder_sampling; // Encoder sampling period in micro sec |
| 46 | + unsigned int decoder_rate; // Decoder utilization rate in % |
| 47 | + unsigned int decoder_sampling; // Decoder sampling period in micro sec |
| 48 | + unsigned long long free_memory; // Unallocated memory (bytes) |
| 49 | + unsigned long long total_memory; // Total memory (bytes) |
| 50 | + unsigned long long used_memory; // Allocated memory (bytes) |
| 51 | + unsigned int cur_pcie_link_gen; // PCIe link generation used |
| 52 | + unsigned int max_pcie_link_gen; // PCIe link generation max |
| 53 | + unsigned int cur_pcie_link_width; // PCIe line width used |
| 54 | + unsigned int max_pcie_link_width; // PCIe line width max |
| 55 | + unsigned int pcie_rx; // PCIe throughput in KB/s |
| 56 | + unsigned int pcie_tx; // PCIe throughput in KB/s |
| 57 | + unsigned int fan_speed; // Fan speed percentage |
| 58 | + unsigned int gpu_temp; // GPU temperature °c |
| 59 | + unsigned int gpu_temp_slowdown; // GPU temperature °c |
| 60 | + unsigned int gpu_temp_shutdown; // GPU temperature °c |
| 61 | + unsigned int power_draw; // Power usage in milliwatts |
| 62 | + unsigned int power_draw_max; // Max power usage in milliwatts |
| 63 | + unsigned int size_proc_buffers; // Number of Compute processes (Cuda) |
| 64 | + unsigned int num_compute_procs; // Number of Compute processes (Cuda) |
| 65 | + unsigned int num_graphical_procs; // Number of Graphical processes |
| 66 | + struct gpu_process *graphic_procs; // Graphical process info |
| 67 | + struct gpu_process *compute_procs; // Compute processes info |
| 68 | + nvmlProcessInfo_t *process_infos; // Internal use |
| 69 | +}; |
| 70 | + |
| 71 | +bool init_gpu_info_extraction(void); |
| 72 | + |
| 73 | +bool shutdown_gpu_info_extraction(void); |
| 74 | + |
| 75 | +unsigned int initialize_device_info(struct device_info **dev_info); |
| 76 | + |
| 77 | +void update_device_infos( |
| 78 | + unsigned int num_devs, |
| 79 | + struct device_info *dev_info); |
| 80 | + |
| 81 | +void clean_device_info(unsigned int num_devs, struct device_info *dev_info); |
| 82 | + |
| 83 | +#endif // __EXTRACT_GPUINFO_H_ |
0 commit comments