libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
thread_traits.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_COMMON_THREAD_TRAITS_HPP
2 # define ISIMUD_EXCHANGES_COMMON_THREAD_TRAITS_HPP
3 
4 /******************************************************************************
5 ** Copyright © 2019 by J.M.McGuiness, isimud@hussar.me.uk
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2.1 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include "core/numa_traits.hpp"
23 
24 #include <iostream>
25 
26 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace common {
27 
28 /// From the detected NUMA layout, assign cores to the logical threads in the FIX-to-exchange translator.
29 struct thread_traits {
30  using api_threading_traits=libjmmcg::ppd::api_threading_traits<libjmmcg::ppd::platform_api, libjmmcg::ppd::heavyweight_threading>;
31  struct thread_info {
33  const api_threading_traits::api_params_type::priority_type priority{};
34 
35  friend std::ostream &operator<<(std::ostream &os, thread_info const &ti) noexcept(false);
36  };
37 
38  /// The numa-node upon which the code is compiled to run optimally.
39  /**
40  This value should be the same as that used by numactl in the start-script (e.g. "start_all_links.sh"), otherwise the code will run on the wrong processor. (One can determine which node the code has been compiled for by running the executable with the "--help" option.)
41 
42  \see NUMA_INDEX
43  */
44  static inline constexpr auto numa_index=(libjmmcg::ppd::numa_cpu_traits::is_numa ? libjmmcg::ppd::numa_cpu_traits::node_mapping.max_size()-1 : 0);
45  static inline constexpr auto max_threads_on_node=libjmmcg::ppd::numa_cpu_traits::node_mapping[numa_index].max_size();
46 
47  /**
48  Put this well out of the way of anything important.
49  */
50  static inline constexpr auto main_thread=thread_info{
51  libjmmcg::ppd::numa_cpu_traits::node_mapping[0][0%max_threads_on_node],
52  api_threading_traits::api_params_type::priority_type::idle
53  };
54  static inline constexpr auto heartbeat_thread=thread_info{
55  libjmmcg::ppd::numa_cpu_traits::node_mapping[numa_index][0%max_threads_on_node],
56  api_threading_traits::api_params_type::priority_type::idle
57  };
58  static inline constexpr auto exchange_to_client_thread=thread_info{
59  libjmmcg::ppd::numa_cpu_traits::node_mapping[numa_index][1%max_threads_on_node],
60  api_threading_traits::api_params_type::priority_type::normal
61  };
62  static inline constexpr auto client_to_exchange_thread=thread_info{
63  libjmmcg::ppd::numa_cpu_traits::node_mapping[numa_index][2%max_threads_on_node],
64  api_threading_traits::api_params_type::priority_type::time_critical
65  };
66  static inline constexpr auto exchange_simulator_thread=thread_info{
67  libjmmcg::ppd::numa_cpu_traits::node_mapping[numa_index][3%max_threads_on_node],
68  api_threading_traits::api_params_type::priority_type::idle
69  };
70 };
71 
72 inline std::ostream &
73 operator<<(std::ostream &os, thread_traits::thread_info const &ti) noexcept(false) {
74  os<<"core="<<ti.core<<", priority="<<ti.priority;
75  return os;
76 }
77 
78 } } } }
79 
80 #endif