• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #859

05 Jan 2023 05:50PM UTC coverage: 85.881% (-0.6%) from 86.496%
#859

push

StellarBot
Merge #6116

6116: Add new command line argument --hpx:loopback_network r=hkaiser a=JiakunYan

Option `--hpx:loopback_network=0|1`. If set to 1, the network (at least the initialization phase) will be enabled even if the locality number is 1.

It is useful for debugging networks.

Co-authored-by: Jiakun Yan <jiakunyan1998@gmail.com>

4 of 4 new or added lines in 1 file covered. (100.0%)

173321 of 201815 relevant lines covered (85.88%)

1844045.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.3
/libs/core/runtime_configuration/src/runtime_configuration.cpp
1
//  Copyright (c) 2005-2020 Hartmut Kaiser
2
//  Copyright (c)      2011 Bryce Adelstein-Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config/endian.hpp>
9
#include <hpx/assert.hpp>
10
#include <hpx/modules/filesystem.hpp>
11
#include <hpx/modules/itt_notify.hpp>
12
#include <hpx/modules/string_util.hpp>
13
#include <hpx/prefix/find_prefix.hpp>
14
#include <hpx/preprocessor/expand.hpp>
15
#include <hpx/preprocessor/stringize.hpp>
16
#include <hpx/runtime_configuration/agas_service_mode.hpp>
17
#include <hpx/runtime_configuration/component_registry_base.hpp>
18
#include <hpx/runtime_configuration/init_ini_data.hpp>
19
#include <hpx/runtime_configuration/plugin_registry_base.hpp>
20
#include <hpx/runtime_configuration/runtime_configuration.hpp>
21
#include <hpx/runtime_configuration/runtime_mode.hpp>
22
#include <hpx/util/from_string.hpp>
23
#include <hpx/util/get_entry_as.hpp>
24
#include <hpx/version.hpp>
25

26
#include <algorithm>
27
#include <cstddef>
28
#include <cstdint>
29
#include <cstdlib>
30
#include <iterator>
31
#include <limits>
32
#include <map>
33
#include <memory>
34
#include <set>
35
#include <string>
36
#include <system_error>
37
#include <utility>
38
#include <vector>
39

40
#if defined(HPX_WINDOWS)
41
#include <process.h>
42
#elif defined(HPX_HAVE_UNISTD_H)
43
#include <unistd.h>
44
#endif
45

46
#if (defined(__linux) || defined(linux) || defined(__linux__))
47
#include <arpa/inet.h>
48
#include <ifaddrs.h>
49
#include <netinet/in.h>
50
#include <sys/types.h>
51
#endif
52

53
#if !defined(HPX_WINDOWS)
54
#if defined(HPX_DEBUG)
55
#define HPX_DLL_STRING "libhpxd" HPX_SHARED_LIB_EXTENSION
56
#else
57
#define HPX_DLL_STRING "libhpx" HPX_SHARED_LIB_EXTENSION
58
#endif
59
#elif defined(HPX_DEBUG)
60
#define HPX_DLL_STRING "hpxd" HPX_SHARED_LIB_EXTENSION
61
#else
62
#define HPX_DLL_STRING "hpx" HPX_SHARED_LIB_EXTENSION
63
#endif
64

65
#include <limits>
66

