Skip to content

Commit 5019693

Browse files
committed
Merge master into ascend branch
2 parents 8661d4e + e86438b commit 5019693

27 files changed

+2747
-15
lines changed

AppImage/make_appimage_ubuntu_1804_docker.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
install_deps() {
44
apt-get update
5-
apt-get install -y cmake gcc g++ libncurses5-dev libncursesw5-dev libdrm-dev wget file libudev-dev
5+
apt-get install -y gcc g++ libncurses5-dev libncursesw5-dev libdrm-dev wget file libudev-dev
66
}
77

88
configure_nvtop() {
@@ -23,8 +23,15 @@ get_linuxdeploy() {
2323
./linuxdeploy-x86_64.AppImage --appimage-extract
2424
}
2525

26+
get_cmake() {
27+
wget -nc https://github.com/Kitware/CMake/releases/download/v3.18.0/cmake-3.18.0.tar.gz
28+
tar zxf cmake-3.18.0.tar.gz
29+
./cmake-3.18.0/bootstrap --prefix=/usr && make && make install
30+
}
31+
2632
create_AppImage() {
2733
install_deps
34+
get_cmake
2835
mkdir nvtop_build
2936
cd nvtop_build
3037
configure_nvtop

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,26 @@ if(APPLE)
6666
set(AMDGPU_SUPPORT_DEFAULT OFF)
6767
set(INTEL_SUPPORT_DEFAULT OFF)
6868
set(MSM_SUPPORT_DEFAULT OFF)
69+
set(PANFROST_SUPPORT_DEFAULT OFF)
70+
set(PANTHOR_SUPPORT_DEFAULT OFF)
6971
set(ASCEND_SUPPORT_DEFAULT OFF)
7072
elseif(ASCEND_SUPPORT)
7173
set(APPLE_SUPPORT_DEFAULT OFF)
7274
set(NVIDIA_SUPPORT_DEFAULT OFF)
7375
set(AMDGPU_SUPPORT_DEFAULT OFF)
7476
set(INTEL_SUPPORT_DEFAULT OFF)
7577
set(MSM_SUPPORT_DEFAULT OFF)
78+
set(PANFROST_SUPPORT_DEFAULT OFF)
79+
set(PANTHOR_SUPPORT_DEFAULT OFF)
7680
set(ASCEND_SUPPORT_DEFAULT ON)
7781
else()
7882
set(APPLE_SUPPORT_DEFAULT OFF)
7983
set(NVIDIA_SUPPORT_DEFAULT ON)
8084
set(AMDGPU_SUPPORT_DEFAULT ON)
8185
set(INTEL_SUPPORT_DEFAULT ON)
8286
set(MSM_SUPPORT_DEFAULT ON)
87+
set(PANFROST_SUPPORT_DEFAULT ON)
88+
set(PANTHOR_SUPPORT_DEFAULT ON)
8389
set(ASCEND_SUPPORT_DEFAULT OFF)
8490
endif()
8591

@@ -88,6 +94,8 @@ option(AMDGPU_SUPPORT "Build support for AMD GPUs through amdgpu driver" ${AMDGP
8894
option(INTEL_SUPPORT "Build support for Intel GPUs through i915 driver" ${INTEL_SUPPORT_DEFAULT})
8995
option(MSM_SUPPORT "Build support for Adreno GPUs through msm driver" ${MSM_SUPPORT_DEFAULT})
9096
option(APPLE_SUPPORT "Build support for Apple GPUs through Metal" ${APPLE_SUPPORT_DEFAULT})
97+
option(PANFROST_SUPPORT "Build support for Mali GPUs through panfrost driver" ${PANFROST_SUPPORT_DEFAULT})
98+
option(PANTHOR_SUPPORT "Build support for Mali GPUs through panthor driver" ${PANTHOR_SUPPORT_DEFAULT})
9199
option(ASCEND_SUPPORT "Build support for Ascend NPUs through Ascend DCMI" ${ASCEND_SUPPORT_DEFAULT})
92100

93101
add_subdirectory(src)

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ FROM ${IMAGE} as builder
1111
ENV DEBIAN_FRONTEND=noninteractive
1212

1313
RUN apt-get update && \
14-
apt-get install -yq build-essential cmake libncurses5-dev libncursesw5-dev \
14+
apt-get install -yq build-essential wget libncurses5-dev libncursesw5-dev libssl-dev \
1515
pkg-config libdrm-dev libgtest-dev libudev-dev
1616

17+
RUN wget https://github.com/Kitware/CMake/releases/download/v3.18.0/cmake-3.18.0.tar.gz
18+
RUN tar zxf cmake-3.18.0.tar.gz
19+
RUN ./cmake-3.18.0/bootstrap --prefix=/usr && make && make install
20+
1721
COPY . /nvtop
1822
WORKDIR /nvtop
1923
RUN mkdir -p /nvtop/build && \

include/nvtop/extract_gpuinfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ bool gpuinfo_fix_dynamic_info_from_process_info(struct list_head *devices);
3838

3939
bool gpuinfo_refresh_processes(struct list_head *devices);
4040

41+
bool gpuinfo_utilisation_rate(struct list_head *devices);
42+
4143
void gpuinfo_clean(struct list_head *devices);
4244

4345
void gpuinfo_clear_cache(void);

include/nvtop/extract_gpuinfo_common.h

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
#include "list.h"
3232

33+
#define STRINGIFY(x) STRINGIFY_HELPER_(x)
34+
#define STRINGIFY_HELPER_(x) #x
35+
3336
#define IS_VALID(x, y) ((y)[(x) / CHAR_BIT] & (1 << ((x) % CHAR_BIT)))
3437
#define SET_VALID(x, y) ((y)[(x) / CHAR_BIT] |= (1 << ((x) % CHAR_BIT)))
3538
#define RESET_VALID(x, y) ((y)[(x) / CHAR_BIT] &= ~(1 << ((x) % CHAR_BIT)))
@@ -55,6 +58,9 @@ enum gpuinfo_static_info_valid {
5558
gpuinfo_max_pcie_link_width_valid,
5659
gpuinfo_temperature_shutdown_threshold_valid,
5760
gpuinfo_temperature_slowdown_threshold_valid,
61+
gpuinfo_n_shared_cores_valid,
62+
gpuinfo_l2cache_size_valid,
63+
gpuinfo_n_exec_engines_valid,
5864
gpuinfo_static_info_count,
5965
};
6066

@@ -66,6 +72,9 @@ struct gpuinfo_static_info {
6672
unsigned max_pcie_link_width;
6773
unsigned temperature_shutdown_threshold;
6874
unsigned temperature_slowdown_threshold;
75+
unsigned n_shared_cores;
76+
unsigned l2cache_size;
77+
unsigned n_exec_engines;
6978
bool integrated_graphics;
7079
unsigned char valid[(gpuinfo_static_info_count + CHAR_BIT - 1) / CHAR_BIT];
7180
};
@@ -146,6 +155,8 @@ enum gpuinfo_process_info_valid {
146155
gpuinfo_process_cpu_usage_valid,
147156
gpuinfo_process_cpu_memory_virt_valid,
148157
gpuinfo_process_cpu_memory_res_valid,
158+
gpuinfo_process_gpu_cycles_valid,
159+
gpuinfo_process_sample_delta_valid,
149160
gpuinfo_process_info_count
150161
};
151162

@@ -154,10 +165,12 @@ struct gpu_process {
154165
pid_t pid; // Process ID
155166
char *cmdline; // Process User Name
156167
char *user_name; // Process User Name
168+
uint64_t sample_delta; // Time spent between two successive samples
157169
uint64_t gfx_engine_used; // Time in nanoseconds this process spent using the GPU gfx
158170
uint64_t compute_engine_used; // Time in nanoseconds this process spent using the GPU compute
159171
uint64_t enc_engine_used; // Time in nanoseconds this process spent using the GPU encoder
160172
uint64_t dec_engine_used; // Time in nanoseconds this process spent using the GPU decoder
173+
uint64_t gpu_cycles; // Number of GPU cycles spent in the GPU gfx engine
161174
unsigned gpu_usage; // Percentage of GPU used by the process
162175
unsigned encode_usage; // Percentage of GPU encoder used by the process
163176
unsigned decode_usage; // Percentage of GPU decoder used by the process
@@ -184,6 +197,7 @@ struct gpu_vendor {
184197

185198
void (*populate_static_info)(struct gpu_info *gpu_info);
186199
void (*refresh_dynamic_info)(struct gpu_info *gpu_info);
200+
void (*refresh_utilisation_rate)(struct gpu_info *gpu_info);
187201

188202
void (*refresh_running_processes)(struct gpu_info *gpu_info);
189203
char *name;
@@ -205,6 +219,8 @@ void register_gpu_vendor(struct gpu_vendor *vendor);
205219

206220
bool extract_drm_fdinfo_key_value(char *buf, char **key, char **val);
207221

222+
void gpuinfo_refresh_utilisation_rate(struct gpu_info *gpu_info);
223+
208224
// fdinfo DRM interface names common to multiple drivers
209225
extern const char drm_pdev[];
210226
extern const char drm_client_id[];

include/nvtop/interface_internal_common.h

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ struct device_window {
6565
WINDOW *gpu_clock_info;
6666
WINDOW *mem_clock_info;
6767
WINDOW *pcie_info;
68+
WINDOW *shader_cores;
69+
WINDOW *l2_cache_size;
70+
WINDOW *exec_engines;
6871
bool enc_was_visible;
6972
bool dec_was_visible;
7073
nvtop_time last_decode_seen;
@@ -140,6 +143,9 @@ enum device_field {
140143
device_power,
141144
device_pcie,
142145
device_clock,
146+
device_shadercores,
147+
device_l2features,
148+
device_execengines,
143149
device_field_count,
144150
};
145151

include/nvtop/interface_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ typedef struct nvtop_interface_option_struct {
4949
// process list are displayed
5050
bool show_startup_messages; // True to show the startup messages
5151
bool filter_nvtop_pid; // Do not show nvtop pid in the processes list
52-
bool has_monitored_set_changed; // True if the set of monitored gpu was modified through the interface
52+
bool has_monitored_set_changed; // True if the set of monitored gpu was modified through the interface
53+
bool has_gpu_info_bar; // Show info bar with additional GPU parametres
5354
} nvtop_interface_option;
5455

5556
inline bool plot_isset_draw_info(enum plot_information check_info, plot_info_to_draw to_draw) {

src/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ if(AMDGPU_SUPPORT OR MSM_SUPPORT)
9090
target_sources(nvtop PRIVATE extract_gpuinfo_msm.c)
9191
target_sources(nvtop PRIVATE extract_gpuinfo_msm_utils.c)
9292
endif()
93+
9394
else()
9495
message(FATAL_ERROR "libdrm not found; This library is required for AMDGPU and MSM support")
9596
endif()
@@ -109,6 +110,20 @@ if(APPLE_SUPPORT)
109110
"-framework IOKit")
110111
endif()
111112

113+
if (PANFROST_SUPPORT)
114+
target_sources(nvtop PRIVATE extract_gpuinfo_panfrost.c)
115+
target_sources(nvtop PRIVATE extract_gpuinfo_panfrost_utils.c)
116+
endif()
117+
118+
if (PANTHOR_SUPPORT)
119+
target_sources(nvtop PRIVATE extract_gpuinfo_panthor.c)
120+
target_sources(nvtop PRIVATE extract_gpuinfo_panthor_utils.c)
121+
endif()
122+
123+
if ((PANFROST_SUPPORT) OR (PANTHOR_SUPPORT))
124+
target_sources(nvtop PRIVATE extract_gpuinfo_mali_common.c)
125+
endif()
126+
112127
target_include_directories(nvtop PRIVATE
113128
${PROJECT_SOURCE_DIR}/include
114129
${PROJECT_BINARY_DIR}/include)

src/extract_gpuinfo.c

+48
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ bool gpuinfo_refresh_processes(struct list_head *devices) {
253253
return true;
254254
}
255255

256+
bool gpuinfo_utilisation_rate(struct list_head *devices) {
257+
struct gpu_info *device;
258+
259+
list_for_each_entry(device, devices, list) {
260+
if (device->vendor->refresh_utilisation_rate)
261+
device->vendor->refresh_utilisation_rate(device);
262+
}
263+
264+
return true;
265+
}
266+
256267
void gpuinfo_clear_cache(void) {
257268
if (cached_process_info) {
258269
struct process_info_cache *pid_cached, *tmp;
@@ -311,3 +322,40 @@ unsigned nvtop_pcie_gen_from_link_speed(unsigned linkSpeed) {
311322
}
312323
return pcieGen;
313324
}
325+
326+
void gpuinfo_refresh_utilisation_rate(struct gpu_info *gpu_info) {
327+
/*
328+
* kernel Documentation/gpu/drm-usage-stats.rst:
329+
* - drm-maxfreq-<keystr>: <uint> [Hz|MHz|KHz]
330+
* Engine identifier string must be the same as the one specified in the
331+
* drm-engine-<keystr> tag and shall contain the maximum frequency for the given
332+
* engine. Taken together with drm-cycles-<keystr>, this can be used to calculate
333+
* percentage utilization of the engine, whereas drm-engine-<keystr> only reflects
334+
* time active without considering what frequency the engine is operating as a
335+
* percentage of it's maximum frequency.
336+
*
337+
*/
338+
339+
uint64_t gfx_total_process_cycles = 0;
340+
uint64_t total_delta = 0;
341+
unsigned int utilisation_rate;
342+
uint64_t max_freq_hz;
343+
double avg_delta_secs;
344+
345+
for (unsigned processIdx = 0; processIdx < gpu_info->processes_count; ++processIdx) {
346+
struct gpu_process *process_info = &gpu_info->processes[processIdx];
347+
348+
gfx_total_process_cycles += process_info->gpu_cycles;
349+
total_delta += process_info->sample_delta;
350+
}
351+
352+
if (!gfx_total_process_cycles)
353+
return;
354+
355+
avg_delta_secs = ((double)total_delta / gpu_info->processes_count) / 1000000000.0;
356+
max_freq_hz = gpu_info->dynamic_info.gpu_clock_speed_max * 1000000;
357+
utilisation_rate = (unsigned int)((((double)gfx_total_process_cycles) / (((double)max_freq_hz) * avg_delta_secs * 2)) * 100);
358+
utilisation_rate = utilisation_rate > 100 ? 100 : utilisation_rate;
359+
360+
SET_GPUINFO_DYNAMIC(&gpu_info->dynamic_info, gpu_util_rate, utilisation_rate);
361+
}

0 commit comments

Comments
 (0)