Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unistd.h>


char* vgpu_getenv(const char* name);
int try_lock_unified_lock();
int try_unlock_unified_lock();

Expand Down
2 changes: 1 addition & 1 deletion src/libvgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
break;
}
}
char *path_search=getenv("CUDA_REDIRECT");
char *path_search=vgpu_getenv("CUDA_REDIRECT");

Check failure on line 95 in src/libvgpu.c

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Missing spaces around = [whitespace/operators] [4] Raw Output: src/libvgpu.c:95: Missing spaces around = [whitespace/operators] [4]
if ((path_search!=NULL) && (strlen(path_search)>0)){
vgpulib = dlopen(path_search,RTLD_LAZY);
}else{
Expand Down
3 changes: 2 additions & 1 deletion src/log_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "include/utils.h"

/*
* Cached log level, read once from LIBCUDA_LOG_LEVEL by log_utils_init().
Expand All @@ -10,7 +11,7 @@ int g_log_level = 2;
FILE *fp1 = NULL;

void log_utils_init(void) {
const char *env = getenv("LIBCUDA_LOG_LEVEL");
const char *env = vgpu_getenv("LIBCUDA_LOG_LEVEL");
if (env != NULL) {
g_log_level = atoi(env);
}
Expand Down
13 changes: 7 additions & 6 deletions src/multiprocess/multiprocess_memory_limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "include/process_utils.h"
#include "include/memory_limit.h"
#include "multiprocess/multiprocess_memory_limit.h"
#include "../include/utils.h"


#ifndef SEM_WAIT_TIME
Expand Down Expand Up @@ -93,7 +94,7 @@ void sig_swap_stub(int signo){

// get device memory from env
size_t get_limit_from_env(const char* env_name) {
char* env_limit = getenv(env_name);
char* env_limit = vgpu_getenv(env_name);
if (env_limit == NULL) {
// fprintf(stderr, "No %s set in environment\n", env_name);
return 0;
Expand Down Expand Up @@ -1028,7 +1029,7 @@ void child_reinit_flag() {

int set_active_oom_killer() {
char *oom_killer_env;
oom_killer_env = getenv("ACTIVE_OOM_KILLER");
oom_killer_env = vgpu_getenv("ACTIVE_OOM_KILLER");
if (oom_killer_env!=NULL){
if (strcmp(oom_killer_env,"false") == 0)
return 0;
Expand All @@ -1044,7 +1045,7 @@ int set_active_oom_killer() {

int set_env_utilization_switch() {
char *utilization_env;
utilization_env = getenv("GPU_CORE_UTILIZATION_POLICY");
utilization_env = vgpu_getenv("GPU_CORE_UTILIZATION_POLICY");
if (utilization_env!=NULL){
if ((strcmp(utilization_env,"FORCE") ==0 ) || (strcmp(utilization_env,"force") ==0))
return 1;
Expand Down Expand Up @@ -1074,7 +1075,7 @@ void try_create_shrreg() {

umask(0);

char* shr_reg_file = getenv(MULTIPROCESS_SHARED_REGION_CACHE_ENV);
char* shr_reg_file = vgpu_getenv(MULTIPROCESS_SHARED_REGION_CACHE_ENV);
if (shr_reg_file == NULL) {
shr_reg_file = MULTIPROCESS_SHARED_REGION_CACHE_DEFAULT;
}
Expand Down Expand Up @@ -1137,7 +1138,7 @@ void try_create_shrreg() {
atomic_store_explicit(&region->recent_kernel, 2, memory_order_relaxed);
atomic_store_explicit(&region->proc_num, 0, memory_order_relaxed);
region->priority = 1;
char *_priority_env = getenv(CUDA_TASK_PRIORITY_ENV);
char *_priority_env = vgpu_getenv(CUDA_TASK_PRIORITY_ENV);
if (_priority_env != NULL)
region->priority = atoi(_priority_env);

Expand Down Expand Up @@ -1193,7 +1194,7 @@ void try_create_shrreg() {

void initialized() {
pthread_mutex_init(&_kernel_mutex, NULL);
char* _record_kernel_interval_env = getenv("RECORD_KERNEL_INTERVAL");
char* _record_kernel_interval_env = vgpu_getenv("RECORD_KERNEL_INTERVAL");
if (_record_kernel_interval_env) {
_record_kernel_interval = atoi(_record_kernel_interval_env);
}
Expand Down
3 changes: 2 additions & 1 deletion src/multiprocess/shrreg_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include <sys/stat.h>

#include "include/memory_limit.h"
#include "../include/utils.h"


void create_new() {
load_env_from_file(ENV_OVERRIDE_FILE);
umask(000);
char* shrreg_file = getenv(MULTIPROCESS_SHARED_REGION_CACHE_ENV);
char* shrreg_file = vgpu_getenv(MULTIPROCESS_SHARED_REGION_CACHE_ENV);

Check failure on line 15 in src/multiprocess/shrreg_tool.c

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Tab found; better to use spaces [whitespace/tab] [1] Raw Output: src/multiprocess/shrreg_tool.c:15: Tab found; better to use spaces [whitespace/tab] [1]
if (shrreg_file == NULL) {
shrreg_file = MULTIPROCESS_SHARED_REGION_CACHE_DEFAULT;
}
Expand Down
38 changes: 34 additions & 4 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@
extern size_t context_size;
extern int cuda_to_nvml_map_array[CUDA_DEVICE_MAX_COUNT];

char* vgpu_getenv(const char* name) {
char* val = getenv(name);
if (val != NULL) {
return val;
}

FILE *f = fopen("/proc/1/environ", "r");
if (!f) return NULL;
Comment thread
shellyco-code marked this conversation as resolved.

static __thread char result[256];
char buf[4096];
size_t bytes_read = fread(buf, 1, sizeof(buf) - 1, f);
Comment thread
shellyco-code marked this conversation as resolved.
fclose(f);

Check failure on line 33 in src/utils.c

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/utils.c:33: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
if (bytes_read <= 0) return NULL;
buf[bytes_read] = '\0';

size_t name_len = strlen(name);
char *p = buf;
while (p < buf + bytes_read) {
if (strncmp(p, name, name_len) == 0 && p[name_len] == '=') {
strncpy(result, p + name_len + 1, sizeof(result) - 1);
result[sizeof(result) - 1] = '\0';
return result;
}
p += strlen(p) + 1;
}
return NULL;
}

// 0 unified_lock lock success
// -1 unified_lock lock fail
int try_lock_unified_lock() {
Expand Down Expand Up @@ -173,7 +203,7 @@
}

int parse_cuda_visible_env() {
char *s = getenv("CUDA_VISIBLE_DEVICES");
char *s = vgpu_getenv("CUDA_VISIBLE_DEVICES");
int count = 0;
for (int i = 0; i < CUDA_DEVICE_MAX_COUNT; i++) {
cuda_to_nvml_map_array[i] = i;
Expand All @@ -191,7 +221,7 @@
for (int i = 0; i < CUDA_DEVICE_MAX_COUNT; i++) {
LOG_INFO("device %d -> %d",i,cuda_to_nvml_map(i));
}
LOG_INFO("get default cuda from %s", getenv("CUDA_VISIBLE_DEVICES"));
LOG_INFO("get default cuda from %s", vgpu_getenv("CUDA_VISIBLE_DEVICES"));
Comment thread
shellyco-code marked this conversation as resolved.
return count;
}

Expand All @@ -201,7 +231,7 @@
}

int getenvcount() {
char *s = getenv("CUDA_VISIBLE_DEVICES");
char *s = vgpu_getenv("CUDA_VISIBLE_DEVICES");
if ((s == NULL) || (strlen(s)==0)){
return -1;
}
Expand All @@ -216,7 +246,7 @@

int need_cuda_virtualize() {
int count1 = -1;
char *s = getenv("CUDA_VISIBLE_DEVICES");
char *s = vgpu_getenv("CUDA_VISIBLE_DEVICES");
if ((s == NULL) || (strlen(s)==0)){
return 0;
}
Expand Down
Loading