67
///////////////////////////////////////////////////////////////////////////////
68
namespace hpx { namespace util {
69

70
    namespace detail {
71

72
        // CMake does not deal with explicit semicolons well, for this reason,
73
        // the paths are delimited with ':'. On Windows those need to be
74
        // converted to ';'.
75
        std::string convert_delimiters(std::string paths)
4,852✔
76
        {
77
#if defined(HPX_WINDOWS)
78
            std::replace(paths.begin(), paths.end(), ':', ';');
79
#endif
80
            return paths;
4,852✔
81
        }
82
    }    // namespace detail
83

84
    // pre-initialize entries with compile time based values
85
    void runtime_configuration::pre_initialize_ini()
6,072✔
86
    {
87
        if (!need_to_call_pre_initialize)
6,072✔
88
            return;
1,220✔
89

90
        std::vector<std::string> lines = {
621,056✔
91
            // clang-format off
92
            // create an empty application section
93
            "[application]",
4,852✔
94

95
            // create system and application instance specific entries
96
            "[system]",
4,852✔
97
            "pid = " + std::to_string(getpid()),
4,852✔
98
            "prefix = " + find_prefix(),
4,852✔
99
#if defined(__linux) || defined(linux) || defined(__linux__)
100
            "executable_prefix = " + get_executable_prefix(argv0),
4,852✔
101
#else
102
            "executable_prefix = " + get_executable_prefix(),
103
#endif
104
            // create default installation location and logging settings
105
            "[hpx]",
4,852✔
106
            "location = ${HPX_LOCATION:$[system.prefix]}",
4,852✔
107
            "component_paths = ${HPX_COMPONENT_PATHS}",
4,852✔
108
            "component_base_paths = $[hpx.location]"    // NOLINT
4,852✔
109
                HPX_INI_PATH_DELIMITER "$[system.executable_prefix]",
110
            "component_path_suffixes = " +
4,852✔
111
                detail::convert_delimiters(HPX_DEFAULT_COMPONENT_PATH_SUFFIXES),
4,852✔
112
            "master_ini_path = $[hpx.location]" HPX_INI_PATH_DELIMITER
4,852✔
113
            "$[system.executable_prefix]/",
114
            "master_ini_path_suffixes = /share/" HPX_BASE_DIR_NAME
4,852✔
115
                HPX_INI_PATH_DELIMITER "/../share/" HPX_BASE_DIR_NAME,
116
#ifdef HPX_HAVE_ITTNOTIFY
117
            "use_itt_notify = ${HPX_HAVE_ITTNOTIFY:0}",
118
#endif
119
            "finalize_wait_time = ${HPX_FINALIZE_WAIT_TIME:-1.0}",
4,852✔
120
            "shutdown_timeout = ${HPX_SHUTDOWN_TIMEOUT:-1.0}",
4,852✔
121
            "shutdown_check_count = ${HPX_SHUTDOWN_CHECK_COUNT:10}",
4,852✔
122
#ifdef HPX_HAVE_VERIFY_LOCKS
123
#if defined(HPX_DEBUG)
124
            "lock_detection = ${HPX_LOCK_DETECTION:1}",
4,852✔
125
#else
126
            "lock_detection = ${HPX_LOCK_DETECTION:0}",
127
#endif
128
            "throw_on_held_lock = ${HPX_THROW_ON_HELD_LOCK:1}",
4,852✔
129
#endif
130
#ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION
131
#ifdef HPX_DEBUG
132
            "minimal_deadlock_detection = ${HPX_MINIMAL_DEADLOCK_DETECTION:1}",
133
#else
134
            "minimal_deadlock_detection = ${HPX_MINIMAL_DEADLOCK_DETECTION:0}",
135
#endif
136
#endif
137
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
138
#ifdef HPX_DEBUG
139
            "spinlock_deadlock_detection = "
4,852✔
140
            "${HPX_SPINLOCK_DEADLOCK_DETECTION:1}",
141
#else
142
            "spinlock_deadlock_detection = "
143
            "${HPX_SPINLOCK_DEADLOCK_DETECTION:0}",
144
#endif
145
            "spinlock_deadlock_detection_limit = "
4,852✔
146
            "${HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT:" HPX_PP_STRINGIZE(
147
                HPX_PP_EXPAND(HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT)) "}",
148
#endif
149
            "expect_connecting_localities = "
4,852✔
150
            "${HPX_EXPECT_CONNECTING_LOCALITIES:0}",
151

152
            // add placeholders for keys to be added by command line handling
153
            "os_threads = cores",
4,852✔
154
            "cores = all",
4,852✔
155
            "localities = 1",
4,852✔
156
            "first_pu = 0",
4,852✔
157
            "runtime_mode = console",
4,852✔
158
            "scheduler = local-priority-fifo",
4,852✔
159
            "affinity = core",
4,852✔
160
            "pu_step = 1",
4,852✔
161
            "pu_offset = 0",
4,852✔
162
            "numa_sensitive = 0",
4,852✔
163
            "loopback_network = 0",
4,852✔
164
            "max_background_threads = "
4,852✔
165
            "${HPX_MAX_BACKGROUND_THREADS:$[hpx.os_threads]}",
166
            "max_idle_loop_count = ${HPX_MAX_IDLE_LOOP_COUNT:" HPX_PP_STRINGIZE(
4,852✔
167
                HPX_PP_EXPAND(HPX_IDLE_LOOP_COUNT_MAX)) "}",
168
            "max_busy_loop_count = ${HPX_MAX_BUSY_LOOP_COUNT:" HPX_PP_STRINGIZE(
4,852✔
169
                HPX_PP_EXPAND(HPX_BUSY_LOOP_COUNT_MAX)) "}",
170
#if defined(HPX_HAVE_THREAD_MANAGER_IDLE_BACKOFF)
171
            "max_idle_backoff_time = "
4,852✔
172
            "${HPX_MAX_IDLE_BACKOFF_TIME:" HPX_PP_STRINGIZE(
173
                HPX_PP_EXPAND(HPX_IDLE_BACKOFF_TIME_MAX)) "}",
174
#endif
175
            "default_scheduler_mode = ${HPX_DEFAULT_SCHEDULER_MODE}",
4,852✔
176

177
        /// If HPX_HAVE_ATTACH_DEBUGGER_ON_TEST_FAILURE is set,
178
        /// then apply the test-failure value as default.
179
#if defined(HPX_HAVE_ATTACH_DEBUGGER_ON_TEST_FAILURE)
180
            "attach_debugger = ${HPX_ATTACH_DEBUGGER:test-failure}",
181
#else
182
            "attach_debugger = ${HPX_ATTACH_DEBUGGER}",
4,852✔
183
#endif
184
            "exception_verbosity = ${HPX_EXCEPTION_VERBOSITY:2}",
4,852✔
185
            "trace_depth = ${HPX_TRACE_DEPTH:" HPX_PP_STRINGIZE(
4,852✔
186
                HPX_PP_EXPAND(HPX_HAVE_THREAD_BACKTRACE_DEPTH)) "}",
187
#if !defined(HPX_WINDOWS)
188
            "handle_signals = ${HPX_HANDLE_SIGNALS:1}",
4,852✔
189
#endif
190
            // arity for collective operations implemented in a tree fashion
191
            "[hpx.lcos.collectives]",
4,852✔
192
            "arity = ${HPX_LCOS_COLLECTIVES_ARITY:32}",
4,852✔
193
            "cut_off = ${HPX_LCOS_COLLECTIVES_CUT_OFF:-1}",
4,852✔
194

195
            // connect back to the given latch if specified
196
            "[hpx.on_startup]",
4,852✔
197
            "wait_on_latch = ${HPX_ON_STARTUP_WAIT_ON_LATCH}",
4,852✔
198

199
#if defined(HPX_HAVE_NETWORKING)
200
            // by default, enable networking
201
            "[hpx.parcel]",
4,852✔
202
            "enable = 1",
4,852✔
203
#endif
204

205
            "[hpx.stacks]",
4,852✔
206
            "small_size = ${HPX_SMALL_STACK_SIZE:" HPX_PP_STRINGIZE(
4,852✔
207
                HPX_PP_EXPAND(HPX_SMALL_STACK_SIZE)) "}",
208
            "medium_size = ${HPX_MEDIUM_STACK_SIZE:" HPX_PP_STRINGIZE(
4,852✔
209
                HPX_PP_EXPAND(HPX_MEDIUM_STACK_SIZE)) "}",
210
            "large_size = ${HPX_LARGE_STACK_SIZE:" HPX_PP_STRINGIZE(
4,852✔
211
                HPX_PP_EXPAND(HPX_LARGE_STACK_SIZE)) "}",
212
            "huge_size = ${HPX_HUGE_STACK_SIZE:" HPX_PP_STRINGIZE(
4,852✔
213
                HPX_PP_EXPAND(HPX_HUGE_STACK_SIZE)) "}",
214
#if defined(__linux) || defined(linux) || defined(__linux__) ||                \
215
    defined(__FreeBSD__)
216
            "use_guard_pages = ${HPX_USE_GUARD_PAGES:1}",
4,852✔
217
#endif
218

219
            "[hpx.threadpools]",
4,852✔
220
#if defined(HPX_HAVE_IO_POOL)
221
            "io_pool_size = ${HPX_NUM_IO_POOL_SIZE:" HPX_PP_STRINGIZE(
4,852✔
222
                HPX_PP_EXPAND(HPX_NUM_IO_POOL_SIZE)) "}",
223
#endif
224
#if defined(HPX_HAVE_NETWORKING)
225
            "parcel_pool_size = ${HPX_NUM_PARCEL_POOL_SIZE:" HPX_PP_STRINGIZE(
4,852✔
226
                HPX_PP_EXPAND(HPX_NUM_PARCEL_POOL_SIZE)) "}",
227
#endif
228
#if defined(HPX_HAVE_TIMER_POOL)
229
            "timer_pool_size = ${HPX_NUM_TIMER_POOL_SIZE:" HPX_PP_STRINGIZE(
4,852✔
230
                HPX_PP_EXPAND(HPX_NUM_TIMER_POOL_SIZE)) "}",
231
#endif
232

233
            "[hpx.thread_queue]",
4,852✔
234
            "max_thread_count = ${HPX_THREAD_QUEUE_MAX_THREAD_COUNT:" HPX_PP_STRINGIZE(
4,852✔
235
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_THREAD_COUNT)) "}",
236
            "min_tasks_to_steal_pending = "
4,852✔
237
            "${HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING:" HPX_PP_STRINGIZE(
238
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING)) "}",
239
            "min_tasks_to_steal_staged = "
4,852✔
240
            "${HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED:" HPX_PP_STRINGIZE(
241
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED)) "}",
242
            "min_add_new_count = "
4,852✔
243
            "${HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT:" HPX_PP_STRINGIZE(
244
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT)) "}",
245
            "max_add_new_count = "
