LCOV - code coverage report
Current view: top level - lib/eal/linux - eal_lcore.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 12 17 70.6 %
Date: 2024-01-22 16:13:49 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 16 68.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <unistd.h>
       6                 :            : #include <limits.h>
       7                 :            : 
       8                 :            : #include <rte_log.h>
       9                 :            : 
      10                 :            : #include "eal_private.h"
      11                 :            : #include "eal_filesystem.h"
      12                 :            : #include "eal_thread.h"
      13                 :            : 
      14                 :            : #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
      15                 :            : #define CORE_ID_FILE "topology/core_id"
      16                 :            : #define NUMA_NODE_PATH "/sys/devices/system/node"
      17                 :            : 
      18                 :            : /* Check if a cpu is present by the presence of the cpu information for it */
      19                 :            : int
      20         [ +  - ]:     240676 : eal_cpu_detected(unsigned lcore_id)
      21                 :            : {
      22                 :            :         char path[PATH_MAX];
      23                 :            :         int len = snprintf(path, sizeof(path), SYS_CPU_DIR
      24                 :            :                 "/"CORE_ID_FILE, lcore_id);
      25         [ +  - ]:     240676 :         if (len <= 0 || (unsigned)len >= sizeof(path))
      26                 :            :                 return 0;
      27         [ +  + ]:     240676 :         if (access(path, F_OK) != 0)
      28                 :     236880 :                 return 0;
      29                 :            : 
      30                 :            :         return 1;
      31                 :            : }
      32                 :            : 
      33                 :            : /*
      34                 :            :  * Get CPU socket id (NUMA node) for a logical core.
      35                 :            :  *
      36                 :            :  * This searches each nodeX directories in /sys for the symlink for the given
      37                 :            :  * lcore_id and returns the numa node where the lcore is found. If lcore is not
      38                 :            :  * found on any numa node, returns zero.
      39                 :            :  */
      40                 :            : unsigned
      41                 :      31566 : eal_cpu_socket_id(unsigned lcore_id)
      42                 :            : {
      43                 :            :         unsigned socket;
      44                 :            : 
      45         [ +  + ]:     875686 :         for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
      46                 :            :                 char path[PATH_MAX];
      47                 :            : 
      48                 :            :                 snprintf(path, sizeof(path), "%s/node%u/cpu%u", NUMA_NODE_PATH,
      49                 :            :                                 socket, lcore_id);
      50         [ +  + ]:     849366 :                 if (access(path, F_OK) == 0)
      51                 :       5246 :                         return socket;
      52                 :            :         }
      53                 :            :         return 0;
      54                 :            : }
      55                 :            : 
      56                 :            : /* Get the cpu core id value from the /sys/.../cpuX core_id value */
      57                 :            : unsigned
      58         [ -  + ]:       3760 : eal_cpu_core_id(unsigned lcore_id)
      59                 :            : {
      60                 :            :         char path[PATH_MAX];
      61                 :            :         unsigned long id;
      62                 :            : 
      63                 :            :         int len = snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", lcore_id, CORE_ID_FILE);
      64         [ -  + ]:       3760 :         if (len <= 0 || (unsigned)len >= sizeof(path))
      65                 :          0 :                 goto err;
      66         [ -  + ]:       3760 :         if (eal_parse_sysfs_value(path, &id) != 0)
      67                 :          0 :                 goto err;
      68                 :       3760 :         return (unsigned)id;
      69                 :            : 
      70                 :          0 : err:
      71                 :          0 :         EAL_LOG(ERR, "Error reading core id value from %s "
      72                 :            :                         "for lcore %u - assuming core 0", SYS_CPU_DIR, lcore_id);
      73                 :          0 :         return 0;
      74                 :            : }

Generated by: LCOV version 1.14