LCOV - code coverage report
Current view: top level - source/lib/sysdep - os_cpu.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 21 9.5 %
Date: 2023-01-19 00:18:29 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* Copyright (C) 2010 Wildfire Games.
       2             :  *
       3             :  * Permission is hereby granted, free of charge, to any person obtaining
       4             :  * a copy of this software and associated documentation files (the
       5             :  * "Software"), to deal in the Software without restriction, including
       6             :  * without limitation the rights to use, copy, modify, merge, publish,
       7             :  * distribute, sublicense, and/or sell copies of the Software, and to
       8             :  * permit persons to whom the Software is furnished to do so, subject to
       9             :  * the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included
      12             :  * in all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      15             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      16             :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      17             :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      18             :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      19             :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      20             :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      21             :  */
      22             : 
      23             : /*
      24             :  * OS-specific support functions relating to CPU and memory
      25             :  */
      26             : 
      27             : #include "precompiled.h"
      28             : #include "lib/sysdep/os_cpu.h"
      29             : 
      30             : #include "lib/alignment.h"
      31             : #include "lib/sysdep/smbios.h"
      32             : 
      33             : #if OS_WIN
      34             : # include "lib/sysdep/os/win/wcpu.h"
      35             : #endif
      36             : 
      37             : static const StatusDefinition osCpuStatusDefinitions[] = {
      38             :     { ERR::OS_CPU_RESTRICTED_AFFINITY, L"Cannot set desired CPU affinity" }
      39             : };
      40           1 : STATUS_ADD_DEFINITIONS(osCpuStatusDefinitions);
      41             : 
      42             : 
      43           0 : double os_cpu_ClockFrequency()
      44             : {
      45             :     static double clockFrequency;
      46           0 :     if(clockFrequency != 0.0)   // already initialized
      47           0 :         return clockFrequency;
      48             : 
      49             : #if OS_WIN
      50             :     u32 freqMhz;
      51             :     if(wcpu_ReadFrequencyFromRegistry(freqMhz) == INFO::OK)
      52             :         return clockFrequency = freqMhz * 1e6;
      53             : #endif
      54             : 
      55           0 :     const SMBIOS::Structures* structures = SMBIOS::GetStructures();
      56           0 :     if(structures->Processor_)
      57           0 :         return clockFrequency = structures->Processor_->maxFrequency * 1e6;
      58             : 
      59           0 :     return clockFrequency = -1.0;   // unknown
      60             : }
      61             : 
      62             : 
      63           0 : size_t os_cpu_MemorySize()
      64             : {
      65             :     static size_t memorySize;
      66           0 :     if(memorySize != 0) // already initialized
      67           0 :         return memorySize;
      68             : 
      69           0 :     memorySize = os_cpu_QueryMemorySize();
      70             : 
      71             :     // replace with the sum of all memory devices reported by SMBIOS if
      72             :     // that's within 10% of what the OS reported
      73             :     {
      74           0 :         const SMBIOS::Structures* structures = SMBIOS::GetStructures();
      75           0 :         u64 memorySizeBytes = 0;
      76           0 :         for(const SMBIOS::MemoryDevice* p = structures->MemoryDevice_; p; p = p->next)
      77           0 :             memorySizeBytes += p->size;
      78           0 :         const size_t memorySize2 = memorySizeBytes/MiB;
      79           0 :         if(9*memorySize/10 <= memorySize2 && memorySize2 <= 11*memorySize/10)
      80           0 :             memorySize = memorySize2;
      81             :     }
      82             : 
      83           0 :     return memorySize;
      84           3 : }

Generated by: LCOV version 1.13