4,852✔
246
            "${HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT:" HPX_PP_STRINGIZE(
247
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT)) "}",
248
            "min_delete_count = "
4,852✔
249
            "${HPX_THREAD_QUEUE_MIN_DELETE_COUNT:" HPX_PP_STRINGIZE(
250
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_DELETE_COUNT)) "}",
251
            "max_delete_count = "
4,852✔
252
            "${HPX_THREAD_QUEUE_MAX_DELETE_COUNT:" HPX_PP_STRINGIZE(
253
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_THREAD_COUNT)) "}",
254
            "max_terminated_threads = "
4,852✔
255
            "${HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS:" HPX_PP_STRINGIZE(
256
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS)) "}",
257
            "init_threads_count = "
4,852✔
258
            "${HPX_THREAD_QUEUE_INIT_THREADS_COUNT:" HPX_PP_STRINGIZE(
259
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_INIT_THREADS_COUNT)) "}",
260

261
            "[hpx.commandline]",
4,852✔
262
            // enable aliasing
263
            "aliasing = ${HPX_COMMANDLINE_ALIASING:1}",
4,852✔
264

265
            // allow for unknown options to be passed through
266
            "allow_unknown = ${HPX_COMMANDLINE_ALLOW_UNKNOWN:0}",
4,852✔
267

268
            // allow for command line options to to be passed through the
269
            // environment
270
            "prepend_options = ${HPX_COMMANDLINE_OPTIONS}",
4,852✔
271

272
            // predefine command line aliases
273
            "[hpx.commandline.aliases]",
4,852✔
274
            "-a = --hpx:agas",
4,852✔
275
            "-c = --hpx:console",
4,852✔
276
            "-h = --hpx:help",
4,852✔
277
            "-I = --hpx:ini",
4,852✔
278
            "-l = --hpx:localities",
4,852✔
279
            "-p = --hpx:app-config",
4,852✔
280
            "-q = --hpx:queuing",
4,852✔
281
            "-r = --hpx:run-agas-server",
4,852✔
282
            "-t = --hpx:threads",
4,852✔
283
            "-v = --hpx:version",
4,852✔
284
            "-w = --hpx:worker",
4,852✔
285
            "-x = --hpx:hpx",
4,852✔
286
            "-0 = --hpx:node=0",
4,852✔
287
            "-1 = --hpx:node=1",
4,852✔
288
            "-2 = --hpx:node=2",
4,852✔
289
            "-3 = --hpx:node=3",
4,852✔
290
            "-4 = --hpx:node=4",
4,852✔
291
            "-5 = --hpx:node=5",
4,852✔
292
            "-6 = --hpx:node=6",
4,852✔
293
            "-7 = --hpx:node=7",
4,852✔
294
            "-8 = --hpx:node=8",
4,852✔
295
            "-9 = --hpx:node=9",
4,852✔
296

297
            "[hpx.agas]",
4,852✔
298
            // 'address' has deliberately no default, see
299
            // command_line_handling.cpp
300
            "address = ${HPX_AGAS_SERVER_ADDRESS}",
4,852✔
301
            "port = ${HPX_AGAS_SERVER_PORT:" HPX_PP_STRINGIZE(
4,852✔
302
                HPX_PP_EXPAND(HPX_INITIAL_IP_PORT)) "}",
303
            "max_pending_refcnt_requests = "
4,852✔
304
            "${HPX_AGAS_MAX_PENDING_REFCNT_REQUESTS:" HPX_PP_STRINGIZE(
305
                HPX_PP_EXPAND(
306
                    HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS)) "}",
307
            "service_mode = hosted",
4,852✔
308
            "local_cache_size = ${HPX_AGAS_LOCAL_CACHE_SIZE:" HPX_PP_STRINGIZE(
4,852✔
309
                HPX_PP_EXPAND(HPX_AGAS_LOCAL_CACHE_SIZE)) "}",
310
            "use_range_caching = ${HPX_AGAS_USE_RANGE_CACHING:1}",
4,852✔
311
            "use_caching = ${HPX_AGAS_USE_CACHING:1}",
4,852✔
312

313
            "[hpx.components]",
4,852✔
314
            "load_external = ${HPX_LOAD_EXTERNAL_COMPONENTS:1}",
4,852✔
315

316
            "[hpx.components.barrier]",
4,852✔
317
            "name = hpx",
4,852✔
318
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
4,852✔
319
            "enabled = 1",
4,852✔
320

321
            "[hpx.components.hpx_lcos_server_latch]",
4,852✔
322
            "name = hpx",
4,852✔
323
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
4,852✔
324
            "enabled = 1",
4,852✔
325

326
            "[hpx.components.raw_counter]",
4,852✔
327
            "name = hpx",
4,852✔
328
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
4,852✔
329
            "enabled = 1",
4,852✔
330

331
            "[hpx.components.average_count_counter]",
4,852✔
332
            "name = hpx",
4,852✔
333
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
4,852✔
334
            "enabled = 1",
4,852✔
335

336
            "[hpx.components.elapsed_time_counter]",
4,852✔
337
            "name = hpx",
4,852✔
338
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
4,852✔
339
            "enabled = 1"
4,852✔
340
            // clang-format on
341
        };
342

343
        lines.insert(lines.end(), extra_static_ini_defs.begin(),
9,704✔
344
            extra_static_ini_defs.end());
4,852✔
345

346
        // don't overload user overrides
347
        this->parse("<static defaults>", lines, false, false, false);
4,852✔
348

349
        need_to_call_pre_initialize = false;
4,852✔
350
    }
6,072✔
351

352
    void runtime_configuration::post_initialize_ini(std::string& hpx_ini_file_,
4,852✔
353
        std::vector<std::string> const& cmdline_ini_defs_)
354
    {
355
        util::init_ini_data_base(*this, hpx_ini_file_);
4,852✔
356
        need_to_call_pre_initialize = true;
4,852✔
357

358
        // let the command line override the config file.
359
        if (!cmdline_ini_defs_.empty())
4,852✔
360
        {
361
            // do not weed out comments
362
            this->parse(
3,627✔
363
                "<command line definitions>", cmdline_ini_defs_, true, false);
3,627✔
364
            need_to_call_pre_initialize = true;
3,627✔
365
        }
3,627✔
366
    }
4,852✔
367

368
    void runtime_configuration::pre_initialize_logging_ini()
