From f8d5f56deeac8718b93b78e8396df7c0c9462707 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 8 Jul 2024 09:11:53 +0800 Subject: [PATCH] GPU (Linux): remove possible overhead --- src/common/io/io.h | 24 ++++++++++++++++-------- src/detection/gpu/gpu_linux.c | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/common/io/io.h b/src/common/io/io.h index 305cb03e7..2958ac454 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -101,17 +101,25 @@ static inline bool ffPathExists(const char* path, FFPathType pathType) #else - struct stat fileStat; - if(stat(path, &fileStat) != 0) - return false; + if (pathType == FF_PATHTYPE_ANY) + { + // Zero overhead + return access(path, F_OK) == 0; + } + else + { + struct stat fileStat; + if(stat(path, &fileStat) != 0) + return false; - unsigned int mode = fileStat.st_mode & S_IFMT; + unsigned int mode = fileStat.st_mode & S_IFMT; - if(pathType & FF_PATHTYPE_FILE && mode != S_IFDIR) - return true; + if(pathType & FF_PATHTYPE_FILE && mode != S_IFDIR) + return true; - if(pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR) - return true; + if(pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR) + return true; + } #endif diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 96921085d..dc860b099 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -78,7 +78,7 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, const uint32_t hwmonLen = pciDir->length; ffStrbufAppendS(pciDir, "in1_input"); // Northbridge voltage in millivolts (APUs only) - if (ffPathExists(pciDir->chars, FF_PATHTYPE_FILE)) + if (ffPathExists(pciDir->chars, FF_PATHTYPE_ANY)) gpu->type = FF_GPU_TYPE_INTEGRATED; else gpu->type = FF_GPU_TYPE_DISCRETE;