Skip to content

Commit 4daa109

Browse files
Syllomaxious
authored andcommitted
Merge pull request Syllo#413 from polluks/master
Update nvtop manpage with additional options
2 parents 5f6d3df + 7563806 commit 4daa109

File tree

5 files changed

+393
-12
lines changed

5 files changed

+393
-12
lines changed

manpage/nvtop.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ nvtop \- interactive GPU process viewer
88

99
.SH SYNOPSIS
1010
.B nvtop
11-
\fR[\fB\-hv\fR]
11+
\fR[\fB\-hvCfpPris\fR]
1212
\fR[\fB\-d\fR \fIdelay\fR]
13+
\fR[\fB\-c\fR \fIconfig-file\fR]
14+
\fR[\fB\-E\fR \fIseconds\fR]
1315

1416
.SH DESCRIPTION
1517
nvtop is a ncurses\-based GPU status viewer for AMD, Intel and NVIDIA GPUs.

src/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ if(INTEL_SUPPORT)
101101
target_sources(nvtop PRIVATE extract_gpuinfo_intel.c)
102102
target_sources(nvtop PRIVATE extract_gpuinfo_intel_i915.c)
103103
target_sources(nvtop PRIVATE extract_gpuinfo_intel_xe.c)
104+
105+
find_library(LIBXPUM
106+
NAMES libxpum.so
107+
PATHS /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib64 /usr/local/lib
108+
HINTS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/lib64
109+
)
110+
if(LIBXPUM)
111+
message(STATUS "Found libxpum.so; Intel XPU Manager support enabled")
112+
target_sources(nvtop PRIVATE extract_gpuinfo_intel_xpumanager.c)
113+
target_link_libraries(nvtop PRIVATE "${LIBXPUM}")
114+
else()
115+
message(STATUS "libxpum.so not found; XPU Manager metrics will not be available")
116+
endif()
104117
endif()
105118

106119
if(V3D_SUPPORT)

src/extract_gpuinfo_intel.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,20 @@ static struct gpu_info_intel *gpu_infos;
6666

6767
__attribute__((constructor)) static void init_extract_gpuinfo_intel(void) { register_gpu_vendor(&gpu_vendor_intel); }
6868

69-
bool gpuinfo_intel_init(void) { return true; }
69+
bool gpuinfo_intel_init(void) {
70+
gpuinfo_intel_xpumanager_init();
71+
return true;
72+
}
73+
7074
void gpuinfo_intel_shutdown(void) {
71-
for (unsigned i = 0; i < intel_gpu_count; ++i) {
72-
struct gpu_info_intel *current = &gpu_infos[i];
73-
if (current->card_fd)
74-
close(current->card_fd);
75-
nvtop_device_unref(current->card_device);
76-
nvtop_device_unref(current->driver_device);
77-
}
75+
for (unsigned i = 0; i < intel_gpu_count; ++i) {
76+
struct gpu_info_intel *current = &gpu_infos[i];
77+
if (current->card_fd)
78+
close(current->card_fd);
79+
nvtop_device_unref(current->card_device);
80+
nvtop_device_unref(current->driver_device);
81+
}
82+
gpuinfo_intel_xpumanager_shutdown();
7883
}
7984