4,852✔
369
    {
370
#if defined(HPX_HAVE_LOGGING)
371
        std::vector<std::string> lines = {
232,896✔
372
        // clang-format off
373
#define HPX_TIMEFORMAT "$hh:$mm.$ss.$mili"
374
#define HPX_LOGFORMAT "(T%locality%/%hpxthread%.%hpxphase%/%hpxcomponent%) "
375

376
            // general logging
377
            "[hpx.logging]",
4,852✔
378
            "level = ${HPX_LOGLEVEL:0}",
4,852✔
379
            "destination = ${HPX_LOGDESTINATION:console}",
4,852✔
380
            "format = ${HPX_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
381
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
382
                HPX_TIMEFORMAT ") [%idx%]|\\n}",
383

384
            // general console logging
385
            "[hpx.logging.console]",
4,852✔
386
            "level = ${HPX_LOGLEVEL:$[hpx.logging.level]}",
4,852✔
387
#if defined(ANDROID) || defined(__ANDROID__)
388
            "destination = ${HPX_CONSOLE_LOGDESTINATION:android_log}",
389
#else
390
            "destination = ${HPX_CONSOLE_LOGDESTINATION:"
4,852✔
391
                "file(hpx.$[system.pid].log)}",
392
#endif
393
            "format = ${HPX_CONSOLE_LOGFORMAT:|}",
4,852✔
394

395
            // logging related to timing
396
            "[hpx.logging.timing]",
4,852✔
397
            "level = ${HPX_TIMING_LOGLEVEL:-1}",
4,852✔
398
            "destination = ${HPX_TIMING_LOGDESTINATION:console}",
4,852✔
399
            "format = ${HPX_TIMING_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
400
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
401
                HPX_TIMEFORMAT ") [%idx%] [TIM] |\\n}",
402

403
            // console logging related to timing
404
            "[hpx.logging.console.timing]",
4,852✔
405
            "level = ${HPX_TIMING_LOGLEVEL:$[hpx.logging.timing.level]}",
4,852✔
406
#if defined(ANDROID) || defined(__ANDROID__)
407
            "destination = ${HPX_CONSOLE_TIMING_LOGDESTINATION:android_log}",
408
#else
409
            "destination = ${HPX_CONSOLE_TIMING_LOGDESTINATION:"
4,852✔
410
                "file(hpx.timing.$[system.pid].log)}",
411
#endif
412
            "format = ${HPX_CONSOLE_TIMING_LOGFORMAT:|}",
4,852✔
413

414
            // logging related to AGAS
415
            "[hpx.logging.agas]",
4,852✔
416
            "level = ${HPX_AGAS_LOGLEVEL:-1}",
4,852✔
417
            "destination = ${HPX_AGAS_LOGDESTINATION:"
4,852✔
418
                "file(hpx.agas.$[system.pid].log)}",
419
            "format = ${HPX_AGAS_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
420
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
421
                    HPX_TIMEFORMAT ") [%idx%][AGAS] |\\n}",
422

423
            // console logging related to AGAS
424
            "[hpx.logging.console.agas]",
4,852✔
425
            "level = ${HPX_AGAS_LOGLEVEL:$[hpx.logging.agas.level]}",
4,852✔
426
#if defined(ANDROID) || defined(__ANDROID__)
427
            "destination = ${HPX_CONSOLE_AGAS_LOGDESTINATION:android_log}",
428
#else
429
            "destination = ${HPX_CONSOLE_AGAS_LOGDESTINATION:"
4,852✔
430
                "file(hpx.agas.$[system.pid].log)}",
431
#endif
432
            "format = ${HPX_CONSOLE_AGAS_LOGFORMAT:|}",
4,852✔
433

434
            // logging related to the parcel transport
435
            "[hpx.logging.parcel]",
4,852✔
436
            "level = ${HPX_PARCEL_LOGLEVEL:-1}",
4,852✔
437
            "destination = ${HPX_PARCEL_LOGDESTINATION:"
4,852✔
438
                "file(hpx.parcel.$[system.pid].log)}",
439
            "format = ${HPX_PARCEL_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
440
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
441
                HPX_TIMEFORMAT ") [%idx%][  PT] |\\n}",
442

443
            // console logging related to the parcel transport
444
            "[hpx.logging.console.parcel]",
4,852✔
445
            "level = ${HPX_PARCEL_LOGLEVEL:$[hpx.logging.parcel.level]}",
4,852✔
446
#if defined(ANDROID) || defined(__ANDROID__)
447
            "destination = ${HPX_CONSOLE_PARCEL_LOGDESTINATION:android_log}",
448
#else
449
            "destination = ${HPX_CONSOLE_PARCEL_LOGDESTINATION:"
4,852✔
450
                "file(hpx.parcel.$[system.pid].log)}",
451
#endif
452
            "format = ${HPX_CONSOLE_PARCEL_LOGFORMAT:|}",
4,852✔
453

454
            // logging related to applications
455
            "[hpx.logging.application]",
4,852✔
456
            "level = ${HPX_APP_LOGLEVEL:-1}",
4,852✔
457
            "destination = ${HPX_APP_LOGDESTINATION:console}",
4,852✔
458
            "format = ${HPX_APP_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
459
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
460
                HPX_TIMEFORMAT ") [%idx%] [APP] |\\n}",
461

462
            // console logging related to applications
463
            "[hpx.logging.console.application]",
4,852✔
464
            "level = ${HPX_APP_LOGLEVEL:$[hpx.logging.application.level]}",
4,852✔
465
#if defined(ANDROID) || defined(__ANDROID__)
466
            "destination = ${HPX_CONSOLE_APP_LOGDESTINATION:android_log}",
467
#else
468
            "destination = ${HPX_CONSOLE_APP_LOGDESTINATION:"
4,852✔
469
                "file(hpx.application.$[system.pid].log)}",
470
#endif
471
            "format = ${HPX_CONSOLE_APP_LOGFORMAT:|}",
4,852✔
472

473
            // logging of debug channel
474
            "[hpx.logging.debuglog]",
4,852✔
475
            "level = ${HPX_DEB_LOGLEVEL:-1}",
4,852✔
476
            "destination = ${HPX_DEB_LOGDESTINATION:console}",
4,852✔
477
            "format = ${HPX_DEB_LOGFORMAT:" HPX_LOGFORMAT
4,852✔
478
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
479
                HPX_TIMEFORMAT ") [%idx%] [DEB] |\\n}",
480

481
            "[hpx.logging.console.debuglog]",
4,852✔
482
            "level = ${HPX_DEB_LOGLEVEL:$[hpx.logging.debuglog.level]}",
4,852✔
483
#if defined(ANDROID) || defined(__ANDROID__)
484
            "destination = ${HPX_CONSOLE_DEB_LOGDESTINATION:android_log}",
485
#else
486
            "destination = ${HPX_CONSOLE_DEB_LOGDESTINATION:"
4,852✔
487
                "file(hpx.debuglog.$[system.pid].log)}",
488
#endif
489
            "format = ${HPX_CONSOLE_DEB_LOGFORMAT:|}"
4,852✔
490

491
#undef HPX_TIMEFORMAT
492
#undef HPX_LOGFORMAT
493
            // clang-format on
494
        };
495

496
        // don't overload user overrides
497
        this->parse("<static logging defaults>", lines, false, false);
4,852✔
498
#endif
499
    }
4,852✔
500

501
    ///////////////////////////////////////////////////////////////////////////
502
    // load information about statically known components
503
    void runtime_configuration::load_components_static(
594✔
504
        std::vector<components::static_factory_load_data_type> const&
505
            static_modules)
