libfoedus-core
FOEDUS Core Library
thread_options.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
19 
20 #include <numa.h>
21 
22 #include <thread>
23 
25 
26 namespace foedus {
27 namespace thread {
29  int total_cores;
30  if (::numa_available() < 0) {
31  group_count_ = 1;
32  total_cores = std::thread::hardware_concurrency(); // seems to use pthread_num_processors_np?
33  } else {
35  if (group_count_ == 0) {
36  group_count_ = 1;
37  }
38 
39  total_cores = ::numa_num_configured_cpus();
40  if (total_cores == 0) {
41  total_cores = 1;
42  }
43  }
44  thread_count_per_group_ = total_cores / group_count_;
48 }
49 
50 ErrorStack ThreadOptions::load(tinyxml2::XMLElement* element) {
56  return kRetOk;
57 }
58 
59 ErrorStack ThreadOptions::save(tinyxml2::XMLElement* element) const {
60  CHECK_ERROR(insert_comment(element, "Set of options about threads and thread-groups"));
61 
63  "Number of ThreadGroup in the engine.\n"
64  " Default value is hardware NUMA node count (::numa_num_configured_nodes()).");
66  "Number of Thread in each ThreadGroup. Default value is hardware NUMA core count;\n"
67  " ::numa_num_configured_cpus() / ::numa_num_configured_nodes()");
69  "Whether to overwrite policy/priority of worker threads.");
71  "Thread policy for worker threads. ignored if overwrite_thread_schedule_==false\n"
72  "The values are compatible with pthread's values.");
74  "Thread priority for worker threads. ignored if overwrite_thread_schedule_==false\n"
75  "The values are compatible with pthread's values.");
76  return kRetOk;
77 }
78 
79 } // namespace thread
80 } // namespace foedus
#define EXTERNALIZE_LOAD_ELEMENT(element, attribute)
Reads a child xml element to load a member variable of this object.
ThreadOptions()
Constructs option values with default values.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
static ErrorStack insert_comment(tinyxml2::XMLElement *element, const std::string &comment)
#define EXTERNALIZE_SAVE_ENUM_ELEMENT(element, attribute, comment)
Adds an xml element to represent a member variable of this object.
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
bool overwrite_thread_schedule_
Whether to overwrite policy/priority of worker threads.
int numa_num_configured_nodes()
ErrorStack load(tinyxml2::XMLElement *element) override
Reads the content of this object from the given XML element.
int numa_num_configured_cpus()
int numa_available(void)
#define EXTERNALIZE_LOAD_ENUM_ELEMENT(element, attribute)
Reads a child xml element to load a member variable of this object.
ThreadPriority thread_priority_
Thread priority for worker threads.
uint16_t group_count_
Number of ThreadGroup in the engine.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
ThreadPolicy thread_policy_
Thread policy for worker threads.
#define EXTERNALIZE_SAVE_ELEMENT(element, attribute, comment)
Adds an xml element to represent a member variable of this object.
ErrorStack save(tinyxml2::XMLElement *element) const override
Writes the content of this object to the given XML element.