Coverage Report

Created: 2025-10-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hwloc/include/hwloc/inlines.h
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: BSD-3-Clause
3
 * Copyright © 2009 CNRS
4
 * Copyright © 2009-2025 Inria.  All rights reserved.
5
 * Copyright © 2009-2012 Université Bordeaux
6
 * Copyright © 2009-2010 Cisco Systems, Inc.  All rights reserved.
7
 * See COPYING in top-level directory.
8
 */
9
10
/**
11
 * This file contains the inline code of functions declared in hwloc.h
12
 */
13
14
#ifndef HWLOC_INLINES_H
15
#define HWLOC_INLINES_H
16
17
#ifndef HWLOC_H
18
#error Please include the main hwloc.h instead
19
#endif
20
21
#include <stdlib.h>
22
#include <errno.h>
23
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
static __hwloc_inline int
30
hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
31
0
{
32
0
  int depth = hwloc_get_type_depth(topology, type);
33
0
34
0
  if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
35
0
    return depth;
36
0
37
0
  /* find the highest existing level with type order >= */
38
0
  for(depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU); ; depth--)
39
0
    if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) < 0)
40
0
      return depth+1;
41
0
42
0
  /* Shouldn't ever happen, as there is always a Machine level with lower order and known depth.  */
43
0
  /* abort(); */
44
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_type_or_below_depth
Unexecuted instantiation: base64.c:hwloc_get_type_or_below_depth
45
46
static __hwloc_inline int
47
hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
48
0
{
49
0
  int depth = hwloc_get_type_depth(topology, type);
50
0
51
0
  if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
52
0
    return depth;
53
0
54
0
  /* find the lowest existing level with type order <= */
55
0
  for(depth = 0; ; depth++)
56
0
    if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) > 0)
57
0
      return depth-1;
58
0
59
0
  /* Shouldn't ever happen, as there is always a PU level with higher order and known depth.  */
60
0
  /* abort(); */
61
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_type_or_above_depth
Unexecuted instantiation: base64.c:hwloc_get_type_or_above_depth
62
63
static __hwloc_inline int
64
hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
65
0
{
66
0
  int depth = hwloc_get_type_depth(topology, type);
67
0
  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
68
0
    return 0;
69
0
  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
70
0
    return -1; /* FIXME: agregate nbobjs from different levels? */
71
0
  return (int) hwloc_get_nbobjs_by_depth(topology, depth);
72
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_nbobjs_by_type
Unexecuted instantiation: base64.c:hwloc_get_nbobjs_by_type
73
74
static __hwloc_inline hwloc_obj_t
75
hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
76
0
{
77
0
  int depth = hwloc_get_type_depth(topology, type);
78
0
  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
79
0
    return NULL;
80
0
  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
81
0
    return NULL;
82
0
  return hwloc_get_obj_by_depth(topology, depth, idx);
83
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_obj_by_type
Unexecuted instantiation: base64.c:hwloc_get_obj_by_type
84
85
static __hwloc_inline hwloc_obj_t
86
hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev)
87
0
{
88
0
  if (!prev)
89
0
    return hwloc_get_obj_by_depth (topology, depth, 0);
90
0
  if (prev->depth != depth)
91
0
    return NULL;
92
0
  return prev->next_cousin;
93
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_next_obj_by_depth
Unexecuted instantiation: base64.c:hwloc_get_next_obj_by_depth
94
95
static __hwloc_inline hwloc_obj_t
96
hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
97
          hwloc_obj_t prev)
98
0
{
99
0
  int depth = hwloc_get_type_depth(topology, type);
100
0
  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
101
0
    return NULL;
102
0
  return hwloc_get_next_obj_by_depth (topology, depth, prev);
103
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_next_obj_by_type
Unexecuted instantiation: base64.c:hwloc_get_next_obj_by_type
104
105
static __hwloc_inline hwloc_obj_t
106
hwloc_get_root_obj (hwloc_topology_t topology)
107
0
{
108
0
  return hwloc_get_obj_by_depth (topology, 0, 0);
109
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_root_obj
Unexecuted instantiation: base64.c:hwloc_get_root_obj
110
111
static __hwloc_inline const char *
112
hwloc_get_info_by_name(struct hwloc_infos_s *infos, const char *name)
113
0
{
114
0
  unsigned i;
115
0
  for(i=0; i<infos->count; i++) {
116
0
    struct hwloc_info_s *info = &infos->array[i];
117
0
    if (!strcmp(info->name, name))
118
0
      return info->value;
119
0
  }
120
0
  return NULL;
121
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_get_info_by_name
Unexecuted instantiation: base64.c:hwloc_get_info_by_name
122
123
static __hwloc_inline const char *
124
hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
125
0
{
126
0
  return hwloc_get_info_by_name(&obj->infos, name);
127
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_obj_get_info_by_name
Unexecuted instantiation: base64.c:hwloc_obj_get_info_by_name
128
129
static __hwloc_inline int
130
hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value)
131
0
{
132
0
  return hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, name, value) >= 0 ? 0 : -1;
133
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_obj_add_info
Unexecuted instantiation: base64.c:hwloc_obj_add_info
134
135
static __hwloc_inline void *
136
hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t set, hwloc_membind_policy_t policy, int flags)
137
0
{
138
0
  void *p = hwloc_alloc_membind(topology, len, set, policy, flags);
139
0
  if (p)
140
0
    return p;
141
0
142
0
  if (hwloc_set_membind(topology, set, policy, flags) < 0)
143
0
    /* hwloc_set_membind() takes care of ignoring errors if non-STRICT */
144
0
    return NULL;
145
0
146
0
  p = hwloc_alloc(topology, len);
147
0
  if (p && policy != HWLOC_MEMBIND_FIRSTTOUCH)
148
0
    /* Enforce the binding by touching the data */
149
0
    memset(p, 0, len);
150
0
  return p;
151
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_alloc_membind_policy
Unexecuted instantiation: base64.c:hwloc_alloc_membind_policy
152
153
154
#ifdef __cplusplus
155
} /* extern "C" */
156
#endif
157
158
159
#endif /* HWLOC_INLINES_H */