506
    {
507
        std::vector<std::shared_ptr<components::component_registry_base>>
508
            registries;
594✔
509
        for (components::static_factory_load_data_type const& d :
1,441✔
510
            static_modules)
594✔
511
        {
512
            auto new_registries = util::load_component_factory_static(
847✔
513
                *this, d.name, d.get_factory);
847✔
514
            registries.reserve(registries.size() + new_registries.size());
847✔
515
            std::copy(new_registries.begin(), new_registries.end(),
847✔
516
                std::back_inserter(registries));
847✔
517
        }
847✔
518

519
        // read system and user ini files _again_, to allow the user to
520
        // overwrite the settings from the default component ini's.
521
        util::init_ini_data_base(*this, hpx_ini_file);
594✔
522

523
        // let the command line override the config file.
524
        if (!cmdline_ini_defs.empty())
594✔
525
            parse("<command line definitions>", cmdline_ini_defs, true, false);
594✔
526

527
        // merge all found ini files of all components
528
        util::merge_component_inis(*this);
594✔
529

530
        need_to_call_pre_initialize = true;
594✔
531

532
        // invoke last reconfigure
533
        reconfigure();
594✔
534
        for (auto& registry : registries)
16,885✔
535
        {
536
            registry->register_component_type();
16,291✔
537
        }
538
    }
594✔
539

540
    ///////////////////////////////////////////////////////////////////////////
541
    // collect all directories where to use for the search for plugins
542
    void runtime_configuration::load_component_path(
3,500✔
543
        std::vector<std::shared_ptr<plugins::plugin_registry_base>>&
544
            plugin_registries,
545
        std::vector<std::shared_ptr<components::component_registry_base>>&
546
            component_registries,
547
        std::string const& path, std::set<std::string>& component_paths,
548
        std::map<std::string, filesystem::path>& basenames)
549
    {
550
        namespace fs = filesystem;
551

552
        using plugin_list_type =
553
            std::vector<std::shared_ptr<plugins::plugin_registry_base>>;
554

555
        if (!path.empty())
3,500✔
556
        {
557
            fs::path this_p(path);
3,500✔
558
            std::error_code fsec;
3,500✔
559
            fs::path canonical_p =
560
                fs::canonical(this_p, fs::initial_path(), fsec);
3,500✔
561
            if (fsec)
3,500✔
562
                canonical_p = this_p;
1,774✔
563

564
            std::pair<std::set<std::string>::iterator, bool> p =
565
                component_paths.insert(canonical_p.string());
3,500✔
566

567
            if (p.second)
3,500✔
568
            {
569
                // have all path elements, now find ini files in there...
570
                fs::path this_path(*p.first);
1,196✔
571
                if (fs::exists(this_path, fsec) && !fsec)
1,196✔
572
                {
573
                    plugin_list_type tmp_regs =
574
                        util::init_ini_data_default(this_path.string(), *this,
586✔
575
                            basenames, modules_, component_registries);
586✔
576

577
                    std::copy(tmp_regs.begin(), tmp_regs.end(),
586✔
578
                        std::back_inserter(plugin_registries));
586✔
579
                }
586✔
580
            }
1,196✔
581
        }
3,500✔
582
    }
3,500✔
583

584
    void runtime_configuration::load_component_paths(
1,196✔
585
        std::vector<std::shared_ptr<plugins::plugin_registry_base>>&
586
            plugin_registries,
587
        std::vector<std::shared_ptr<components::component_registry_base>>&
588
            component_registries,
589
        std::string const& component_base_paths,
590
        std::string const& component_path_suffixes,
591
        std::set<std::string>& component_paths,
592
        std::map<std::string, filesystem::path>& basenames)
593
    {
594
        namespace fs = filesystem;
595

596
        // try to build default ini structure from shared libraries in default
597
        // installation location, this allows to install simple components
598
        // without the need to install an ini file
599
        // split of the separate paths from the given path list
600
        hpx::string_util::char_separator sep(HPX_INI_PATH_DELIMITER);
1,196✔
601
        hpx::string_util::tokenizer tok_path(component_base_paths, sep);
1,196✔
602
        hpx::string_util::tokenizer tok_suffixes(component_path_suffixes, sep);
1,196✔
603
        auto end_path = tok_path.end();
1,196✔
604
        auto end_suffixes = tok_suffixes.end();
1,196✔
605

606
        for (auto it = tok_path.begin(); it != end_path; ++it)
2,071✔
607
        {
608
            std::string const& path = *it;
875✔
609
            if (tok_suffixes.begin() != tok_suffixes.end())
875✔
610
            {
611
                for (auto jt = tok_suffixes.begin(); jt != end_suffixes; ++jt)
4,375✔
612
                {
613
                    std::string p = path;
3,500✔
614
                    p += *jt;
3,500✔
615
                    load_component_path(plugin_registries, component_registries,
7,000✔
616
                        p, component_paths, basenames);
3,500✔
617
                }
3,500✔
618
            }
875✔
619
            else
620
            {
621
                load_component_path(plugin_registries, component_registries,
×
622
                    path, component_paths, basenames);
×
623
            }
624
        }
875✔
625
    }
1,196✔
626

627
    // load information about dynamically discovered plugins
628
    std::vector<std::shared_ptr<plugins::plugin_registry_base>>
629
    runtime_configuration::load_modules(
598✔
630
        std::vector<std::shared_ptr<components::component_registry_base>>&
631
            component_registries)
632
    {
633
        typedef std::vector<std::shared_ptr<plugins::plugin_registry_base>>
634
            plugin_list_type;
635

636
        // protect against duplicate paths
637
        std::set<std::string> component_paths;
598✔
638

639
        // list of base names avoiding to load a module more than once
640
        std::map<std::string, filesystem::path> basenames;
598✔
641

642
        // plugin registry object
643
        plugin_list_type plugin_registries;
598✔
644

645
        // load plugin paths from component_base_paths and suffixes
646
        std::string component_base_paths(
647
            get_entry("hpx.component_base_paths", HPX_DEFAULT_COMPONENT_PATH));
598✔
648
        std::string component_path_suffixes(
649
            get_entry("hpx.component_path_suffixes", "/lib/hpx"));
598✔
650

651
        load_component_paths(plugin_registries, component_registries,
598✔
652
            component_base_paths, component_path_suffixes, component_paths,
653
            basenames);
654

655
        // load additional explicit plugin paths from plugin_paths key
656
        std::string plugin_paths(get_entry("hpx.component_paths", ""));
598✔
657
        load_component_paths(plugin_registries, component_registries,
598✔
658
            plugin_paths, "", component_paths, basenames);
598✔
659

660
        // read system and user ini files _again_, to allow the user to
661
        // overwrite the settings from the default component ini's.
662
        util::init_ini_data_base(*this, hpx_ini_file);
598✔
663

664
        // let the command line override the config file.
665
        if (!cmdline_ini_defs.empty())
598✔
666
            parse("<command line definitions>", cmdline_ini_defs, true, false);
596✔
667

668
        // merge all found ini files of all components
669
        util::merge_component_inis(*this);
598✔
670

671
        need_to_call_pre_initialize = true;
598✔
672

673
        // invoke reconfigure
674
        reconfigure();
598✔
675

676
        return plugin_registries;
598✔
677
    }