8085
const char *gpuinfo_intel_last_error_string(void) { return "Err"; }
@@ -109,6 +114,7 @@ static void add_intel_cards(struct nvtop_device *dev, struct list_head *devices,
109114
thisGPU->card_device = nvtop_device_ref(dev);
110115
thisGPU->driver_device = nvtop_device_ref(parent);
111116
thisGPU->hwmon_device = nvtop_device_get_hwmon(thisGPU->driver_device);
117+
thisGPU->xpum_device_id = -1;
112118

113119
const char *devname;
114120
if (nvtop_device_get_devname(thisGPU->card_device, &devname) >= 0)
@@ -118,6 +124,12 @@ static void add_intel_cards(struct nvtop_device *dev, struct list_head *devices,
118124
int retval = nvtop_device_get_property_value(thisGPU->driver_device, "PCI_SLOT_NAME", &pdev_val);
119125
assert(retval >= 0 && pdev_val != NULL && "Could not retrieve device PCI slot name");
120126
strncpy(thisGPU->base.pdev, pdev_val, PDEV_LEN);
127+
128+
if (gpuinfo_intel_xpumanager_is_available()) {
129+
gpuinfo_intel_xpumanager_get_device_id(pdev_val, &thisGPU->xpum_device_id);
130+
gpuinfo_intel_xpumanager_populate_static_info(&thisGPU->base, thisGPU->xpum_device_id);
131+
}
132+
121133
list_add_tail(&thisGPU->base.list, devices);
122134
// Register a fdinfo callback for this GPU
123135
processinfo_register_fdinfo_callback(parse_drm_fdinfo_intel, &thisGPU->base);
@@ -224,6 +236,13 @@ void gpuinfo_intel_refresh_dynamic_info(struct gpu_info *_gpu_info) {
224236

225237
RESET_ALL(dynamic_info->valid);
226238

239+
if (gpu_info->xpum_device_id >= 0 && gpuinfo_intel_xpumanager_is_available()) {
240+
gpuinfo_intel_xpumanager_refresh_dynamic_info(_gpu_info, gpu_info->xpum_device_id);
241+
if (GPUINFO_DYNAMIC_FIELD_VALID(dynamic_info, gpu_util_rate)) {
242+
return;
243+
}
244+
}
245+
227246
// We are creating new devices because the device_get_sysattr_value caches its querries
228247
const char *syspath;
229248
nvtop_device *card_dev_noncached = NULL;

src/extract_gpuinfo_intel.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
#include <stdint.h>
2-
#include <uthash.h>
1+
#include <stdio.h>
2+
#include <limits.h>
3+
#include <stdbool.h>
4+
#include <string.h>
5+
#include <unistd.h>
6+
#include <fcntl.h>
7+
#include <stdlib.h>
8+
#include <time.h>
9+
#include "list.h"
10+
#include "uthash.h"
11+
#include <nvtop/time.h>
12+
#include <nvtop/extract_gpuinfo_common.h>
313

414
#define HASH_FIND_CLIENT(head, key_ptr, out_ptr) HASH_FIND(hh, head, key_ptr, sizeof(struct unique_cache_id), out_ptr)
515
#define HASH_ADD_CLIENT(head, in_ptr) HASH_ADD(hh, head, client_id, sizeof(struct unique_cache_id), in_ptr)
@@ -59,10 +69,12 @@ struct gpu_info_intel {
5969

6070
struct nvtop_device *driver_device;
6171
struct nvtop_device *hwmon_device;
62-
struct intel_process_info_cache *last_update_process_cache, *current_update_process_cache; // Cached processes info
72+
struct intel_process_info_cache *last_update_process_cache, *current_update_process_cache;
6373

6474
struct nvtop_device *bridge_device;
6575

76+
int xpum_device_id;
77+
6678
struct {
6779
unsigned energy_uj;
6880
struct timespec time;
@@ -74,3 +86,10 @@ extern void gpuinfo_intel_xe_refresh_dynamic_info(struct gpu_info *_gpu_info);
7486

7587
extern bool parse_drm_fdinfo_intel_i915(struct gpu_info *info, FILE *fdinfo_file, struct gpu_process *process_info);
7688
extern bool parse_drm_fdinfo_intel_xe(struct gpu_info *info, FILE *fdinfo_file, struct gpu_process *process_info);
89+
90+
extern bool gpuinfo_intel_xpumanager_init(void);
91+
extern void gpuinfo_intel_xpumanager_shutdown(void);
92+
extern bool gpuinfo_intel_xpumanager_get_device_id(const char *pci_bdf, int *device_id);
93+
extern void gpuinfo_intel_xpumanager_populate_static_info(struct gpu_info *gpu_info, int xpum_device_id);
94+
extern void gpuinfo_intel_xpumanager_refresh_dynamic_info(struct gpu_info *gpu_info, int xpum_device_id);
95+
extern bool gpuinfo_intel_xpumanager_is_available(void);

0 commit comments

Comments
 (0)