Atlas Runtime
log_structure.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef LOG_STRUCTURE_HPP
18 #define LOG_STRUCTURE_HPP
19 
20 #include <atomic>
21 
22 #include <stdlib.h>
23 #include <stdint.h>
24 
25 #include "log_configs.hpp"
26 
27 namespace Atlas {
28 
29 // Structure of an undo log entry
30 struct LogEntry
31 {
32  LogEntry(void *addr, uintptr_t val_or_ptr, LogEntry *next,
33  size_t sz, LogType type)
34  : Addr{addr}, ValueOrPtr{val_or_ptr}, Next{next},
35  Size{sz}, Type{type} {}
36 
37  void *Addr; /* address of mloc or lock object */
38  uintptr_t ValueOrPtr; /* either value or ptr (for sync ops) */
39  std::atomic<LogEntry*> Next; /* ptr to next log entry in program order */
40  size_t Size:60; /* mloc size or a generation # for sync ops */
42 
43  bool isDummy() const { return Type == LE_dummy; }
44  bool isAcquire() const { return Type == LE_acquire; }
45  bool isRWLockRdLock() const { return Type == LE_rwlock_rdlock; }
46  bool isRWLockWrLock() const { return Type == LE_rwlock_wrlock; }
47  bool isBeginDurable() const { return Type == LE_begin_durable; }
48  bool isRelease() const { return Type == LE_release; }
49  bool isRWLockUnlock() const { return Type == LE_rwlock_unlock; }
50  bool isEndDurable() const { return Type == LE_end_durable; }
51  bool isStr() const { return Type == LE_str; }
52  bool isMemset() const { return Type == LE_memset; }
53  bool isMemcpy() const { return Type == LE_memcpy; }
54  bool isMemmove() const { return Type == LE_memmove; }
55  bool isMemop() const {
56  return Type == LE_memset || Type == LE_memcpy || Type == LE_memmove;
57  }
58  bool isAlloc() const { return Type == LE_alloc; }
59  bool isFree() const { return Type == LE_free; }
60  bool isStrcpy() const { return Type == LE_strcpy; }
61  bool isStrcat() const { return Type == LE_strcat; }
62  bool isStrop() const { return Type == LE_strcpy || Type == LE_strcat; }
63  bool isStartSection() const {
64  return isAcquire() || isRWLockRdLock() || isRWLockWrLock() ||
66  }
67  bool isEndSection() const
68  { return isRelease() || isRWLockUnlock() || isEndDurable(); }
69 };
70 
71 #define LAST_LOG_ELEM(p) ((char*)(p)+24)
72 
73 // Log structure header: A shared statically allocated header points at
74 // the start of this structure, so it is available to all threads. Every
75 // entry has a pointer to a particular thread's log structure and a next
76 // pointer
78 {
80  : Le{le},
81  Next{next} {}
82 
83  LogEntry *Le; // points to first non-deleted thread-specific log entry
84  // Insertion happens at the head, so the following is write-once before
85  // getting published.
87 };
88 
89 static inline bool isDummy(LogType le_type)
90 {
91  return le_type == LE_dummy;
92 }
93 
94 static inline bool isAcquire(LogType le_type)
95 {
96  return le_type == LE_acquire;
97 }
98 
99 static inline bool isRWLockRdLock(LogType le_type)
100 {
101  return le_type == LE_rwlock_rdlock;
102 }
103 
104 static inline bool isRWLockWrLock(LogType le_type)
105 {
106  return le_type == LE_rwlock_wrlock;
107 }
108 
109 static inline bool isBeginDurable(LogType le_type)
110 {
111  return le_type == LE_begin_durable;
112 }
113 
114 static inline bool isRelease(LogType le_type)
115 {
116  return le_type == LE_release;
117 }
118 
119 static inline bool isRWLockUnlock(LogType le_type)
120 {
121  return le_type == LE_rwlock_unlock;
122 }
123 
124 static inline bool isEndDurable(LogType le_type)
125 {
126  return le_type == LE_end_durable;
127 }
128 
129 static inline bool isStr(LogType le_type)
130 {
131  return le_type == LE_str;
132 }
133 
134 static inline bool isMemset(LogType le_type)
135 {
136  return le_type == LE_memset;
137 }
138 
139 static inline bool isMemcpy(LogType le_type)
140 {
141  return le_type == LE_memcpy;
142 }
143 
144 static inline bool isMemmove(LogType le_type)
145 {
146  return le_type == LE_memmove;
147 }
148 
149 static inline bool isMemop(LogType le_type)
150 {
151  return le_type == LE_memset || le_type == LE_memcpy ||
152  le_type == LE_memmove;
153 }
154 
155 static inline bool isAlloc(LogType le_type)
156 {
157  return le_type == LE_alloc;
158 }
159 
160 static inline bool isFree(LogType le_type)
161 {
162  return le_type == LE_free;
163 }
164 
165 static inline bool isStrcpy(LogType le_type)
166 {
167  return le_type == LE_strcpy;
168 }
169 
170 static inline bool isStrcat(LogType le_type)
171 {
172  return le_type == LE_strcat;
173 }
174 
175 static inline bool isStrop(LogType le_type)
176 {
177  return le_type == LE_strcpy || le_type == LE_strcat;
178 }
179 
180 static inline bool isStartSection(LogType le_type)
181 {
182  return isAcquire(le_type) || isRWLockRdLock(le_type) ||
183  isRWLockWrLock(le_type) || isBeginDurable(le_type);
184 }
185 
186 static inline bool isEndSection(LogType le_type)
187 {
188  return isRelease(le_type) || isRWLockUnlock(le_type) ||
189  isEndDurable(le_type);
190 }
191 
192 } // namespace Atlas
193 
194 #endif
Definition: log_configs.hpp:36
Definition: log_configs.hpp:34
Definition: log_configs.hpp:35
Definition: log_configs.hpp:33
bool isRWLockUnlock() const
Definition: log_structure.hpp:49
Definition: log_configs.hpp:36
bool isStartSection() const
Definition: log_structure.hpp:63
Definition: log_structure.hpp:30
Definition: log_configs.hpp:33
size_t Size
Definition: log_structure.hpp:40
LogType
Definition: log_configs.hpp:32
bool isStr() const
Definition: log_structure.hpp:51
LogStructure(LogEntry *le, LogStructure *next)
Definition: log_structure.hpp:79
Definition: log_configs.hpp:34
bool isAcquire() const
Definition: log_structure.hpp:44
bool isEndSection() const
Definition: log_structure.hpp:67
bool isStrop() const
Definition: log_structure.hpp:62
bool isMemop() const
Definition: log_structure.hpp:55
LogEntry * Le
Definition: log_structure.hpp:83
Definition: log_configs.hpp:35
bool isBeginDurable() const
Definition: log_structure.hpp:47
std::atomic< LogEntry * > Next
Definition: log_structure.hpp:39
bool isDummy() const
Definition: log_structure.hpp:43
bool isRWLockRdLock() const
Definition: log_structure.hpp:45
bool isRelease() const
Definition: log_structure.hpp:48
bool isEndDurable() const
Definition: log_structure.hpp:50
bool isMemcpy() const
Definition: log_structure.hpp:53
LogType Type
Definition: log_structure.hpp:41
bool isMemset() const
Definition: log_structure.hpp:52
Definition: log_configs.hpp:33
Definition: log_configs.hpp:34
Definition: log_configs.hpp:35
Definition: log_configs.hpp:34
Definition: log_structure.hpp:77
bool isRWLockWrLock() const
Definition: log_structure.hpp:46
Definition: log_configs.hpp:36
bool isMemmove() const
Definition: log_structure.hpp:54
bool isFree() const
Definition: log_structure.hpp:59
LogEntry(void *addr, uintptr_t val_or_ptr, LogEntry *next, size_t sz, LogType type)
Definition: log_structure.hpp:32
uintptr_t ValueOrPtr
Definition: log_structure.hpp:38
Definition: log_configs.hpp:33
bool isStrcat() const
Definition: log_structure.hpp:61
bool isAlloc() const
Definition: log_structure.hpp:58
void * Addr
Definition: log_structure.hpp:37
Definition: log_configs.hpp:36
LogStructure * Next
Definition: log_structure.hpp:86
Definition: atlas_alloc_cpp.hpp:21
Definition: log_configs.hpp:35
bool isStrcpy() const
Definition: log_structure.hpp:60