598✔
678

679
    ///////////////////////////////////////////////////////////////////////////
680
    runtime_configuration::runtime_configuration(char const* argv0_,
1,220✔
681
        runtime_mode mode,
682
        std::vector<std::string> const& extra_static_ini_defs_)
683
      : extra_static_ini_defs(extra_static_ini_defs_)
1,220✔
684
      , mode_(mode)
1,220✔
685
      , num_localities(0)
1,220✔
686
      , num_os_threads(0)
1,220✔
687
      , small_stacksize(HPX_SMALL_STACK_SIZE)
1,220✔
688
      , medium_stacksize(HPX_MEDIUM_STACK_SIZE)
1,220✔
689
      , large_stacksize(HPX_LARGE_STACK_SIZE)
1,220✔
690
      , huge_stacksize(HPX_HUGE_STACK_SIZE)
1,220✔
691
      , need_to_call_pre_initialize(true)
1,220✔
692
#if defined(__linux) || defined(linux) || defined(__linux__)
693
      , argv0(argv0_)
1,220✔
694
#endif
695
    {
1,220✔
696
        (void) argv0_;
697

698
        pre_initialize_ini();
1,220✔
699

700
        // set global config options
701
#if HPX_HAVE_ITTNOTIFY != 0
702
        use_ittnotify_api = get_itt_notify_mode();
703
#endif
704
        HPX_ASSERT(init_small_stack_size() >= HPX_SMALL_STACK_SIZE);
1,220✔
705

706
        small_stacksize = init_small_stack_size();
1,220✔
707
        medium_stacksize = init_medium_stack_size();
1,220✔
708
        large_stacksize = init_large_stack_size();
1,220✔
709
        HPX_ASSERT(init_huge_stack_size() <= HPX_HUGE_STACK_SIZE);
1,220✔
710
        huge_stacksize = init_huge_stack_size();
1,220✔
711
    }
1,220✔
712

713
    ///////////////////////////////////////////////////////////////////////////
714
    void runtime_configuration::reconfigure(std::string const& hpx_ini_file_)
1,220✔
715
    {
716
        hpx_ini_file = hpx_ini_file_;
1,220✔
717
        reconfigure();
1,220✔
718
    }
1,220✔
719

720
    void runtime_configuration::reconfigure(
2,440✔
721
        std::vector<std::string> const& cmdline_ini_defs_)
722
    {
723
        cmdline_ini_defs = cmdline_ini_defs_;
2,440✔
724
        reconfigure();
2,440✔
725
    }
2,440✔
726

727
    void runtime_configuration::reconfigure()
4,852✔
728
    {
729
        pre_initialize_ini();
4,852✔
730
        pre_initialize_logging_ini();
4,852✔
731
        post_initialize_ini(hpx_ini_file, cmdline_ini_defs);
4,852✔
732

733
        // set global config options
734
#if HPX_HAVE_ITTNOTIFY != 0
735
        use_ittnotify_api = get_itt_notify_mode();
736
#endif
737
        HPX_ASSERT(init_small_stack_size() >= HPX_SMALL_STACK_SIZE);
4,852✔
738

739
        small_stacksize = init_small_stack_size();
4,852✔
740
        medium_stacksize = init_medium_stack_size();
4,852✔
741
        large_stacksize = init_large_stack_size();
4,852✔
742
        huge_stacksize = init_huge_stack_size();
4,852✔
743
    }
4,852✔
744

745
    std::size_t runtime_configuration::get_ipc_data_buffer_cache_size() const
×
746
    {
747
        if (util::section const* sec = get_section("hpx.parcel.ipc");
×
748
            nullptr != sec)
×
749
        {
750
            return hpx::util::get_entry_as<std::size_t>(*sec,
×
751
                "data_buffer_cache_size",
×
752
                HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE);
×
753
        }
754
        return HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE;
×
755
    }
×
756

757
    agas::service_mode runtime_configuration::get_agas_service_mode() const
1,924✔
758
    {
759
        // load all components as described in the configuration information
760
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
1,924✔
761
        {
762
            std::string const m = sec->get_entry("service_mode", "hosted");
1,924✔
763

764
            if (m == "hosted")
1,924✔
765
            {
766
                return agas::service_mode::hosted;
568✔
767
            }
768
            else if (m == "bootstrap")
1,356✔
769
            {
770
                return agas::service_mode::bootstrap;
1,356✔
771
            }
772
            else
773
            {
774
                // REVIEW: exception type is overused
775
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
×
776
                    "runtime_configuration::get_agas_service_mode",
777
                    "invalid AGAS router mode \"{}\"", m);
778
            }
779
        }
1,924✔
780
        return agas::service_mode::hosted;
×
781
    }
1,924✔
782

783
    std::uint32_t runtime_configuration::get_num_localities() const
69,062✔
784
    {
785
        if (num_localities == 0)
69,062✔
786
        {
787
            if (util::section const* sec = get_section("hpx"); nullptr != sec)
454✔
788
            {
789
                num_localities = hpx::util::get_entry_as<std::uint32_t>(
454✔
790
                    *sec, "localities", 1);
454✔
791
            }
454✔
792
        }
454✔
793

794
        HPX_ASSERT(num_localities != 0);
69,062✔
795
        return num_localities;
69,062✔
796
    }
×
797

798
    void runtime_configuration::set_num_localities(
142✔
799
        std::uint32_t num_localities_)
800
    {
801
        // this function should not be called on the AGAS server
802
        HPX_ASSERT(agas::service_mode::bootstrap != get_agas_service_mode());
142✔
803
        num_localities = num_localities_;
142✔
804

805
        if (util::section* sec = get_section("hpx"); nullptr != sec)
142✔
806
        {
807
            sec->add_entry("localities", std::to_string(num_localities));
142✔
808
        }
142✔
809
    }
142✔
810

811
    // this function should figure out whether networking has to be enabled.
812
    bool runtime_configuration::enable_networking() const
3,635✔
813
    {
814
#if defined(HPX_HAVE_NETWORKING)
815
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
3,635✔
816
        {
817
            // get the number of initial localities
818
            if (hpx::util::get_entry_as<std::uint32_t>(*sec, "localities", 1) >
3,635✔
819
                1)
820
            {
821
                return true;
1,124✔
822
            }
823

824
            // on localities other than locality zero the number of
825
            // localities might not have been initialized yet
826
            if (hpx::util::get_entry_as<std::int32_t>(*sec, "node", -1) > 0)
2,511✔
827
            {
828
                return true;
×
829
            }
830

831
            // get whether localities are expected to connect
832
            if (hpx::util::get_entry_as<std::int32_t>(
2,511✔
833
                    *sec, "expect_connecting_localities", 0) != 0)
2,511✔
834
            {
835
                return true;
18✔
836
            }
837

838
            // for any runtime mode except 'console' networking should be
839
            // enabled as well
840
            if (hpx::util::get_entry_as<std::string>(
4,986✔
841
                    *sec, "runtime_mode", "") != "console")
4,986✔
842
            {
843
                return true;
×
844
            }
845

846
            // whether the user has explicitly asked for network enabled
847
            if (hpx::util::get_entry_as<std::int32_t>(
2,493✔
848
                    *sec, "loopback_network", 0) != 0)
2,493✔
849
            {
850
                return true;
×
851
            }
852
        }
2,493✔
853
#endif
854
        return false;
2,493✔
855
    }
