1 //  Copyright (c) 2007-2016 Hartmut Kaiser
2 //  Copyright (c)      2011 Bryce Lelbach
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
5 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef HPX_UTIL_RUNTIME_CONFIGURATION_HPP
8 #define HPX_UTIL_RUNTIME_CONFIGURATION_HPP
9 
10 #include <hpx/config.hpp>
11 #include <hpx/runtime/agas_fwd.hpp>
12 #include <hpx/runtime/components/static_factory_data.hpp>
13 #include <hpx/runtime/runtime_mode.hpp>
14 #include <hpx/runtime/threads/thread_enums.hpp>
15 #include <hpx/util/ini.hpp>
16 #include <hpx/util/plugin/dll.hpp>
17 #include <hpx/plugins/plugin_registry_base.hpp>
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 ///////////////////////////////////////////////////////////////////////////////
27 namespace hpx { namespace util
28 {
29     ///////////////////////////////////////////////////////////////////////////
30     // The runtime_configuration class is a wrapper for the runtime
31     // configuration data allowing to extract configuration information in a
32     // more convenient way
33     class HPX_EXPORT runtime_configuration : public section
34     {
35         std::string hpx_ini_file;
36         std::vector<std::string> cmdline_ini_defs;
37 
38     public:
39         // initialize and load configuration information
40         runtime_configuration(char const* argv0, runtime_mode mode);
41 
42         // re-initialize all entries based on the additional information from
43         // the given configuration file
44         void reconfigure(std::string const& ini_file);
45 
46         // re-initialize all entries based on the additional information from
47         // any explicit command line options
48         void reconfigure(std::vector<std::string> const& ini_defs);
49 
50         std::vector<std::shared_ptr<plugins::plugin_registry_base> >
51             load_modules();
52 
53         void load_components_static(std::vector<
54             components::static_factory_load_data_type> const& static_modules);
55 
56         // Returns the AGAS mode of this locality, returns either hosted (for
57         // localities connecting to a remote AGAS server) or bootstrap for the
58         // locality hosting the AGAS server.
59         agas::service_mode get_agas_service_mode() const;
60 
61         // initial number of localities
62         std::uint32_t get_num_localities() const;
63         void set_num_localities(std::uint32_t);
64 
65         // sequence number of first usable pu
66         std::uint32_t get_first_used_core() const;
67         void set_first_used_core(std::uint32_t);
68 
69         // Get the size of the ipc parcelport data buffer cache
70         std::size_t get_ipc_data_buffer_cache_size() const;
71 
72         // Get AGAS client-side local cache size
73         std::size_t get_agas_local_cache_size(
74             std::size_t dflt = HPX_AGAS_LOCAL_CACHE_SIZE) const;
75 
76         bool get_agas_caching_mode() const;
77 
78         bool get_agas_range_caching_mode() const;
79 
80         std::size_t get_agas_max_pending_refcnt_requests() const;
81 
82         // Load application specific configuration and merge it with the
83         // default configuration loaded from hpx.ini
84         bool load_application_configuration(char const* filename,
85             error_code& ec = throws);
86 
87         // Can be set to true if we want to use the ITT notify tools API.
88         bool get_itt_notify_mode() const;
89 
90         // Enable lock detection during suspension
91         bool enable_lock_detection() const;
92 
93         // Enable global lock tracking
94         bool enable_global_lock_detection() const;
95 
96         // Enable minimal deadlock detection for HPX threads
97         bool enable_minimal_deadlock_detection() const;
98         bool enable_spinlock_deadlock_detection() const;
99         std::size_t get_spinlock_deadlock_detection_limit() const;
100 
101         // Returns the number of OS threads this locality is running.
102         std::size_t get_os_thread_count() const;
103 
104         // Returns the command line that this locality was invoked with.
105         std::string get_cmd_line() const;
106 
107         // Will return the default stack size to use for all HPX-threads.
get_default_stack_size() const108         std::ptrdiff_t get_default_stack_size() const
109         {
110             return small_stacksize;
111         }
112 
113         // Will return the requested stack size to use for an HPX-threads.
114         std::ptrdiff_t get_stack_size(threads::thread_stacksize stacksize) const;
115 
116         // Return the configured sizes of any of the know thread pools
117         std::size_t get_thread_pool_size(char const* poolname) const;
118 
119         // Return the endianess to be used for out-serialization
120         std::string get_endian_out() const;
121 
122         // Return maximally allowed message sizes
123         std::uint64_t get_max_inbound_message_size() const;
124         std::uint64_t get_max_outbound_message_size() const;
125 
modules()126         std::map<std::string, hpx::util::plugin::dll> & modules()
127         {
128             return modules_;
129         }
130 
131     private:
132         std::ptrdiff_t init_stack_size(char const* entryname,
133             char const* defaultvaluestr, std::ptrdiff_t defaultvalue) const;
134 
135         std::ptrdiff_t init_small_stack_size() const;
136         std::ptrdiff_t init_medium_stack_size() const;
137         std::ptrdiff_t init_large_stack_size() const;
138         std::ptrdiff_t init_huge_stack_size() const;
139 
140 #if defined(__linux) || defined(linux) || defined(__linux__) || defined(__FreeBSD__)
141         bool init_use_stack_guard_pages() const;
142 #endif
143 
144         void pre_initialize_ini();
145         void post_initialize_ini(std::string& hpx_ini_file,
146             std::vector<std::string> const& cmdline_ini_defs);
147 
148         void reconfigure();
149 
150     public:
151         runtime_mode mode_;
152 
153     private:
154         mutable std::uint32_t num_localities;
155         std::ptrdiff_t small_stacksize;
156         std::ptrdiff_t medium_stacksize;
157         std::ptrdiff_t large_stacksize;
158         std::ptrdiff_t huge_stacksize;
159         bool need_to_call_pre_initialize;
160 #if defined(__linux) || defined(linux) || defined(__linux__)
161         char const* argv0;
162 #endif
163 
164         std::map<std::string, hpx::util::plugin::dll> modules_;
165     };
166 }}
167 
168 #endif /*HPX_UTIL_RUNTIME_CONFIGURATION_HPP*/
169