libfoedus-core
FOEDUS Core Library
thread_id.hpp
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  */
18 #ifndef FOEDUS_THREAD_THREAD_ID_HPP_
19 #define FOEDUS_THREAD_THREAD_ID_HPP_
20 #include <stdint.h>
21 
22 #include "foedus/cxx11.hpp"
23 
29 namespace foedus {
30 namespace thread {
38 typedef uint8_t ThreadGroupId;
39 
40 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
41 CXX11_STATIC_ASSERT (sizeof(ThreadGroupId) == 1, "Max NUMA node count must be 1 byte");
42 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
43 
49 const ThreadGroupId kMaxThreadGroupId = 0xFF;
50 
58 typedef uint8_t ThreadLocalOrdinal;
59 
60 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
61 CXX11_STATIC_ASSERT (sizeof(ThreadLocalOrdinal) == 1, "Max core-per-node must be 1 byte");
62 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
63 
69 const ThreadLocalOrdinal kMaxThreadLocalOrdinal = 0xFF;
70 
80 typedef uint16_t ThreadId;
81 
82 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
83 CXX11_STATIC_ASSERT (sizeof(ThreadId) == 2, "Max thread count must be 2 bytes");
84 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
85 
98 typedef uint16_t ThreadGlobalOrdinal;
99 
105 const ThreadId kMaxThreadId = 0xFFFF;
106 
117 typedef uint64_t ThreadTicket;
118 
123 inline ThreadId compose_thread_id(ThreadGroupId node, ThreadLocalOrdinal local_core) {
124  return (node << 8) | local_core;
125 }
126 
131 inline ThreadGroupId decompose_numa_node(ThreadId global_id) {
132  return (global_id >> 8) & 0xFF;
133 }
134 
139 inline ThreadLocalOrdinal decompose_numa_local_ordinal(ThreadId global_id) {
140  return global_id & 0xFF;
141 }
142 
147 inline ThreadGlobalOrdinal to_global_ordinal(ThreadId thread_id, uint8_t threads_per_nodes) {
148  return decompose_numa_node(thread_id) * threads_per_nodes
149  + decompose_numa_local_ordinal(thread_id);
150 }
151 
159 typedef int64_t TimeoutMicrosec;
160 
177  // no SCHED_DEADLINE. Too new (linux 3.14~).
178 };
191 };
192 
218 };
219 
220 } // namespace thread
221 } // namespace foedus
222 #endif // FOEDUS_THREAD_THREAD_ID_HPP_
const ThreadLocalOrdinal kMaxThreadLocalOrdinal
Maximum possible value of ThreadLocalOrdinal.
Definition: thread_id.hpp:69
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
ThreadPolicy
Thread policy for worker threads.
Definition: thread_id.hpp:166
Idle state, receiving a new task.
Definition: thread_id.hpp:207
ThreadStatus
Impersonation status of each worker thread.
Definition: thread_id.hpp:203
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
ThreadPriority
Thread priority for worker threads.
Definition: thread_id.hpp:186
A client has set a next task.
Definition: thread_id.hpp:209
ThreadLocalOrdinal decompose_numa_local_ordinal(ThreadId global_id)
Extracts local ordinal from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:139
const ThreadGroupId kMaxThreadGroupId
Maximum possible value of ThreadGroupId.
Definition: thread_id.hpp:49
The thread is requested to terminate.
Definition: thread_id.hpp:215
The thread has picked the task up and is now running.
Definition: thread_id.hpp:211
int64_t TimeoutMicrosec
Used as a general timeout parameter (in microseconds) for synchronous methods.
Definition: thread_id.hpp:159
ThreadGroupId decompose_numa_node(ThreadId global_id)
Extracts NUMA node ID from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:131
#define CXX11_STATIC_ASSERT(expr, message)
Used in public headers in place of "static_assert" of C++11.
Definition: cxx11.hpp:135
ThreadId compose_thread_id(ThreadGroupId node, ThreadLocalOrdinal local_core)
Returns a globally unique ID of Thread (core) for the given node and ordinal in the node...
Definition: thread_id.hpp:123
uint16_t ThreadGlobalOrdinal
Typedef for a globally and contiguously numbered ID of thread.
Definition: thread_id.hpp:98
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
const ThreadId kMaxThreadId
Maximum possible value of ThreadId.
Definition: thread_id.hpp:105
The thread has completed the task and set the result.
Definition: thread_id.hpp:213
ThreadGlobalOrdinal to_global_ordinal(ThreadId thread_id, uint8_t threads_per_nodes)
Calculate ThreadGlobalOrdinal from ThreadId.
Definition: thread_id.hpp:147
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
The thread has terminated (either error or normal, check the result to differentiate them)...
Definition: thread_id.hpp:217
uint64_t ThreadTicket
Typedef for a monotonically increasing ticket for thread impersonation.
Definition: thread_id.hpp:117