3,635✔
856

857
    std::uint32_t runtime_configuration::get_first_used_core() const
1,334✔
858
    {
859
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,334✔
860
        {
861
            return hpx::util::get_entry_as<std::uint32_t>(
1,334✔
862
                *sec, "first_used_core", 0);
1,334✔
863
        }
864
        return 0;
×
865
    }
1,334✔
866

867
    void runtime_configuration::set_first_used_core(
594✔
868
        std::uint32_t first_used_core)
869
    {
870
        if (util::section* sec = get_section("hpx"); nullptr != sec)
594✔
871
        {
872
            sec->add_entry("first_used_core", std::to_string(first_used_core));
594✔
873
        }
594✔
874
    }
594✔
875

876
    std::size_t runtime_configuration::get_agas_local_cache_size(
594✔
877
        std::size_t dflt) const
878
    {
879
        std::size_t cache_size = dflt;
594✔
880

881
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
594✔
882
        {
883
            cache_size = hpx::util::get_entry_as<std::size_t>(
594✔
884
                *sec, "local_cache_size", cache_size);
594✔
885
        }
594✔
886

887
        if (cache_size != std::size_t(~0x0ul) && cache_size < 16ul)
594✔
888
        {
889
            cache_size = 16;    // limit lower bound
×
890
        }
×
891
        return cache_size;
594✔
892
    }
×
893

894
    bool runtime_configuration::get_agas_caching_mode() const
594✔
895
    {
896
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
594✔
897
        {
898
            return hpx::util::get_entry_as<int>(*sec, "use_caching", 1) != 0;
594✔
899
        }
900
        return false;
×
901
    }
594✔
902

903
    bool runtime_configuration::get_agas_range_caching_mode() const
594✔
904
    {
905
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
594✔
906
        {
907
            return hpx::util::get_entry_as<int>(*sec, "use_range_caching", 1) !=
594✔
908
                0;
909
        }
910
        return false;
×
911
    }
594✔
912

913
    std::size_t runtime_configuration::get_agas_max_pending_refcnt_requests()
594✔
914
        const
915
    {
916
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
594✔
917
        {
918
            return hpx::util::get_entry_as<std::size_t>(*sec,
594✔
919
                "max_pending_refcnt_requests",
594✔
920
                HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS);
594✔
921
        }
922
        return HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS;
×
923
    }
594✔
924

925
    bool runtime_configuration::get_itt_notify_mode() const
×
926
    {
927
#if HPX_HAVE_ITTNOTIFY != 0
928
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
929
        {
930
            return hpx::util::get_entry_as<int>(*sec, "use_itt_notify", 0) != 0;
931
        }
932
#endif
933
        return false;
×
934
    }
935

936
    // Enable lock detection during suspension
937
    bool runtime_configuration::enable_lock_detection() const
1,220✔
938
    {
939
#ifdef HPX_HAVE_VERIFY_LOCKS
940
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,220✔
941
        {
942
            return hpx::util::get_entry_as<int>(*sec, "lock_detection", 0) != 0;
1,220✔
943
        }
944
#endif
945
        return false;
×
946
    }
1,220✔
947

948
    // Enable minimal deadlock detection for HPX threads
949
    bool runtime_configuration::enable_minimal_deadlock_detection() const
×
950
    {
951
#ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION
952
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
953
        {
954
#ifdef HPX_DEBUG
955
            return hpx::util::get_entry_as<int>(
956
                       *sec, "minimal_deadlock_detection", 1) != 0;
957
#else
958
            return hpx::util::get_entry_as<int>(
959
                       *sec, "minimal_deadlock_detection", 0) != 0;
960
#endif
961
        }
962

963
#ifdef HPX_DEBUG
964
        return true;
965
#else
966
        return false;
967
#endif
968

969
#else
970
        return false;
×
971
#endif
972
    }
973

974
    ///////////////////////////////////////////////////////////////////////////
975
    bool runtime_configuration::enable_spinlock_deadlock_detection() const
1,220✔
976
    {
977
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
978
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,220✔
979
        {
980
#ifdef HPX_DEBUG
981
            return hpx::util::get_entry_as<int>(
1,220✔
982
                       *sec, "spinlock_deadlock_detection", 1) != 0;
1,220✔
983
#else
984
            return hpx::util::get_entry_as<int>(
985
                       *sec, "spinlock_deadlock_detection", 0) != 0;
986
#endif
987
        }
988

989
#ifdef HPX_DEBUG
990
        return true;
×
991
#else
992
        return false;
993
#endif
994

995
#else
996
        return false;
997
#endif
998
    }
1,220✔
999

1000
    ///////////////////////////////////////////////////////////////////////////
1001
    std::size_t runtime_configuration::get_spinlock_deadlock_detection_limit()
1,220✔
1002
        const
1003
    {
1004
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
1005
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,220✔
1006
        {
1007
            return hpx::util::get_entry_as<std::size_t>(*sec,
1,220✔
1008
                "spinlock_deadlock_detection_limit",
1,220✔
1009
                HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT);
1,220✔
1010
        }
1011
        return HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT;
×
1012
#else
1013
        return std::size_t(-1);
1014
#endif
1015
    }
1,220✔
1016

1017
    std::size_t runtime_configuration::trace_depth() const
1,220✔
1018
    {
1019
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,220✔
1020
        {
1021
            return hpx::util::get_entry_as<std::size_t>(
1,220✔
1022
                *sec, "trace_depth", HPX_HAVE_THREAD_BACKTRACE_DEPTH);
1,220✔
1023
        }
1024
        return HPX_HAVE_THREAD_BACKTRACE_DEPTH;
×
1025
    }
1,220✔
1026

1027
    std::size_t runtime_configuration::get_os_thread_count() const
1,597✔
1028
    {
1029
        if (num_os_threads == 0)
1,597✔
1030
        {
1031
            num_os_threads = 1;
202✔
1032
            if (util::section const* sec = get_section("hpx"); nullptr != sec)
202✔
1033
            {
1034
                num_os_threads = hpx::util::get_entry_as<std::uint32_t>(
202✔
1035
                    *sec, "os_threads", 1);
202✔
1036
            }
202✔
1037
        }
202✔
1038
        return static_cast<std::size_t>(num_os_threads);
1,597✔
1039
    }
×
1040

1041
    std::string runtime_configuration::get_cmd_line() const
1,202✔
1042
    {
1043
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1,202✔
1044
        {
1045
            return sec->get_entry("cmd_line", "");
1,202✔
1046
        }
1047
        return "";
×
1048
    }
1,202✔
1049

1050
    // Return the configured sizes of any of the know thread pools
1051
    std::size_t runtime_configuration::get_thread_pool_size(
2,434✔
1052
        char const* poolname) const
