game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
system_info_service.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// system_info_service.cpp
4// ==============================================================================
5// Implementation of centralized system detection service
6// ==============================================================================
7
9#include "logger.h"
10#include "steam_integration.h"
11
12#include <algorithm>
13#include <cctype>
14#include <cstdlib>
15#include <filesystem>
16#include <fstream>
17#include <regex>
18#include <sstream>
19#include <sys/resource.h>
20#include <sys/statvfs.h>
21
22// ==============================================================================
23// Singleton Instance
24// ==============================================================================
25
31
32// Lazy initialization - detection happens on first access.
34
35// ==============================================================================
36// Quick Access Methods
37// ==============================================================================
38
40{
41 std::lock_guard<std::mutex> lock(mutex_);
42 if (!initialized_)
43 {
44 detectGPU();
45 }
46 return capabilities_.gpu.vendor;
47}
48
50{
51 std::lock_guard<std::mutex> lock(mutex_);
52 if (!initialized_)
53 {
54 detectGPU();
55 }
56 return capabilities_.gpu.vendorName;
57}
58
60{
61 std::lock_guard<std::mutex> lock(mutex_);
62 if (!initialized_)
63 {
64 detectKernel();
65 }
66 return capabilities_.kernel.isCachyOS;
67}
68
70{
71 std::lock_guard<std::mutex> lock(mutex_);
72 if (!initialized_)
73 {
74 detectKernel();
75 }
76 return capabilities_.kernel.supportsFsync;
77}
78
80{
81 std::lock_guard<std::mutex> lock(mutex_);
82 if (!initialized_)
83 {
84 detectKernel();
85 }
86 return capabilities_.kernel.supportsNTSync;
87}
88
90{
91 std::lock_guard<std::mutex> lock(mutex_);
92 if (!initialized_)
93 {
94 detectKernel();
95 }
96 return capabilities_.getRecommendedSyncMethod();
97}
98
100{
101 std::lock_guard<std::mutex> lock(mutex_);
102 if (!initialized_)
103 {
104 detectDisplayServer();
105 }
106 return capabilities_.displayServer;
107}
108
109// ==============================================================================
110// Detailed Info Methods
111// ==============================================================================
112
114{
115 std::lock_guard<std::mutex> lock(mutex_);
116 if (!initialized_)
117 {
118 detectGPU();
119 }
120 return capabilities_.gpu;
121}
122
124{
125 std::lock_guard<std::mutex> lock(mutex_);
126 if (!initialized_)
127 {
128 detectCPU();
129 }
130 return capabilities_.cpu;
131}
132
134{
135 std::lock_guard<std::mutex> lock(mutex_);
136 if (!initialized_)
137 {
138 detectKernel();
139 }
140 return capabilities_.kernel;
141}
142
144{
145 std::lock_guard<std::mutex> lock(mutex_);
146 if (!initialized_)
147 {
148 detectTools();
149 }
150 return capabilities_.tools;
151}
152
153const std::vector<RunnerInfo>& SystemInfoService::getInstalledRunners()
154{
155 std::lock_guard<std::mutex> lock(mutex_);
156 if (!initialized_ || capabilities_.runners.empty())
157 {
158 detectRunners();
159 }
160 return capabilities_.runners;
161}
162
164{
165 std::lock_guard<std::mutex> lock(mutex_);
166 if (!initialized_)
167 {
168 detectGPU();
169 detectCPU();
170 detectKernel();
171 detectMemory();
172 detectTools();
173 detectRunners();
174 detectDisplayServer();
175 detectMonitors();
176 detectControllers();
177 detectStorage();
178 detectPower();
179 detectSystemReadiness();
180 initialized_ = true;
181 lastFullRefresh_ = std::chrono::steady_clock::now();
182 }
183 return capabilities_;
184}
185
187{
188 std::lock_guard<std::mutex> lock(mutex_);
189 if (!initialized_)
190 {
191 detectMemory();
192 }
193 return capabilities_.memory;
194}
195
196const std::vector<MonitorInfo>& SystemInfoService::getMonitors()
197{
198 std::lock_guard<std::mutex> lock(mutex_);
199 if (!initialized_)
200 {
201 detectMonitors();
202 }
203 return capabilities_.monitors;
204}
205
206const std::vector<ControllerInfo>& SystemInfoService::getControllers()
207{
208 std::lock_guard<std::mutex> lock(mutex_);
209 if (!initialized_)
210 {
211 detectControllers();
212 }
213 return capabilities_.controllers;
214}
215
216const std::vector<StorageInfo>& SystemInfoService::getStorageInfo()
217{
218 std::lock_guard<std::mutex> lock(mutex_);
219 if (!initialized_)
220 {
221 detectStorage();
222 }
223 return capabilities_.storage;
224}
225
227{
228 std::lock_guard<std::mutex> lock(mutex_);
229 if (!initialized_)
230 {
231 detectPower();
232 }
233 return capabilities_.power;
234}
235
237{
238 std::lock_guard<std::mutex> lock(mutex_);
239 if (!initialized_)
240 {
241 detectSystemReadiness();
242 }
243 return capabilities_.systemReadiness;
244}
245
246// ==============================================================================
247// Refresh Methods
248// ==============================================================================
249
251{
252 std::lock_guard<std::mutex> lock(mutex_);
253 initialized_ = false;
254 capabilities_ = SystemCapabilities{};
255
256 detectGPU();
257 detectCPU();
258 detectKernel();
259 detectMemory();
260 detectTools();
261 detectRunners();
262 detectDisplayServer();
263 detectMonitors();
264 detectControllers();
265 detectStorage();
266 detectPower();
267 detectSystemReadiness();
268
269 initialized_ = true;
270 lastFullRefresh_ = std::chrono::steady_clock::now();
271 Logger::info("System info refreshed");
272}
273
275{
276 std::lock_guard<std::mutex> lock(mutex_);
277 capabilities_.runners.clear();
278 detectRunners();
279 lastRunnerRefresh_ = std::chrono::steady_clock::now();
280}
281
282bool SystemInfoService::isToolAvailable(const std::string& toolName)
283{
284 return !getToolPath(toolName).empty();
285}
286
287std::string SystemInfoService::getToolPath(const std::string& toolName)
288{
289 // Check common paths
290 std::vector<std::string> searchPaths = {
291 "/usr/bin/" + toolName,
292 "/usr/local/bin/" + toolName,
293 "/bin/" + toolName,
294 };
295
296 // Also check PATH
297 if (const char* pathEnv = std::getenv("PATH"))
298 {
299 std::istringstream pathStream(pathEnv);
300 std::string pathDir;
301 while (std::getline(pathStream, pathDir, ':'))
302 {
303 searchPaths.push_back(pathDir + "/" + toolName);
304 }
305 }
306
307 for (const auto& path : searchPaths)
308 {
309 if (std::filesystem::exists(path))
310 {
311 return path;
312 }
313 }
314
315 return "";
316}
317
318// ==============================================================================
319// Detection Methods
320// ==============================================================================
321
322void SystemInfoService::detectGPU()
323{
324 GPUInfo& gpu = capabilities_.gpu;
325 std::string pciSlot; // Store PCI slot for lspci lookup
326
327 // Try reading from /sys/class/drm
328 try
329 {
330 for (const auto& entry : std::filesystem::directory_iterator("/sys/class/drm"))
331 {
332 std::string name = entry.path().filename().string();
333 if (name.find("card") == 0 && name.find("-") == std::string::npos)
334 {
335 std::filesystem::path devicePath = entry.path() / "device";
336
337 // Read vendor ID
338 std::filesystem::path vendorPath = devicePath / "vendor";
339 if (std::filesystem::exists(vendorPath))
340 {
341 std::ifstream vendorFile(vendorPath);
342 std::string vendorId;
343 if (vendorFile >> vendorId)
344 {
345 if (vendorId == "0x1002" || vendorId == "0x1022")
346 {
348 gpu.vendorName = "AMD";
349 gpu.supportsFSR = true; // All AMD GPUs support FSR
350 }
351 else if (vendorId == "0x10de")
352 {
354 gpu.vendorName = "NVIDIA";
355 }
356 else if (vendorId == "0x8086")
357 {
359 gpu.vendorName = "Intel";
360 }
361 }
362 }
363
364 // Read device ID for generation detection
365 std::filesystem::path deviceIdPath = devicePath / "device";
366 if (std::filesystem::exists(deviceIdPath))
367 {
368 std::ifstream deviceIdFile(deviceIdPath);
369 std::string deviceIdStr;
370 if (deviceIdFile >> deviceIdStr)
371 {
372 try
373 {
374 gpu.deviceId =
375 static_cast<uint16_t>(std::stoul(deviceIdStr, nullptr, 16));
376 }
377 catch (...)
378 {
379 }
380 }
381 }
382
383 // Read PCI slot from uevent for lspci lookup
384 std::filesystem::path ueventPath = devicePath / "uevent";
385 if (std::filesystem::exists(ueventPath))
386 {
387 std::ifstream ueventFile(ueventPath);
388 std::string line;
389 while (std::getline(ueventFile, line))
390 {
391 if (line.find("PCI_SLOT_NAME=") == 0)
392 {
393 pciSlot = line.substr(14); // Extract slot after "PCI_SLOT_NAME="
394 break;
395 }
396 }
397 }
398
399 // Read VRAM size from /sys/class/drm/card*/device/mem_info_vram_total
400 // or from /sys/class/drm/card*/device/resource (AMD)
401 std::filesystem::path vramPath = devicePath / "mem_info_vram_total";
402 if (std::filesystem::exists(vramPath))
403 {
404 std::ifstream vramFile(vramPath);
405 uint64_t vramBytes = 0;
406 if (vramFile >> vramBytes)
407 {
408 gpu.vramMB = vramBytes / (1024 * 1024);
409 }
410 }
411
412 // Found primary GPU, stop searching
413 if (gpu.vendor != GPUVendor::Unknown)
414 {
415 break;
416 }
417 }
418 }
419 }
420 catch (const std::exception& e)
421 {
422 Logger::warn("Error detecting GPU: {}", e.what());
423 }
424
425 // Get GPU model name from lspci (most reliable source)
426 if (!pciSlot.empty())
427 {
428 detectGPUModelFromLspci(pciSlot, gpu);
429 }
430
431 // Detect GPU generation and set feature support
432 detectGPUGeneration();
433
434 // Detect driver version (Mesa or NVIDIA)
435 detectDriverVersion();
436
437 // Check Vulkan support
438 gpu.supportsVulkan =
439 std::filesystem::exists("/usr/share/vulkan/icd.d") || isToolAvailable("vulkaninfo");
440
441 if (gpu.vendor == GPUVendor::Unknown)
442 {
443 gpu.vendorName = "Unknown";
444 }
445
446 Logger::info("Detected GPU: {} {} (Gen: {}, VRAM: {}MB, Vulkan: {}, Driver: {})",
447 gpu.vendorName, gpu.model.empty() ? "" : gpu.model,
448 static_cast<int>(gpu.generation), gpu.vramMB, gpu.supportsVulkan ? "yes" : "no",
449 gpu.driverVersion.empty() ? "unknown" : gpu.driverVersion);
450}
451
452void SystemInfoService::detectGPUModelFromLspci(const std::string& pciSlot, GPUInfo& gpu)
453{
454 // Run lspci to get the full GPU model name
455 // lspci output format: "03:00.0 VGA compatible controller: Advanced Micro Devices, Inc.
456 // [AMD/ATI] Navi 31 [Radeon RX 7900 XT/7900 XTX/7900 GRE/7900M] (rev c8)"
457 try
458 {
459 // Validate pciSlot to prevent shell injection: only allow hex digits, colons, and dots
460 static const std::regex pciSlotPattern("^[0-9a-fA-F:.]+$");
461 if (!std::regex_match(pciSlot, pciSlotPattern))
462 {
463 Logger::warn("detectGPUModelFromLspci: invalid PCI slot '{}', skipping lspci", pciSlot);
464 return;
465 }
466 std::string cmd = "lspci -s " + pciSlot + " 2>/dev/null";
467 FILE* pipe = popen(cmd.c_str(), "r");
468 if (!pipe)
469 {
470 Logger::warn("Failed to run lspci for GPU model detection");
471 return;
472 }
473
474 char buffer[512];
475 std::string result;
476 // refresh() holds mutex_ to serialize the detect-all sequence
477 // against concurrent capability getters; the lspci probe IS the
478 // detection work. Refresh runs on a background thread (see
479 // refreshAsync) so the foreground UI is not blocked.
480 // NOLINTNEXTLINE(clang-analyzer-unix.BlockInCriticalSection) - see comment above.
481 while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
482 {
483 result += buffer;
484 }
485 pclose(pipe);
486
487 if (result.empty())
488 {
489 return;
490 }
491
492 // Parse the lspci output to extract the model name
493 // Look for the part after the vendor name in brackets or after the colon
494 size_t colonPos = result.find(':');
495 if (colonPos != std::string::npos)
496 {
497 // Skip past "VGA compatible controller: " or similar
498 colonPos = result.find(':', colonPos + 1);
499 if (colonPos != std::string::npos)
500 {
501 std::string devicePart = result.substr(colonPos + 1);
502
503 // Trim leading/trailing whitespace
504 size_t start = devicePart.find_first_not_of(" \t\n\r");
505 size_t end = devicePart.find_last_not_of(" \t\n\r");
506 if (start != std::string::npos && end != std::string::npos)
507 {
508 devicePart = devicePart.substr(start, end - start + 1);
509 }
510
511 // Remove revision info like "(rev c8)" at the end
512 size_t revPos = devicePart.rfind(" (rev");
513 if (revPos != std::string::npos)
514 {
515 devicePart = devicePart.substr(0, revPos);
516 }
517
518 // For AMD: Extract the model from brackets like "[Radeon RX 7900 XTX]"
519 // For NVIDIA: Extract model like "GeForce RTX 4090"
520 if (gpu.vendor == GPUVendor::AMD)
521 {
522 // AMD format: "Advanced Micro Devices, Inc. [AMD/ATI] Navi 31 [Radeon RX 7900
523 // XT/7900 XTX/7900 GRE/7900M]" We want to extract: "Navi 31 [Radeon RX 7900
524 // XT/7900 XTX/7900 GRE/7900M]"
525 size_t amdBracket = devicePart.find("[AMD/ATI]");
526 if (amdBracket != std::string::npos)
527 {
528 devicePart = devicePart.substr(amdBracket + 9); // Skip "[AMD/ATI]"
529 // Trim again
530 start = devicePart.find_first_not_of(" \t");
531 if (start != std::string::npos)
532 {
533 devicePart = devicePart.substr(start);
534 }
535 }
536 gpu.model = devicePart;
537 }
538 else if (gpu.vendor == GPUVendor::NVIDIA)
539 {
540 // NVIDIA format: "NVIDIA Corporation GeForce RTX 4090"
541 size_t nvPos = devicePart.find("NVIDIA Corporation");
542 if (nvPos != std::string::npos)
543 {
544 devicePart = devicePart.substr(nvPos + 18); // Skip "NVIDIA Corporation"
545 start = devicePart.find_first_not_of(" \t");
546 if (start != std::string::npos)
547 {
548 devicePart = devicePart.substr(start);
549 }
550 }
551 gpu.model = devicePart;
552 }
553 else if (gpu.vendor == GPUVendor::Intel)
554 {
555 // Intel format: "Intel Corporation Device XXXX" or "Intel Corporation Arc A770"
556 size_t intelPos = devicePart.find("Intel Corporation");
557 if (intelPos != std::string::npos)
558 {
559 devicePart = devicePart.substr(intelPos + 17); // Skip "Intel Corporation"
560 start = devicePart.find_first_not_of(" \t");
561 if (start != std::string::npos)
562 {
563 devicePart = devicePart.substr(start);
564 }
565 }
566 gpu.model = devicePart;
567 }
568 else
569 {
570 gpu.model = devicePart;
571 }
572
573 Logger::info("GPU model from lspci: {}", gpu.model);
574 }
575 }
576 }
577 catch (const std::exception& e)
578 {
579 Logger::warn("Error getting GPU model from lspci: {}", e.what());
580 }
581}
582
583void SystemInfoService::detectGPUGeneration()
584{
585 GPUInfo& gpu = capabilities_.gpu;
586
587 switch (gpu.vendor)
588 {
589 case GPUVendor::AMD:
590 gpu.generation = detectAMDGeneration(gpu.deviceId);
591 // Fallback: try model name parsing if device ID didn't work
592 if (gpu.generation == GPUGeneration::AMD_Older && !gpu.model.empty())
593 {
594 gpu.generation = detectAMDGenerationFromModel(gpu.model);
595 }
596 // Set feature support based on generation
597 gpu.supportsFSR = true; // All AMD GPUs support FSR1
598 gpu.supportsFSR3 = gpu.isRDNA2OrNewer();
599 gpu.supportsFSR4 = gpu.isRDNA4(); // Native FSR4 ML upscaling
601 gpu.isRDNA3OrNewer(); // RDNA3 can opt-in via PROTON_FSR4_RDNA3_UPGRADE
603 Logger::info("AMD GPU generation: {} (RDNA2+: {}, FSR3: {}, FSR4: {}, FSR4-on-RDNA3: {})",
604 static_cast<int>(gpu.generation), gpu.isRDNA2OrNewer() ? "yes" : "no",
605 gpu.supportsFSR3 ? "yes" : "no", gpu.supportsFSR4 ? "yes" : "no",
606 gpu.supportsFSR4RDNA3 ? "yes" : "no");
607 break;
608
610 gpu.generation = detectNVIDIAGeneration(gpu.deviceId);
611 // Fallback: try model name parsing if device ID didn't work
612 if (gpu.generation == GPUGeneration::NVIDIA_Older && !gpu.model.empty())
613 {
614 gpu.generation = detectNVIDIAGenerationFromModel(gpu.model);
615 }
616 // DLSS requires RTX (Turing or newer)
617 gpu.supportsDLSS = gpu.isRTXCapable();
620 // FSR works on all GPUs
621 gpu.supportsFSR = true;
622 Logger::info("NVIDIA GPU generation: {} (RTX: {}, DLSS: {}, DLSS3: {})",
623 static_cast<int>(gpu.generation), gpu.isRTXCapable() ? "yes" : "no",
624 gpu.supportsDLSS ? "yes" : "no", gpu.supportsDLSS3 ? "yes" : "no");
625 break;
626
627 case GPUVendor::Intel:
628 gpu.generation = detectIntelGeneration(gpu.deviceId);
629 // Fallback: try model name parsing
630 if (gpu.generation == GPUGeneration::Intel_Older && !gpu.model.empty())
631 {
632 gpu.generation = detectIntelGenerationFromModel(gpu.model);
633 }
634 gpu.supportsXeSS = gpu.isArcGPU();
635 gpu.supportsRayTracing = gpu.isArcGPU();
636 gpu.supportsFSR = true; // FSR works on all GPUs
637 Logger::info("Intel GPU generation: {} (Arc: {}, XeSS: {})",
638 static_cast<int>(gpu.generation), gpu.isArcGPU() ? "yes" : "no",
639 gpu.supportsXeSS ? "yes" : "no");
640 break;
641
642 default:
644 break;
645 }
646}
647
648GPUGeneration SystemInfoService::detectAMDGenerationFromModel(const std::string& model)
649{
650 std::string modelLower = model;
651 std::transform(modelLower.begin(), modelLower.end(), modelLower.begin(),
652 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
653
654 // RDNA4 - RX 9000 series (Navi 48 = 9070 series, Navi 44 = 9060 series)
655 if (modelLower.find("rx 90") != std::string::npos || // 9000-level generic
656 modelLower.find("rx 9070") != std::string::npos ||
657 modelLower.find("rx 9060") != std::string::npos ||
658 modelLower.find("navi 48") != std::string::npos ||
659 modelLower.find("navi 44") != std::string::npos)
660 {
661 Logger::info("Detected RDNA4 from model name: {}", model);
663 }
664
665 // RDNA3 - RX 7000 series
666 if (modelLower.find("rx 79") != std::string::npos || // 7900
667 modelLower.find("rx 78") != std::string::npos || // 7800
668 modelLower.find("rx 77") != std::string::npos || // 7700
669 modelLower.find("rx 76") != std::string::npos || // 7600
670 modelLower.find("radeon 780m") != std::string::npos || // Phoenix APU
671 modelLower.find("radeon 760m") != std::string::npos)
672 {
673 Logger::info("Detected RDNA3 from model name: {}", model);
675 }
676
677 // RDNA2 - RX 6000 series
678 if (modelLower.find("rx 69") != std::string::npos || // 6900
679 modelLower.find("rx 68") != std::string::npos || // 6800
680 modelLower.find("rx 67") != std::string::npos || // 6700
681 modelLower.find("rx 66") != std::string::npos || // 6600
682 modelLower.find("rx 65") != std::string::npos || // 6500
683 modelLower.find("rx 64") != std::string::npos || // 6400
684 modelLower.find("van gogh") != std::string::npos || // Steam Deck
685 modelLower.find("rembrandt") != std::string::npos || // Rembrandt APU
686 modelLower.find("radeon 680m") != std::string::npos || // APU
687 modelLower.find("radeon 660m") != std::string::npos)
688 {
689 Logger::info("Detected RDNA2 from model name: {}", model);
691 }
692
693 // RDNA1 - RX 5000 series
694 if (modelLower.find("rx 57") != std::string::npos || // 5700
695 modelLower.find("rx 56") != std::string::npos || // 5600
696 modelLower.find("rx 55") != std::string::npos) // 5500
697 {
698 Logger::info("Detected RDNA1 from model name: {}", model);
700 }
701
702 // Vega
703 if (modelLower.find("vega") != std::string::npos ||
704 modelLower.find("radeon vii") != std::string::npos)
705 {
706 Logger::info("Detected Vega from model name: {}", model);
708 }
709
710 // Polaris - RX 400/500 series
711 if (modelLower.find("rx 5") != std::string::npos &&
712 modelLower.find("rx 55") == std::string::npos &&
713 modelLower.find("rx 56") == std::string::npos &&
714 modelLower.find("rx 57") == std::string::npos) // RX 5xx but not 5xxx
715 {
716 Logger::info("Detected Polaris from model name: {}", model);
718 }
719 if (modelLower.find("rx 4") != std::string::npos) // RX 4xx
720 {
721 Logger::info("Detected Polaris from model name: {}", model);
723 }
724
725 // GCN 4 - R9 Fury, R9 Nano, R9 380, R9 285 (Tonga/Fiji)
726 if (modelLower.find("r9 fury") != std::string::npos ||
727 modelLower.find("r9 nano") != std::string::npos ||
728 modelLower.find("r9 380") != std::string::npos ||
729 modelLower.find("r9 285") != std::string::npos ||
730 modelLower.find("fiji") != std::string::npos ||
731 modelLower.find("tonga") != std::string::npos)
732 {
733 Logger::info("Detected GCN4 from model name: {}", model);
735 }
736
737 // GCN 3 - R9 290/290X, R9 295X2, R7 260/260X (Hawaii/Bonaire)
738 if (modelLower.find("r9 29") != std::string::npos || // R9 290/290X/295X2
739 modelLower.find("r7 260") != std::string::npos ||
740 modelLower.find("hawaii") != std::string::npos ||
741 modelLower.find("bonaire") != std::string::npos)
742 {
743 Logger::info("Detected GCN3 from model name: {}", model);
745 }
746
747 // GCN 2 - R9 270/270X, R7 250 (Pitcairn refresh/Oland)
748 if (modelLower.find("r9 270") != std::string::npos ||
749 modelLower.find("r7 250") != std::string::npos ||
750 modelLower.find("r7 240") != std::string::npos ||
751 modelLower.find("oland") != std::string::npos)
752 {
753 Logger::info("Detected GCN2 from model name: {}", model);
755 }
756
757 // GCN 1 - HD 7000 series (Tahiti, Pitcairn, Cape Verde)
758 if (modelLower.find("hd 79") != std::string::npos || // HD 7970/7950/7900
759 modelLower.find("hd 78") != std::string::npos || // HD 7870/7850
760 modelLower.find("hd 77") != std::string::npos || // HD 7770/7750
761 modelLower.find("hd 76") != std::string::npos || // HD 7600
762 modelLower.find("tahiti") != std::string::npos ||
763 modelLower.find("pitcairn") != std::string::npos ||
764 modelLower.find("cape verde") != std::string::npos)
765 {
766 Logger::info("Detected GCN1 from model name: {}", model);
768 }
769
770 // TeraScale 3 - HD 6000 series
771 if (modelLower.find("hd 69") != std::string::npos || // HD 6970/6950/6900
772 modelLower.find("hd 68") != std::string::npos || // HD 6870/6850
773 modelLower.find("hd 67") != std::string::npos || // HD 6770/6750/6700/6670
774 modelLower.find("hd 66") != std::string::npos || // HD 6600
775 modelLower.find("hd 65") != std::string::npos || // HD 6500
776 modelLower.find("hd 64") != std::string::npos || // HD 6400
777 modelLower.find("cayman") != std::string::npos ||
778 modelLower.find("barts") != std::string::npos ||
779 modelLower.find("turks") != std::string::npos)
780 {
781 Logger::info("Detected TeraScale (HD 6000) from model name: {}", model);
783 }
784
785 // TeraScale 2 - HD 5000 series
786 if (modelLower.find("hd 58") != std::string::npos || // HD 5870/5850
787 modelLower.find("hd 57") != std::string::npos || // HD 5770/5750/5700
788 modelLower.find("hd 56") != std::string::npos || // HD 5670/5600
789 modelLower.find("hd 55") != std::string::npos || // HD 5570/5550/5500
790 modelLower.find("hd 54") != std::string::npos || // HD 5450
791 modelLower.find("cypress") != std::string::npos ||
792 modelLower.find("juniper") != std::string::npos ||
793 modelLower.find("redwood") != std::string::npos ||
794 modelLower.find("cedar") != std::string::npos)
795 {
796 Logger::info("Detected TeraScale (HD 5000) from model name: {}", model);
798 }
799
800 // TeraScale 1 - HD 2000/3000/4000 series
801 if (modelLower.find("hd 48") != std::string::npos || // HD 4870/4850
802 modelLower.find("hd 47") != std::string::npos || // HD 4770
803 modelLower.find("hd 46") != std::string::npos || // HD 4670/4650
804 modelLower.find("hd 45") != std::string::npos || // HD 4550
805 modelLower.find("hd 43") != std::string::npos || // HD 4350
806 modelLower.find("hd 38") != std::string::npos || // HD 3870/3850
807 modelLower.find("hd 36") != std::string::npos || // HD 3650
808 modelLower.find("hd 34") != std::string::npos || // HD 3450
809 modelLower.find("hd 29") != std::string::npos || // HD 2900
810 modelLower.find("hd 26") != std::string::npos || // HD 2600
811 modelLower.find("hd 24") != std::string::npos) // HD 2400
812 {
813 Logger::info("Detected TeraScale (HD 2000-4000) from model name: {}", model);
815 }
816
817 Logger::warn("Could not determine AMD generation from model: {}", model);
819}
820
821GPUGeneration SystemInfoService::detectNVIDIAGenerationFromModel(const std::string& model)
822{
823 std::string modelLower = model;
824 std::transform(modelLower.begin(), modelLower.end(), modelLower.begin(),
825 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
826
827 // Ada Lovelace - RTX 40 series
828 if (modelLower.find("rtx 40") != std::string::npos ||
829 modelLower.find("rtx 4090") != std::string::npos ||
830 modelLower.find("rtx 4080") != std::string::npos ||
831 modelLower.find("rtx 4070") != std::string::npos ||
832 modelLower.find("rtx 4060") != std::string::npos ||
833 modelLower.find("rtx 4050") != std::string::npos)
834 {
835 Logger::info("Detected Ada from model name: {}", model);
837 }
838
839 // Ampere - RTX 30 series
840 if (modelLower.find("rtx 30") != std::string::npos ||
841 modelLower.find("rtx 3090") != std::string::npos ||
842 modelLower.find("rtx 3080") != std::string::npos ||
843 modelLower.find("rtx 3070") != std::string::npos ||
844 modelLower.find("rtx 3060") != std::string::npos ||
845 modelLower.find("rtx 3050") != std::string::npos ||
846 modelLower.find("rtx a") != std::string::npos) // RTX A series workstation
847 {
848 Logger::info("Detected Ampere from model name: {}", model);
850 }
851
852 // Turing - RTX 20 series, GTX 16 series
853 if (modelLower.find("rtx 20") != std::string::npos ||
854 modelLower.find("rtx 2080") != std::string::npos ||
855 modelLower.find("rtx 2070") != std::string::npos ||
856 modelLower.find("rtx 2060") != std::string::npos ||
857 modelLower.find("gtx 16") != std::string::npos ||
858 modelLower.find("gtx 1660") != std::string::npos ||
859 modelLower.find("gtx 1650") != std::string::npos)
860 {
861 Logger::info("Detected Turing from model name: {}", model);
863 }
864
865 // Pascal - GTX 10 series
866 if (modelLower.find("gtx 10") != std::string::npos ||
867 modelLower.find("gtx 1080") != std::string::npos ||
868 modelLower.find("gtx 1070") != std::string::npos ||
869 modelLower.find("gtx 1060") != std::string::npos ||
870 modelLower.find("gtx 1050") != std::string::npos ||
871 modelLower.find("titan x") != std::string::npos)
872 {
873 Logger::info("Detected Pascal from model name: {}", model);
875 }
876
877 Logger::warn("Could not determine NVIDIA generation from model: {}", model);
879}
880
881GPUGeneration SystemInfoService::detectIntelGenerationFromModel(const std::string& model)
882{
883 std::string modelLower = model;
884 std::transform(modelLower.begin(), modelLower.end(), modelLower.begin(),
885 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
886
887 // Intel Arc - Alchemist
888 if (modelLower.find("arc a") != std::string::npos ||
889 modelLower.find("arc a770") != std::string::npos ||
890 modelLower.find("arc a750") != std::string::npos ||
891 modelLower.find("arc a580") != std::string::npos ||
892 modelLower.find("arc a380") != std::string::npos ||
893 modelLower.find("arc a310") != std::string::npos)
894 {
895 Logger::info("Detected Intel Arc from model name: {}", model);
897 }
898
899 // Intel Xe integrated
900 if (modelLower.find("xe") != std::string::npos ||
901 modelLower.find("iris xe") != std::string::npos ||
902 modelLower.find("uhd 7") != std::string::npos) // UHD 700 series
903 {
904 Logger::info("Detected Intel Xe from model name: {}", model);
906 }
907
908 Logger::warn("Could not determine Intel generation from model: {}", model);
910}
911
912GPUGeneration SystemInfoService::detectAMDGeneration(uint16_t deviceId)
913{
914 // AMD Device ID ranges - comprehensive list
915 // Sources: https://devicehunt.com/view/type/pci/vendor/1002
916 // Mesa radeonsi driver source
917
918 // RDNA4 (RX 9000 series) - Navi 48 (9070/9070 XT/GRE), Navi 44 (9060 XT/9060)
919 // Requires kernel 6.12+ and Mesa 25.0+.
920 if ((deviceId >= 0x7550 && deviceId <= 0x756F) || // Navi 48
921 (deviceId >= 0x7590 && deviceId <= 0x75AF)) // Navi 44
922 {
923 Logger::debug("GPU detected as RDNA4 (device ID: 0x{:04x})", deviceId);
925 }
926
927 // RDNA3 (RX 7000 series)
928 // Desktop: Navi 31 (7900 XT/XTX), Navi 32 (7800/7700), Navi 33 (7600)
929 if ((deviceId >= 0x7440 && deviceId <= 0x747F) || // Navi 31 desktop
930 (deviceId >= 0x7480 && deviceId <= 0x74BF) || // Navi 32
931 (deviceId >= 0x74C0 && deviceId <= 0x74FF) || // Navi 33
932 (deviceId >= 0x15BF && deviceId <= 0x15EF) || // RDNA3 mobile/APU
933 deviceId == 0x744C || deviceId == 0x7448) // 7900 GRE, specific variants
934 {
935 Logger::debug("GPU detected as RDNA3 (device ID: 0x{:04x})", deviceId);
937 }
938
939 // RDNA2 (RX 6000 series)
940 // Desktop: Navi 21 (6800/6900), Navi 22 (6700), Navi 23 (6600), Navi 24 (6400/6500)
941 if ((deviceId >= 0x73A0 && deviceId <= 0x73FF) || // Navi 21/22/23
942 (deviceId >= 0x73BF && deviceId <= 0x73EF) || // Navi 21 variants
943 (deviceId >= 0x7420 && deviceId <= 0x743F) || // Navi 24
944 (deviceId >= 0x1638 && deviceId <= 0x164F) || // Van Gogh APU (Steam Deck)
945 (deviceId >= 0x1681 && deviceId <= 0x169F) || // Rembrandt APU
946 deviceId == 0x73AF || deviceId == 0x73BF || // 6900 XT variants
947 deviceId == 0x73DF || deviceId == 0x73EF || // 6800 XT/6800 variants
948 deviceId == 0x73FF || deviceId == 0x7421 || // 6700 XT, 6500 XT
949 deviceId == 0x7422 || deviceId == 0x7423 || // 6400
950 deviceId == 0x743F) // More Navi 24
951 {
952 Logger::debug("GPU detected as RDNA2 (device ID: 0x{:04x})", deviceId);
954 }
955
956 // RDNA1 (RX 5000 series)
957 // Desktop: Navi 10 (5600/5700), Navi 14 (5500)
958 if ((deviceId >= 0x7310 && deviceId <= 0x7340) || // Navi 10
959 (deviceId >= 0x7340 && deviceId <= 0x735F) || // Navi 14
960 deviceId == 0x731F || deviceId == 0x7312 || // 5700 XT/5700
961 deviceId == 0x7318 || deviceId == 0x7319 || // 5600 XT
962 deviceId == 0x7340 || deviceId == 0x7341) // 5500 XT
963 {
964 Logger::debug("GPU detected as RDNA1 (device ID: 0x{:04x})", deviceId);
966 }
967
968 // Vega (RX Vega 56/64, VII)
969 if ((deviceId >= 0x6860 && deviceId <= 0x6880) || // Vega 10
970 (deviceId >= 0x66A0 && deviceId <= 0x66BF) || // Vega 20 (VII)
971 deviceId == 0x687F || deviceId == 0x6867 || // Vega 64/56
972 deviceId == 0x66AF) // Vega 20
973 {
974 Logger::debug("GPU detected as Vega (device ID: 0x{:04x})", deviceId);
976 }
977
978 // Polaris (RX 400/500 series)
979 if ((deviceId >= 0x67C0 && deviceId <= 0x67FF) || // Polaris 10
980 (deviceId >= 0x6980 && deviceId <= 0x69BF) || // Polaris 11/12
981 deviceId == 0x67DF || deviceId == 0x67EF || // RX 480/470
982 deviceId == 0x6FDF) // RX 580/570
983 {
984 Logger::debug("GPU detected as Polaris (device ID: 0x{:04x})", deviceId);
986 }
987
988 // GCN 4 (Tonga, Fiji) - R9 285, R9 380, R9 Fury, R9 Nano
989 if ((deviceId >= 0x6920 && deviceId <= 0x6939) || // Tonga
990 (deviceId >= 0x7300 && deviceId <= 0x730F) || // Fiji
991 deviceId == 0x692B || deviceId == 0x692F || // Tonga Pro/XT
992 deviceId == 0x6930 || deviceId == 0x6938 || // Tonga variants
993 deviceId == 0x7300) // Fiji (R9 Fury/Nano)
994 {
995 Logger::debug("GPU detected as GCN4 (device ID: 0x{:04x})", deviceId);
997 }
998
999 // GCN 3 (Hawaii, Bonaire) - R9 290/290X, R7 260/260X
1000 if ((deviceId >= 0x67A0 && deviceId <= 0x67BF) || // Hawaii
1001 (deviceId >= 0x6640 && deviceId <= 0x665F) || // Bonaire
1002 deviceId == 0x67B0 || deviceId == 0x67B1 || // Hawaii (R9 290/290X)
1003 deviceId == 0x6640 || deviceId == 0x6641 || // Bonaire (R7 260)
1004 deviceId == 0x6646 || deviceId == 0x6647 || // Bonaire Pro
1005 deviceId == 0x6649 || deviceId == 0x665C) // Bonaire XT
1006 {
1007 Logger::debug("GPU detected as GCN3 (device ID: 0x{:04x})", deviceId);
1009 }
1010
1011 // GCN 2 (Oland, Pitcairn refresh) - R7 250, R9 270
1012 if ((deviceId >= 0x6600 && deviceId <= 0x663F) || // Oland
1013 deviceId == 0x6600 || deviceId == 0x6601 || // Oland (R7 250)
1014 deviceId == 0x6604 || deviceId == 0x6605 || // Oland variants
1015 deviceId == 0x6610 || deviceId == 0x6611 || // Oland Pro
1016 deviceId == 0x6808 || deviceId == 0x6809 || // Pitcairn refresh
1017 deviceId == 0x6810 || deviceId == 0x6811) // R9 270/270X
1018 {
1019 Logger::debug("GPU detected as GCN2 (device ID: 0x{:04x})", deviceId);
1021 }
1022
1023 // GCN 1 (Tahiti, Pitcairn, Cape Verde, Hainan) - HD 7000 series
1024 if ((deviceId >= 0x6780 && deviceId <= 0x67A0) || // Tahiti
1025 (deviceId >= 0x6800 && deviceId <= 0x683F) || // Pitcairn
1026 (deviceId >= 0x6820 && deviceId <= 0x685F) || // Cape Verde
1027 deviceId == 0x6780 || deviceId == 0x6784 || // Tahiti XT/Pro (HD 7970/7950)
1028 deviceId == 0x6788 || deviceId == 0x678A || // Tahiti variants
1029 deviceId == 0x6798 || deviceId == 0x679A || // Tahiti LE
1030 deviceId == 0x6800 || deviceId == 0x6801 || // Pitcairn XT (HD 7870)
1031 deviceId == 0x6818 || deviceId == 0x6819 || // Pitcairn Pro (HD 7850)
1032 deviceId == 0x6820 || deviceId == 0x6821 || // Cape Verde XT (HD 7770)
1033 deviceId == 0x6823 || deviceId == 0x6824 || // Cape Verde Pro (HD 7750)
1034 deviceId == 0x6825 || deviceId == 0x6826 || // Cape Verde variants
1035 deviceId == 0x6827 || deviceId == 0x6660 || // Hainan
1036 deviceId == 0x6663 || deviceId == 0x6664 || // Hainan variants
1037 deviceId == 0x6665 || deviceId == 0x6667) // Hainan LE
1038 {
1039 Logger::debug("GPU detected as GCN1 (device ID: 0x{:04x})", deviceId);
1041 }
1042
1043 // TeraScale 3 (Northern Islands) - HD 6000 series (Cayman, Barts, Turks, Caicos)
1044 if ((deviceId >= 0x6700 && deviceId <= 0x673F) || // Cayman
1045 (deviceId >= 0x6740 && deviceId <= 0x677F) || // Barts
1046 (deviceId >= 0x6840 && deviceId <= 0x687F && // Turks/Caicos (but not Vega!)
1047 deviceId < 0x6860) || // Vega starts at 0x6860
1048 deviceId == 0x6718 ||
1049 deviceId == 0x6719 || // Cayman XT/Pro (HD 6970/6950)
1050 deviceId == 0x671C || deviceId == 0x671D || // Cayman LE
1051 deviceId == 0x6720 || deviceId == 0x6738 || // Barts XT (HD 6870)
1052 deviceId == 0x6739 || deviceId == 0x6759 || // Barts Pro (HD 6850)
1053 deviceId == 0x6840 || deviceId == 0x6841 || // Turks XT (HD 6670)
1054 deviceId == 0x6842 || deviceId == 0x6843) // Turks Pro (HD 6570)
1055 {
1056 Logger::debug("GPU detected as TeraScale (HD 6000, device ID: 0x{:04x})", deviceId);
1058 }
1059
1060 // TeraScale 2 (Evergreen) - HD 5000 series (Cypress, Juniper, Redwood, Cedar)
1061 if ((deviceId >= 0x6880 && deviceId <= 0x68BF) || // Cypress
1062 (deviceId >= 0x68C0 && deviceId <= 0x68FF) || // Juniper
1063 (deviceId >= 0x68A0 && deviceId <= 0x68BF) || // Redwood
1064 deviceId == 0x6898 || deviceId == 0x6899 || // Cypress XT/Pro (HD 5870/5850)
1065 deviceId == 0x689B || deviceId == 0x689C || // Cypress LE
1066 deviceId == 0x68B8 || deviceId == 0x68B9 || // Juniper XT (HD 5770)
1067 deviceId == 0x68BA || deviceId == 0x68BE || // Juniper Pro (HD 5750)
1068 deviceId == 0x68C0 || deviceId == 0x68C1 || // Redwood XT (HD 5670)
1069 deviceId == 0x68D8 || deviceId == 0x68D9 || // Redwood Pro (HD 5570)
1070 deviceId == 0x68E0 || deviceId == 0x68E1) // Cedar (HD 5450)
1071 {
1072 Logger::debug("GPU detected as TeraScale (HD 5000, device ID: 0x{:04x})", deviceId);
1074 }
1075
1076 // TeraScale 1 - HD 2000/3000/4000 series
1077 if ((deviceId >= 0x9400 && deviceId <= 0x94FF) || // R600 (HD 2900)
1078 (deviceId >= 0x9500 && deviceId <= 0x95FF) || // RV630 (HD 2600)
1079 (deviceId >= 0x9440 && deviceId <= 0x949F) || // RV770 (HD 4800)
1080 (deviceId >= 0x94C0 && deviceId <= 0x94FF) || // RV610 (HD 2400)
1081 (deviceId >= 0x9540 && deviceId <= 0x957F) || // RV710 (HD 4350)
1082 (deviceId >= 0x9580 && deviceId <= 0x95FF) || // RV630 variants
1083 (deviceId >= 0x9600 && deviceId <= 0x96FF) || // RV635 (HD 3650)
1084 (deviceId >= 0x9700 && deviceId <= 0x97FF)) // RV740 (HD 4770)
1085 {
1086 Logger::debug("GPU detected as TeraScale (HD 2000-4000, device ID: 0x{:04x})", deviceId);
1088 }
1089
1090 Logger::debug("GPU detected as AMD_Older (device ID: 0x{:04x})", deviceId);
1092}
1093
1094GPUGeneration SystemInfoService::detectNVIDIAGeneration(uint16_t deviceId)
1095{
1096 // NVIDIA Device ID ranges - comprehensive list
1097 // Sources: https://devicehunt.com/view/type/pci/vendor/10DE
1098 // nvidia.ko source
1099
1100 // Ada Lovelace (RTX 40 series)
1101 // RTX 4090, 4080, 4070, etc.
1102 if ((deviceId >= 0x2680 && deviceId <= 0x27FF) || // AD102, AD103, AD104
1103 (deviceId >= 0x2780 && deviceId <= 0x27BF) || // AD106, AD107
1104 deviceId == 0x2684 || deviceId == 0x2702 || // 4090, 4080 SUPER
1105 deviceId == 0x2704 || deviceId == 0x2705 || // 4080, variants
1106 deviceId == 0x2782 || deviceId == 0x2783 || // 4070 Ti SUPER
1107 deviceId == 0x2786) // 4070 SUPER
1108 {
1109 Logger::debug("GPU detected as NVIDIA Ada (device ID: 0x{:04x})", deviceId);
1111 }
1112
1113 // Ampere (RTX 30 series)
1114 // RTX 3090, 3080, 3070, 3060, etc.
1115 if ((deviceId >= 0x2200 && deviceId <= 0x267F) || // GA102, GA103, GA104, GA106, GA107
1116 deviceId == 0x2204 || deviceId == 0x2206 || // 3090, 3080
1117 deviceId == 0x2208 || deviceId == 0x220A || // 3080 Ti, variants
1118 deviceId == 0x2216 || deviceId == 0x2231 || // 3080 12GB, 3060
1119 deviceId == 0x2414 || deviceId == 0x2420 || // 3060 Ti
1120 deviceId == 0x2482 || deviceId == 0x2484 || // 3070 Ti, 3070
1121 deviceId == 0x2503 || deviceId == 0x2504 || // 3060, 3060 12GB
1122 deviceId == 0x2507 || deviceId == 0x2508 || // 3050
1123 deviceId == 0x2520 || deviceId == 0x2531) // 3060 laptop
1124 {
1125 Logger::debug("GPU detected as NVIDIA Ampere (device ID: 0x{:04x})", deviceId);
1127 }
1128
1129 // Turing (RTX 20 series, GTX 16 series)
1130 if ((deviceId >= 0x1E00 && deviceId <= 0x21FF) || // TU102, TU104, TU106, TU116, TU117
1131 deviceId == 0x1E02 || deviceId == 0x1E04 || // Titan RTX, 2080 Ti
1132 deviceId == 0x1E07 || deviceId == 0x1E30 || // 2080 SUPER
1133 deviceId == 0x1E81 || deviceId == 0x1E82 || // 2080, variants
1134 deviceId == 0x1E87 || deviceId == 0x1E89 || // 2070 SUPER
1135 deviceId == 0x1F02 || deviceId == 0x1F06 || // 2070
1136 deviceId == 0x1F07 || deviceId == 0x1F08 || // 2060 SUPER
1137 deviceId == 0x1F82 || deviceId == 0x1F91 || // 1660 Ti
1138 deviceId == 0x2182 || deviceId == 0x2184 || // 1660 SUPER
1139 deviceId == 0x2187 || deviceId == 0x2188 || // 1650 SUPER
1140 deviceId == 0x1F0A || deviceId == 0x1F12) // 2060, 1660
1141 {
1142 Logger::debug("GPU detected as NVIDIA Turing (device ID: 0x{:04x})", deviceId);
1144 }
1145
1146 // Pascal (GTX 10 series)
1147 if ((deviceId >= 0x1B00 && deviceId <= 0x1DFF) || // GP100, GP102, GP104, GP106, GP107, GP108
1148 deviceId == 0x1B00 || deviceId == 0x1B02 || // Titan X, Titan Xp
1149 deviceId == 0x1B06 || deviceId == 0x1B80 || // 1080 Ti, 1080
1150 deviceId == 0x1B81 || deviceId == 0x1B82 || // 1070 Ti, 1070
1151 deviceId == 0x1B83 || deviceId == 0x1B84 || // 1060
1152 deviceId == 0x1C02 || deviceId == 0x1C03 || // 1060 variants
1153 deviceId == 0x1C81 || deviceId == 0x1C82 || // 1050 Ti, 1050
1154 deviceId == 0x1D01) // 1030
1155 {
1156 Logger::debug("GPU detected as NVIDIA Pascal (device ID: 0x{:04x})", deviceId);
1158 }
1159
1160 Logger::debug("GPU detected as NVIDIA_Older (device ID: 0x{:04x})", deviceId);
1162}
1163
1164GPUGeneration SystemInfoService::detectIntelGeneration(uint16_t deviceId)
1165{
1166 // Intel Arc (Alchemist): 0x5690-0x56FF
1167 // Xe integrated: Various IDs
1168
1169 if (deviceId >= 0x5690 && deviceId <= 0x56FF)
1171 if (deviceId >= 0x9A00 && deviceId <= 0x9AFF)
1173
1175}
1176
1177void SystemInfoService::detectCPU()
1178{
1179 CPUInfo& cpu = capabilities_.cpu;
1180
1181 try
1182 {
1183 std::ifstream cpuinfo("/proc/cpuinfo");
1184 std::string line;
1185 int processorCount = 0;
1186
1187 while (std::getline(cpuinfo, line))
1188 {
1189 if (line.find("model name") == 0)
1190 {
1191 size_t colonPos = line.find(':');
1192 if (colonPos != std::string::npos && cpu.model.empty())
1193 {
1194 cpu.model = line.substr(colonPos + 2);
1195
1196 // Determine vendor from model name
1197 if (cpu.model.find("AMD") != std::string::npos)
1198 {
1199 cpu.vendor = "AMD";
1200 }
1201 else if (cpu.model.find("Intel") != std::string::npos)
1202 {
1203 cpu.vendor = "Intel";
1204 }
1205 }
1206 }
1207 else if (line.find("processor") == 0)
1208 {
1209 processorCount++;
1210 }
1211 else if (line.find("cpu cores") == 0)
1212 {
1213 size_t colonPos = line.find(':');
1214 if (colonPos != std::string::npos && cpu.coreCount == 0)
1215 {
1216 try
1217 {
1218 cpu.coreCount = std::stoi(line.substr(colonPos + 2));
1219 }
1220 catch (...)
1221 {
1222 }
1223 }
1224 }
1225 else if (line.find("cpu MHz") == 0)
1226 {
1227 size_t colonPos = line.find(':');
1228 if (colonPos != std::string::npos && cpu.frequencyMHz == 0.0)
1229 {
1230 try
1231 {
1232 cpu.frequencyMHz = std::stod(line.substr(colonPos + 2));
1233 }
1234 catch (...)
1235 {
1236 }
1237 }
1238 }
1239 }
1240
1241 cpu.threadCount = processorCount;
1242 if (cpu.coreCount == 0)
1243 {
1244 cpu.coreCount = processorCount; // Fallback
1245 }
1246
1247 // Detect Intel hybrid architecture (P+E cores)
1248 if (cpu.vendor == "Intel")
1249 {
1250 // Check for different core types via /sys/devices/system/cpu/cpu*/topology/core_type
1251 // or by looking for "Core" and "Atom" mentions in /proc/cpuinfo
1252 std::ifstream hybridCheck("/sys/devices/system/cpu/cpu0/topology/core_type");
1253 if (hybridCheck.is_open())
1254 {
1255 cpu.isHybrid = true;
1256 // Count P-cores and E-cores would require iterating all CPUs
1257 // For now, we just mark it as hybrid
1258 }
1259 }
1260
1261 Logger::info("Detected CPU: {} ({} cores, {} threads, hybrid={})", cpu.model, cpu.coreCount,
1262 cpu.threadCount, cpu.isHybrid ? "yes" : "no");
1263 }
1264 catch (const std::exception& e)
1265 {
1266 Logger::warn("Error detecting CPU: {}", e.what());
1267 }
1268
1269 // Detect governor and scheduler (these need kernel to be detected first for scheduler)
1270 detectCPUGovernor();
1271}
1272
1273void SystemInfoService::detectKernel()
1274{
1275 KernelInfo& kernel = capabilities_.kernel;
1276
1277 // Get kernel version from uname
1278 try
1279 {
1280 std::ifstream versionFile("/proc/version");
1281 std::string versionLine;
1282 if (std::getline(versionFile, versionLine))
1283 {
1284 // Extract version number
1285 std::regex versionRegex(R"(Linux version (\S+))");
1286 std::smatch match;
1287 if (std::regex_search(versionLine, match, versionRegex))
1288 {
1289 kernel.version = match[1].str();
1290
1291 // Parse major.minor.patch version
1292 std::regex numRegex(R"((\d+)\.(\d+)\.?(\d*))");
1293 std::smatch numMatch;
1294 if (std::regex_search(kernel.version, numMatch, numRegex))
1295 {
1296 kernel.majorVersion = std::stoi(numMatch[1].str());
1297 kernel.minorVersion = std::stoi(numMatch[2].str());
1298 if (numMatch[3].length() > 0)
1299 {
1300 kernel.patchVersion = std::stoi(numMatch[3].str());
1301 }
1302 }
1303 }
1304
1305 // Check for CachyOS kernel
1306 if (versionLine.find("cachyos") != std::string::npos ||
1307 versionLine.find("CachyOS") != std::string::npos)
1308 {
1309 kernel.isCachyOS = true;
1310 }
1311 }
1312 }
1313 catch (...)
1314 {
1315 }
1316
1317 // Detect distro
1318 try
1319 {
1320 std::ifstream osRelease("/etc/os-release");
1321 std::string line;
1322 while (std::getline(osRelease, line))
1323 {
1324 if (line.find("NAME=") == 0)
1325 {
1326 size_t start = line.find('"');
1327 size_t end = line.rfind('"');
1328 if (start != std::string::npos && end != std::string::npos && end > start)
1329 {
1330 kernel.distro = line.substr(start + 1, end - start - 1);
1331 }
1332 else
1333 {
1334 kernel.distro = line.substr(5);
1335 }
1336
1337 if (kernel.distro.find("CachyOS") != std::string::npos)
1338 {
1339 kernel.isCachyOS = true;
1340 }
1341 break;
1342 }
1343 }
1344 }
1345 catch (...)
1346 {
1347 }
1348
1349 // Check fsync support (kernel 5.16+)
1350 bool foundFsyncSymbol = false;
1351 try
1352 {
1353 // Check if futex_waitv syscall is available (fsync)
1354 std::ifstream kallsyms("/proc/kallsyms");
1355 std::string line;
1356 while (std::getline(kallsyms, line))
1357 {
1358 if (line.find("futex_waitv") != std::string::npos)
1359 {
1360 kernel.supportsFsync = true;
1361 kernel.fsyncStatus = "available";
1362 foundFsyncSymbol = true;
1363 break;
1364 }
1365 }
1366 }
1367 catch (...)
1368 {
1369 }
1370
1371 // Fallback: check kernel version for fsync
1372 if (!foundFsyncSymbol)
1373 {
1374 bool kernelSupports =
1375 (kernel.majorVersion > 5) || (kernel.majorVersion == 5 && kernel.minorVersion >= 16);
1376 kernel.supportsFsync = kernelSupports;
1377 kernel.fsyncStatus = kernelSupports ? "available" : "kernel_too_old";
1378 }
1379
1380 // Detect NTSync support
1381 detectNTSync();
1382
1383 // Detect kernel parameters
1384 detectKernelParams();
1385
1386 // Esync is always supported on modern kernels
1387 kernel.supportsEsync = true;
1388
1390 "Detected kernel: {} (distro: {}, fsync: {}, ntsync: {} [loaded: {}], CachyOS: {})",
1391 kernel.version, kernel.distro, kernel.fsyncStatus, kernel.ntsyncStatus,
1392 kernel.ntsyncModuleLoaded ? "yes" : "no", kernel.isCachyOS ? "yes" : "no");
1393
1394 // Detect CPU scheduler (needs kernel version info)
1395 detectScheduler();
1396}
1397
1398void SystemInfoService::detectNTSync()
1399{
1400 KernelInfo& kernel = capabilities_.kernel;
1401
1402 // NTSync was merged in kernel 6.14 (not 6.2 as previously thought)
1403 // Reference:
1404 // https://www.gamingonlinux.com/2025/12/fedora-linux-44-will-get-improved-ntsync-enabling-for-proton-wine/
1405 bool ntsyncKernelOk =
1406 (kernel.majorVersion > 6) || (kernel.majorVersion == 6 && kernel.minorVersion >= 14);
1407
1408 // CachyOS and some other distros backport ntsync to earlier kernels
1409 // So we also check for the module/device presence regardless of kernel version
1410 bool ntsyncDeviceExists = std::filesystem::exists("/dev/ntsync");
1411 bool ntsyncModuleExists = std::filesystem::exists("/sys/module/ntsync");
1412
1413 // Check if module is loaded via lsmod equivalent
1414 bool moduleLoaded = ntsyncDeviceExists || ntsyncModuleExists;
1415
1416 // Also check kallsyms for built-in ntsync (kernel compiled with CONFIG_NTSYNC=y)
1417 if (!moduleLoaded)
1418 {
1419 try
1420 {
1421 std::ifstream kallsyms("/proc/kallsyms");
1422 std::string line;
1423 while (std::getline(kallsyms, line))
1424 {
1425 if (line.find("ntsync") != std::string::npos)
1426 {
1427 moduleLoaded = true;
1428 break;
1429 }
1430 }
1431 }
1432 catch (...)
1433 {
1434 }
1435 }
1436
1437 kernel.ntsyncModuleLoaded = moduleLoaded;
1438
1439 if (!ntsyncKernelOk && !moduleLoaded)
1440 {
1441 // Kernel too old and no backported module
1442 kernel.supportsNTSync = false;
1443 kernel.ntsyncStatus = "kernel_too_old";
1444 }
1445 else if (ntsyncKernelOk && !moduleLoaded)
1446 {
1447 // Kernel supports it but module not loaded - can be enabled with modprobe
1448 kernel.supportsNTSync = true; // Technically available
1449 kernel.ntsyncStatus = "needs_modprobe";
1450 }
1451 else if (moduleLoaded)
1452 {
1453 // Module is loaded and working
1454 kernel.supportsNTSync = true;
1455 kernel.ntsyncStatus = "available";
1456 }
1457 else
1458 {
1459 kernel.supportsNTSync = false;
1460 kernel.ntsyncStatus = "module_not_loaded";
1461 }
1462}
1463
1464void SystemInfoService::detectKernelParams()
1465{
1466 KernelInfo& kernel = capabilities_.kernel;
1467
1468 // Check vm.max_map_count (recommended: >= 2147483642 for gaming)
1469 try
1470 {
1471 std::ifstream maxMapFile("/proc/sys/vm/max_map_count");
1472 if (maxMapFile >> kernel.maxMapCount)
1473 {
1474 // Recommended value from Arch Wiki Gaming
1475 kernel.maxMapCountOk = (kernel.maxMapCount >= 1048576); // 1M is common gaming minimum
1476 }
1477 }
1478 catch (...)
1479 {
1480 }
1481
1482 // Check vm.swappiness (lower is better for gaming, recommended <= 10)
1483 try
1484 {
1485 std::ifstream swappinessFile("/proc/sys/vm/swappiness");
1486 if (swappinessFile >> kernel.swappiness)
1487 {
1488 kernel.swappinessOk = (kernel.swappiness <= 10);
1489 }
1490 }
1491 catch (...)
1492 {
1493 }
1494
1495 Logger::info("Kernel params: max_map_count={} (ok: {}), swappiness={} (ok: {})",
1496 kernel.maxMapCount, kernel.maxMapCountOk ? "yes" : "no", kernel.swappiness,
1497 kernel.swappinessOk ? "yes" : "no");
1498}
1499
1500void SystemInfoService::detectTools()
1501{
1502 ToolAvailability& tools = capabilities_.tools;
1503
1504 // Check for MangoHud
1505 tools.mangoHud = isToolAvailable("mangohud");
1506 if (tools.mangoHud)
1507 {
1508 // Try to get version
1509 // mangohud --version
1510 }
1511
1512 // Check for GameMode
1513 tools.gameMode = isToolAvailable("gamemoderun");
1514 if (tools.gameMode)
1515 {
1516 // Try to get version
1517 }
1518
1519 // Check for game-performance (CachyOS)
1520 tools.gamePerformance = isToolAvailable("game-performance");
1521
1522 // Check for VkBasalt
1523 tools.vkBasalt =
1524 isToolAvailable("vkbasalt") || std::filesystem::exists("/usr/share/vkBasalt/vkBasalt.conf");
1525
1526 // Check for Gamescope
1527 tools.gamescope = isToolAvailable("gamescope");
1528
1529 // Check for libstrangle
1530 tools.strangle = isToolAvailable("strangle");
1531
1532 // Check for power-profiles-daemon
1533 tools.powerProfilesDaemon =
1534 isToolAvailable("powerprofilesctl") ||
1535 std::filesystem::exists("/usr/lib/systemd/system/power-profiles-daemon.service");
1536
1537 // Check for ananicy-cpp active. CachyOS gaming spins enable this by
1538 // default and it conflicts with gamemoderun — both race on
1539 // sched_setscheduler, per CachyOS forum guidance. systemctl exits 0
1540 // when the unit is active; pipe to /dev/null to suppress output.
1541 {
1542 const int rc = std::system("systemctl is-active --quiet ananicy-cpp.service 2>/dev/null");
1543 tools.ananicyCppActive = (rc == 0);
1544 }
1545
1546 Logger::info("Detected tools: MangoHud={}, GameMode={}, game-performance={}, VkBasalt={}, "
1547 "Gamescope={}, power-profiles={}, ananicy-cpp={}",
1548 tools.mangoHud ? "yes" : "no", tools.gameMode ? "yes" : "no",
1549 tools.gamePerformance ? "yes" : "no", tools.vkBasalt ? "yes" : "no",
1550 tools.gamescope ? "yes" : "no", tools.powerProfilesDaemon ? "yes" : "no",
1551 tools.ananicyCppActive ? "active" : "inactive");
1552}
1553
1554void SystemInfoService::detectRunners()
1555{
1556 std::vector<RunnerInfo>& runners = capabilities_.runners;
1557 runners.clear();
1558
1559 // Use existing Proton scanner
1560 auto protonVersions = SteamLibraryScanner::scanProtonVersions();
1561
1562 for (const auto& [name, path] : protonVersions)
1563 {
1564 RunnerInfo info;
1565 info.name = name;
1566 info.path = path.string();
1567 info.version = name;
1568
1569 // Categorize the runner
1570 std::string nameLower = name;
1571 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(),
1572 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
1573
1574 if (nameLower.find("cachyos") != std::string::npos)
1575 {
1576 info.type = "proton-cachyos";
1577 }
1578 else if (nameLower.find("ge-proton") != std::string::npos)
1579 {
1580 info.type = "proton-ge";
1581 }
1582 else if (nameLower.find("proton") != std::string::npos)
1583 {
1584 info.type = "proton";
1585 }
1586 else if (nameLower.find("wine") != std::string::npos)
1587 {
1588 info.type = "wine";
1589 }
1590 else
1591 {
1592 info.type = "proton"; // Default assumption
1593 }
1594
1595 runners.push_back(std::move(info));
1596 }
1597
1598 // Check for system Wine
1599 if (isToolAvailable("wine"))
1600 {
1601 RunnerInfo sysWine;
1602 sysWine.name = "System Wine";
1603 sysWine.path = getToolPath("wine");
1604 sysWine.type = "wine";
1605 runners.push_back(std::move(sysWine));
1606 }
1607
1608 Logger::info("Detected {} runner(s)", runners.size());
1609}
1610
1611void SystemInfoService::detectDisplayServer()
1612{
1613 // Check XDG_SESSION_TYPE first
1614 if (const char* sessionType = std::getenv("XDG_SESSION_TYPE"))
1615 {
1616 std::string type = sessionType;
1617 if (type == "wayland")
1618 {
1619 capabilities_.displayServer = DisplayServer::Wayland;
1620 Logger::info("Display server: Wayland");
1621 return;
1622 }
1623 else if (type == "x11")
1624 {
1625 capabilities_.displayServer = DisplayServer::X11;
1626 Logger::info("Display server: X11");
1627 return;
1628 }
1629 }
1630
1631 // Fallback: check WAYLAND_DISPLAY and DISPLAY
1632 if (std::getenv("WAYLAND_DISPLAY"))
1633 {
1634 capabilities_.displayServer = DisplayServer::Wayland;
1635 Logger::info("Display server: Wayland (via WAYLAND_DISPLAY)");
1636 }
1637 else if (std::getenv("DISPLAY"))
1638 {
1639 capabilities_.displayServer = DisplayServer::X11;
1640 Logger::info("Display server: X11 (via DISPLAY)");
1641 }
1642 else
1643 {
1644 capabilities_.displayServer = DisplayServer::Unknown;
1645 Logger::info("Display server: Unknown");
1646 }
1647}
1648
1649// ==============================================================================
1650// Memory Detection
1651// ==============================================================================
1652
1653void SystemInfoService::detectMemory()
1654{
1655 MemoryInfo& mem = capabilities_.memory;
1656
1657 try
1658 {
1659 std::ifstream meminfo("/proc/meminfo");
1660 std::string line;
1661
1662 while (std::getline(meminfo, line))
1663 {
1664 if (line.find("MemTotal:") == 0)
1665 {
1666 // Format: "MemTotal: 32567432 kB"
1667 std::istringstream iss(line);
1668 std::string label;
1669 uint64_t value;
1670 iss >> label >> value;
1671 mem.totalMB = value / 1024;
1672 }
1673 else if (line.find("MemAvailable:") == 0)
1674 {
1675 std::istringstream iss(line);
1676 std::string label;
1677 uint64_t value;
1678 iss >> label >> value;
1679 mem.availableMB = value / 1024;
1680 }
1681 else if (line.find("SwapTotal:") == 0)
1682 {
1683 std::istringstream iss(line);
1684 std::string label;
1685 uint64_t value;
1686 iss >> label >> value;
1687 mem.swapTotalMB = value / 1024;
1688 }
1689 else if (line.find("SwapFree:") == 0)
1690 {
1691 std::istringstream iss(line);
1692 std::string label;
1693 uint64_t value;
1694 iss >> label >> value;
1695 mem.swapFreeMB = value / 1024;
1696 }
1697 }
1698
1699 Logger::info("Detected memory: {}MB total, {}MB available, {}MB swap", mem.totalMB,
1700 mem.availableMB, mem.swapTotalMB);
1701 }
1702 catch (const std::exception& e)
1703 {
1704 Logger::warn("Error detecting memory: {}", e.what());
1705 }
1706}
1707
1708// ==============================================================================
1709// Driver Version Detection
1710// ==============================================================================
1711
1712void SystemInfoService::detectDriverVersion()
1713{
1714 GPUInfo& gpu = capabilities_.gpu;
1715
1716 if (gpu.vendor == GPUVendor::NVIDIA)
1717 {
1718 // Read NVIDIA driver version from /proc/driver/nvidia/version
1719 try
1720 {
1721 std::ifstream nvVersion("/proc/driver/nvidia/version");
1722 std::string line;
1723 if (std::getline(nvVersion, line))
1724 {
1725 // Format: "NVRM version: NVIDIA UNIX x86_64 Kernel Module 565.57.01 ..."
1726 std::regex versionRegex(R"((\d+\.\d+\.\d+))");
1727 std::smatch match;
1728 if (std::regex_search(line, match, versionRegex))
1729 {
1730 gpu.driverVersion = match[1].str();
1731 }
1732 }
1733 }
1734 catch (...)
1735 {
1736 }
1737 }
1738 else if (gpu.vendor == GPUVendor::AMD || gpu.vendor == GPUVendor::Intel)
1739 {
1740 // Read Mesa version from glxinfo or vulkaninfo
1741 // Try parsing from /usr/share/vulkan/icd.d or libGL.so
1742 try
1743 {
1744 // Method 1: Check Mesa version from package or library
1745 std::ifstream mesaVersion("/usr/share/doc/mesa/version");
1746 if (mesaVersion.is_open())
1747 {
1748 std::getline(mesaVersion, gpu.mesaVersion);
1749 }
1750 else
1751 {
1752 // Method 2: Parse from DRI debug output (less reliable)
1753 // Most systems have mesa version in /proc/dri/*/name
1754 for (const auto& entry : std::filesystem::directory_iterator("/sys/class/drm"))
1755 {
1756 std::string name = entry.path().filename().string();
1757 if (name.find("card") == 0 && name.find("-") == std::string::npos)
1758 {
1759 std::filesystem::path driverPath = entry.path() / "device/driver";
1760 if (std::filesystem::exists(driverPath))
1761 {
1762 auto resolved = std::filesystem::read_symlink(driverPath);
1763 std::string driverName = resolved.filename().string();
1764 if (driverName == "amdgpu" || driverName == "radeon" ||
1765 driverName == "i915")
1766 {
1767 gpu.driverVersion = driverName;
1768 }
1769 }
1770 break;
1771 }
1772 }
1773 }
1774 }
1775 catch (...)
1776 {
1777 }
1778 }
1779
1780 if (!gpu.driverVersion.empty())
1781 {
1782 Logger::info("Detected driver version: {}", gpu.driverVersion);
1783 }
1784}
1785
1786// ==============================================================================
1787// CPU Governor and Scheduler Detection
1788// ==============================================================================
1789
1790void SystemInfoService::detectCPUGovernor()
1791{
1792 CPUInfo& cpu = capabilities_.cpu;
1793
1794 try
1795 {
1796 // Read current governor from first CPU
1797 std::ifstream govFile("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
1798 if (govFile.is_open())
1799 {
1800 std::getline(govFile, cpu.governor);
1801 }
1802
1803 // Read max frequency
1804 std::ifstream maxFreqFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
1805 if (maxFreqFile.is_open())
1806 {
1807 uint64_t maxFreqKHz;
1808 maxFreqFile >> maxFreqKHz;
1809 cpu.maxFrequencyMHz = static_cast<double>(maxFreqKHz) / 1000.0;
1810 }
1811
1812 Logger::info("CPU governor: {}, max freq: {:.0f}MHz", cpu.governor, cpu.maxFrequencyMHz);
1813 }
1814 catch (const std::exception& e)
1815 {
1816 Logger::warn("Error detecting CPU governor: {}", e.what());
1817 }
1818}
1819
1820void SystemInfoService::detectScheduler()
1821{
1822 CPUInfo& cpu = capabilities_.cpu;
1823
1824 // Detect scheduler by checking kernel config or sched features
1825 try
1826 {
1827 // =======================================================================
1828 // Step 1: Check for sched-ext (BPF-based pluggable schedulers)
1829 // sched-ext allows loading custom schedulers like scx_lavd, scx_rusty
1830 // =======================================================================
1831
1832 // Check if sched-ext is supported by looking for the sysfs interface
1833 bool schedExtSupported = std::filesystem::exists("/sys/kernel/sched_ext");
1834 cpu.hasSchedExt = schedExtSupported;
1835
1836 if (schedExtSupported)
1837 {
1838 // Check which sched-ext scheduler is currently active
1839 std::ifstream stateFile("/sys/kernel/sched_ext/state");
1840 if (stateFile.is_open())
1841 {
1842 std::string state;
1843 std::getline(stateFile, state);
1844
1845 // If state is "enabled", a sched-ext scheduler is active
1846 if (state.find("enabled") != std::string::npos)
1847 {
1848 // Try to get the scheduler name
1849 std::ifstream nameFile("/sys/kernel/sched_ext/root/name");
1850 if (nameFile.is_open())
1851 {
1852 std::string schedName;
1853 std::getline(nameFile, schedName);
1854 cpu.schedExtName = schedName;
1855
1856 // Categorize the sched-ext scheduler
1857 if (schedName.find("lavd") != std::string::npos ||
1858 schedName.find("LAVD") != std::string::npos)
1859 {
1861 Logger::info("Detected scheduler: sched-ext LAVD (gaming-optimized)");
1862 }
1863 else if (schedName.find("rusty") != std::string::npos)
1864 {
1866 Logger::info("Detected scheduler: sched-ext Rusty");
1867 }
1868 else if (schedName.find("bpfland") != std::string::npos)
1869 {
1871 Logger::info("Detected scheduler: sched-ext Bpfland");
1872 }
1873 else
1874 {
1876 Logger::info("Detected scheduler: sched-ext ({})", schedName);
1877 }
1878 return;
1879 }
1880 }
1881 }
1882 }
1883
1884 // =======================================================================
1885 // Step 2: Check for BORE scheduler (CachyOS default when not using sched-ext)
1886 // =======================================================================
1887 std::ifstream schedFile("/sys/kernel/debug/sched/features");
1888 if (schedFile.is_open())
1889 {
1890 std::string features;
1891 std::getline(schedFile, features);
1892
1893 if (features.find("BORE") != std::string::npos)
1894 {
1896 Logger::info("Detected scheduler: BORE");
1897 return;
1898 }
1899 }
1900
1901 // =======================================================================
1902 // Step 3: Fall back to kernel version detection (EEVDF 6.6+ or CFS)
1903 // =======================================================================
1904 const auto& kernel = capabilities_.kernel;
1905 if (kernel.majorVersion > 6 || (kernel.majorVersion == 6 && kernel.minorVersion >= 6))
1906 {
1908 Logger::info("Detected scheduler: EEVDF (kernel 6.6+)");
1909 }
1910 else
1911 {
1913 Logger::info("Detected scheduler: CFS");
1914 }
1915 }
1916 catch (...)
1917 {
1919 }
1920}
1921
1922// ==============================================================================
1923// Monitor Detection
1924// ==============================================================================
1925
1926void SystemInfoService::detectMonitors()
1927{
1928 std::vector<MonitorInfo>& monitors = capabilities_.monitors;
1929 monitors.clear();
1930
1931 // Try to read from /sys/class/drm for connected displays
1932 try
1933 {
1934 for (const auto& entry : std::filesystem::directory_iterator("/sys/class/drm"))
1935 {
1936 std::string name = entry.path().filename().string();
1937
1938 // Look for connectors like "card0-DP-1", "card0-HDMI-A-1"
1939 if (name.find("card") != 0 || name.find("-") == std::string::npos)
1940 continue;
1941
1942 // Check if connected
1943 std::filesystem::path statusPath = entry.path() / "status";
1944 if (!std::filesystem::exists(statusPath))
1945 continue;
1946
1947 std::ifstream statusFile(statusPath);
1948 std::string status;
1949 std::getline(statusFile, status);
1950
1951 if (status != "connected")
1952 continue;
1953
1954 MonitorInfo monitor;
1955
1956 // Extract connector type from name (e.g., "card0-DP-1" -> "DP-1")
1957 size_t dashPos = name.find('-');
1958 if (dashPos != std::string::npos)
1959 {
1960 monitor.connector = name.substr(dashPos + 1);
1961 }
1962
1963 // Try to read EDID for monitor name
1964 std::filesystem::path edidPath = entry.path() / "edid";
1965 if (std::filesystem::exists(edidPath))
1966 {
1967 // EDID parsing is complex, we'll just mark it as detected
1968 // A full implementation would parse the EDID binary
1969 }
1970
1971 // Read current mode for resolution/refresh
1972 std::filesystem::path modesPath = entry.path() / "modes";
1973 if (std::filesystem::exists(modesPath))
1974 {
1975 std::ifstream modesFile(modesPath);
1976 std::string firstMode;
1977 if (std::getline(modesFile, firstMode))
1978 {
1979 // Format: "1920x1080" or "2560x1440@144"
1980 std::regex modeRegex(R"((\d+)x(\d+)(?:@(\d+))?)");
1981 std::smatch match;
1982 if (std::regex_match(firstMode, match, modeRegex))
1983 {
1984 monitor.widthPixels = std::stoi(match[1].str());
1985 monitor.heightPixels = std::stoi(match[2].str());
1986 if (match[3].matched)
1987 {
1988 monitor.refreshRate = std::stod(match[3].str());
1989 }
1990 }
1991 }
1992 }
1993
1994 // Check for VRR support
1995 std::filesystem::path vrrPath = entry.path() / "vrr_capable";
1996 if (std::filesystem::exists(vrrPath))
1997 {
1998 std::ifstream vrrFile(vrrPath);
1999 int vrrCapable = 0;
2000 vrrFile >> vrrCapable;
2001 monitor.supportsVRR = (vrrCapable == 1);
2002 }
2003
2004 // Check for HDR support (via hdr_output_metadata or colorspace)
2005 std::filesystem::path hdrPath = entry.path() / "hdr_output_metadata";
2006 if (std::filesystem::exists(hdrPath))
2007 {
2008 monitor.supportsHDR = true;
2009 }
2010
2011 // First monitor is typically primary
2012 monitor.isPrimary = monitors.empty();
2013 monitor.name = monitor.connector;
2014
2015 monitors.push_back(std::move(monitor));
2016 }
2017
2018 Logger::info("Detected {} monitor(s)", monitors.size());
2019 for (const auto& m : monitors)
2020 {
2021 Logger::info(" {} : {}x{} @{:.0f}Hz VRR={} HDR={}", m.connector, m.widthPixels,
2022 m.heightPixels, m.refreshRate, m.supportsVRR ? "yes" : "no",
2023 m.supportsHDR ? "yes" : "no");
2024 }
2025 }
2026 catch (const std::exception& e)
2027 {
2028 Logger::warn("Error detecting monitors: {}", e.what());
2029 }
2030}
2031
2032// ==============================================================================
2033// Controller Detection
2034// ==============================================================================
2035
2036void SystemInfoService::detectControllers()
2037{
2038 std::vector<ControllerInfo>& controllers = capabilities_.controllers;
2039 controllers.clear();
2040
2041 try
2042 {
2043 // Scan /dev/input for joysticks and gamepads
2044 for (const auto& entry : std::filesystem::directory_iterator("/dev/input"))
2045 {
2046 std::string name = entry.path().filename().string();
2047
2048 // Look for event devices or js devices
2049 if (name.find("js") != 0)
2050 continue;
2051
2052 // Get device info from /sys/class/input
2053 std::filesystem::path sysPath = "/sys/class/input/" + name + "/device";
2054
2055 if (!std::filesystem::exists(sysPath))
2056 continue;
2057
2058 ControllerInfo controller;
2059 controller.path = entry.path().string();
2060
2061 // Read device name
2062 std::filesystem::path namePath = sysPath / "name";
2063 if (std::filesystem::exists(namePath))
2064 {
2065 std::ifstream nameFile(namePath);
2066 std::getline(nameFile, controller.name);
2067 }
2068
2069 // Read vendor/product IDs
2070 std::filesystem::path idPath = sysPath / "id";
2071 if (std::filesystem::exists(idPath))
2072 {
2073 std::filesystem::path vendorPath = idPath / "vendor";
2074 std::filesystem::path productPath = idPath / "product";
2075
2076 if (std::filesystem::exists(vendorPath))
2077 {
2078 std::ifstream vendorFile(vendorPath);
2079 std::string vendorStr;
2080 vendorFile >> vendorStr;
2081 try
2082 {
2083 controller.vendorId =
2084 static_cast<uint16_t>(std::stoul(vendorStr, nullptr, 16));
2085 }
2086 catch (...)
2087 {
2088 }
2089 }
2090
2091 if (std::filesystem::exists(productPath))
2092 {
2093 std::ifstream productFile(productPath);
2094 std::string productStr;
2095 productFile >> productStr;
2096 try
2097 {
2098 controller.productId =
2099 static_cast<uint16_t>(std::stoul(productStr, nullptr, 16));
2100 }
2101 catch (...)
2102 {
2103 }
2104 }
2105 }
2106
2107 // Detect controller type
2108 controller.type = detectControllerType(controller.vendorId, controller.productId);
2109
2110 // Check if wireless (heuristic: bluetooth or wireless in name)
2111 std::string nameLower = controller.name;
2112 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(),
2113 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
2114 controller.isWireless = (nameLower.find("bluetooth") != std::string::npos ||
2115 nameLower.find("wireless") != std::string::npos);
2116
2117 controllers.push_back(std::move(controller));
2118 }
2119
2120 Logger::info("Detected {} controller(s)", controllers.size());
2121 for (const auto& c : controllers)
2122 {
2123 Logger::info(" {} ({}) VID={:04x} PID={:04x}", c.name, c.type, c.vendorId,
2124 c.productId);
2125 }
2126 }
2127 catch (const std::exception& e)
2128 {
2129 Logger::warn("Error detecting controllers: {}", e.what());
2130 }
2131}
2132
2133std::string SystemInfoService::detectControllerType(uint16_t vendorId, uint16_t productId)
2134{
2135 (void)productId; // Used for more specific detection if needed
2136
2137 // Known vendor IDs
2138 constexpr uint16_t VENDOR_MICROSOFT = 0x045e;
2139 constexpr uint16_t VENDOR_SONY = 0x054c;
2140 constexpr uint16_t VENDOR_NINTENDO = 0x057e;
2141 constexpr uint16_t VENDOR_VALVE = 0x28de;
2142 constexpr uint16_t VENDOR_8BITDO = 0x2dc8;
2143
2144 switch (vendorId)
2145 {
2146 case VENDOR_MICROSOFT:
2147 return "xbox";
2148 case VENDOR_SONY:
2149 return "playstation";
2150 case VENDOR_NINTENDO:
2151 return "nintendo";
2152 case VENDOR_VALVE:
2153 return "steam";
2154 case VENDOR_8BITDO:
2155 return "8bitdo";
2156 default:
2157 return "generic";
2158 }
2159}
2160
2161// ==============================================================================
2162// Storage Detection
2163// ==============================================================================
2164
2165void SystemInfoService::detectStorage()
2166{
2167 std::vector<StorageInfo>& storage = capabilities_.storage;
2168 storage.clear();
2169
2170 try
2171 {
2172 // Read /proc/mounts to get mounted filesystems
2173 std::ifstream mounts("/proc/mounts");
2174 std::string line;
2175
2176 while (std::getline(mounts, line))
2177 {
2178 std::istringstream iss(line);
2179 std::string device, mountPoint, fsType;
2180 iss >> device >> mountPoint >> fsType;
2181
2182 // Skip virtual filesystems
2183 if (device.find("/dev/") != 0)
2184 continue;
2185
2186 // Skip non-storage filesystems
2187 if (fsType == "tmpfs" || fsType == "devtmpfs" || fsType == "proc" ||
2188 fsType == "sysfs" || fsType == "cgroup" || fsType == "cgroup2")
2189 continue;
2190
2191 StorageInfo info;
2192 info.device = device;
2193 info.mountPoint = mountPoint;
2194 info.filesystem = fsType;
2195
2196 // Detect storage type
2197 info.type = detectStorageType(device);
2198
2199 // Get disk space using statvfs
2200 struct statvfs stat;
2201 if (statvfs(mountPoint.c_str(), &stat) == 0)
2202 {
2203 info.totalGB = (stat.f_blocks * stat.f_frsize) / (1024ULL * 1024 * 1024);
2204 info.freeGB = (stat.f_bavail * stat.f_frsize) / (1024ULL * 1024 * 1024);
2205 }
2206
2207 // Check for discard/TRIM support
2208 std::string deviceName = std::filesystem::path(device).filename().string();
2209 // Remove partition number to get base device
2210 while (!deviceName.empty() &&
2211 std::isdigit(static_cast<unsigned char>(deviceName.back())))
2212 {
2213 deviceName.pop_back();
2214 }
2215 // Remove 'p' from nvme devices (nvme0n1p1 -> nvme0n1)
2216 if (deviceName.size() > 1 && deviceName.back() == 'p' &&
2217 deviceName.find("nvme") != std::string::npos)
2218 {
2219 deviceName.pop_back();
2220 }
2221
2222 std::filesystem::path discardPath =
2223 "/sys/block/" + deviceName + "/queue/discard_max_bytes";
2224 if (std::filesystem::exists(discardPath))
2225 {
2226 std::ifstream discardFile(discardPath);
2227 uint64_t discardMax = 0;
2228 discardFile >> discardMax;
2229 info.isTRIM = (discardMax > 0);
2230 }
2231
2232 storage.push_back(std::move(info));
2233 }
2234
2235 Logger::info("Detected {} mount point(s)", storage.size());
2236 for (const auto& s : storage)
2237 {
2238 Logger::info(" {} on {} ({}) - {} {}GB free/{}GB", s.device, s.mountPoint,
2239 s.filesystem,
2240 s.type == StorageType::NVMe ? "NVMe"
2241 : s.type == StorageType::SSD ? "SSD"
2242 : s.type == StorageType::HDD ? "HDD"
2243 : "Unknown",
2244 s.freeGB, s.totalGB);
2245 }
2246 }
2247 catch (const std::exception& e)
2248 {
2249 Logger::warn("Error detecting storage: {}", e.what());
2250 }
2251}
2252
2253StorageType SystemInfoService::detectStorageType(const std::string& device)
2254{
2255 std::string deviceName = std::filesystem::path(device).filename().string();
2256
2257 // Remove partition number to get base device
2258 while (!deviceName.empty() && std::isdigit(static_cast<unsigned char>(deviceName.back())))
2259 {
2260 deviceName.pop_back();
2261 }
2262 // Remove 'p' from nvme devices
2263 if (deviceName.size() > 1 && deviceName.back() == 'p' &&
2264 deviceName.find("nvme") != std::string::npos)
2265 {
2266 deviceName.pop_back();
2267 }
2268
2269 // NVMe devices
2270 if (deviceName.find("nvme") != std::string::npos)
2271 {
2272 return StorageType::NVMe;
2273 }
2274
2275 // Check rotational flag for SSD vs HDD
2276 std::filesystem::path rotationalPath = "/sys/block/" + deviceName + "/queue/rotational";
2277 if (std::filesystem::exists(rotationalPath))
2278 {
2279 std::ifstream rotFile(rotationalPath);
2280 int rotational = 1;
2281 rotFile >> rotational;
2282 return (rotational == 0) ? StorageType::SSD : StorageType::HDD;
2283 }
2284
2285 return StorageType::Unknown;
2286}
2287
2289{
2290 // Find the mount point that contains this path
2291 std::string bestMatch;
2293
2294 for (const auto& s : storage)
2295 {
2296 if (path.find(s.mountPoint) == 0)
2297 {
2298 if (s.mountPoint.length() > bestMatch.length())
2299 {
2300 bestMatch = s.mountPoint;
2301 bestType = s.type;
2302 }
2303 }
2304 }
2305
2306 return bestType;
2307}
2308
2309// ==============================================================================
2310// Power/Battery Detection
2311// ==============================================================================
2312
2313void SystemInfoService::detectPower()
2314{
2315 PowerInfo& power = capabilities_.power;
2316
2317 try
2318 {
2319 // Check for battery (indicates laptop)
2320 std::filesystem::path powerSupplyPath = "/sys/class/power_supply";
2321 if (std::filesystem::exists(powerSupplyPath))
2322 {
2323 for (const auto& entry : std::filesystem::directory_iterator(powerSupplyPath))
2324 {
2325 // Check type
2326 std::filesystem::path typePath = entry.path() / "type";
2327 if (std::filesystem::exists(typePath))
2328 {
2329 std::ifstream typeFile(typePath);
2330 std::string type;
2331 std::getline(typeFile, type);
2332
2333 if (type == "Battery")
2334 {
2335 power.isLaptop = true;
2336
2337 // Read battery status
2338 std::filesystem::path statusPath = entry.path() / "status";
2339 if (std::filesystem::exists(statusPath))
2340 {
2341 std::ifstream statusFile(statusPath);
2342 std::string status;
2343 std::getline(statusFile, status);
2344 power.onBattery = (status == "Discharging");
2345 }
2346
2347 // Read battery capacity
2348 std::filesystem::path capacityPath = entry.path() / "capacity";
2349 if (std::filesystem::exists(capacityPath))
2350 {
2351 std::ifstream capacityFile(capacityPath);
2352 capacityFile >> power.batteryPercent;
2353 }
2354
2355 break; // Found a battery
2356 }
2357 }
2358 }
2359 }
2360
2361 // Check for TLP
2362 power.hasTLP = isToolAvailable("tlp") || std::filesystem::exists("/etc/tlp.conf");
2363
2364 // Try to get current power profile from power-profiles-daemon
2365 if (capabilities_.tools.powerProfilesDaemon)
2366 {
2367 // Read from powerprofilesctl or D-Bus
2368 // For simplicity, check the current profile file
2369 std::filesystem::path profilePath = "/var/lib/power-profiles-daemon/power_profile";
2370 if (std::filesystem::exists(profilePath))
2371 {
2372 std::ifstream profileFile(profilePath);
2373 std::getline(profileFile, power.activeProfile);
2374 }
2375
2376 if (power.activeProfile == "performance")
2377 {
2379 }
2380 else if (power.activeProfile == "balanced")
2381 {
2383 }
2384 else if (power.activeProfile == "power-saver")
2385 {
2387 }
2388 }
2389
2390 Logger::info("Power: laptop={}, onBattery={}, battery={}%, profile={}",
2391 power.isLaptop ? "yes" : "no", power.onBattery ? "yes" : "no",
2392 power.batteryPercent,
2393 power.activeProfile.empty() ? "unknown" : power.activeProfile);
2394 }
2395 catch (const std::exception& e)
2396 {
2397 Logger::warn("Error detecting power info: {}", e.what());
2398 }
2399}
2400
2401// ==============================================================================
2402// SystemReadiness - warnings()
2403// ==============================================================================
2404
2405std::vector<std::string> SystemReadiness::warnings() const
2406{
2407 std::vector<std::string> result;
2408
2409 if (!maxMapCountOk)
2410 {
2411 result.push_back("vm.max_map_count is " + std::to_string(maxMapCount) +
2412 " (should be >= 1048576). Some games may crash. "
2413 "Fix: sudo sysctl -w vm.max_map_count=1048576");
2414 }
2415
2416 if (!splitLockOk)
2417 {
2418 std::string val = (splitLockMitigate == -1) ? "unknown" : std::to_string(splitLockMitigate);
2419 result.push_back("kernel.split_lock_mitigate is " + val +
2420 " (should be 0). Some games may stutter. "
2421 "Fix: sudo sysctl -w kernel.split_lock_mitigate=0");
2422 }
2423
2424 if (!nofileLimitOk)
2425 {
2426 result.push_back("Open file limit (RLIMIT_NOFILE) is " + std::to_string(nofileSoft) +
2427 " (should be >= 524288). Some games may fail to load assets. "
2428 "Fix: Add '* soft nofile 524288' to /etc/security/limits.conf");
2429 }
2430
2431 if (!thpOk)
2432 {
2433 result.push_back(
2434 "Transparent Hugepages is '" + thpSetting +
2435 "' (should be 'madvise'). Performance may be inconsistent. "
2436 "Fix: echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled");
2437 }
2438
2439 return result;
2440}
2441
2442// ==============================================================================
2443// SystemInfoService - detectSystemReadiness()
2444// ==============================================================================
2445
2446void SystemInfoService::detectSystemReadiness()
2447{
2448 SystemReadiness& readiness = capabilities_.systemReadiness;
2449
2450 // Check vm.max_map_count >= 1048576
2451 try
2452 {
2453 std::ifstream maxMapFile("/proc/sys/vm/max_map_count");
2454 if (maxMapFile >> readiness.maxMapCount)
2455 {
2456 readiness.maxMapCountOk = (readiness.maxMapCount >= 1048576);
2457 }
2458 }
2459 catch (...)
2460 {
2461 }
2462
2463 // Check kernel.split_lock_mitigate == 0
2464 try
2465 {
2466 std::ifstream splitLockFile("/proc/sys/kernel/split_lock_mitigate");
2467 if (splitLockFile >> readiness.splitLockMitigate)
2468 {
2469 readiness.splitLockOk = (readiness.splitLockMitigate == 0);
2470 }
2471 }
2472 catch (...)
2473 {
2474 // File may not exist on non-Intel or older kernels — treat as OK
2475 readiness.splitLockOk = true;
2476 }
2477
2478 // Check RLIMIT_NOFILE soft >= 524288
2479 try
2480 {
2481 struct rlimit rl;
2482 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
2483 {
2484 readiness.nofileSoft = static_cast<uint64_t>(rl.rlim_cur);
2485 readiness.nofileLimitOk = (readiness.nofileSoft >= 524288);
2486 }
2487 }
2488 catch (...)
2489 {
2490 }
2491
2492 // Check transparent_hugepage == madvise
2493 try
2494 {
2495 std::ifstream thpFile("/sys/kernel/mm/transparent_hugepage/enabled");
2496 std::string line;
2497 if (std::getline(thpFile, line))
2498 {
2499 // Format: "always [madvise] never" - the active value is in brackets
2500 auto bracketStart = line.find('[');
2501 auto bracketEnd = line.find(']');
2502 if (bracketStart != std::string::npos && bracketEnd != std::string::npos)
2503 {
2504 readiness.thpSetting = line.substr(bracketStart + 1, bracketEnd - bracketStart - 1);
2505 }
2506 else
2507 {
2508 readiness.thpSetting = line;
2509 }
2510 readiness.thpOk = (readiness.thpSetting == "madvise");
2511 }
2512 }
2513 catch (...)
2514 {
2515 }
2516
2517 Logger::info("System readiness: max_map_count={} (ok: {}), split_lock={} (ok: {}), "
2518 "nofile={} (ok: {}), thp='{}' (ok: {}), all_ok={}",
2519 readiness.maxMapCount, readiness.maxMapCountOk ? "yes" : "no",
2520 readiness.splitLockMitigate, readiness.splitLockOk ? "yes" : "no",
2521 readiness.nofileSoft, readiness.nofileLimitOk ? "yes" : "no", readiness.thpSetting,
2522 readiness.thpOk ? "yes" : "no", readiness.allOk() ? "yes" : "no");
2523}
static void info(const std::string &message, Args &&... args)
Log info message (general information).
Definition logger.h:108
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
Definition logger.h:100
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
Definition logger.h:116
static std::vector< std::pair< std::string, std::filesystem::path > > scanProtonVersions()
Scan for all installed Proton versions.
std::string getToolPath(const std::string &toolName)
Get path to tool binary.
static SystemInfoService & instance()
Get singleton instance.
std::string getRecommendedSyncMethod()
Get recommended sync method as string.
const std::vector< RunnerInfo > & getInstalledRunners()
Get all installed runners (Proton/Wine versions).
GPUVendor getGPUVendor()
Get GPU vendor.
const SystemCapabilities & getCapabilities()
Get complete system capabilities.
const std::vector< MonitorInfo > & getMonitors()
Get connected monitors.
const ToolAvailability & getToolAvailability()
Get available performance tools.
const SystemReadiness & getSystemReadiness()
Get system readiness checks.
const MemoryInfo & getMemoryInfo()
Get memory information.
bool isCachyOS()
Check if running on CachyOS.
void refresh()
Force refresh of all cached data.
void refreshRunners()
Refresh only runner list (faster than full refresh).
bool isToolAvailable(const std::string &toolName)
Check if tool is available by name.
bool supportsFsync()
Check if fsync is supported.
const KernelInfo & getKernelInfo()
Get kernel information.
SystemInfoService(const SystemInfoService &)=delete
DisplayServer getDisplayServer()
Get display server type.
const GPUInfo & getGPUInfo()
Get full GPU information.
bool supportsNTSync()
Check if NTSync is supported (kernel 6.2+ with module loaded).
const std::vector< StorageInfo > & getStorageInfo()
Get storage information.
std::string getGPUVendorName()
Get GPU vendor name as string.
const PowerInfo & getPowerInfo()
Get power/battery information.
const CPUInfo & getCPUInfo()
Get full CPU information.
const std::vector< ControllerInfo > & getControllers()
Get connected controllers.
Detected CPU information.
std::string schedExtName
double maxFrequencyMHz
CPUScheduler scheduler
std::string governor
std::string model
std::string vendor
Detected GPU information.
bool isRDNA4() const
bool isArcGPU() const
bool isRTXCapable() const
bool isRDNA3OrNewer() const
std::string mesaVersion
uint16_t deviceId
bool isRDNA2OrNewer() const
GPUVendor vendor
std::string driverVersion
GPUGeneration generation
std::string model
std::string vendorName
Kernel version and feature support.
std::string distro
std::string fsyncStatus
std::string ntsyncStatus
std::string version
System memory information.
std::string connector
Power and thermal information.
PowerProfile profile
std::string activeProfile
std::string version
std::string filesystem
std::string mountPoint
Complete system capabilities summary.
StorageType getStorageTypeForPath(const std::string &path) const
SystemReadiness systemReadiness
std::vector< StorageInfo > storage
System readiness checks for optimal gaming.
std::vector< std::string > warnings() const
Available performance tools and utilities.