LCOV - code coverage report
Current view: top level - lib/eal/x86 - rte_hypervisor.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 10 10 100.0 %
Date: 2025-02-01 18:54:23 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 10 60.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2017 Mellanox Technologies, Ltd
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "rte_hypervisor.h"
       6                 :            : 
       7                 :            : #include <stdint.h>
       8                 :            : #include <string.h>
       9                 :            : 
      10                 :            : #include "rte_cpuflags.h"
      11                 :            : #include "rte_cpuid.h"
      12                 :            : 
      13                 :            : /* See http://lwn.net/Articles/301888/ */
      14                 :            : #define HYPERVISOR_INFO_LEAF 0x40000000
      15                 :            : 
      16                 :            : enum rte_hypervisor
      17                 :        252 : rte_hypervisor_get(void)
      18                 :            : {
      19                 :            :         cpuid_registers_t regs;
      20                 :            :         int reg;
      21                 :            :         char name[13];
      22                 :            : 
      23         [ +  - ]:        252 :         if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_HYPERVISOR))
      24                 :            :                 return RTE_HYPERVISOR_NONE;
      25                 :            : 
      26                 :            : #ifdef RTE_TOOLCHAIN_MSVC
      27                 :            :         __cpuid(regs, HYPERVISOR_INFO_LEAF);
      28                 :            : #else
      29                 :        252 :         __cpuid(HYPERVISOR_INFO_LEAF,
      30                 :            :                         regs[RTE_REG_EAX], regs[RTE_REG_EBX],
      31                 :            :                         regs[RTE_REG_ECX], regs[RTE_REG_EDX]);
      32                 :            : #endif
      33         [ +  + ]:       1008 :         for (reg = 1; reg < 4; reg++)
      34                 :        756 :                 memcpy(name + (reg - 1) * 4, &regs[reg], 4);
      35                 :        252 :         name[12] = '\0';
      36                 :            : 
      37         [ +  - ]:        252 :         if (strcmp("KVMKVMKVM", name) == 0)
      38                 :            :                 return RTE_HYPERVISOR_KVM;
      39         [ +  - ]:        252 :         if (strcmp("Microsoft Hv", name) == 0)
      40                 :            :                 return RTE_HYPERVISOR_HYPERV;
      41         [ +  - ]:        252 :         if (strcmp("VMwareVMware", name) == 0)
      42                 :        252 :                 return RTE_HYPERVISOR_VMWARE;
      43                 :            :         return RTE_HYPERVISOR_UNKNOWN;
      44                 :            : }

Generated by: LCOV version 1.14