1053
    {
1054
        if (util::section const* sec = get_section("hpx.threadpools");
2,434✔
1055
            nullptr != sec)
2,434✔
1056
        {
1057
            return hpx::util::get_entry_as<std::size_t>(
2,434✔
1058
                *sec, std::string(poolname) + "_size", 2);
2,434✔
1059
        }
1060
        return 2;    // the default size for all pools is 2
×
1061
    }
2,434✔
1062

1063
    // Return the endianness to be used for out-serialization
1064
    std::string runtime_configuration::get_endian_out() const
×
1065
    {
1066
        if (util::section const* sec = get_section("hpx.parcel");
×
1067
            nullptr != sec)
×
1068
        {
1069
            return sec->get_entry(
×
1070
                "endian_out", endian::native == endian::big ? "big" : "little");
×
1071
        }
1072
        return endian::native == endian::big ? "big" : "little";
×
1073
    }
×
1074

1075
    // Will return the stack size to use for all HPX-threads.
1076
    std::ptrdiff_t runtime_configuration::init_stack_size(char const* entryname,
31,580✔
1077
        char const* defaultvaluestr, std::ptrdiff_t defaultvalue) const
1078
    {
1079
        if (util::section const* sec = get_section("hpx.stacks");
31,580✔
1080
            nullptr != sec)
31,580✔
1081
        {
1082
            std::string entry = sec->get_entry(entryname, defaultvaluestr);
31,580✔
1083
            char* endptr = nullptr;
31,580✔
1084
            std::ptrdiff_t val =
31,580✔
1085
                std::strtoll(entry.c_str(), &endptr, /*base:*/ 0);
31,580✔
1086
            return endptr != entry.c_str() ? val : defaultvalue;
31,580✔
1087
        }
31,580✔
1088
        return defaultvalue;
×
1089
    }
31,580✔
1090

1091
#if defined(__linux) || defined(linux) || defined(__linux__) ||                \
1092
    defined(__FreeBSD__)
1093
    bool runtime_configuration::use_stack_guard_pages() const
1,220✔
1094
    {
1095
        if (util::section const* sec = get_section("hpx.stacks");
1,220✔
1096
            nullptr != sec)
1,220✔
1097
        {
1098
            return hpx::util::get_entry_as<int>(*sec, "use_guard_pages", 1) !=
1,220✔
1099
                0;
1100
        }
1101
        return true;    // default is true
×
1102
    }
1,220✔
1103
#endif
1104

1105
    std::ptrdiff_t runtime_configuration::init_small_stack_size() const
12,144✔
1106
    {
1107
        return init_stack_size("small_size",
12,144✔
1108
            HPX_PP_STRINGIZE(HPX_SMALL_STACK_SIZE), HPX_SMALL_STACK_SIZE);
1109
    }
1110

1111
    std::ptrdiff_t runtime_configuration::init_medium_stack_size() const
6,072✔
1112
    {
1113
        return init_stack_size("medium_size",
6,072✔
1114
            HPX_PP_STRINGIZE(HPX_MEDIUM_STACK_SIZE), HPX_MEDIUM_STACK_SIZE);
1115
    }
1116

1117
    std::ptrdiff_t runtime_configuration::init_large_stack_size() const
6,072✔
1118
    {
1119
        return init_stack_size("large_size",
6,072✔
1120
            HPX_PP_STRINGIZE(HPX_LARGE_STACK_SIZE), HPX_LARGE_STACK_SIZE);
1121
    }
1122

1123
    std::ptrdiff_t runtime_configuration::init_huge_stack_size() const
7,292✔
1124
    {
1125
        return init_stack_size("huge_size",
7,292✔
1126
            HPX_PP_STRINGIZE(HPX_HUGE_STACK_SIZE), HPX_HUGE_STACK_SIZE);
1127
    }
1128

1129
    ///////////////////////////////////////////////////////////////////////////
1130
    // Return maximally allowed message size
1131
    std::uint64_t runtime_configuration::get_max_inbound_message_size() const
284✔
1132
    {
1133
        if (util::section const* sec = get_section("hpx.parcel");
284✔
1134
            nullptr != sec)
284✔
1135
        {
1136
            std::uint64_t maxsize = hpx::util::get_entry_as<std::uint64_t>(
284✔
1137
                *sec, "max_message_size", HPX_PARCEL_MAX_MESSAGE_SIZE);
284✔
1138
            if (maxsize > 0)
284✔
1139
                return maxsize;
284✔
1140
        }
×
1141
        return HPX_PARCEL_MAX_MESSAGE_SIZE;    // default is 1GByte
×
1142
    }
284✔
1143

1144
    std::uint64_t runtime_configuration::get_max_outbound_message_size() const
284✔
1145
    {
1146
        if (util::section const* sec = get_section("hpx.parcel");
284✔
1147
            nullptr != sec)
284✔
1148
        {
1149
            std::uint64_t maxsize = hpx::util::get_entry_as<std::uint64_t>(*sec,
284✔
1150
                "max_outbound_message_size",
284✔
1151
                HPX_PARCEL_MAX_OUTBOUND_MESSAGE_SIZE);
284✔
1152
            if (maxsize > 0)
284✔
1153
                return maxsize;
284✔
1154
        }
×
1155
        return HPX_PARCEL_MAX_OUTBOUND_MESSAGE_SIZE;    // default is 1GByte
×
1156
    }
284✔
1157

1158
    ///////////////////////////////////////////////////////////////////////////
1159
    bool runtime_configuration::load_application_configuration(
×
1160
        char const* filename, error_code& ec)
1161
    {
1162
        try
1163
        {
1164
            section appcfg(filename);
×
1165
            section applroot;
×
1166
            applroot.add_section("application", appcfg);
×
1167
            this->section::merge(applroot);
×
1168
        }
×
1169
        catch (hpx::exception const& e)
1170
        {
1171
            // file doesn't exist or is ill-formed
1172
            if (&ec == &throws)
×
1173
                throw;
×
1174
            ec = make_error_code(
×
1175
                e.get_error(), e.what(), hpx::throwmode::rethrow);
×
1176
            return false;
×
1177
        }
×
1178
        return true;
×
1179
    }
×
1180

1181
    ///////////////////////////////////////////////////////////////////////////
1182
    std::ptrdiff_t runtime_configuration::get_stack_size(
1,600,063✔
1183
        threads::thread_stacksize stacksize) const
1184
    {
1185
        switch (stacksize)
1,600,078✔
1186
        {
1187
        case threads::thread_stacksize::medium:
1188
            return medium_stacksize;
3,505✔
1189

1190
        case threads::thread_stacksize::large:
1191
            return large_stacksize;
1,816✔
1192

1193
        case threads::thread_stacksize::huge:
1194
            return huge_stacksize;
1,220✔
1195

1196
        case threads::thread_stacksize::nostack:
1197
            return (std::numeric_limits<std::ptrdiff_t>::max)();
×
1198

1199
        default:
1200
        case threads::thread_stacksize::small_:
1201
            break;
1,593,536✔
1202
        }
1203
        return small_stacksize;
1,593,544✔
1204
    }
1,600,086✔
1205
}}    // namespace hpx::util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc