Atlas Runtime
atlas_api.h
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 ATLAS_API_H
18 #define ATLAS_API_H
19 
20 #include <stdlib.h>
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 //
28 // Here are the APIs for initializing/finalizing Atlas. Each of the
29 // following 2 interfaces must be called only once.
30 
35 void NVM_Initialize();
36 
43 void NVM_Finalize();
44 
45 //
46 // No special interfaces are required for lock-based critical
47 // sections if compiler support is available. Use the
48 // compiler-plugin to take advantage of automatic instrumentation
49 // of critical sections.
50 //
51 
58 void nvm_begin_durable();
59 void nvm_end_durable();
60 
61 //
62 // The following interfaces are for low-level programming of
63 // persistent memory, where the high-level consistency support
64 // afforded by Atlas is not used. Instead, persistence is explicitly
65 // managed by the following interfaces.
66 //
67 
72 int NVM_IsInOpenPR(void *addr, size_t sz /* in bytes */);
73 
77 void nvm_psync(void *addr, size_t sz /* in bytes */);
78 
82 void nvm_psync_acq(void *addr, size_t sz /* in bytes */);
83 
84 // This may be invoked by a user program to print out Atlas statistics
85 #ifdef NVM_STATS
86  void NVM_PrintStats();
87 #endif
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 // End of Atlas APIs
94 
95 #ifdef NVM_STATS
96 extern __thread uint64_t num_flushes;
97 #endif
98 
99 // Useful macros
100 #define NVM_BEGIN_DURABLE() nvm_begin_durable()
101 #define NVM_END_DURABLE() nvm_end_durable()
102 
103 #define NVM_CLFLUSH(p) nvm_clflush((char*)(void*)(p))
104 
105 #ifndef DISABLE_FLUSHES
106 #define NVM_FLUSH(p) \
107  { full_fence(); \
108  NVM_CLFLUSH((p)); \
109  full_fence(); \
110  }
111 
112 #define NVM_FLUSH_COND(p) \
113  { if (NVM_IsInOpenPR(p, 1)) { \
114  full_fence(); \
115  NVM_CLFLUSH((p)); \
116  full_fence(); \
117  } \
118  }
119 
120 #define NVM_FLUSH_ACQ(p) \
121  { full_fence(); \
122  NVM_CLFLUSH(p); \
123  }
124 
125 #define NVM_FLUSH_ACQ_COND(p) \
126  { if (NVM_IsInOpenPR(p, 1)) { \
127  full_fence(); \
128  NVM_CLFLUSH(p); \
129  } \
130  }
131 
132 #define NVM_PSYNC(p1,s) nvm_psync(p1,s)
133 
134 #define NVM_PSYNC_COND(p1,s) \
135  { if (NVM_IsInOpenPR(p1, s)) nvm_psync(p1,s); }
136 
137 #define NVM_PSYNC_ACQ(p1,s) \
138  { \
139  nvm_psync_acq(p1,s); \
140  } \
141 
142 #define NVM_PSYNC_ACQ_COND(p1,s) \
143  { \
144  if (NVM_IsInOpenPR(p1, s)) nvm_psync_acq(p1, s); \
145  } \
146 
147 #else
148 #define NVM_FLUSH(p)
149 #define NVM_FLUSH_COND(p)
150 #define NVM_FLUSH_ACQ(p)
151 #define NVM_FLUSH_ACQ_COND(p)
152 #define NVM_PSYNC(p1,s)
153 #define NVM_PSYNC_COND(p1,s)
154 #define NVM_PSYNC_ACQ(p1,s)
155 #define NVM_PSYNC_ACQ_COND(p1,s)
156 #endif
157 
158 static __inline void nvm_clflush(const void *p)
159 {
160 #ifndef DISABLE_FLUSHES
161 #ifdef NVM_STATS
162  ++num_flushes;
163 #endif
164  __asm__ __volatile__ (
165  "clflush %0 \n" : "+m" (*(char*)(p))
166  );
167 #endif
168 }
169 
170 // Used in conjunction with clflush.
171 static __inline void full_fence() {
172  __asm__ __volatile__ ("mfence" ::: "memory");
173  }
174 
175 #endif
void nvm_begin_durable()
Definition: log_mgr_api.cpp:72
void NVM_Initialize()
Definition: log_mgr_api.cpp:26
int NVM_IsInOpenPR(void *addr, size_t sz)
Definition: pregion_mgr_api.cpp:90
__thread uint64_t num_flushes
Definition: stats.cpp:27
void nvm_psync(void *addr, size_t sz)
Definition: log_mgr_api.cpp:154
void nvm_psync_acq(void *addr, size_t sz)
Definition: log_mgr_api.cpp:162
void nvm_end_durable()
Definition: log_mgr_api.cpp:78
void NVM_Finalize()
Definition: log_mgr_api.cpp:36