Skip to content

Commit

Permalink
Merge pull request Syllo#247 from Syllo/deactivate_callback_for_hidde…
Browse files Browse the repository at this point in the history
…n_gpus

Deactivate callback for hidden gpus
  • Loading branch information
Syllo authored Oct 21, 2023
2 parents 11abc2c + d70c8a2 commit 45a1796
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
8 changes: 8 additions & 0 deletions include/nvtop/extract_processinfo_fdinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ void processinfo_register_fdinfo_callback(processinfo_fdinfo_callback callback,
*/
void processinfo_drop_callback(const struct gpu_info *info);

/**
* @brief Enables or disables a fdinfo processing callback
*
* @param info Enabling/Disabling the callback to this gpu_info
* @param enable True to enable the callback, false to disable
*/
void processinfo_enable_disable_callback_for(const struct gpu_info *info, bool enable);

/**
* @brief Scann all the processes in /proc. Call the registered callbacks on
* each file descriptor to the DRM driver that can successfully be oppened. If a
Expand Down
2 changes: 2 additions & 0 deletions src/extract_gpuinfo_amdgpu_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "amdgpu_ids.h"

const char *amdgpu_parse_marketing_name(struct amdgpu_gpu_info *info);

const char * amdgpu_parse_marketing_name(struct amdgpu_gpu_info *info)
{
int i;
Expand Down
11 changes: 5 additions & 6 deletions src/extract_gpuinfo_msm.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ static int gpuinfo_msm_query_param(int gpu, uint32_t param, uint64_t *value) {
void gpuinfo_msm_populate_static_info(struct gpu_info *_gpu_info) {
struct gpu_info_msm *gpu_info = container_of(_gpu_info, struct gpu_info_msm, base);
struct gpuinfo_static_info *static_info = &gpu_info->base.static_info;
const char *dev_name;

static_info->integrated_graphics = true;
RESET_ALL(static_info->valid);
Expand All @@ -488,18 +487,18 @@ static const char meminfo_available[] = "MemAvailable";

void gpuinfo_msm_refresh_dynamic_info(struct gpu_info *_gpu_info) {
struct gpu_info_msm *gpu_info = container_of(_gpu_info, struct gpu_info_msm, base);
struct gpuinfo_static_info *static_info = &gpu_info->base.static_info;
// struct gpuinfo_static_info *static_info = &gpu_info->base.static_info;
struct gpuinfo_dynamic_info *dynamic_info = &gpu_info->base.dynamic_info;

RESET_ALL(dynamic_info->valid);
dynamic_info->encode_decode_shared = true;

// GPU clock
uint64_t val;
if (gpuinfo_msm_query_param(gpu_info->fd, MSM_PARAM_MAX_FREQ, &val) == 0) {
uint64_t clock_val;
if (gpuinfo_msm_query_param(gpu_info->fd, MSM_PARAM_MAX_FREQ, &clock_val) == 0) {
// TODO: No way to query current clock speed.
SET_GPUINFO_DYNAMIC(dynamic_info, gpu_clock_speed, val / 1000000);
SET_GPUINFO_DYNAMIC(dynamic_info, gpu_clock_speed_max, val / 1000000);
SET_GPUINFO_DYNAMIC(dynamic_info, gpu_clock_speed, clock_val / 1000000);
SET_GPUINFO_DYNAMIC(dynamic_info, gpu_clock_speed_max, clock_val / 1000000);
}

// Mem clock
Expand Down
2 changes: 2 additions & 0 deletions src/extract_gpuinfo_msm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static const struct msm_id_struct msm_ids[] = {
{0x006006030500, "Adreno 7c+ Gen 3 Lite"},
};

const char * msm_parse_marketing_name(uint64_t gpu_id);

const char * msm_parse_marketing_name(uint64_t gpu_id) {
for (unsigned i = 0; i < ARRAY_SIZE(msm_ids); i++) {
if (gpu_id == msm_ids[i].id) {
Expand Down
23 changes: 21 additions & 2 deletions src/extract_processinfo_fdinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "nvtop/extract_processinfo_fdinfo.h"
#include "nvtop/common.h"
#include "nvtop/extract_gpuinfo_common.h"

#include <ctype.h>
#include <dirent.h>
Expand All @@ -38,6 +39,7 @@
struct callback_entry {
struct gpu_info *gpu_info;
processinfo_fdinfo_callback callback;
bool active;
};

static unsigned registered_callback_entries;
Expand Down Expand Up @@ -66,9 +68,18 @@ void processinfo_register_fdinfo_callback(processinfo_fdinfo_callback callback,
}
callback_entries[registered_callback_entries].gpu_info = info;
callback_entries[registered_callback_entries].callback = callback;
callback_entries[registered_callback_entries].active = true;
registered_callback_entries++;
}

void processinfo_enable_disable_callback_for(const struct gpu_info *info, bool enable) {
for (unsigned index = 0; index < registered_callback_entries; ++index) {
if (callback_entries[index].gpu_info == info) {
callback_entries[index].active = enable;
}
}
}

static bool is_drm_fd(int fd_dir_fd, const char *name) {
struct stat stat;
int ret;
Expand All @@ -83,7 +94,12 @@ static bool is_drm_fd(int fd_dir_fd, const char *name) {
#define DRM_FD_LINEAR_REALLOC_INC 8

void processinfo_sweep_fdinfos(void) {
if (registered_callback_entries == 0)
bool anyActiveCallback = false;
for (unsigned callback_idx = 0; !anyActiveCallback && callback_idx < registered_callback_entries; ++callback_idx) {
struct callback_entry *current_callback = &callback_entries[callback_idx];
anyActiveCallback = anyActiveCallback || current_callback->active;
}
if (!anyActiveCallback)
return;

DIR *proc_dir = opendir("/proc");
Expand Down Expand Up @@ -178,7 +194,10 @@ void processinfo_sweep_fdinfos(void) {
RESET_ALL(processes_info_local.valid);
processes_info_local.type = gpu_process_unknown;
current_callback = &callback_entries[callback_idx];
callback_success = current_callback->callback(current_callback->gpu_info, fdinfo_file, &processes_info_local);
if (current_callback->active)
callback_success = current_callback->callback(current_callback->gpu_info, fdinfo_file, &processes_info_local);
else
callback_success = false;
}
fclose(fdinfo_file);
if (!callback_success)
Expand Down
3 changes: 3 additions & 0 deletions src/interface_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "nvtop/interface_options.h"
#include "ini.h"
#include "nvtop/extract_processinfo_fdinfo.h"
#include "nvtop/interface_common.h"

#include <assert.h>
Expand Down Expand Up @@ -98,6 +99,8 @@ unsigned interface_check_and_fix_monitored_gpus(unsigned num_devices, struct lis
options->gpu_specific_opts[0].doNotMonitor = false;
numMonitored++;
}
list_for_each_entry(device, monitoredGpu, list) { processinfo_enable_disable_callback_for(device, true); }
list_for_each_entry(device, nonMonitoredGpu, list) { processinfo_enable_disable_callback_for(device, false); }
return numMonitored;
}

Expand Down

0 comments on commit 45a1796

Please sign in to comment.