diff options
-rw-r--r-- | arch/x86/include/asm/special_insns.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h index aeb4666e0c0a..2270e41b32fd 100644 --- a/arch/x86/include/asm/special_insns.h +++ b/arch/x86/include/asm/special_insns.h | |||
@@ -215,6 +215,44 @@ static inline void clwb(volatile void *__p) | |||
215 | : [pax] "a" (p)); | 215 | : [pax] "a" (p)); |
216 | } | 216 | } |
217 | 217 | ||
218 | /** | ||
219 | * pcommit_sfence() - persistent commit and fence | ||
220 | * | ||
221 | * The PCOMMIT instruction ensures that data that has been flushed from the | ||
222 | * processor's cache hierarchy with CLWB, CLFLUSHOPT or CLFLUSH is accepted to | ||
223 | * memory and is durable on the DIMM. The primary use case for this is | ||
224 | * persistent memory. | ||
225 | * | ||
226 | * This function shows how to properly use CLWB/CLFLUSHOPT/CLFLUSH and PCOMMIT | ||
227 | * with appropriate fencing. | ||
228 | * | ||
229 | * Example: | ||
230 | * void flush_and_commit_buffer(void *vaddr, unsigned int size) | ||
231 | * { | ||
232 | * unsigned long clflush_mask = boot_cpu_data.x86_clflush_size - 1; | ||
233 | * void *vend = vaddr + size; | ||
234 | * void *p; | ||
235 | * | ||
236 | * for (p = (void *)((unsigned long)vaddr & ~clflush_mask); | ||
237 | * p < vend; p += boot_cpu_data.x86_clflush_size) | ||
238 | * clwb(p); | ||
239 | * | ||
240 | * // SFENCE to order CLWB/CLFLUSHOPT/CLFLUSH cache flushes | ||
241 | * // MFENCE via mb() also works | ||
242 | * wmb(); | ||
243 | * | ||
244 | * // PCOMMIT and the required SFENCE for ordering | ||
245 | * pcommit_sfence(); | ||
246 | * } | ||
247 | * | ||
248 | * After this function completes the data pointed to by 'vaddr' has been | ||
249 | * accepted to memory and will be durable if the 'vaddr' points to persistent | ||
250 | * memory. | ||
251 | * | ||
252 | * PCOMMIT must always be ordered by an MFENCE or SFENCE, so to help simplify | ||
253 | * things we include both the PCOMMIT and the required SFENCE in the | ||
254 | * alternatives generated by pcommit_sfence(). | ||
255 | */ | ||
218 | static inline void pcommit_sfence(void) | 256 | static inline void pcommit_sfence(void) |
219 | { | 257 | { |
220 | alternative(ASM_NOP7, | 258 | alternative(ASM_NOP7, |