OpenCoverage

nproc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/lib/nproc.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28static unsigned long-
29num_processors_via_affinity_mask (void)-
30{-
31 {-
32 cpu_set_t set;-
33-
34 if (sched_getaffinity (0, sizeof (set), &set) == 0
sched_getaffin...t), &set) == 0Description
TRUEevaluated 714 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEnever evaluated
)
0-714
35 {-
36 unsigned long count;-
37-
38-
39-
40 count = -
41 __sched_cpucount (sizeof (cpu_set_t), -
42 &set-
43 )-
44 ;-
45 if (count > 0
count > 0Description
TRUEevaluated 714 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEnever evaluated
)
0-714
46 return
executed 714 times by 2 tests: return count;
Executed by:
  • nproc
  • sort
count;
executed 714 times by 2 tests: return count;
Executed by:
  • nproc
  • sort
714
47 }
never executed: end of block
0
48 }-
49 return
never executed: return 0;
0;
never executed: return 0;
0
50}-
51-
52-
53-
54-
55static unsigned long int-
56num_processors_ignoring_omp (enum nproc_query query)-
57{-
58 if (query == NPROC_CURRENT
query == NPROC_CURRENTDescription
TRUEevaluated 714 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEevaluated 2 times by 1 test
Evaluated by:
  • nproc
)
2-714
59 {-
60-
61 {-
62 unsigned long nprocs = num_processors_via_affinity_mask ();-
63-
64 if (nprocs > 0
nprocs > 0Description
TRUEevaluated 714 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEnever evaluated
)
0-714
65 return
executed 714 times by 2 tests: return nprocs;
Executed by:
  • nproc
  • sort
nprocs;
executed 714 times by 2 tests: return nprocs;
Executed by:
  • nproc
  • sort
714
66 }-
67-
68-
69 {-
70-
71 long int nprocs = sysconf (-
72 _SC_NPROCESSORS_ONLN-
73 );-
74 if (nprocs > 0
nprocs > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 return
never executed: return nprocs;
nprocs;
never executed: return nprocs;
0
76 }-
77-
78 }
never executed: end of block
0
79 else-
80 {-
81-
82 {-
83-
84 long int nprocs = sysconf (-
85 _SC_NPROCESSORS_CONF-
86 );-
87-
88-
89-
90-
91-
92-
93-
94 if (nprocs == 1
nprocs == 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • nproc
)
0-2
95 {-
96 unsigned long nprocs_current = num_processors_via_affinity_mask ();-
97-
98 if (nprocs_current > 0
nprocs_current > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
99 nprocs = nprocs_current;
never executed: nprocs = nprocs_current;
0
100 }
never executed: end of block
0
101-
102-
103 if (nprocs > 0
nprocs > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • nproc
FALSEnever evaluated
)
0-2
104 return
executed 2 times by 1 test: return nprocs;
Executed by:
  • nproc
nprocs;
executed 2 times by 1 test: return nprocs;
Executed by:
  • nproc
2
105 }-
106-
107 }
never executed: end of block
0
108 return
never executed: return 1;
1;
never executed: return 1;
0
109}-
110-
111-
112-
113static unsigned long int-
114parse_omp_threads (char const* threads)-
115{-
116 unsigned long int ret = 0;-
117-
118 if (threads ==
threads == ((void *)0)Description
TRUEevaluated 1425 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEevaluated 29 times by 1 test
Evaluated by:
  • nproc
29-1425
119 ((void *)0)
threads == ((void *)0)Description
TRUEevaluated 1425 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEevaluated 29 times by 1 test
Evaluated by:
  • nproc
29-1425
120 )-
121 return
executed 1425 times by 2 tests: return ret;
Executed by:
  • nproc
  • sort
ret;
executed 1425 times by 2 tests: return ret;
Executed by:
  • nproc
  • sort
1425
122-
123-
124-
125 while (*
*threads != '\0'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 1 time by 1 test
Evaluated by:
  • nproc
threads != '\0'
*threads != '\0'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 1 time by 1 test
Evaluated by:
  • nproc
&& c_isspace (*threads)
c_isspace (*threads)Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • nproc
)
0-28
126 threads++;
never executed: threads++;
0
127-
128-
129 if (c_isdigit (*threads)
c_isdigit (*threads)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 3 times by 1 test
Evaluated by:
  • nproc
)
3-26
130 {-
131 char *endptr = -
132 ((void *)0)-
133 ;-
134 unsigned long int value = strtoul (threads, &endptr, 10);-
135-
136 if (endptr !=
endptr != ((void *)0)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • nproc
FALSEnever evaluated
0-26
137 ((void *)0)
endptr != ((void *)0)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • nproc
FALSEnever evaluated
0-26
138 )-
139 {-
140 while (*
*endptr != '\0'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 17 times by 1 test
Evaluated by:
  • nproc
endptr != '\0'
*endptr != '\0'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 17 times by 1 test
Evaluated by:
  • nproc
&& c_isspace (*endptr)
c_isspace (*endptr)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • nproc
)
0-17
141 endptr++;
never executed: endptr++;
0
142 if (*
*endptr == '\0'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 9 times by 1 test
Evaluated by:
  • nproc
endptr == '\0'
*endptr == '\0'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 9 times by 1 test
Evaluated by:
  • nproc
)
9-17
143 return
executed 17 times by 1 test: return value;
Executed by:
  • nproc
value;
executed 17 times by 1 test: return value;
Executed by:
  • nproc
17
144-
145-
146 else if (*
*endptr == ','Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 3 times by 1 test
Evaluated by:
  • nproc
endptr == ','
*endptr == ','Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 3 times by 1 test
Evaluated by:
  • nproc
)
3-6
147 return
executed 6 times by 1 test: return value;
Executed by:
  • nproc
value;
executed 6 times by 1 test: return value;
Executed by:
  • nproc
6
148 }
executed 3 times by 1 test: end of block
Executed by:
  • nproc
3
149 }
executed 3 times by 1 test: end of block
Executed by:
  • nproc
3
150-
151 return
executed 6 times by 1 test: return ret;
Executed by:
  • nproc
ret;
executed 6 times by 1 test: return ret;
Executed by:
  • nproc
6
152}-
153-
154unsigned long int-
155num_processors (enum nproc_query query)-
156{-
157 unsigned long int omp_env_limit = -
158 (0x7fffffffffffffffL * 2UL + 1UL)-
159 ;-
160-
161 if (query == NPROC_CURRENT_OVERRIDABLE
query == NPROC...NT_OVERRIDABLEDescription
TRUEevaluated 727 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEevaluated 2 times by 1 test
Evaluated by:
  • nproc
)
2-727
162 {-
163 unsigned long int omp_env_threads;-
164-
165-
166 omp_env_threads = parse_omp_threads (getenv ("OMP_NUM_THREADS"));-
167 omp_env_limit = parse_omp_threads (getenv ("OMP_THREAD_LIMIT"));-
168 if (! omp_env_limit
! omp_env_limitDescription
TRUEevaluated 721 times by 2 tests
Evaluated by:
  • nproc
  • sort
FALSEevaluated 6 times by 1 test
Evaluated by:
  • nproc
)
6-721
169 omp_env_limit =
executed 721 times by 2 tests: omp_env_limit = (0x7fffffffffffffffL * 2UL + 1UL) ;
Executed by:
  • nproc
  • sort
721
170 (0x7fffffffffffffffL * 2UL + 1UL)
executed 721 times by 2 tests: omp_env_limit = (0x7fffffffffffffffL * 2UL + 1UL) ;
Executed by:
  • nproc
  • sort
721
171 ;
executed 721 times by 2 tests: omp_env_limit = (0x7fffffffffffffffL * 2UL + 1UL) ;
Executed by:
  • nproc
  • sort
721
172-
173 if (omp_env_threads
omp_env_threadsDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • nproc
FALSEevaluated 714 times by 2 tests
Evaluated by:
  • nproc
  • sort
)
13-714
174 return
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
175 (((
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
176 omp_env_threads
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
177 )<(
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
178 omp_env_limit
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
179 ))?(
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
180 omp_env_threads
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
181 ):(
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
182 omp_env_limit
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
183 ))
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
184 ;
executed 13 times by 1 test: return ((( omp_env_threads )<( omp_env_limit ))?( omp_env_threads ):( omp_env_limit )) ;
Executed by:
  • nproc
13
185-
186 query = NPROC_CURRENT;-
187 }
executed 714 times by 2 tests: end of block
Executed by:
  • nproc
  • sort
714
188-
189 {-
190 unsigned long nprocs = num_processors_ignoring_omp (query);-
191 return
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
192 (((
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
193 nprocs
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
194 )<(
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
195 omp_env_limit
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
196 ))?(
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
197 nprocs
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
198 ):(
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
199 omp_env_limit
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
200 ))
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
201 ;
executed 716 times by 2 tests: return ((( nprocs )<( omp_env_limit ))?( nprocs ):( omp_env_limit )) ;
Executed by:
  • nproc
  • sort
716
202 }-
203}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2