repo
stringlengths
1
152
file
stringlengths
14
221
code
stringlengths
501
25k
file_length
int64
501
25k
avg_line_length
float64
20
99.5
max_line_length
int64
21
134
extension_type
stringclasses
2 values
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_check_allocations/cto_check_allocations.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cto_check_allocations -- unit test for cto_check_allocations * * usage: cto_check_allocations filename */ #include "unittest.h" #define MAX_ALLOC_SIZE (4L * 1024L * 1024L) #define NALLOCS 16 #define POOL_SIZE (2 * PMEMCTO_MIN_POOL) /* buffer for all allocation pointers */ static char *ptrs[NALLOCS]; int main(int argc, char *argv[]) { START(argc, argv, "cto_check_allocations"); if (argc != 2) UT_FATAL("usage: %s filename", argv[0]); PMEMctopool *pcp = pmemcto_create(argv[1], "test", POOL_SIZE, 0666); UT_ASSERTne(pcp, NULL); for (size_t size = 8; size <= MAX_ALLOC_SIZE; size *= 2) { memset(ptrs, 0, sizeof(ptrs)); int i; for (i = 0; i < NALLOCS; ++i) { ptrs[i] = pmemcto_malloc(pcp, size); if (ptrs[i] == NULL) { /* out of memory in pool */ break; } /* check that pointer came from mem_pool */ UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE); /* fill each allocation with a unique value */ memset(ptrs[i], (char)i, size); } UT_OUT("size %zu cnt %d", size, i); UT_ASSERT((i > 0) && (i + 1 < MAX_ALLOC_SIZE)); /* check for unexpected modifications of the data */ for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i) { for (size_t j = 0; j < size; ++j) UT_ASSERTeq(ptrs[i][j], (char)i); pmemcto_free(pcp, ptrs[i]); } } pmemcto_close(pcp); DONE(NULL); }
2,940
30.287234
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_include/blk_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_include.c -- include test for libpmemblk * * this is only a compilation test - do not run this program */ #include <libpmemblk.h> int main(int argc, char *argv[]) { return 0; }
1,790
37.934783
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_aligned_alloc/cto_aligned_alloc.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cto_aligned_alloc.c -- unit test for pmemcto_aligned_alloc * * usage: cto_aligned_alloc filename */ #include "unittest.h" #define MAX_ALIGNMENT (4L * 1024L * 1024L) #define NALLOCS 16 /* buffer for all allocation pointers */ static int *ptrs[NALLOCS]; int main(int argc, char *argv[]) { START(argc, argv, "cto_aligned_alloc"); if (argc != 2) UT_FATAL("usage: %s filename", argv[0]); /* test with address alignment from 2B to 4MB */ size_t alignment; for (alignment = 2; alignment <= MAX_ALIGNMENT; alignment *= 2) { PMEMctopool *pcp = pmemcto_create(argv[1], "test", PMEMCTO_MIN_POOL, 0666); UT_ASSERTne(pcp, NULL); memset(ptrs, 0, sizeof(ptrs)); int i; for (i = 0; i < NALLOCS; ++i) { ptrs[i] = pmemcto_aligned_alloc(pcp, alignment, sizeof(int)); /* at least one allocation must succeed */ UT_ASSERT(i != 0 || ptrs[i] != NULL); if (ptrs[i] == NULL) { /* out of memory in pool */ break; } /* check that pointer came from mem_pool */ UT_ASSERTrange(ptrs[i], pcp, PMEMCTO_MIN_POOL); /* check for correct address alignment */ UT_ASSERTeq((uintptr_t)(ptrs[i]) & (alignment - 1), 0); /* ptr should be usable */ *ptrs[i] = i; UT_ASSERTeq(*ptrs[i], i); } /* check for unexpected modifications of the data */ for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i) pmemcto_free(pcp, ptrs[i]); pmemcto_close(pcp); UNLINK(argv[1]); } DONE(NULL); }
3,043
30.061224
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_sync/mocks_windows.h
/* * Copyright 2016-2017, Intel Corporation * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_windows.h -- redefinitions of pthread functions * * This file is Windows-specific. * * This file should be included (i.e. using Forced Include) by libpmemobj * files, when compiled for the purpose of obj_sync test. * It would replace default implementation with mocked functions defined * in obj_sync.c. * * These defines could be also passed as preprocessor definitions. */ #ifndef WRAP_REAL #define os_mutex_init __wrap_os_mutex_init #define os_rwlock_init __wrap_os_rwlock_init #define os_cond_init __wrap_os_cond_init #endif
2,221
41.730769
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_sync/obj_sync.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_sync.c -- unit test for PMEM-resident locks */ #include "obj.h" #include "sync.h" #include "unittest.h" #include "util.h" #include "os.h" #define MAX_THREAD_NUM 200 #define DATA_SIZE 128 #define LOCKED_MUTEX 1 #define NANO_PER_ONE 1000000000LL #define TIMEOUT (NANO_PER_ONE / 1000LL) #define WORKER_RUNS 10 #define MAX_OPENS 5 #define FATAL_USAGE() UT_FATAL("usage: obj_sync [mrc] <num_threads> <runs>\n") /* posix thread worker typedef */ typedef void *(*worker)(void *); /* the mock pmemobj pool */ static PMEMobjpool Mock_pop; /* the tested object containing persistent synchronization primitives */ static struct mock_obj { PMEMmutex mutex; PMEMmutex mutex_locked; PMEMcond cond; PMEMrwlock rwlock; int check_data; uint8_t data[DATA_SIZE]; } *Test_obj; PMEMobjpool * pmemobj_pool_by_ptr(const void *arg) { return &Mock_pop; } /* * mock_open_pool -- (internal) simulate pool opening */ static void mock_open_pool(PMEMobjpool *pop) { util_fetch_and_add64(&pop->run_id, 2); } /* * mutex_write_worker -- (internal) write data with mutex */ static void * mutex_write_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) { UT_ERR("pmemobj_mutex_lock"); return NULL; } memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE); if (pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex)) UT_ERR("pmemobj_mutex_unlock"); } return NULL; } /* * mutex_check_worker -- (internal) check consistency with mutex */ static void * mutex_check_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) { UT_ERR("pmemobj_mutex_lock"); return NULL; } uint8_t val = Test_obj->data[0]; for (int i = 1; i < DATA_SIZE; i++) UT_ASSERTeq(Test_obj->data[i], val); memset(Test_obj->data, 0, DATA_SIZE); if (pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex)) UT_ERR("pmemobj_mutex_unlock"); } return NULL; } /* * cond_write_worker -- (internal) write data with cond variable */ static void * cond_write_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) return NULL; memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE); Test_obj->check_data = 1; if (pmemobj_cond_signal(&Mock_pop, &Test_obj->cond)) UT_ERR("pmemobj_cond_signal"); pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex); } return NULL; } /* * cond_check_worker -- (internal) check consistency with cond variable */ static void * cond_check_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) return NULL; while (Test_obj->check_data != 1) { if (pmemobj_cond_wait(&Mock_pop, &Test_obj->cond, &Test_obj->mutex)) UT_ERR("pmemobj_cond_wait"); } uint8_t val = Test_obj->data[0]; for (int i = 1; i < DATA_SIZE; i++) UT_ASSERTeq(Test_obj->data[i], val); memset(Test_obj->data, 0, DATA_SIZE); pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex); } return NULL; } /* * rwlock_write_worker -- (internal) write data with rwlock */ static void * rwlock_write_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_rwlock_wrlock(&Mock_pop, &Test_obj->rwlock)) { UT_ERR("pmemobj_rwlock_wrlock"); return NULL; } memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE); if (pmemobj_rwlock_unlock(&Mock_pop, &Test_obj->rwlock)) UT_ERR("pmemobj_rwlock_unlock"); } return NULL; } /* * rwlock_check_worker -- (internal) check consistency with rwlock */ static void * rwlock_check_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { if (pmemobj_rwlock_rdlock(&Mock_pop, &Test_obj->rwlock)) { UT_ERR("pmemobj_rwlock_rdlock"); return NULL; } uint8_t val = Test_obj->data[0]; for (int i = 1; i < DATA_SIZE; i++) UT_ASSERTeq(Test_obj->data[i], val); if (pmemobj_rwlock_unlock(&Mock_pop, &Test_obj->rwlock)) UT_ERR("pmemobj_rwlock_unlock"); } return NULL; } /* * timed_write_worker -- (internal) intentionally doing nothing */ static void * timed_write_worker(void *arg) { return NULL; } /* * timed_check_worker -- (internal) check consistency with mutex */ static void * timed_check_worker(void *arg) { for (unsigned run = 0; run < WORKER_RUNS; run++) { int mutex_id = (int)(uintptr_t)arg % 2; PMEMmutex *mtx = mutex_id == LOCKED_MUTEX ? &Test_obj->mutex_locked : &Test_obj->mutex; struct timespec t1, t2, abs_time; os_clock_gettime(CLOCK_REALTIME, &t1); abs_time = t1; abs_time.tv_nsec += TIMEOUT; if (abs_time.tv_nsec >= NANO_PER_ONE) { abs_time.tv_sec++; abs_time.tv_nsec -= NANO_PER_ONE; } int ret = pmemobj_mutex_timedlock(&Mock_pop, mtx, &abs_time); os_clock_gettime(CLOCK_REALTIME, &t2); if (mutex_id == LOCKED_MUTEX) { UT_ASSERTeq(ret, ETIMEDOUT); uint64_t diff = (uint64_t)((t2.tv_sec - t1.tv_sec) * NANO_PER_ONE + t2.tv_nsec - t1.tv_nsec); UT_ASSERT(diff >= TIMEOUT); return NULL; } if (ret == 0) { UT_ASSERTne(mutex_id, LOCKED_MUTEX); pmemobj_mutex_unlock(&Mock_pop, mtx); } else if (ret == ETIMEDOUT) { uint64_t diff = (uint64_t)((t2.tv_sec - t1.tv_sec) * NANO_PER_ONE + t2.tv_nsec - t1.tv_nsec); UT_ASSERT(diff >= TIMEOUT); } else { errno = ret; UT_ERR("!pmemobj_mutex_timedlock"); } } return NULL; } /* * cleanup -- (internal) clean up after each run */ static void cleanup(char test_type) { switch (test_type) { case 'm': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); break; case 'r': os_rwlock_destroy(&((PMEMrwlock_internal *) &(Test_obj->rwlock))->PMEMrwlock_lock); break; case 'c': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); os_cond_destroy(&((PMEMcond_internal *) &(Test_obj->cond))->PMEMcond_cond); break; case 't': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex_locked))->PMEMmutex_lock); break; default: FATAL_USAGE(); } } static int obj_sync_persist(void *ctx, const void *ptr, size_t sz, unsigned flags) { /* no-op */ return 0; } int main(int argc, char *argv[]) { START(argc, argv, "obj_sync"); util_init(); if (argc < 4) FATAL_USAGE(); worker writer; worker checker; char test_type = argv[1][0]; switch (test_type) { case 'm': writer = mutex_write_worker; checker = mutex_check_worker; break; case 'r': writer = rwlock_write_worker; checker = rwlock_check_worker; break; case 'c': writer = cond_write_worker; checker = cond_check_worker; break; case 't': writer = timed_write_worker; checker = timed_check_worker; break; default: FATAL_USAGE(); } unsigned long num_threads = strtoul(argv[2], NULL, 10); if (num_threads > MAX_THREAD_NUM) UT_FATAL("Do not use more than %d threads.\n", MAX_THREAD_NUM); unsigned long opens = strtoul(argv[3], NULL, 10); if (opens > MAX_OPENS) UT_FATAL("Do not use more than %d runs.\n", MAX_OPENS); os_thread_t *write_threads = (os_thread_t *)MALLOC(num_threads * sizeof(os_thread_t)); os_thread_t *check_threads = (os_thread_t *)MALLOC(num_threads * sizeof(os_thread_t)); /* first pool open */ mock_open_pool(&Mock_pop); Mock_pop.p_ops.persist = obj_sync_persist; Mock_pop.p_ops.base = &Mock_pop; Test_obj = (struct mock_obj *)MALLOC(sizeof(struct mock_obj)); /* zero-initialize the test object */ pmemobj_mutex_zero(&Mock_pop, &Test_obj->mutex); pmemobj_mutex_zero(&Mock_pop, &Test_obj->mutex_locked); pmemobj_cond_zero(&Mock_pop, &Test_obj->cond); pmemobj_rwlock_zero(&Mock_pop, &Test_obj->rwlock); Test_obj->check_data = 0; memset(&Test_obj->data, 0, DATA_SIZE); for (unsigned long run = 0; run < opens; run++) { if (test_type == 't') { pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex_locked); } for (unsigned i = 0; i < num_threads; i++) { PTHREAD_CREATE(&write_threads[i], NULL, writer, (void *)(uintptr_t)i); PTHREAD_CREATE(&check_threads[i], NULL, checker, (void *)(uintptr_t)i); } for (unsigned i = 0; i < num_threads; i++) { PTHREAD_JOIN(&write_threads[i], NULL); PTHREAD_JOIN(&check_threads[i], NULL); } if (test_type == 't') { pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex_locked); } /* up the run_id counter and cleanup */ mock_open_pool(&Mock_pop); cleanup(test_type); } FREE(check_threads); FREE(write_threads); FREE(Test_obj); DONE(NULL); }
10,261
24.029268
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_sync/mocks_windows.c
/* * Copyright 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mock-windows.c -- redefinitions of locks function */ #include "os.h" #include "unittest.h" FUNC_MOCK(os_mutex_init, int, os_mutex_t *__restrict mutex) FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_mutex_init, mutex) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END FUNC_MOCK(os_rwlock_init, int, os_rwlock_t *__restrict rwlock) FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_rwlock_init, rwlock) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END FUNC_MOCK(os_cond_init, int, os_cond_t *__restrict cond) FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_cond_init, cond) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END
2,202
32.378788
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_sync/mocks_posix.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_posix.c -- redefinitions of lock functions (Posix implementation) */ #include <pthread.h> #include "util.h" #include "os.h" #include "unittest.h" FUNC_MOCK(pthread_mutex_init, int, pthread_mutex_t *__restrict mutex, const pthread_mutexattr_t *__restrict attr) FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_mutex_init, mutex, attr) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END FUNC_MOCK(pthread_rwlock_init, int, pthread_rwlock_t *__restrict rwlock, const pthread_rwlockattr_t *__restrict attr) FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_rwlock_init, rwlock, attr) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END FUNC_MOCK(pthread_cond_init, int, pthread_cond_t *__restrict cond, const pthread_condattr_t *__restrict attr) FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_cond_init, cond, attr) FUNC_MOCK_RUN(1) { return -1; } FUNC_MOCK_END
2,465
34.73913
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_check_version/vmem_check_version.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_check_version.c -- unit test for vmem_check_version */ #include "unittest.h" int main(int argc, char *argv[]) { START(argc, argv, "vmem_check_version"); UT_OUT("compile-time libvmem version is %d.%d", VMEM_MAJOR_VERSION, VMEM_MINOR_VERSION); const char *errstr = vmem_check_version(VMEM_MAJOR_VERSION, VMEM_MINOR_VERSION); UT_ASSERTinfo(errstr == NULL, errstr); errstr = vmem_check_version(VMEM_MAJOR_VERSION + 1, VMEM_MINOR_VERSION); UT_ASSERT(errstr != NULL); UT_OUT("for major version %d, vmem_check_version returned: %s", VMEM_MAJOR_VERSION + 1, errstr); DONE(NULL); }
2,213
35.295082
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/out_err_mt_win/out_err_mt_win.c
/* * Copyright 2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * out_err_mt_win.c -- unit test for error messages */ #include <sys/types.h> #include <stdarg.h> #include <errno.h> #include "unittest.h" #include "valgrind_internal.h" #include "util.h" #define NUM_THREADS 16 static void print_errors(const wchar_t *msg) { UT_OUT("%S", msg); UT_OUT("PMEM: %S", pmem_errormsgW()); UT_OUT("PMEMOBJ: %S", pmemobj_errormsgW()); UT_OUT("PMEMLOG: %S", pmemlog_errormsgW()); UT_OUT("PMEMBLK: %S", pmemblk_errormsgW()); UT_OUT("PMEMCTO: %S", pmemcto_errormsgW()); UT_OUT("VMEM: %S", vmem_errormsgW()); UT_OUT("PMEMPOOL: %S", pmempool_errormsgW()); } static void check_errors(int ver) { int ret; int err_need; int err_found; ret = swscanf(pmem_errormsgW(), L"libpmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION); ret = swscanf(pmemobj_errormsgW(), L"libpmemobj major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION); ret = swscanf(pmemlog_errormsgW(), L"libpmemlog major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION); ret = swscanf(pmemblk_errormsgW(), L"libpmemblk major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); ret = swscanf(pmemcto_errormsgW(), L"libpmemcto major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMCTO_MAJOR_VERSION); ret = swscanf(vmem_errormsgW(), L"libvmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION); ret = swscanf(pmempool_errormsgW(), L"libpmempool major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMPOOL_MAJOR_VERSION); } static void * do_test(void *arg) { int ver = *(int *)arg; pmem_check_version(ver, 0); pmemobj_check_version(ver, 0); pmemlog_check_version(ver, 0); pmemblk_check_version(ver, 0); pmemcto_check_version(ver, 0); vmem_check_version(ver, 0); pmempool_check_version(ver, 0); check_errors(ver); return NULL; } static void run_mt_test(void *(*worker)(void *)) { os_thread_t thread[NUM_THREADS]; int ver[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; ++i) { ver[i] = 10000 + i; PTHREAD_CREATE(&thread[i], NULL, worker, &ver[i]); } for (int i = 0; i < NUM_THREADS; ++i) { PTHREAD_JOIN(&thread[i], NULL); } } int wmain(int argc, wchar_t *argv[]) { STARTW(argc, argv, "out_err_mt_win"); if (argc != 6) UT_FATAL("usage: %S file1 file2 file3 file4 dir", argv[0]); print_errors(L"start"); PMEMobjpool *pop = pmemobj_createW(argv[1], L"test", PMEMOBJ_MIN_POOL, 0666); PMEMlogpool *plp = pmemlog_createW(argv[2], PMEMLOG_MIN_POOL, 0666); PMEMblkpool *pbp = pmemblk_createW(argv[3], 128, PMEMBLK_MIN_POOL, 0666); PMEMctopool *pcp = pmemcto_createW(argv[4], L"test", PMEMCTO_MIN_POOL, 0666); VMEM *vmp = vmem_createW(argv[5], VMEM_MIN_POOL); util_init(); pmem_check_version(10000, 0); pmemobj_check_version(10001, 0); pmemlog_check_version(10002, 0); pmemblk_check_version(10003, 0); pmemcto_check_version(10004, 0); vmem_check_version(10005, 0); pmempool_check_version(10006, 0); print_errors(L"version check"); void *ptr = NULL; /* * We are testing library error reporting and we don't want this test * to fail under memcheck. */ VALGRIND_DO_DISABLE_ERROR_REPORTING; pmem_msync(ptr, 1); VALGRIND_DO_ENABLE_ERROR_REPORTING; print_errors(L"pmem_msync"); int ret; PMEMoid oid; ret = pmemobj_alloc(pop, &oid, 0, 0, NULL, NULL); UT_ASSERTeq(ret, -1); print_errors(L"pmemobj_alloc"); pmemlog_append(plp, NULL, PMEMLOG_MIN_POOL); print_errors(L"pmemlog_append"); size_t nblock = pmemblk_nblock(pbp); pmemblk_set_error(pbp, nblock + 1); print_errors(L"pmemblk_set_error"); char dummy[8192 + 64] = { 0 }; pmemcto_close((PMEMctopool *)&dummy); print_errors(L"pmemcto_check"); VMEM *vmp2 = vmem_create_in_region(NULL, 1); UT_ASSERTeq(vmp2, NULL); print_errors(L"vmem_create_in_region"); run_mt_test(do_test); pmemobj_close(pop); pmemlog_close(plp); pmemblk_close(pbp); pmemcto_close(pcp); vmem_delete(vmp); PMEMpoolcheck *ppc; struct pmempool_check_args args = {0, }; ppc = pmempool_check_init(&args, sizeof(args) / 2); UT_ASSERTeq(ppc, NULL); print_errors(L"pmempool_check_init"); DONEW(NULL); }
6,392
27.162996
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_oid_thread/obj_oid_thread.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_oid_thread.c -- unit test for the reverse direct operation */ #include "unittest.h" #include "lane.h" #include "obj.h" #define MAX_PATH_LEN 255 #define LAYOUT_NAME "direct" static os_mutex_t lock; static os_cond_t cond; static int flag = 1; static PMEMoid thread_oid; /* * test_worker -- (internal) test worker thread */ static void * test_worker(void *arg) { os_mutex_lock(&lock); /* before pool is closed */ void *direct = pmemobj_direct(thread_oid); UT_ASSERT(OID_EQUALS(thread_oid, pmemobj_oid(direct))); flag = 0; os_cond_signal(&cond); os_mutex_unlock(&lock); os_mutex_lock(&lock); while (flag == 0) os_cond_wait(&cond, &lock); /* after pool is closed */ UT_ASSERT(OID_IS_NULL(pmemobj_oid(direct))); os_mutex_unlock(&lock); return NULL; } int main(int argc, char *argv[]) { START(argc, argv, "obj_oid_thread"); if (argc != 3) UT_FATAL("usage: %s [directory] [# of pools]", argv[0]); os_mutex_init(&lock); os_cond_init(&cond); unsigned npools = ATOU(argv[2]); const char *dir = argv[1]; int r; PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMoid *)); size_t length = strlen(dir) + MAX_PATH_LEN; char *path = MALLOC(length); for (unsigned i = 0; i < npools; ++i) { int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d", dir, i); if (ret < 0 || ret >= length) UT_FATAL("snprintf: %d", ret); pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); if (pops[i] == NULL) UT_FATAL("!pmemobj_create"); } /* Address outside the pmemobj pool */ void *allocated_memory = MALLOC(sizeof(int)); UT_ASSERT(OID_IS_NULL(pmemobj_oid(allocated_memory))); PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid)); PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid)); UT_ASSERT(OID_IS_NULL(pmemobj_oid(NULL))); oids[0] = OID_NULL; for (unsigned i = 0; i < npools; ++i) { uint64_t off = pops[i]->heap_offset; oids[i] = (PMEMoid) {pops[i]->uuid_lo, off}; UT_ASSERT(OID_EQUALS(oids[i], pmemobj_oid(pmemobj_direct(oids[i])))); r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL); UT_ASSERTeq(r, 0); UT_ASSERT(OID_EQUALS(tmpoids[i], pmemobj_oid(pmemobj_direct(tmpoids[i])))); } r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL); UT_ASSERTeq(r, 0); UT_ASSERT(!OID_IS_NULL(pmemobj_oid(pmemobj_direct(thread_oid)))); os_mutex_lock(&lock); os_thread_t t; PTHREAD_CREATE(&t, NULL, test_worker, NULL); /* wait for the thread to perform the first direct */ while (flag != 0) os_cond_wait(&cond, &lock); for (unsigned i = 0; i < npools; ++i) { pmemobj_free(&tmpoids[i]); UT_ASSERT(OID_IS_NULL(pmemobj_oid( pmemobj_direct(tmpoids[i])))); pmemobj_close(pops[i]); UT_ASSERT(OID_IS_NULL(pmemobj_oid( pmemobj_direct(oids[i])))); } /* signal the waiting thread */ flag = 1; os_cond_signal(&cond); os_mutex_unlock(&lock); PTHREAD_JOIN(&t, NULL); FREE(path); FREE(tmpoids); FREE(oids); FREE(pops); FREE(allocated_memory); os_mutex_destroy(&lock); os_cond_destroy(&cond); DONE(NULL); }
4,661
26.585799
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_file_open/util_file_open.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util_file_open.c -- unit test for util_file_open() * * usage: util_file_open minlen path [path]... */ #include "unittest.h" #include "file.h" int main(int argc, char *argv[]) { START(argc, argv, "util_file_open"); if (argc < 3) UT_FATAL("usage: %s minlen path...", argv[0]); char *fname; size_t minsize = strtoul(argv[1], &fname, 0); for (int arg = 2; arg < argc; arg++) { size_t size = 0; int fd = util_file_open(argv[arg], &size, minsize, O_RDWR); if (fd == -1) UT_OUT("!%s: util_file_open", argv[arg]); else { UT_OUT("%s: open, len %zu", argv[arg], size); os_close(fd); } } DONE(NULL); }
2,237
32.402985
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libvmmalloc/libvmmalloc.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libvmmalloc.c -- entry points for libvmmalloc * * NOTES: * 1) Since some standard library functions (fopen, sprintf) use malloc * internally, then at initialization phase, malloc(3) calls are redirected * to the standard jemalloc interfaces that operate on a system heap. * There is no need to track these allocations. For small allocations, * jemalloc is able to detect the corresponding pool the memory was * allocated from, and Vmp argument is actually ignored. So, it is safe * to reclaim this memory using je_vmem_pool_free(). * The problem may occur for huge allocations only (>2MB), but it seems * like such allocations do not happen at initialization phase. * * 2) Debug traces in malloc(3) functions are not available until library * initialization (vmem pool creation) is completed. This is to avoid * recursive calls to malloc, leading to stack overflow. * * 3) Malloc hooks in glibc are overridden to prevent any references to glibc's * malloc(3) functions in case the application uses dlopen with * RTLD_DEEPBIND flag. (Not relevant for FreeBSD since FreeBSD supports * neither malloc hooks nor RTLD_DEEPBIND.) * * 4) If the process forks, there is no separate log file open for a new * process, even if the configured log file name is terminated with "-". * * 5) Fork options 2 and 3 are currently not supported on FreeBSD because * locks are dynamically allocated on FreeBSD and hence they would be cloned * as part of the pool. This may be solvable. */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <sys/param.h> #include <errno.h> #include <stdint.h> #include <signal.h> #include <fcntl.h> #include <unistd.h> #include <pthread.h> #ifndef __FreeBSD__ #include <malloc.h> #endif #include "libvmem.h" #include "libvmmalloc.h" #include "jemalloc.h" #include "pmemcommon.h" #include "file.h" #include "os.h" #include "os_thread.h" #include "vmem.h" #include "vmmalloc.h" #include "valgrind_internal.h" #define HUGE (2 * 1024 * 1024) /* * private to this file... */ static size_t Header_size; static VMEM *Vmp; static char *Dir; static int Fd; static int Fd_clone; static int Private; static int Forkopt = 1; /* default behavior - remap as private */ static bool Destructed; /* when set - ignore all calls (do not call jemalloc) */ /* * malloc -- allocate a block of size bytes */ __ATTR_MALLOC__ __ATTR_ALLOC_SIZE__(1) void * malloc(size_t size) { if (unlikely(Destructed)) return NULL; if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_malloc(size); } LOG(4, "size %zu", size); return je_vmem_pool_malloc( (pool_t *)((uintptr_t)Vmp + Header_size), size); } /* * calloc -- allocate a block of nmemb * size bytes and set its contents to zero */ __ATTR_MALLOC__ __ATTR_ALLOC_SIZE__(1, 2) void * calloc(size_t nmemb, size_t size) { if (unlikely(Destructed)) return NULL; if (Vmp == NULL) { ASSERT((nmemb * size) <= HUGE); return je_vmem_calloc(nmemb, size); } LOG(4, "nmemb %zu, size %zu", nmemb, size); return je_vmem_pool_calloc((pool_t *)((uintptr_t)Vmp + Header_size), nmemb, size); } /* * realloc -- resize a block previously allocated by malloc */ __ATTR_ALLOC_SIZE__(2) void * realloc(void *ptr, size_t size) { if (unlikely(Destructed)) return NULL; if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_realloc(ptr, size); } LOG(4, "ptr %p, size %zu", ptr, size); return je_vmem_pool_ralloc((pool_t *)((uintptr_t)Vmp + Header_size), ptr, size); } /* * free -- free a block previously allocated by malloc */ void free(void *ptr) { if (unlikely(Destructed)) return; if (Vmp == NULL) { je_vmem_free(ptr); return; } LOG(4, "ptr %p", ptr); je_vmem_pool_free((pool_t *)((uintptr_t)Vmp + Header_size), ptr); } /* * cfree -- free a block previously allocated by calloc * * the implementation is identical to free() * * XXX Not supported on FreeBSD, but we define it anyway */ void cfree(void *ptr) { if (unlikely(Destructed)) return; if (Vmp == NULL) { je_vmem_free(ptr); return; } LOG(4, "ptr %p", ptr); je_vmem_pool_free((pool_t *)((uintptr_t)Vmp + Header_size), ptr); } /* * memalign -- allocate a block of size bytes, starting on an address * that is a multiple of boundary * * XXX Not supported on FreeBSD, but we define it anyway */ __ATTR_MALLOC__ __ATTR_ALLOC_ALIGN__(1) __ATTR_ALLOC_SIZE__(2) void * memalign(size_t boundary, size_t size) { if (unlikely(Destructed)) return NULL; if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_aligned_alloc(boundary, size); } LOG(4, "boundary %zu size %zu", boundary, size); return je_vmem_pool_aligned_alloc( (pool_t *)((uintptr_t)Vmp + Header_size), boundary, size); } /* * aligned_alloc -- allocate a block of size bytes, starting on an address * that is a multiple of alignment * * size must be a multiple of alignment */ __ATTR_MALLOC__ __ATTR_ALLOC_ALIGN__(1) __ATTR_ALLOC_SIZE__(2) void * aligned_alloc(size_t alignment, size_t size) { if (unlikely(Destructed)) return NULL; /* XXX - check if size is a multiple of alignment */ if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_aligned_alloc(alignment, size); } LOG(4, "alignment %zu size %zu", alignment, size); return je_vmem_pool_aligned_alloc( (pool_t *)((uintptr_t)Vmp + Header_size), alignment, size); } /* * posix_memalign -- allocate a block of size bytes, starting on an address * that is a multiple of alignment */ __ATTR_NONNULL__(1) int posix_memalign(void **memptr, size_t alignment, size_t size) { if (unlikely(Destructed)) return ENOMEM; int ret = 0; int oerrno = errno; if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_posix_memalign(memptr, alignment, size); } LOG(4, "alignment %zu size %zu", alignment, size); *memptr = je_vmem_pool_aligned_alloc( (pool_t *)((uintptr_t)Vmp + Header_size), alignment, size); if (*memptr == NULL) ret = errno; errno = oerrno; return ret; } /* * valloc -- allocate a block of size bytes, starting on a page boundary */ __ATTR_MALLOC__ __ATTR_ALLOC_SIZE__(1) void * valloc(size_t size) { if (unlikely(Destructed)) return NULL; ASSERTne(Pagesize, 0); if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_aligned_alloc(Pagesize, size); } LOG(4, "size %zu", size); return je_vmem_pool_aligned_alloc( (pool_t *)((uintptr_t)Vmp + Header_size), Pagesize, size); } /* * pvalloc -- allocate a block of size bytes, starting on a page boundary * * Requested size is also aligned to page boundary. * * XXX Not supported on FreeBSD, but we define it anyway. */ __ATTR_MALLOC__ __ATTR_ALLOC_SIZE__(1) void * pvalloc(size_t size) { if (unlikely(Destructed)) return NULL; ASSERTne(Pagesize, 0); if (Vmp == NULL) { ASSERT(size <= HUGE); return je_vmem_aligned_alloc(Pagesize, roundup(size, Pagesize)); } LOG(4, "size %zu", size); return je_vmem_pool_aligned_alloc( (pool_t *)((uintptr_t)Vmp + Header_size), Pagesize, roundup(size, Pagesize)); } /* * malloc_usable_size -- get usable size of allocation */ size_t malloc_usable_size(void *ptr) { if (unlikely(Destructed)) return 0; if (Vmp == NULL) { return je_vmem_malloc_usable_size(ptr); } LOG(4, "ptr %p", ptr); return je_vmem_pool_malloc_usable_size( (pool_t *)((uintptr_t)Vmp + Header_size), ptr); } #if (defined(__GLIBC__) && !defined(__UCLIBC__)) #ifndef __MALLOC_HOOK_VOLATILE #define __MALLOC_HOOK_VOLATILE #endif /* * Interpose malloc hooks in glibc. Even if the application uses dlopen * with RTLD_DEEPBIND flag, all the references to libc's malloc(3) functions * will be redirected to libvmmalloc. */ void *(*__MALLOC_HOOK_VOLATILE __malloc_hook) (size_t size, const void *caller) = (void *)malloc; void *(*__MALLOC_HOOK_VOLATILE __realloc_hook) (void *ptr, size_t size, const void *caller) = (void *)realloc; void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *ptr, const void *caller) = (void *)free; void *(*__MALLOC_HOOK_VOLATILE __memalign_hook) (size_t size, size_t alignment, const void *caller) = (void *)memalign; #endif /* * print_jemalloc_messages -- (internal) custom print function, for jemalloc * * Prints traces from jemalloc. All traces from jemalloc * are considered as error messages. */ static void print_jemalloc_messages(void *ignore, const char *s) { LOG_NONL(1, "%s", s); } /* * print_jemalloc_stats -- (internal) print function for jemalloc statistics */ static void print_jemalloc_stats(void *ignore, const char *s) { LOG_NONL(0, "%s", s); } /* * libvmmalloc_create -- (internal) create a memory pool in a temp file */ static VMEM * libvmmalloc_create(const char *dir, size_t size) { LOG(3, "dir \"%s\" size %zu", dir, size); if (size < VMMALLOC_MIN_POOL) { LOG(1, "size %zu smaller than %zu", size, VMMALLOC_MIN_POOL); errno = EINVAL; return NULL; } /* silently enforce multiple of page size */ size = roundup(size, Pagesize); Fd = util_tmpfile(dir, "/vmem.XXXXXX", O_EXCL); if (Fd == -1) return NULL; if ((errno = os_posix_fallocate(Fd, 0, (os_off_t)size)) != 0) { ERR("!posix_fallocate"); (void) os_close(Fd); return NULL; } void *addr; if ((addr = util_map(Fd, size, MAP_SHARED, 0, 4 << 20, NULL)) == NULL) { (void) os_close(Fd); return NULL; } /* store opaque info at beginning of mapped area */ struct vmem *vmp = addr; memset(&vmp->hdr, '\0', sizeof(vmp->hdr)); memcpy(vmp->hdr.signature, VMEM_HDR_SIG, POOL_HDR_SIG_LEN); vmp->addr = addr; vmp->size = size; vmp->caller_mapped = 0; /* Prepare pool for jemalloc */ if (je_vmem_pool_create((void *)((uintptr_t)addr + Header_size), size - Header_size, 1 /* zeroed */, 1 /* empty */) == NULL) { LOG(1, "vmem pool creation failed"); util_unmap(vmp->addr, vmp->size); return NULL; } /* * If possible, turn off all permissions on the pool header page. * * The prototype PMFS doesn't allow this when large pages are in * use. It is not considered an error if this fails. */ util_range_none(addr, sizeof(struct pool_hdr)); LOG(3, "vmp %p", vmp); return vmp; } /* * libvmmalloc_clone - (internal) clone the entire pool */ static int libvmmalloc_clone(void) { LOG(3, NULL); int err; Fd_clone = util_tmpfile(Dir, "/vmem.XXXXXX", O_EXCL); if (Fd_clone == -1) return -1; err = os_posix_fallocate(Fd_clone, 0, (os_off_t)Vmp->size); if (err != 0) { errno = err; ERR("!posix_fallocate"); goto err_close; } void *addr = mmap(NULL, Vmp->size, PROT_READ|PROT_WRITE, MAP_SHARED, Fd_clone, 0); if (addr == MAP_FAILED) { LOG(1, "!mmap"); goto err_close; } LOG(3, "copy the entire pool file: dst %p src %p size %zu", addr, Vmp->addr, Vmp->size); util_range_rw(Vmp->addr, sizeof(struct pool_hdr)); /* * Part of vmem pool was probably freed at some point, so Valgrind * marked it as undefined/inaccessible. We need to duplicate the whole * pool, so as a workaround temporarily disable error reporting. */ VALGRIND_DO_DISABLE_ERROR_REPORTING; memcpy(addr, Vmp->addr, Vmp->size); VALGRIND_DO_ENABLE_ERROR_REPORTING; if (munmap(addr, Vmp->size)) { ERR("!munmap"); goto err_close; } util_range_none(Vmp->addr, sizeof(struct pool_hdr)); return 0; err_close: (void) os_close(Fd_clone); return -1; } /* * remap_as_private -- (internal) remap the pool as private */ static void remap_as_private(void) { LOG(3, "remap the pool file as private"); void *r = mmap(Vmp->addr, Vmp->size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, Fd, 0); if (r == MAP_FAILED) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): remapping failed\n"); abort(); } if (r != Vmp->addr) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): wrong address\n"); abort(); } Private = 1; } /* * libvmmalloc_prefork -- (internal) prepare for fork() * * Clones the entire pool or remaps it with MAP_PRIVATE flag. */ static void libvmmalloc_prefork(void) { LOG(3, NULL); /* * There's no need to grab any locks here, as jemalloc pre-fork handler * is executed first, and it does all the synchronization. */ ASSERTne(Vmp, NULL); ASSERTne(Dir, NULL); if (Private) { LOG(3, "already mapped as private - do nothing"); return; } switch (Forkopt) { case 3: /* clone the entire pool; if it fails - remap it as private */ LOG(3, "clone or remap"); case 2: LOG(3, "clone the entire pool file"); if (libvmmalloc_clone() == 0) break; if (Forkopt == 2) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "pool cloning failed\n"); abort(); } /* cloning failed; fall-thru to remapping */ case 1: remap_as_private(); break; case 0: LOG(3, "do nothing"); break; default: FATAL("invalid fork action %d", Forkopt); } } /* * libvmmalloc_postfork_parent -- (internal) parent post-fork handler */ static void libvmmalloc_postfork_parent(void) { LOG(3, NULL); if (Forkopt == 0) { /* do nothing */ return; } if (Private) { LOG(3, "pool mapped as private - do nothing"); } else { LOG(3, "close the cloned pool file"); (void) os_close(Fd_clone); } } /* * libvmmalloc_postfork_child -- (internal) child post-fork handler */ static void libvmmalloc_postfork_child(void) { LOG(3, NULL); if (Forkopt == 0) { /* do nothing */ return; } if (Private) { LOG(3, "pool mapped as private - do nothing"); } else { LOG(3, "close the original pool file"); (void) os_close(Fd); Fd = Fd_clone; void *addr = Vmp->addr; size_t size = Vmp->size; LOG(3, "mapping cloned pool file at %p", addr); Vmp = mmap(addr, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, Fd, 0); if (Vmp == MAP_FAILED) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "mapping failed\n"); abort(); } if (Vmp != addr) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "wrong address\n"); abort(); } } /* XXX - open a new log file, with the new PID in the name */ } /* * libvmmalloc_init -- load-time initialization for libvmmalloc * * Called automatically by the run-time loader. * The constructor priority guarantees this is executed before * libjemalloc constructor. */ __attribute__((constructor(101))) static void libvmmalloc_init(void) { char *env_str; size_t size; /* * Register fork handlers before jemalloc initialization. * This provides the correct order of fork handlers execution. * Note that the first malloc() will trigger jemalloc init, so we * have to register fork handlers before the call to out_init(), * as it may indirectly call malloc() when opening the log file. */ if (os_thread_atfork(libvmmalloc_prefork, libvmmalloc_postfork_parent, libvmmalloc_postfork_child) != 0) { perror("Error (libvmmalloc): os_thread_atfork"); abort(); } common_init(VMMALLOC_LOG_PREFIX, VMMALLOC_LOG_LEVEL_VAR, VMMALLOC_LOG_FILE_VAR, VMMALLOC_MAJOR_VERSION, VMMALLOC_MINOR_VERSION); out_set_vsnprintf_func(je_vmem_navsnprintf); LOG(3, NULL); /* set up jemalloc messages to a custom print function */ je_vmem_malloc_message = print_jemalloc_messages; Header_size = roundup(sizeof(VMEM), Pagesize); if ((Dir = os_getenv(VMMALLOC_POOL_DIR_VAR)) == NULL) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "environment variable %s not specified", VMMALLOC_POOL_DIR_VAR); abort(); } if ((env_str = os_getenv(VMMALLOC_POOL_SIZE_VAR)) == NULL) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "environment variable %s not specified", VMMALLOC_POOL_SIZE_VAR); abort(); } else { long long v = atoll(env_str); if (v < 0) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): negative %s", VMMALLOC_POOL_SIZE_VAR); abort(); } size = (size_t)v; } if (size < VMMALLOC_MIN_POOL) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "%s value is less than minimum (%zu < %zu)", VMMALLOC_POOL_SIZE_VAR, size, VMMALLOC_MIN_POOL); abort(); } if ((env_str = os_getenv(VMMALLOC_FORK_VAR)) != NULL) { Forkopt = atoi(env_str); if (Forkopt < 0 || Forkopt > 3) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "incorrect %s value (%d)", VMMALLOC_FORK_VAR, Forkopt); abort(); } #ifdef __FreeBSD__ if (Forkopt > 1) { out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): " "%s value %d not supported on FreeBSD", VMMALLOC_FORK_VAR, Forkopt); abort(); } #endif LOG(4, "Fork action %d", Forkopt); } /* * XXX - vmem_create() could be used here, but then we need to * link vmem.o, including all the vmem API. */ Vmp = libvmmalloc_create(Dir, size); if (Vmp == NULL) { out_log(NULL, 0, NULL, 0, "!Error (libvmmalloc): " "vmem pool creation failed"); abort(); } LOG(2, "initialization completed"); } /* * libvmmalloc_fini -- libvmmalloc cleanup routine * * Called automatically when the process terminates and prints * some basic allocator statistics. */ __attribute__((destructor(102))) static void libvmmalloc_fini(void) { LOG(3, NULL); char *env_str = os_getenv(VMMALLOC_LOG_STATS_VAR); if ((env_str != NULL) && strcmp(env_str, "1") == 0) { LOG_NONL(0, "\n========= system heap ========\n"); je_vmem_malloc_stats_print( print_jemalloc_stats, NULL, "gba"); LOG_NONL(0, "\n========= vmem pool ========\n"); je_vmem_pool_malloc_stats_print( (pool_t *)((uintptr_t)Vmp + Header_size), print_jemalloc_stats, NULL, "gba"); } common_fini(); Destructed = true; }
19,087
23.534704
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libvmmalloc/vmmalloc.h
/* * Copyright 2014-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmmalloc.h -- internal definitions for libvmmalloc */ #define VMMALLOC_LOG_PREFIX "libvmmalloc" #define VMMALLOC_LOG_LEVEL_VAR "VMMALLOC_LOG_LEVEL" #define VMMALLOC_LOG_FILE_VAR "VMMALLOC_LOG_FILE" #define VMMALLOC_LOG_STATS_VAR "VMMALLOC_LOG_STATS" #define VMMALLOC_POOL_DIR_VAR "VMMALLOC_POOL_DIR" #define VMMALLOC_POOL_SIZE_VAR "VMMALLOC_POOL_SIZE" #define VMMALLOC_FORK_VAR "VMMALLOC_FORK"
2,005
43.577778
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_fip_common.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_fip_common.h -- common definitions for librpmem and rpmemd */ #ifndef RPMEM_FIP_COMMON_H #define RPMEM_FIP_COMMON_H 1 #include <string.h> #include <netinet/in.h> #include <rdma/fabric.h> #include <rdma/fi_cm.h> #include <rdma/fi_rma.h> #ifdef __cplusplus extern "C" { #endif #define RPMEM_FIVERSION FI_VERSION(1, 4) #define RPMEM_FIP_CQ_WAIT_MS 100 #define min(a, b) ((a) < (b) ? (a) : (b)) /* * rpmem_fip_node -- client or server node type */ enum rpmem_fip_node { RPMEM_FIP_NODE_CLIENT, RPMEM_FIP_NODE_SERVER, MAX_RPMEM_FIP_NODE, }; /* * rpmem_fip_probe -- list of providers */ struct rpmem_fip_probe { unsigned providers; }; /* * rpmem_fip_probe -- returns true if specified provider is available */ static inline int rpmem_fip_probe(struct rpmem_fip_probe probe, enum rpmem_provider provider) { return (probe.providers & (1U << provider)) != 0; } /* * rpmem_fip_probe_any -- returns true if any provider is available */ static inline int rpmem_fip_probe_any(struct rpmem_fip_probe probe) { return probe.providers != 0; } int rpmem_fip_probe_get(const char *target, struct rpmem_fip_probe *probe); struct fi_info *rpmem_fip_get_hints(enum rpmem_provider provider); int rpmem_fip_read_eq_check(struct fid_eq *eq, struct fi_eq_cm_entry *entry, uint32_t exp_event, fid_t exp_fid, int timeout); int rpmem_fip_read_eq(struct fid_eq *eq, struct fi_eq_cm_entry *entry, uint32_t *event, int timeout); size_t rpmem_fip_cq_size(enum rpmem_persist_method pm, enum rpmem_fip_node node); size_t rpmem_fip_tx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node); size_t rpmem_fip_rx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node); size_t rpmem_fip_max_nlanes(struct fi_info *fi); void rpmem_fip_print_info(struct fi_info *fi); #ifdef __cplusplus } #endif #endif
3,428
28.307692
76
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_fip_common.c
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_common.c -- common definitions for librpmem and rpmemd */ #include <stdint.h> #include <stdlib.h> #include <string.h> #include <stddef.h> #include <errno.h> #include "rpmem_common.h" #include "rpmem_fip_common.h" #include "rpmem_proto.h" #include "rpmem_common_log.h" #include "valgrind_internal.h" #include <rdma/fi_errno.h> /* * rpmem_fip_get_hints -- return fabric interface information hints */ struct fi_info * rpmem_fip_get_hints(enum rpmem_provider provider) { RPMEMC_ASSERT(provider < MAX_RPMEM_PROV); struct fi_info *hints = fi_allocinfo(); if (!hints) { RPMEMC_LOG(ERR, "!fi_allocinfo"); return NULL; } /* connection-oriented endpoint */ hints->ep_attr->type = FI_EP_MSG; /* * Basic memory registration mode indicates that MR attributes * (rkey, lkey) are selected by provider. */ hints->domain_attr->mr_mode = FI_MR_BASIC; /* * FI_THREAD_SAFE indicates MT applications can access any * resources through interface without any restrictions */ hints->domain_attr->threading = FI_THREAD_SAFE; /* * FI_MSG - SEND and RECV * FI_RMA - WRITE and READ */ hints->caps = FI_MSG | FI_RMA; /* must register locally accessed buffers */ hints->mode = FI_CONTEXT | FI_LOCAL_MR | FI_RX_CQ_DATA; /* READ-after-WRITE and SEND-after-WRITE message ordering required */ hints->tx_attr->msg_order = FI_ORDER_RAW | FI_ORDER_SAW; hints->addr_format = FI_SOCKADDR; if (provider != RPMEM_PROV_UNKNOWN) { const char *prov_name = rpmem_provider_to_str(provider); RPMEMC_ASSERT(prov_name != NULL); hints->fabric_attr->prov_name = strdup(prov_name); if (!hints->fabric_attr->prov_name) { RPMEMC_LOG(ERR, "!strdup(provider)"); goto err_strdup; } } return hints; err_strdup: fi_freeinfo(hints); return NULL; } /* * rpmem_fip_probe_get -- return list of available providers */ int rpmem_fip_probe_get(const char *target, struct rpmem_fip_probe *probe) { struct fi_info *hints = rpmem_fip_get_hints(RPMEM_PROV_UNKNOWN); if (!hints) return -1; int ret; struct fi_info *fi; ret = fi_getinfo(RPMEM_FIVERSION, target, NULL, 0, hints, &fi); if (ret) { goto err_getinfo; } if (probe) { memset(probe, 0, sizeof(*probe)); struct fi_info *prov = fi; while (prov) { enum rpmem_provider p = rpmem_provider_from_str( prov->fabric_attr->prov_name); if (p == RPMEM_PROV_UNKNOWN) { prov = prov->next; continue; } probe->providers |= (1U << p); prov = prov->next; } } fi_freeinfo(fi); err_getinfo: fi_freeinfo(hints); return ret; } /* * rpmem_fip_read_eq -- read event queue entry with specified timeout */ int rpmem_fip_read_eq(struct fid_eq *eq, struct fi_eq_cm_entry *entry, uint32_t *event, int timeout) { int ret; ssize_t sret; struct fi_eq_err_entry err; sret = fi_eq_sread(eq, event, entry, sizeof(*entry), timeout, 0); VALGRIND_DO_MAKE_MEM_DEFINED(&sret, sizeof(sret)); if (timeout != -1 && (sret == -FI_ETIMEDOUT || sret == -FI_EAGAIN)) { errno = ETIMEDOUT; return 1; } if (sret < 0 || (size_t)sret != sizeof(*entry)) { if (sret < 0) ret = (int)sret; else ret = -1; sret = fi_eq_readerr(eq, &err, 0); if (sret < 0) { errno = EIO; RPMEMC_LOG(ERR, "error reading from event queue: " "cannot read error from event queue: %s", fi_strerror((int)sret)); } else if (sret > 0) { RPMEMC_ASSERT(sret == sizeof(err)); errno = -err.prov_errno; RPMEMC_LOG(ERR, "error reading from event queue: %s", fi_eq_strerror(eq, err.prov_errno, NULL, NULL, 0)); } return ret; } return 0; } /* * rpmem_fip_read_eq -- read event queue entry and expect specified event * and fid * * Returns: * 1 - timeout * 0 - success * otherwise - error */ int rpmem_fip_read_eq_check(struct fid_eq *eq, struct fi_eq_cm_entry *entry, uint32_t exp_event, fid_t exp_fid, int timeout) { uint32_t event; int ret = rpmem_fip_read_eq(eq, entry, &event, timeout); if (ret) return ret; if (event != exp_event || entry->fid != exp_fid) { errno = EIO; RPMEMC_LOG(ERR, "unexpected event received (%u) " "expected (%u)%s", event, exp_event, entry->fid != exp_fid ? " invalid endpoint" : ""); return -1; } return 0; } /* * rpmem_fip_lane_attr -- lane attributes * * This structure describes how many SQ, RQ and CQ entries are * required for a single lane. * * NOTE: * - WRITE, READ and SEND requests are placed in SQ, * - RECV requests are placed in RQ. */ struct rpmem_fip_lane_attr { size_t n_per_sq; /* number of entries per lane in send queue */ size_t n_per_rq; /* number of entries per lane in receive queue */ size_t n_per_cq; /* number of entries per lane in completion queue */ }; static struct rpmem_fip_lane_attr rpmem_fip_lane_attrs[MAX_RPMEM_FIP_NODE][MAX_RPMEM_PM] = { [RPMEM_FIP_NODE_CLIENT][RPMEM_PM_GPSPM] = { .n_per_sq = 2, /* WRITE + SEND */ .n_per_rq = 1, /* RECV */ .n_per_cq = 3, }, [RPMEM_FIP_NODE_CLIENT][RPMEM_PM_APM] = { /* WRITE + READ for persist, WRITE + SEND for deep persist */ .n_per_sq = 2, /* WRITE + SEND */ .n_per_rq = 1, /* RECV */ .n_per_cq = 3, }, [RPMEM_FIP_NODE_SERVER][RPMEM_PM_GPSPM] = { .n_per_sq = 1, /* SEND */ .n_per_rq = 1, /* RECV */ .n_per_cq = 3, }, [RPMEM_FIP_NODE_SERVER][RPMEM_PM_APM] = { .n_per_sq = 1, /* SEND */ .n_per_rq = 1, /* RECV */ .n_per_cq = 3, }, }; /* * rpmem_fip_cq_size -- returns completion queue size based on * persist method and node type */ size_t rpmem_fip_cq_size(enum rpmem_persist_method pm, enum rpmem_fip_node node) { RPMEMC_ASSERT(pm < MAX_RPMEM_PM); RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE); struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm]; return attr->n_per_cq ? : 1; } /* * rpmem_fip_tx_size -- returns submission queue (transmit queue) size based * on persist method and node type */ size_t rpmem_fip_tx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node) { RPMEMC_ASSERT(pm < MAX_RPMEM_PM); RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE); struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm]; return attr->n_per_sq ? : 1; } /* * rpmem_fip_tx_size -- returns receive queue size based * on persist method and node type */ size_t rpmem_fip_rx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node) { RPMEMC_ASSERT(pm < MAX_RPMEM_PM); RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE); struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm]; return attr->n_per_rq ? : 1; } /* * rpmem_fip_max_nlanes -- returns maximum number of lanes */ size_t rpmem_fip_max_nlanes(struct fi_info *fi) { return min(min(fi->domain_attr->tx_ctx_cnt, fi->domain_attr->rx_ctx_cnt), fi->domain_attr->cq_cnt); } /* * rpmem_fip_print_info -- print some useful info about fabric interface */ void rpmem_fip_print_info(struct fi_info *fi) { RPMEMC_LOG(INFO, "libfabric version: %s", fi_tostr(fi, FI_TYPE_VERSION)); char *str = fi_tostr(fi, FI_TYPE_INFO); char *buff = strdup(str); if (!buff) { RPMEMC_LOG(ERR, "!allocating string buffer for " "libfabric interface information"); return; } RPMEMC_LOG(INFO, "libfabric interface info:"); char *nl; char *last = buff; while (last != NULL) { nl = strchr(last, '\n'); if (nl) { *nl = '\0'; nl++; } RPMEMC_LOG(INFO, "%s", last); last = nl; } free(buff); }
8,921
23.991597
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_common_log.h
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_common_log.h -- common log macros for librpmem and rpmemd */ #if defined(RPMEMC_LOG_RPMEM) && defined(RPMEMC_LOG_RPMEMD) #error Both RPMEMC_LOG_RPMEM and RPMEMC_LOG_RPMEMD defined #elif !defined(RPMEMC_LOG_RPMEM) && !defined(RPMEMC_LOG_RPMEMD) #define RPMEMC_LOG(level, fmt, args...) do {} while (0) #define RPMEMC_DBG(level, fmt, args...) do {} while (0) #define RPMEMC_FATAL(fmt, args...) do {} while (0) #define RPMEMC_ASSERT(cond) do {} while (0) #elif defined(RPMEMC_LOG_RPMEM) #include "out.h" #include "rpmem_util.h" #define RPMEMC_LOG(level, fmt, args...) RPMEM_LOG(level, fmt, ## args) #define RPMEMC_DBG(level, fmt, args...) RPMEM_DBG(fmt, ## args) #define RPMEMC_FATAL(fmt, args...) RPMEM_FATAL(fmt, ## args) #define RPMEMC_ASSERT(cond) RPMEM_ASSERT(cond) #else #include "rpmemd_log.h" #define RPMEMC_LOG(level, fmt, args...) RPMEMD_LOG(level, fmt, ## args) #define RPMEMC_DBG(level, fmt, args...) RPMEMD_DBG(fmt, ## args) #define RPMEMC_FATAL(fmt, args...) RPMEMD_FATAL(fmt, ## args) #define RPMEMC_ASSERT(cond) RPMEMD_ASSERT(cond) #endif
2,675
38.352941
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_common.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_common.h -- common definitions for librpmem and rpmemd */ #ifndef RPMEM_COMMON_H #define RPMEM_COMMON_H 1 /* * Values for SO_KEEPALIVE socket option */ #define RPMEM_CMD_ENV "RPMEM_CMD" #define RPMEM_SSH_ENV "RPMEM_SSH" #define RPMEM_DEF_CMD "rpmemd" #define RPMEM_DEF_SSH "ssh" #define RPMEM_PROV_SOCKET_ENV "RPMEM_ENABLE_SOCKETS" #define RPMEM_PROV_VERBS_ENV "RPMEM_ENABLE_VERBS" #define RPMEM_MAX_NLANES_ENV "RPMEM_MAX_NLANES" #define RPMEM_ACCEPT_TIMEOUT 30000 #define RPMEM_CONNECT_TIMEOUT 30000 #define RPMEM_MONITOR_TIMEOUT 1000 #include <stdint.h> #include <sys/socket.h> #include <netdb.h> #ifdef __cplusplus extern "C" { #endif /* * rpmem_err -- error codes */ enum rpmem_err { RPMEM_SUCCESS = 0, RPMEM_ERR_BADPROTO = 1, RPMEM_ERR_BADNAME = 2, RPMEM_ERR_BADSIZE = 3, RPMEM_ERR_BADNLANES = 4, RPMEM_ERR_BADPROVIDER = 5, RPMEM_ERR_FATAL = 6, RPMEM_ERR_FATAL_CONN = 7, RPMEM_ERR_BUSY = 8, RPMEM_ERR_EXISTS = 9, RPMEM_ERR_PROVNOSUP = 10, RPMEM_ERR_NOEXIST = 11, RPMEM_ERR_NOACCESS = 12, RPMEM_ERR_POOL_CFG = 13, MAX_RPMEM_ERR, }; /* * rpmem_persist_method -- remote persist operation method */ enum rpmem_persist_method { RPMEM_PM_GPSPM = 1, /* General Purpose Server Persistency Method */ RPMEM_PM_APM = 2, /* Appliance Persistency Method */ MAX_RPMEM_PM, }; const char *rpmem_persist_method_to_str(enum rpmem_persist_method pm); /* * rpmem_provider -- supported providers */ enum rpmem_provider { RPMEM_PROV_UNKNOWN = 0, RPMEM_PROV_LIBFABRIC_VERBS = 1, RPMEM_PROV_LIBFABRIC_SOCKETS = 2, MAX_RPMEM_PROV, }; enum rpmem_provider rpmem_provider_from_str(const char *str); const char *rpmem_provider_to_str(enum rpmem_provider provider); /* * rpmem_req_attr -- arguments for open/create request */ struct rpmem_req_attr { size_t pool_size; unsigned nlanes; size_t buff_size; enum rpmem_provider provider; const char *pool_desc; }; /* * rpmem_resp_attr -- return arguments from open/create request */ struct rpmem_resp_attr { unsigned short port; uint64_t rkey; uint64_t raddr; unsigned nlanes; enum rpmem_persist_method persist_method; }; #define RPMEM_HAS_USER 0x1 #define RPMEM_HAS_SERVICE 0x2 #define RPMEM_FLAGS_USE_IPV4 0x4 #define RPMEM_MAX_USER (32 + 1) /* see useradd(8) + 1 for '\0' */ #define RPMEM_MAX_NODE (255 + 1) /* see gethostname(2) + 1 for '\0' */ #define RPMEM_MAX_SERVICE (NI_MAXSERV + 1) /* + 1 for '\0' */ #define RPMEM_HDR_SIZE 4096 #define RPMEM_CLOSE_FLAGS_REMOVE 0x1 #define RPMEM_DEF_BUFF_SIZE 8192 struct rpmem_target_info { char user[RPMEM_MAX_USER]; char node[RPMEM_MAX_NODE]; char service[RPMEM_MAX_SERVICE]; unsigned flags; }; extern unsigned Rpmem_max_nlanes; extern int Rpmem_fork_unsafe; int rpmem_b64_write(int sockfd, const void *buf, size_t len, int flags); int rpmem_b64_read(int sockfd, void *buf, size_t len, int flags); const char *rpmem_get_ip_str(const struct sockaddr *addr); struct rpmem_target_info *rpmem_target_parse(const char *target); void rpmem_target_free(struct rpmem_target_info *info); int rpmem_xwrite(int fd, const void *buf, size_t len, int flags); int rpmem_xread(int fd, void *buf, size_t len, int flags); char *rpmem_get_ssh_conn_addr(void); #ifdef __cplusplus } #endif #endif
4,838
27.976048
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_proto.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_proto.h -- rpmem protocol definitions */ #ifndef RPMEM_PROTO_H #define RPMEM_PROTO_H 1 #include <stdint.h> #include <endian.h> #include "librpmem.h" #ifdef __cplusplus extern "C" { #endif #define PACKED __attribute__((packed)) #define RPMEM_PROTO "tcp" #define RPMEM_PROTO_MAJOR 0 #define RPMEM_PROTO_MINOR 1 #define RPMEM_SIG_SIZE 8 #define RPMEM_UUID_SIZE 16 #define RPMEM_PROV_SIZE 32 #define RPMEM_USER_SIZE 16 /* * rpmem_msg_type -- type of messages */ enum rpmem_msg_type { RPMEM_MSG_TYPE_CREATE = 1, /* create request */ RPMEM_MSG_TYPE_CREATE_RESP = 2, /* create request response */ RPMEM_MSG_TYPE_OPEN = 3, /* open request */ RPMEM_MSG_TYPE_OPEN_RESP = 4, /* open request response */ RPMEM_MSG_TYPE_CLOSE = 5, /* close request */ RPMEM_MSG_TYPE_CLOSE_RESP = 6, /* close request response */ RPMEM_MSG_TYPE_SET_ATTR = 7, /* set attributes request */ /* set attributes request response */ RPMEM_MSG_TYPE_SET_ATTR_RESP = 8, MAX_RPMEM_MSG_TYPE, }; /* * rpmem_pool_attr_packed -- a packed version */ struct rpmem_pool_attr_packed { char signature[RPMEM_POOL_HDR_SIG_LEN]; /* pool signature */ uint32_t major; /* format major version number */ uint32_t compat_features; /* mask: compatible "may" features */ uint32_t incompat_features; /* mask: "must support" features */ uint32_t ro_compat_features; /* mask: force RO if unsupported */ unsigned char poolset_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* pool uuid */ unsigned char uuid[RPMEM_POOL_HDR_UUID_LEN]; /* first part uuid */ unsigned char next_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* next pool uuid */ unsigned char prev_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* prev pool uuid */ unsigned char user_flags[RPMEM_POOL_USER_FLAGS_LEN]; /* user flags */ } PACKED; /* * rpmem_msg_ibc_attr -- in-band connection attributes * * Used by create request response and open request response. * Contains essential information to proceed with in-band connection * initialization. */ struct rpmem_msg_ibc_attr { uint32_t port; /* RDMA connection port */ uint32_t persist_method; /* persist method */ uint64_t rkey; /* remote key */ uint64_t raddr; /* remote address */ uint32_t nlanes; /* number of lanes */ } PACKED; /* * rpmem_msg_pool_desc -- remote pool descriptor */ struct rpmem_msg_pool_desc { uint32_t size; /* size of pool descriptor */ uint8_t desc[0]; /* pool descriptor, null-terminated string */ } PACKED; /* * rpmem_msg_hdr -- message header which consists of type and size of message * * The type must be one of the rpmem_msg_type values. */ struct rpmem_msg_hdr { uint32_t type; /* type of message */ uint64_t size; /* size of message */ uint8_t body[0]; } PACKED; /* * rpmem_msg_hdr_resp -- message response header which consists of type, size * and status. * * The type must be one of the rpmem_msg_type values. */ struct rpmem_msg_hdr_resp { uint32_t status; /* response status */ uint32_t type; /* type of message */ uint64_t size; /* size of message */ } PACKED; /* * rpmem_msg_common -- common fields for open/create messages */ struct rpmem_msg_common { uint16_t major; /* protocol version major number */ uint16_t minor; /* protocol version minor number */ uint64_t pool_size; /* minimum required size of a pool */ uint32_t nlanes; /* number of lanes used by initiator */ uint32_t provider; /* provider */ uint64_t buff_size; /* buffer size for inline persist */ } PACKED; /* * rpmem_msg_create -- create request message * * The type of message must be set to RPMEM_MSG_TYPE_CREATE. * The size of message must be set to * sizeof(struct rpmem_msg_create) + pool_desc_size */ struct rpmem_msg_create { struct rpmem_msg_hdr hdr; /* message header */ struct rpmem_msg_common c; struct rpmem_pool_attr_packed pool_attr; /* pool attributes */ struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */ } PACKED; /* * rpmem_msg_create_resp -- create request response message * * The type of message must be set to RPMEM_MSG_TYPE_CREATE_RESP. * The size of message must be set to sizeof(struct rpmem_msg_create_resp). */ struct rpmem_msg_create_resp { struct rpmem_msg_hdr_resp hdr; /* message header */ struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */ } PACKED; /* * rpmem_msg_open -- open request message * * The type of message must be set to RPMEM_MSG_TYPE_OPEN. * The size of message must be set to * sizeof(struct rpmem_msg_open) + pool_desc_size */ struct rpmem_msg_open { struct rpmem_msg_hdr hdr; /* message header */ struct rpmem_msg_common c; struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */ } PACKED; /* * rpmem_msg_open_resp -- open request response message * * The type of message must be set to RPMEM_MSG_TYPE_OPEN_RESP. * The size of message must be set to sizeof(struct rpmem_msg_open_resp) */ struct rpmem_msg_open_resp { struct rpmem_msg_hdr_resp hdr; /* message header */ struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */ struct rpmem_pool_attr_packed pool_attr; /* pool attributes */ } PACKED; /* * rpmem_msg_close -- close request message * * The type of message must be set to RPMEM_MSG_TYPE_CLOSE * The size of message must be set to sizeof(struct rpmem_msg_close) */ struct rpmem_msg_close { struct rpmem_msg_hdr hdr; /* message header */ uint32_t flags; /* flags */ } PACKED; /* * rpmem_msg_close_resp -- close request response message * * The type of message must be set to RPMEM_MSG_TYPE_CLOSE_RESP * The size of message must be set to sizeof(struct rpmem_msg_close_resp) */ struct rpmem_msg_close_resp { struct rpmem_msg_hdr_resp hdr; /* message header */ /* no more fields */ } PACKED; #define RPMEM_PERSIST_WRITE 0U /* persist using RDMA WRITE */ #define RPMEM_DEEP_PERSIST 1U /* deep persist operation */ #define RPMEM_PERSIST_SEND 2U /* persist using RDMA SEND */ #define RPMEM_PERSIST_MAX 2U /* maximum valid value */ /* * the two least significant bits * are reserved for mode of persist */ #define RPMEM_PERSIST_MASK 0x3U /* * rpmem_msg_persist -- remote persist message */ struct rpmem_msg_persist { uint32_t flags; /* lane flags */ uint32_t lane; /* lane identifier */ uint64_t addr; /* remote memory address */ uint64_t size; /* remote memory size */ uint8_t data[]; }; /* * rpmem_msg_persist_resp -- remote persist response message */ struct rpmem_msg_persist_resp { uint32_t flags; /* lane flags */ uint32_t lane; /* lane identifier */ }; /* * rpmem_msg_set_attr -- set attributes request message * * The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR. * The size of message must be set to sizeof(struct rpmem_msg_set_attr) */ struct rpmem_msg_set_attr { struct rpmem_msg_hdr hdr; /* message header */ struct rpmem_pool_attr_packed pool_attr; /* pool attributes */ } PACKED; /* * rpmem_msg_set_attr_resp -- set attributes request response message * * The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR_RESP. * The size of message must be set to sizeof(struct rpmem_msg_set_attr_resp). */ struct rpmem_msg_set_attr_resp { struct rpmem_msg_hdr_resp hdr; /* message header */ } PACKED; /* * XXX Begin: Suppress gcc conversion warnings for FreeBSD be*toh macros. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" /* * rpmem_ntoh_msg_ibc_attr -- convert rpmem_msg_ibc attr to host byte order */ static inline void rpmem_ntoh_msg_ibc_attr(struct rpmem_msg_ibc_attr *ibc) { ibc->port = be32toh(ibc->port); ibc->persist_method = be32toh(ibc->persist_method); ibc->rkey = be64toh(ibc->rkey); ibc->raddr = be64toh(ibc->raddr); } /* * rpmem_ntoh_msg_pool_desc -- convert rpmem_msg_pool_desc to host byte order */ static inline void rpmem_ntoh_msg_pool_desc(struct rpmem_msg_pool_desc *pool_desc) { pool_desc->size = be32toh(pool_desc->size); } /* * rpmem_ntoh_pool_attr -- convert rpmem_pool_attr to host byte order */ static inline void rpmem_ntoh_pool_attr(struct rpmem_pool_attr_packed *attr) { attr->major = be32toh(attr->major); attr->ro_compat_features = be32toh(attr->ro_compat_features); attr->incompat_features = be32toh(attr->incompat_features); attr->compat_features = be32toh(attr->compat_features); } /* * rpmem_ntoh_msg_hdr -- convert rpmem_msg_hdr to host byte order */ static inline void rpmem_ntoh_msg_hdr(struct rpmem_msg_hdr *hdrp) { hdrp->type = be32toh(hdrp->type); hdrp->size = be64toh(hdrp->size); } /* * rpmem_hton_msg_hdr -- convert rpmem_msg_hdr to network byte order */ static inline void rpmem_hton_msg_hdr(struct rpmem_msg_hdr *hdrp) { rpmem_ntoh_msg_hdr(hdrp); } /* * rpmem_ntoh_msg_hdr_resp -- convert rpmem_msg_hdr_resp to host byte order */ static inline void rpmem_ntoh_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp) { hdrp->status = be32toh(hdrp->status); hdrp->type = be32toh(hdrp->type); hdrp->size = be64toh(hdrp->size); } /* * rpmem_hton_msg_hdr_resp -- convert rpmem_msg_hdr_resp to network byte order */ static inline void rpmem_hton_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp) { rpmem_ntoh_msg_hdr_resp(hdrp); } /* * rpmem_ntoh_msg_common -- convert rpmem_msg_common to host byte order */ static inline void rpmem_ntoh_msg_common(struct rpmem_msg_common *msg) { msg->major = be16toh(msg->major); msg->minor = be16toh(msg->minor); msg->pool_size = be64toh(msg->pool_size); msg->nlanes = be32toh(msg->nlanes); msg->provider = be32toh(msg->provider); msg->buff_size = be64toh(msg->buff_size); } /* * rpmem_hton_msg_common -- convert rpmem_msg_common to network byte order */ static inline void rpmem_hton_msg_common(struct rpmem_msg_common *msg) { rpmem_ntoh_msg_common(msg); } /* * rpmem_ntoh_msg_create -- convert rpmem_msg_create to host byte order */ static inline void rpmem_ntoh_msg_create(struct rpmem_msg_create *msg) { rpmem_ntoh_msg_hdr(&msg->hdr); rpmem_ntoh_msg_common(&msg->c); rpmem_ntoh_pool_attr(&msg->pool_attr); rpmem_ntoh_msg_pool_desc(&msg->pool_desc); } /* * rpmem_hton_msg_create -- convert rpmem_msg_create to network byte order */ static inline void rpmem_hton_msg_create(struct rpmem_msg_create *msg) { rpmem_ntoh_msg_create(msg); } /* * rpmem_ntoh_msg_create_resp -- convert rpmem_msg_create_resp to host byte * order */ static inline void rpmem_ntoh_msg_create_resp(struct rpmem_msg_create_resp *msg) { rpmem_ntoh_msg_hdr_resp(&msg->hdr); rpmem_ntoh_msg_ibc_attr(&msg->ibc); } /* * rpmem_hton_msg_create_resp -- convert rpmem_msg_create_resp to network byte * order */ static inline void rpmem_hton_msg_create_resp(struct rpmem_msg_create_resp *msg) { rpmem_ntoh_msg_create_resp(msg); } /* * rpmem_ntoh_msg_open -- convert rpmem_msg_open to host byte order */ static inline void rpmem_ntoh_msg_open(struct rpmem_msg_open *msg) { rpmem_ntoh_msg_hdr(&msg->hdr); rpmem_ntoh_msg_common(&msg->c); rpmem_ntoh_msg_pool_desc(&msg->pool_desc); } /* * XXX End: Suppress gcc conversion warnings for FreeBSD be*toh macros */ #pragma GCC diagnostic pop /* * rpmem_hton_msg_open -- convert rpmem_msg_open to network byte order */ static inline void rpmem_hton_msg_open(struct rpmem_msg_open *msg) { rpmem_ntoh_msg_open(msg); } /* * rpmem_ntoh_msg_open_resp -- convert rpmem_msg_open_resp to host byte order */ static inline void rpmem_ntoh_msg_open_resp(struct rpmem_msg_open_resp *msg) { rpmem_ntoh_msg_hdr_resp(&msg->hdr); rpmem_ntoh_msg_ibc_attr(&msg->ibc); rpmem_ntoh_pool_attr(&msg->pool_attr); } /* * rpmem_hton_msg_open_resp -- convert rpmem_msg_open_resp to network byte order */ static inline void rpmem_hton_msg_open_resp(struct rpmem_msg_open_resp *msg) { rpmem_ntoh_msg_open_resp(msg); } /* * rpmem_ntoh_msg_set_attr -- convert rpmem_msg_set_attr to host byte order */ static inline void rpmem_ntoh_msg_set_attr(struct rpmem_msg_set_attr *msg) { rpmem_ntoh_msg_hdr(&msg->hdr); rpmem_ntoh_pool_attr(&msg->pool_attr); } /* * rpmem_hton_msg_set_attr -- convert rpmem_msg_set_attr to network byte order */ static inline void rpmem_hton_msg_set_attr(struct rpmem_msg_set_attr *msg) { rpmem_ntoh_msg_set_attr(msg); } /* * rpmem_ntoh_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to host byte * order */ static inline void rpmem_ntoh_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg) { rpmem_ntoh_msg_hdr_resp(&msg->hdr); } /* * rpmem_hton_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to network * byte order */ static inline void rpmem_hton_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg) { rpmem_hton_msg_hdr_resp(&msg->hdr); } /* * rpmem_ntoh_msg_close -- convert rpmem_msg_close to host byte order */ static inline void rpmem_ntoh_msg_close(struct rpmem_msg_close *msg) { rpmem_ntoh_msg_hdr(&msg->hdr); } /* * rpmem_hton_msg_close -- convert rpmem_msg_close to network byte order */ static inline void rpmem_hton_msg_close(struct rpmem_msg_close *msg) { rpmem_ntoh_msg_close(msg); } /* * rpmem_ntoh_msg_close_resp -- convert rpmem_msg_close_resp to host byte order */ static inline void rpmem_ntoh_msg_close_resp(struct rpmem_msg_close_resp *msg) { rpmem_ntoh_msg_hdr_resp(&msg->hdr); } /* * rpmem_hton_msg_close_resp -- convert rpmem_msg_close_resp to network byte * order */ static inline void rpmem_hton_msg_close_resp(struct rpmem_msg_close_resp *msg) { rpmem_ntoh_msg_close_resp(msg); } /* * pack_rpmem_pool_attr -- copy pool attributes to a packed structure */ static inline void pack_rpmem_pool_attr(const struct rpmem_pool_attr *src, struct rpmem_pool_attr_packed *dst) { memcpy(dst->signature, src->signature, sizeof(src->signature)); dst->major = src->major; dst->compat_features = src->compat_features; dst->incompat_features = src->incompat_features; dst->ro_compat_features = src->ro_compat_features; memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid)); memcpy(dst->uuid, src->uuid, sizeof(dst->uuid)); memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid)); memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid)); memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags)); } /* * unpack_rpmem_pool_attr -- copy pool attributes to an unpacked structure */ static inline void unpack_rpmem_pool_attr(const struct rpmem_pool_attr_packed *src, struct rpmem_pool_attr *dst) { memcpy(dst->signature, src->signature, sizeof(src->signature)); dst->major = src->major; dst->compat_features = src->compat_features; dst->incompat_features = src->incompat_features; dst->ro_compat_features = src->ro_compat_features; memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid)); memcpy(dst->uuid, src->uuid, sizeof(dst->uuid)); memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid)); memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid)); memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags)); } #ifdef __cplusplus } #endif #endif
16,448
27.507799
80
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_common.c
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_common.c -- common definitions for librpmem and rpmemd */ #include <unistd.h> #include <stdint.h> #include <string.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/socket.h> #include <netinet/tcp.h> #include "rpmem_common.h" #include "rpmem_proto.h" #include "rpmem_common_log.h" #include "os.h" unsigned Rpmem_max_nlanes = UINT_MAX; /* * If set, indicates libfabric does not support fork() and consecutive calls to * rpmem_create/rpmem_open must fail. */ int Rpmem_fork_unsafe; /* * rpmem_xwrite -- send entire buffer or fail * * Returns 1 if send returned 0. */ int rpmem_xwrite(int fd, const void *buf, size_t len, int flags) { size_t wr = 0; const uint8_t *cbuf = buf; while (wr < len) { ssize_t sret; if (!flags) sret = write(fd, &cbuf[wr], len - wr); else sret = send(fd, &cbuf[wr], len - wr, flags); if (sret == 0) return 1; if (sret < 0) return (int)sret; wr += (size_t)sret; } return 0; } /* * rpmem_xread -- read entire buffer or fail * * Returns 1 if recv returned 0. */ int rpmem_xread(int fd, void *buf, size_t len, int flags) { size_t rd = 0; uint8_t *cbuf = buf; while (rd < len) { ssize_t sret; if (!flags) sret = read(fd, &cbuf[rd], len - rd); else sret = recv(fd, &cbuf[rd], len - rd, flags); if (sret == 0) { RPMEMC_DBG(ERR, "recv/read returned 0"); return 1; } if (sret < 0) return (int)sret; rd += (size_t)sret; } return 0; } static const char *pm2str[MAX_RPMEM_PM] = { [RPMEM_PM_APM] = "Appliance Persistency Method", [RPMEM_PM_GPSPM] = "General Purpose Server Persistency Method", }; /* * rpmem_persist_method_to_str -- convert enum rpmem_persist_method to string */ const char * rpmem_persist_method_to_str(enum rpmem_persist_method pm) { if (pm >= MAX_RPMEM_PM) return NULL; return pm2str[pm]; } static const char *provider2str[MAX_RPMEM_PROV] = { [RPMEM_PROV_LIBFABRIC_VERBS] = "verbs", [RPMEM_PROV_LIBFABRIC_SOCKETS] = "sockets", }; /* * rpmem_provider_from_str -- convert string to enum rpmem_provider * * Returns RPMEM_PROV_UNKNOWN if provider is not known. */ enum rpmem_provider rpmem_provider_from_str(const char *str) { for (enum rpmem_provider p = 0; p < MAX_RPMEM_PROV; p++) { if (provider2str[p] && strcmp(str, provider2str[p]) == 0) return p; } return RPMEM_PROV_UNKNOWN; } /* * rpmem_provider_to_str -- convert enum rpmem_provider to string */ const char * rpmem_provider_to_str(enum rpmem_provider provider) { if (provider >= MAX_RPMEM_PROV) return NULL; return provider2str[provider]; } /* * rpmem_get_ip_str -- converts socket address to string */ const char * rpmem_get_ip_str(const struct sockaddr *addr) { static char str[INET6_ADDRSTRLEN + NI_MAXSERV + 1]; char ip[INET6_ADDRSTRLEN]; struct sockaddr_in *in4; struct sockaddr_in6 *in6; switch (addr->sa_family) { case AF_INET: in4 = (struct sockaddr_in *)addr; if (!inet_ntop(AF_INET, &in4->sin_addr, ip, sizeof(ip))) return NULL; if (snprintf(str, sizeof(str), "%s:%u", ip, ntohs(in4->sin_port)) < 0) return NULL; break; case AF_INET6: in6 = (struct sockaddr_in6 *)addr; if (!inet_ntop(AF_INET6, &in6->sin6_addr, ip, sizeof(ip))) return NULL; if (snprintf(str, sizeof(str), "%s:%u", ip, ntohs(in6->sin6_port)) < 0) return NULL; break; default: return NULL; } return str; } /* * rpmem_target_parse -- parse target info */ struct rpmem_target_info * rpmem_target_parse(const char *target) { struct rpmem_target_info *info = calloc(1, sizeof(*info)); if (!info) return NULL; char *str = strdup(target); if (!str) goto err_strdup; char *tmp = strchr(str, '@'); if (tmp) { *tmp = '\0'; info->flags |= RPMEM_HAS_USER; strncpy(info->user, str, sizeof(info->user) - 1); tmp++; } else { tmp = str; } if (*tmp == '[') { tmp++; /* IPv6 */ char *end = strchr(tmp, ']'); if (!end) { errno = EINVAL; goto err_ipv6; } *end = '\0'; strncpy(info->node, tmp, sizeof(info->node) - 1); tmp = end + 1; end = strchr(tmp, ':'); if (end) { *end = '\0'; end++; info->flags |= RPMEM_HAS_SERVICE; strncpy(info->service, end, sizeof(info->service) - 1); } } else { char *first = strchr(tmp, ':'); char *last = strrchr(tmp, ':'); if (first == last) { /* IPv4 - one colon */ if (first) { *first = '\0'; first++; info->flags |= RPMEM_HAS_SERVICE; strncpy(info->service, first, sizeof(info->service) - 1); } } strncpy(info->node, tmp, sizeof(info->node) - 1); } if (*info->node == '\0') { errno = EINVAL; goto err_node; } free(str); /* make sure that user, node and service are NULL-terminated */ info->user[sizeof(info->user) - 1] = '\0'; info->node[sizeof(info->node) - 1] = '\0'; info->service[sizeof(info->service) - 1] = '\0'; return info; err_node: err_ipv6: free(str); err_strdup: free(info); return NULL; } /* * rpmem_target_free -- free target info */ void rpmem_target_free(struct rpmem_target_info *info) { free(info); } /* * rpmem_get_ssh_conn_addr -- returns an address which the ssh connection is * established on * * This function utilizes the SSH_CONNECTION environment variable to retrieve * the server IP address. See ssh(1) for details. */ char * rpmem_get_ssh_conn_addr(void) { char *ssh_conn = os_getenv("SSH_CONNECTION"); if (!ssh_conn) { RPMEMC_LOG(ERR, "SSH_CONNECTION variable is not set"); return NULL; } char *sp = strchr(ssh_conn, ' '); if (!sp) goto err_fmt; char *addr = strchr(sp + 1, ' '); if (!addr) goto err_fmt; addr++; sp = strchr(addr, ' '); if (!sp) goto err_fmt; *sp = '\0'; return addr; err_fmt: RPMEMC_LOG(ERR, "invalid format of SSH_CONNECTION variable"); return NULL; }
7,456
21.127596
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_fip_lane.h
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_fip_lane.h -- rpmem fabric provider lane definition */ #include <sched.h> #include <stdint.h> #include "sys_util.h" /* * rpmem_fip_lane -- basic lane structure * * This structure consist of a synchronization object and a return value. * It is possible to wait on the lane for specified event. The event can be * signalled by another thread which can pass the return value if required. * * The sync variable can store up to 64 different events, each event on * separate bit. */ struct rpmem_fip_lane { os_spinlock_t lock; int ret; uint64_t sync; }; /* * rpmem_fip_lane_init -- initialize basic lane structure */ static inline int rpmem_fip_lane_init(struct rpmem_fip_lane *lanep) { lanep->ret = 0; lanep->sync = 0; return util_spin_init(&lanep->lock, PTHREAD_PROCESS_PRIVATE); } /* * rpmem_fip_lane_fini -- deinitialize basic lane structure */ static inline void rpmem_fip_lane_fini(struct rpmem_fip_lane *lanep) { util_spin_destroy(&lanep->lock); } /* * rpmem_fip_lane_busy -- return true if lane has pending events */ static inline int rpmem_fip_lane_busy(struct rpmem_fip_lane *lanep) { util_spin_lock(&lanep->lock); int ret = lanep->sync != 0; util_spin_unlock(&lanep->lock); return ret; } /* * rpmem_fip_lane_begin -- begin waiting for specified event(s) */ static inline void rpmem_fip_lane_begin(struct rpmem_fip_lane *lanep, uint64_t sig) { util_spin_lock(&lanep->lock); lanep->ret = 0; lanep->sync |= sig; util_spin_unlock(&lanep->lock); } static inline int rpmem_fip_lane_is_busy(struct rpmem_fip_lane *lanep, uint64_t sig) { util_spin_lock(&lanep->lock); int ret = (lanep->sync & sig) != 0; util_spin_unlock(&lanep->lock); return ret; } static inline int rpmem_fip_lane_ret(struct rpmem_fip_lane *lanep) { util_spin_lock(&lanep->lock); int ret = lanep->ret; util_spin_unlock(&lanep->lock); return ret; } /* * rpmem_fip_lane_wait -- wait for specified event(s) */ static inline int rpmem_fip_lane_wait(struct rpmem_fip_lane *lanep, uint64_t sig) { while (rpmem_fip_lane_is_busy(lanep, sig)) sched_yield(); return rpmem_fip_lane_ret(lanep); } /* * rpmem_fip_lane_signal -- signal lane about specified event */ static inline void rpmem_fip_lane_signal(struct rpmem_fip_lane *lanep, uint64_t sig) { util_spin_lock(&lanep->lock); lanep->sync &= ~sig; util_spin_unlock(&lanep->lock); } /* * rpmem_fip_lane_signal -- signal lane about specified event and store * return value */ static inline void rpmem_fip_lane_sigret(struct rpmem_fip_lane *lanep, uint64_t sig, int ret) { util_spin_lock(&lanep->lock); lanep->ret = ret; lanep->sync &= ~sig; util_spin_unlock(&lanep->lock); }
4,269
26.197452
75
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/rpmem_common/rpmem_fip_msg.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_fip_msg.h -- simple wrappers for fi_rma(3) and fi_msg(3) functions */ #ifndef RPMEM_FIP_MSG_H #define RPMEM_FIP_MSG_H 1 #include <rdma/fi_rma.h> #ifdef __cplusplus extern "C" { #endif /* * rpmem_fip_rma -- helper struct for RMA operation */ struct rpmem_fip_rma { struct fi_msg_rma msg; /* message structure */ struct iovec msg_iov; /* IO vector buffer */ struct fi_rma_iov rma_iov; /* RMA IO vector buffer */ void *desc; /* local memory descriptor */ uint64_t flags; /* RMA operation flags */ }; /* * rpmem_fip_msg -- helper struct for MSG operation */ struct rpmem_fip_msg { struct fi_msg msg; /* message structure */ struct iovec iov; /* IO vector buffer */ void *desc; /* local memory descriptor */ uint64_t flags; /* MSG operation flags */ }; /* * rpmem_fip_rma_init -- initialize RMA helper struct */ static inline void rpmem_fip_rma_init(struct rpmem_fip_rma *rma, void *desc, fi_addr_t addr, uint64_t rkey, void *context, uint64_t flags) { memset(rma, 0, sizeof(*rma)); rma->desc = desc; rma->flags = flags; rma->rma_iov.key = rkey; rma->msg.context = context; rma->msg.addr = addr; rma->msg.desc = &rma->desc; rma->msg.rma_iov = &rma->rma_iov; rma->msg.rma_iov_count = 1; rma->msg.msg_iov = &rma->msg_iov; rma->msg.iov_count = 1; } /* * rpmem_fip_msg_init -- initialize MSG helper struct */ static inline void rpmem_fip_msg_init(struct rpmem_fip_msg *msg, void *desc, fi_addr_t addr, void *context, void *buff, size_t len, uint64_t flags) { memset(msg, 0, sizeof(*msg)); msg->desc = desc; msg->flags = flags; msg->iov.iov_base = buff; msg->iov.iov_len = len; msg->msg.context = context; msg->msg.addr = addr; msg->msg.desc = &msg->desc; msg->msg.msg_iov = &msg->iov; msg->msg.iov_count = 1; } /* * rpmem_fip_writemsg -- wrapper for fi_writemsg */ static inline int rpmem_fip_writemsg(struct fid_ep *ep, struct rpmem_fip_rma *rma, const void *buff, size_t len, uint64_t addr) { rma->rma_iov.addr = addr; rma->rma_iov.len = len; rma->msg_iov.iov_base = (void *)buff; rma->msg_iov.iov_len = len; return (int)fi_writemsg(ep, &rma->msg, rma->flags); } /* * rpmem_fip_readmsg -- wrapper for fi_readmsg */ static inline int rpmem_fip_readmsg(struct fid_ep *ep, struct rpmem_fip_rma *rma, void *buff, size_t len, uint64_t addr) { rma->rma_iov.addr = addr; rma->rma_iov.len = len; rma->msg_iov.iov_base = buff; rma->msg_iov.iov_len = len; return (int)fi_readmsg(ep, &rma->msg, rma->flags); } /* * rpmem_fip_sendmsg -- wrapper for fi_sendmsg */ static inline int rpmem_fip_sendmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg, size_t len) { msg->iov.iov_len = len; return (int)fi_sendmsg(ep, &msg->msg, msg->flags); } /* * rpmem_fip_recvmsg -- wrapper for fi_recvmsg */ static inline int rpmem_fip_recvmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg) { return (int)fi_recvmsg(ep, &msg->msg, msg->flags); } /* * rpmem_fip_msg_get_pmsg -- returns message buffer as a persist message */ static inline struct rpmem_msg_persist * rpmem_fip_msg_get_pmsg(struct rpmem_fip_msg *msg) { return (struct rpmem_msg_persist *)msg->iov.iov_base; } /* * rpmem_fip_msg_get_pres -- returns message buffer as a persist response */ static inline struct rpmem_msg_persist_resp * rpmem_fip_msg_get_pres(struct rpmem_fip_msg *msg) { return (struct rpmem_msg_persist_resp *)msg->iov.iov_base; } #ifdef __cplusplus } #endif #endif
5,009
27.465909
75
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/libpmempool.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool.c -- entry points for libpmempool */ #include <stdlib.h> #include <stdint.h> #include <errno.h> #include <sys/param.h> #include "pmemcommon.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check.h" #ifdef USE_RPMEM #include "rpmem_common.h" #include "rpmem_util.h" #endif #ifdef _WIN32 #define ANSWER_BUFFSIZE 256 #endif /* * libpmempool_init -- load-time initialization for libpmempool * * Called automatically by the run-time loader. */ ATTR_CONSTRUCTOR void libpmempool_init(void) { common_init(PMEMPOOL_LOG_PREFIX, PMEMPOOL_LOG_LEVEL_VAR, PMEMPOOL_LOG_FILE_VAR, PMEMPOOL_MAJOR_VERSION, PMEMPOOL_MINOR_VERSION); LOG(3, NULL); #ifdef USE_RPMEM util_remote_init(); rpmem_util_cmds_init(); #endif } /* * libpmempool_fini -- libpmempool cleanup routine * * Called automatically when the process terminates. */ ATTR_DESTRUCTOR void libpmempool_fini(void) { LOG(3, NULL); #ifdef USE_RPMEM util_remote_unload(); util_remote_fini(); rpmem_util_cmds_fini(); #endif common_fini(); } /* * pmempool_check_versionU -- see if library meets application version * requirements */ #ifndef _WIN32 static inline #endif const char * pmempool_check_versionU(unsigned major_required, unsigned minor_required) { LOG(3, "major_required %u minor_required %u", major_required, minor_required); if (major_required != PMEMPOOL_MAJOR_VERSION) { ERR("libpmempool major version mismatch (need %u, found %u)", major_required, PMEMPOOL_MAJOR_VERSION); return out_get_errormsg(); } if (minor_required > PMEMPOOL_MINOR_VERSION) { ERR("libpmempool minor version mismatch (need %u, found %u)", minor_required, PMEMPOOL_MINOR_VERSION); return out_get_errormsg(); } return NULL; } #ifndef _WIN32 /* * pmempool_check_version -- see if lib meets application version requirements */ const char * pmempool_check_version(unsigned major_required, unsigned minor_required) { return pmempool_check_versionU(major_required, minor_required); } #else /* * pmempool_check_versionW -- see if library meets application version * requirements as widechar */ const wchar_t * pmempool_check_versionW(unsigned major_required, unsigned minor_required) { if (pmempool_check_versionU(major_required, minor_required) != NULL) return out_get_errormsgW(); else return NULL; } #endif /* * pmempool_errormsgU -- return last error message */ #ifndef _WIN32 static inline #endif const char * pmempool_errormsgU(void) { return out_get_errormsg(); } #ifndef _WIN32 /* * pmempool_errormsg -- return last error message */ const char * pmempool_errormsg(void) { return pmempool_errormsgU(); } #else /* * pmempool_errormsgW -- return last error message as widechar */ const wchar_t * pmempool_errormsgW(void) { return out_get_errormsgW(); } #endif /* * pmempool_ppc_set_default -- (internal) set default values of check context */ static void pmempool_ppc_set_default(PMEMpoolcheck *ppc) { /* all other fields should be zeroed */ const PMEMpoolcheck ppc_default = { .args = { .pool_type = PMEMPOOL_POOL_TYPE_DETECT, }, .result = CHECK_RESULT_CONSISTENT, }; *ppc = ppc_default; } /* * pmempool_check_initU -- initialize check context */ #ifndef _WIN32 static inline #endif PMEMpoolcheck * pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) { LOG(3, "path %s backup_path %s pool_type %u flags %x", args->path, args->backup_path, args->pool_type, args->flags); /* * Currently one size of args structure is supported. The version of the * pmempool_check_args structure can be distinguished based on provided * args_size. */ if (args_size < sizeof(struct pmempool_check_args)) { ERR("provided args_size is not supported"); errno = EINVAL; return NULL; } /* * Dry run does not allow to made changes possibly performed during * repair. Advanced allow to perform more complex repairs. Questions * are ask only if repairs are made. So dry run, advanced and always_yes * can be set only if repair is set. */ if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_REPAIR) && util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN | PMEMPOOL_CHECK_ADVANCED | PMEMPOOL_CHECK_ALWAYS_YES)) { ERR("dry_run, advanced and always_yes are applicable only if " "repair is set"); errno = EINVAL; return NULL; } /* * dry run does not modify anything so performing backup is redundant */ if (util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN) && args->backup_path != NULL) { ERR("dry run does not allow one to perform backup"); errno = EINVAL; return NULL; } /* * libpmempool uses str format of communication so it must be set */ if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_FORMAT_STR)) { ERR("PMEMPOOL_CHECK_FORMAT_STR flag must be set"); errno = EINVAL; return NULL; } PMEMpoolcheck *ppc = calloc(1, sizeof(*ppc)); if (ppc == NULL) { ERR("!calloc"); return NULL; } pmempool_ppc_set_default(ppc); memcpy(&ppc->args, args, sizeof(ppc->args)); ppc->path = strdup(args->path); if (!ppc->path) { ERR("!strdup"); goto error_path_malloc; } ppc->args.path = ppc->path; if (args->backup_path != NULL) { ppc->backup_path = strdup(args->backup_path); if (!ppc->backup_path) { ERR("!strdup"); goto error_backup_path_malloc; } ppc->args.backup_path = ppc->backup_path; } if (check_init(ppc) != 0) goto error_check_init; return ppc; error_check_init: /* in case errno not set by any of the used functions set its value */ if (errno == 0) errno = EINVAL; free(ppc->backup_path); error_backup_path_malloc: free(ppc->path); error_path_malloc: free(ppc); return NULL; } #ifndef _WIN32 /* * pmempool_check_init -- initialize check context */ PMEMpoolcheck * pmempool_check_init(struct pmempool_check_args *args, size_t args_size) { return pmempool_check_initU(args, args_size); } #else /* * pmempool_check_initW -- initialize check context as widechar */ PMEMpoolcheck * pmempool_check_initW(struct pmempool_check_argsW *args, size_t args_size) { char *upath = util_toUTF8(args->path); if (upath == NULL) return NULL; char *ubackup_path = NULL; if (args->backup_path != NULL) { ubackup_path = util_toUTF8(args->backup_path); if (ubackup_path == NULL) { util_free_UTF8(upath); return NULL; } } struct pmempool_check_argsU uargs = { .path = upath, .backup_path = ubackup_path, .pool_type = args->pool_type, .flags = args->flags }; PMEMpoolcheck *ret = pmempool_check_initU(&uargs, args_size); util_free_UTF8(ubackup_path); util_free_UTF8(upath); return ret; } #endif /* * pmempool_checkU -- continue check till produce status to consume for caller */ #ifndef _WIN32 static inline #endif struct pmempool_check_statusU * pmempool_checkU(PMEMpoolcheck *ppc) { LOG(3, NULL); ASSERTne(ppc, NULL); struct check_status *result; do { result = check_step(ppc); if (check_is_end(ppc->data) && result == NULL) return NULL; } while (result == NULL); return check_status_get(result); } #ifndef _WIN32 /* * pmempool_check -- continue check till produce status to consume for caller */ struct pmempool_check_status * pmempool_check(PMEMpoolcheck *ppc) { return pmempool_checkU(ppc); } #else /* * pmempool_checkW -- continue check till produce status to consume for caller */ struct pmempool_check_statusW * pmempool_checkW(PMEMpoolcheck *ppc) { LOG(3, NULL); ASSERTne(ppc, NULL); /* check the cache and convert msg and answer */ char buf[ANSWER_BUFFSIZE]; memset(buf, 0, ANSWER_BUFFSIZE); convert_status_cache(ppc, buf, ANSWER_BUFFSIZE); struct check_status *uresult; do { uresult = check_step(ppc); if (check_is_end(ppc->data) && uresult == NULL) return NULL; } while (uresult == NULL); struct pmempool_check_statusU *uret_res = check_status_get(uresult); const wchar_t *wmsg = util_toUTF16(uret_res->str.msg); if (wmsg == NULL) FATAL("!malloc"); struct pmempool_check_statusW *wret_res = (struct pmempool_check_statusW *)uret_res; /* pointer to old message is freed in next check step */ wret_res->str.msg = wmsg; return wret_res; } #endif /* * pmempool_check_end -- end check and release check context */ enum pmempool_check_result pmempool_check_end(PMEMpoolcheck *ppc) { LOG(3, NULL); const enum check_result result = ppc->result; const unsigned sync_required = ppc->sync_required; check_fini(ppc); free(ppc->path); free(ppc->backup_path); free(ppc); if (sync_required) { switch (result) { case CHECK_RESULT_CONSISTENT: case CHECK_RESULT_REPAIRED: return PMEMPOOL_CHECK_RESULT_SYNC_REQ; default: /* other results require fixing prior to sync */ ; } } switch (result) { case CHECK_RESULT_CONSISTENT: return PMEMPOOL_CHECK_RESULT_CONSISTENT; case CHECK_RESULT_NOT_CONSISTENT: return PMEMPOOL_CHECK_RESULT_NOT_CONSISTENT; case CHECK_RESULT_REPAIRED: return PMEMPOOL_CHECK_RESULT_REPAIRED; case CHECK_RESULT_CANNOT_REPAIR: return PMEMPOOL_CHECK_RESULT_CANNOT_REPAIR; default: return PMEMPOOL_CHECK_RESULT_ERROR; } }
10,657
22.8434
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/replica.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * replica.h -- module for synchronizing and transforming poolset */ #ifndef REPLICA_H #define REPLICA_H #include "libpmempool.h" #include "pool.h" #include "os_badblock.h" #ifdef __cplusplus extern "C" { #endif #define UNDEF_REPLICA UINT_MAX #define UNDEF_PART UINT_MAX /* * A part marked as broken does not exist or is damaged so that * it cannot be opened and has to be recreated. */ #define IS_BROKEN (1U << 0) /* * A replica marked as inconsistent exists but has inconsistent metadata * (e.g. inconsistent parts or replicas linkage) */ #define IS_INCONSISTENT (1U << 1) /* * A part or replica marked in this way has bad blocks inside. */ #define HAS_BAD_BLOCKS (1U << 2) /* * A part marked in this way has bad blocks in the header */ #define HAS_CORRUPTED_HEADER (1U << 3) /* * A flag which can be passed to sync_replica() to indicate that the function is * called by pmempool_transform */ #define IS_TRANSFORMED (1U << 10) /* * Number of lanes utilized when working with remote replicas */ #define REMOTE_NLANES 1 /* * Helping structures for storing part's health status */ struct part_health_status { unsigned flags; struct badblocks bbs; /* structure with bad blocks */ char *recovery_file_name; /* name of bad block recovery file */ int recovery_file_exists; /* bad block recovery file exists */ }; /* * Helping structures for storing replica and poolset's health status */ struct replica_health_status { unsigned nparts; unsigned nhdrs; /* a flag for the replica */ unsigned flags; /* effective size of a pool, valid only for healthy replica */ size_t pool_size; /* flags for each part */ struct part_health_status part[]; }; struct poolset_health_status { unsigned nreplicas; /* a flag for the poolset */ unsigned flags; /* health statuses for each replica */ struct replica_health_status *replica[]; }; /* get index of the (r)th replica health status */ static inline unsigned REP_HEALTHidx(struct poolset_health_status *set, unsigned r) { ASSERTne(set->nreplicas, 0); return (set->nreplicas + r) % set->nreplicas; } /* get index of the (r + 1)th replica health status */ static inline unsigned REPN_HEALTHidx(struct poolset_health_status *set, unsigned r) { ASSERTne(set->nreplicas, 0); return (set->nreplicas + r + 1) % set->nreplicas; } /* get (p)th part health status */ static inline unsigned PART_HEALTHidx(struct replica_health_status *rep, unsigned p) { ASSERTne(rep->nparts, 0); return (rep->nparts + p) % rep->nparts; } /* get (r)th replica health status */ static inline struct replica_health_status * REP_HEALTH(struct poolset_health_status *set, unsigned r) { return set->replica[REP_HEALTHidx(set, r)]; } /* get (p)th part health status */ static inline unsigned PART_HEALTH(struct replica_health_status *rep, unsigned p) { return rep->part[PART_HEALTHidx(rep, p)].flags; } uint64_t replica_get_part_offset(struct pool_set *set, unsigned repn, unsigned partn); void replica_align_badblock_offset_length(size_t *offset, size_t *length, struct pool_set *set_in, unsigned repn, unsigned partn); size_t replica_get_part_data_len(struct pool_set *set_in, unsigned repn, unsigned partn); uint64_t replica_get_part_data_offset(struct pool_set *set_in, unsigned repn, unsigned part); /* * is_dry_run -- (internal) check whether only verification mode is enabled */ static inline bool is_dry_run(unsigned flags) { /* * PMEMPOOL_SYNC_DRY_RUN and PMEMPOOL_TRANSFORM_DRY_RUN * have to have the same value in order to use this common function. */ ASSERT_COMPILE_ERROR_ON(PMEMPOOL_SYNC_DRY_RUN != PMEMPOOL_TRANSFORM_DRY_RUN); return flags & PMEMPOOL_SYNC_DRY_RUN; } /* * fix_bad_blocks -- (internal) fix bad blocks - it causes reading or creating * bad blocks recovery files * (depending on if they exist or not) */ static inline bool fix_bad_blocks(unsigned flags) { return flags & PMEMPOOL_SYNC_FIX_BAD_BLOCKS; } int replica_remove_all_recovery_files(struct poolset_health_status *set_hs); int replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn, int fix_bad_blocks); int replica_create_poolset_health_status(struct pool_set *set, struct poolset_health_status **set_hsp); void replica_free_poolset_health_status(struct poolset_health_status *set_s); int replica_check_poolset_health(struct pool_set *set, struct poolset_health_status **set_hs, int called_from_sync, unsigned flags); int replica_is_part_broken(unsigned repn, unsigned partn, struct poolset_health_status *set_hs); int replica_has_bad_blocks(unsigned repn, struct poolset_health_status *set_hs); int replica_part_has_bad_blocks(struct part_health_status *phs); int replica_part_has_corrupted_header(unsigned repn, unsigned partn, struct poolset_health_status *set_hs); unsigned replica_find_unbroken_part(unsigned repn, struct poolset_health_status *set_hs); int replica_is_replica_broken(unsigned repn, struct poolset_health_status *set_hs); int replica_is_replica_consistent(unsigned repn, struct poolset_health_status *set_hs); int replica_is_replica_healthy(unsigned repn, struct poolset_health_status *set_hs); unsigned replica_find_healthy_replica( struct poolset_health_status *set_hs); unsigned replica_find_replica_healthy_header( struct poolset_health_status *set_hs); int replica_is_poolset_healthy(struct poolset_health_status *set_hs); int replica_is_poolset_transformed(unsigned flags); ssize_t replica_get_pool_size(struct pool_set *set, unsigned repn); int replica_check_part_sizes(struct pool_set *set, size_t min_size); int replica_check_part_dirs(struct pool_set *set); int replica_check_local_part_dir(struct pool_set *set, unsigned repn, unsigned partn); int replica_open_replica_part_files(struct pool_set *set, unsigned repn); int replica_open_poolset_part_files(struct pool_set *set); int replica_sync(struct pool_set *set_in, struct poolset_health_status *set_hs, unsigned flags); int replica_transform(struct pool_set *set_in, struct pool_set *set_out, unsigned flags); #ifdef __cplusplus } #endif #endif
7,734
30.96281
80
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check.h -- internal definitions for logic performing check */ #ifndef CHECK_H #define CHECK_H #ifdef __cplusplus extern "C" { #endif int check_init(PMEMpoolcheck *ppc); struct check_status *check_step(PMEMpoolcheck *ppc); void check_fini(PMEMpoolcheck *ppc); int check_is_end(struct check_data *data); struct pmempool_check_status *check_status_get(struct check_status *status); #ifdef _WIN32 void convert_status_cache(PMEMpoolcheck *ppc, char *buf, size_t size); #endif #ifdef __cplusplus } #endif #endif
2,122
34.383333
76
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_blk.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_blk.c -- check pmemblk */ #include <inttypes.h> #include <sys/param.h> #include <endian.h> #include "out.h" #include "btt.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum question { Q_BLK_BSIZE, }; /* * blk_get_max_bsize -- (internal) return maximum size of block for given file * size */ static inline uint32_t blk_get_max_bsize(uint64_t fsize) { LOG(3, NULL); if (fsize == 0) return 0; /* default nfree */ uint32_t nfree = BTT_DEFAULT_NFREE; /* number of blocks must be at least 2 * nfree */ uint32_t internal_nlba = 2 * nfree; /* compute arena size from file size without pmemblk structure */ uint64_t arena_size = fsize - sizeof(struct pmemblk); if (arena_size > BTT_MAX_ARENA) arena_size = BTT_MAX_ARENA; arena_size = btt_arena_datasize(arena_size, nfree); /* compute maximum internal LBA size */ uint64_t internal_lbasize = (arena_size - BTT_ALIGNMENT) / internal_nlba - BTT_MAP_ENTRY_SIZE; ASSERT(internal_lbasize <= UINT32_MAX); if (internal_lbasize < BTT_MIN_LBA_SIZE) internal_lbasize = BTT_MIN_LBA_SIZE; internal_lbasize = roundup(internal_lbasize, BTT_INTERNAL_LBA_ALIGNMENT) - BTT_INTERNAL_LBA_ALIGNMENT; return (uint32_t)internal_lbasize; } /* * blk_read -- (internal) read pmemblk header */ static int blk_read(PMEMpoolcheck *ppc) { /* * Here we want to read the pmemblk header without the pool_hdr as we've * already done it before. * * Take the pointer to fields right after pool_hdr, compute the size and * offset of remaining fields. */ uint8_t *ptr = (uint8_t *)&ppc->pool->hdr.blk; ptr += sizeof(ppc->pool->hdr.blk.hdr); size_t size = sizeof(ppc->pool->hdr.blk) - sizeof(ppc->pool->hdr.blk.hdr); uint64_t offset = sizeof(ppc->pool->hdr.blk.hdr); if (pool_read(ppc->pool, ptr, size, offset)) { return CHECK_ERR(ppc, "cannot read pmemblk structure"); } /* endianness conversion */ ppc->pool->hdr.blk.bsize = le32toh(ppc->pool->hdr.blk.bsize); return 0; } /* * blk_bsize_valid -- (internal) check if block size is valid for given file * size */ static int blk_bsize_valid(uint32_t bsize, uint64_t fsize) { uint32_t max_bsize = blk_get_max_bsize(fsize); return (bsize >= max_bsize); } /* * blk_hdr_check -- (internal) check pmemblk header */ static int blk_hdr_check(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); CHECK_INFO(ppc, "checking pmemblk header"); if (blk_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } /* check for valid BTT Info arena as we can take bsize from it */ if (!ppc->pool->bttc.valid) pool_blk_get_first_valid_arena(ppc->pool, &ppc->pool->bttc); if (ppc->pool->bttc.valid) { const uint32_t btt_bsize = ppc->pool->bttc.btt_info.external_lbasize; if (ppc->pool->hdr.blk.bsize != btt_bsize) { CHECK_ASK(ppc, Q_BLK_BSIZE, "invalid pmemblk.bsize.|Do you want to set " "pmemblk.bsize to %u from BTT Info?", btt_bsize); } } else if (!ppc->pool->bttc.zeroed) { if (ppc->pool->hdr.blk.bsize < BTT_MIN_LBA_SIZE || blk_bsize_valid(ppc->pool->hdr.blk.bsize, ppc->pool->set_file->size)) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "invalid pmemblk.bsize"); } } if (ppc->result == CHECK_RESULT_CONSISTENT || ppc->result == CHECK_RESULT_REPAIRED) CHECK_INFO(ppc, "pmemblk header correct"); return check_questions_sequence_validate(ppc); } /* * blk_hdr_fix -- (internal) fix pmemblk header */ static int blk_hdr_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); uint32_t btt_bsize; switch (question) { case Q_BLK_BSIZE: /* * check for valid BTT Info arena as we can take bsize from it */ if (!ppc->pool->bttc.valid) pool_blk_get_first_valid_arena(ppc->pool, &ppc->pool->bttc); btt_bsize = ppc->pool->bttc.btt_info.external_lbasize; CHECK_INFO(ppc, "setting pmemblk.b_size to 0x%x", btt_bsize); ppc->pool->hdr.blk.bsize = btt_bsize; break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); enum pool_type type; }; static const struct step steps[] = { { .check = blk_hdr_check, .type = POOL_TYPE_BLK }, { .fix = blk_hdr_fix, .type = POOL_TYPE_BLK }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); ASSERTeq(ppc->pool->params.type, POOL_TYPE_BLK); const struct step *step = &steps[loc->step++]; if (!(step->type & ppc->pool->params.type)) return 0; if (!step->fix) return step->check(ppc, loc); if (blk_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } return check_answer_loop(ppc, loc, NULL, 1, step->fix); } /* * check_blk -- entry point for pmemblk checks */ void check_blk(PMEMpoolcheck *ppc) { LOG(3, NULL); location *loc = check_get_step_data(ppc->data); /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc)) break; } }
6,792
24.441948
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_sds.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_shutdown_state.c -- shutdown state check */ #include <stdio.h> #include <inttypes.h> #include <sys/mman.h> #include <endian.h> #include "out.h" #include "util_pmem.h" #include "libpmempool.h" #include "libpmem.h" #include "pmempool.h" #include "pool.h" #include "set.h" #include "check_util.h" enum question { Q_RESET_SDS, }; #define SDS_CHECK_STR "checking shutdown state" #define SDS_OK_STR "shutdown state correct" #define SDS_DIRTY_STR "shutdown state is dirty" #define ADR_FAILURE_STR \ "an ADR failure was detected - your pool might be corrupted" #define ZERO_SDS_STR \ "Do you want to zero shutdown state?" #define RESET_SDS_STR \ "Do you want to reset shutdown state at your own risk? " \ "If you have more then one replica you will have to " \ "synchronize your pool after this operation." #define SDS_FAIL_MSG(hdrp) \ IGNORE_SDS(hdrp) ? SDS_DIRTY_STR : ADR_FAILURE_STR #define SDS_REPAIR_MSG(hdrp) \ IGNORE_SDS(hdrp) \ ? SDS_DIRTY_STR ".|" ZERO_SDS_STR \ : ADR_FAILURE_STR ".|" RESET_SDS_STR /* * sds_check_replica -- (internal) check if replica is healthy */ static int sds_check_replica(location *loc) { LOG(3, NULL); struct pool_replica *rep = REP(loc->set, loc->replica); if (rep->remote) return 0; /* make a copy of sds as we shouldn't modify a pool */ struct shutdown_state old_sds = loc->hdr.sds; struct shutdown_state curr_sds; if (IGNORE_SDS(&loc->hdr)) return util_is_zeroed(&old_sds, sizeof(old_sds)) ? 0 : -1; shutdown_state_init(&curr_sds, NULL); /* get current shutdown state */ for (unsigned p = 0; p < rep->nparts; ++p) { if (shutdown_state_add_part(&curr_sds, PART(rep, p)->path, NULL)) return -1; } /* compare current and old shutdown state */ return shutdown_state_check(&curr_sds, &old_sds, NULL); } /* * sds_check -- (internal) check shutdown_state */ static int sds_check(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); CHECK_INFO(ppc, "%s" SDS_CHECK_STR, loc->prefix); /* shutdown state is valid */ if (!sds_check_replica(loc)) { CHECK_INFO(ppc, "%s" SDS_OK_STR, loc->prefix); loc->step = CHECK_STEP_COMPLETE; return 0; } /* shutdown state is NOT valid and can NOT be repaired */ if (CHECK_IS_NOT(ppc, REPAIR)) { check_end(ppc->data); ppc->result = CHECK_RESULT_NOT_CONSISTENT; return CHECK_ERR(ppc, "%s%s", loc->prefix, SDS_FAIL_MSG(&loc->hdr)); } /* shutdown state is NOT valid but can be repaired */ CHECK_ASK(ppc, Q_RESET_SDS, "%s%s", loc->prefix, SDS_REPAIR_MSG(&loc->hdr)); return check_questions_sequence_validate(ppc); } /* * sds_fix -- (internal) fix shutdown state */ static int sds_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *context) { LOG(3, NULL); switch (question) { case Q_RESET_SDS: CHECK_INFO(ppc, "%sresetting pool_hdr.sds", loc->prefix); memset(&loc->hdr.sds, 0, sizeof(loc->hdr.sds)); ++loc->healthy_replicas; break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); }; static const struct step steps[] = { { .check = sds_check, }, { .fix = sds_fix, }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static int step_exe(PMEMpoolcheck *ppc, const struct step *steps, location *loc) { const struct step *step = &steps[loc->step++]; if (!step->fix) return step->check(ppc, loc); if (!check_has_answer(ppc->data)) return 0; if (check_answer_loop(ppc, loc, NULL, 0 /* fail on no */, step->fix)) return -1; util_convert2le_hdr(&loc->hdr); memcpy(loc->hdrp, &loc->hdr, sizeof(loc->hdr)); util_persist_auto(loc->is_dev_dax, loc->hdrp, sizeof(*loc->hdrp)); util_convert2h_hdr_nocheck(&loc->hdr); loc->pool_hdr_modified = 1; return 0; } /* * init_prefix -- prepare prefix for messages */ static void init_prefix(location *loc) { if (loc->set->nreplicas > 1) { int ret = snprintf(loc->prefix, PREFIX_MAX_SIZE, "replica %u: ", loc->replica); if (ret < 0 || ret >= PREFIX_MAX_SIZE) FATAL("snprintf: %d", ret); } else loc->prefix[0] = '\0'; loc->step = 0; } /* * init_location_data -- (internal) prepare location information */ static void init_location_data(PMEMpoolcheck *ppc, location *loc) { ASSERTeq(loc->part, 0); loc->set = ppc->pool->set_file->poolset; if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS) init_prefix(loc); struct pool_replica *rep = REP(loc->set, loc->replica); loc->hdrp = HDR(rep, loc->part); memcpy(&loc->hdr, loc->hdrp, sizeof(loc->hdr)); util_convert2h_hdr_nocheck(&loc->hdr); loc->is_dev_dax = PART(rep, 0)->is_dev_dax; } /* * sds_get_healthy_replicas_num -- (internal) get number of healthy replicas */ static void sds_get_healthy_replicas_num(PMEMpoolcheck *ppc, location *loc) { const unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas; loc->healthy_replicas = 0; loc->part = 0; for (; loc->replica < nreplicas; loc->replica++) { init_location_data(ppc, loc); if (!sds_check_replica(loc)) { ++loc->healthy_replicas; /* healthy replica found */ } } loc->replica = 0; /* reset replica index */ } /* * check_sds -- entry point for shutdown state checks */ void check_sds(PMEMpoolcheck *ppc) { LOG(3, NULL); const unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas; location *loc = check_get_step_data(ppc->data); if (!loc->init_done) { sds_get_healthy_replicas_num(ppc, loc); if (loc->healthy_replicas == nreplicas) { /* all replicas have healthy shutdown state */ /* print summary */ for (; loc->replica < nreplicas; loc->replica++) { init_prefix(loc); CHECK_INFO(ppc, "%s" SDS_CHECK_STR, loc->prefix); CHECK_INFO(ppc, "%s" SDS_OK_STR, loc->prefix); } return; } else if (loc->healthy_replicas > 0) { ppc->sync_required = true; return; } loc->init_done = true; } /* produce single healthy replica */ loc->part = 0; for (; loc->replica < nreplicas; loc->replica++) { init_location_data(ppc, loc); while (CHECK_NOT_COMPLETE(loc, steps)) { ASSERT(loc->step < ARRAY_SIZE(steps)); if (step_exe(ppc, steps, loc)) return; } if (loc->healthy_replicas) break; } if (loc->healthy_replicas == 0) { ppc->result = CHECK_RESULT_NOT_CONSISTENT; CHECK_ERR(ppc, "cannot complete repair, reverting changes"); } else if (loc->healthy_replicas < nreplicas) { ppc->sync_required = true; } }
8,112
24.432602
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_log.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_log.c -- check pmemlog */ #include <inttypes.h> #include <sys/param.h> #include <endian.h> #include "out.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum question { Q_LOG_START_OFFSET, Q_LOG_END_OFFSET, Q_LOG_WRITE_OFFSET, }; /* * log_read -- (internal) read pmemlog header */ static int log_read(PMEMpoolcheck *ppc) { /* * Here we want to read the pmemlog header without the pool_hdr as we've * already done it before. * * Take the pointer to fields right after pool_hdr, compute the size and * offset of remaining fields. */ uint8_t *ptr = (uint8_t *)&ppc->pool->hdr.log; ptr += sizeof(ppc->pool->hdr.log.hdr); size_t size = sizeof(ppc->pool->hdr.log) - sizeof(ppc->pool->hdr.log.hdr); uint64_t offset = sizeof(ppc->pool->hdr.log.hdr); if (pool_read(ppc->pool, ptr, size, offset)) return CHECK_ERR(ppc, "cannot read pmemlog structure"); /* endianness conversion */ log_convert2h(&ppc->pool->hdr.log); return 0; } /* * log_hdr_check -- (internal) check pmemlog header */ static int log_hdr_check(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); CHECK_INFO(ppc, "checking pmemlog header"); if (log_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } /* determine constant values for pmemlog */ const uint64_t d_start_offset = roundup(sizeof(ppc->pool->hdr.log), LOG_FORMAT_DATA_ALIGN); if (ppc->pool->hdr.log.start_offset != d_start_offset) { if (CHECK_ASK(ppc, Q_LOG_START_OFFSET, "invalid pmemlog.start_offset: 0x%jx.|Do you " "want to set pmemlog.start_offset to default " "0x%jx?", ppc->pool->hdr.log.start_offset, d_start_offset)) goto error; } if (ppc->pool->hdr.log.end_offset != ppc->pool->set_file->size) { if (CHECK_ASK(ppc, Q_LOG_END_OFFSET, "invalid pmemlog.end_offset: 0x%jx.|Do you " "want to set pmemlog.end_offset to 0x%jx?", ppc->pool->hdr.log.end_offset, ppc->pool->set_file->size)) goto error; } if (ppc->pool->hdr.log.write_offset < d_start_offset || ppc->pool->hdr.log.write_offset > ppc->pool->set_file->size) { if (CHECK_ASK(ppc, Q_LOG_WRITE_OFFSET, "invalid pmemlog.write_offset: 0x%jx.|Do you " "want to set pmemlog.write_offset to " "pmemlog.end_offset?", ppc->pool->hdr.log.write_offset)) goto error; } if (ppc->result == CHECK_RESULT_CONSISTENT || ppc->result == CHECK_RESULT_REPAIRED) CHECK_INFO(ppc, "pmemlog header correct"); return check_questions_sequence_validate(ppc); error: ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); return -1; } /* * log_hdr_fix -- (internal) fix pmemlog header */ static int log_hdr_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); uint64_t d_start_offset; switch (question) { case Q_LOG_START_OFFSET: /* determine constant values for pmemlog */ d_start_offset = roundup(sizeof(ppc->pool->hdr.log), LOG_FORMAT_DATA_ALIGN); CHECK_INFO(ppc, "setting pmemlog.start_offset to 0x%jx", d_start_offset); ppc->pool->hdr.log.start_offset = d_start_offset; break; case Q_LOG_END_OFFSET: CHECK_INFO(ppc, "setting pmemlog.end_offset to 0x%jx", ppc->pool->set_file->size); ppc->pool->hdr.log.end_offset = ppc->pool->set_file->size; break; case Q_LOG_WRITE_OFFSET: CHECK_INFO(ppc, "setting pmemlog.write_offset to " "pmemlog.end_offset"); ppc->pool->hdr.log.write_offset = ppc->pool->set_file->size; break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); enum pool_type type; }; static const struct step steps[] = { { .check = log_hdr_check, .type = POOL_TYPE_LOG }, { .fix = log_hdr_fix, .type = POOL_TYPE_LOG }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); ASSERTeq(ppc->pool->params.type, POOL_TYPE_LOG); const struct step *step = &steps[loc->step++]; if (!(step->type & ppc->pool->params.type)) return 0; if (!step->fix) return step->check(ppc, loc); if (log_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } return check_answer_loop(ppc, loc, NULL, 1, step->fix); } /* * check_log -- entry point for pmemlog checks */ void check_log(PMEMpoolcheck *ppc) { LOG(3, NULL); location *loc = check_get_step_data(ppc->data); /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc)) break; } }
6,275
25.259414
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_util.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_util.h -- internal definitions check util */ #ifndef CHECK_UTIL_H #define CHECK_UTIL_H #include <time.h> #include <limits.h> #include <sys/param.h> #ifdef __cplusplus extern "C" { #endif #define CHECK_STEP_COMPLETE UINT_MAX #define CHECK_INVALID_QUESTION UINT_MAX #define REQUIRE_ADVANCED "the following error can be fixed using " \ "PMEMPOOL_CHECK_ADVANCED flag" #ifndef min #define min(a, b) ((a) < (b) ? (a) : (b)) #endif /* check control context */ struct check_data; struct arena; /* queue of check statuses */ struct check_status; /* container storing state of all check steps */ #define PREFIX_MAX_SIZE 30 typedef struct { unsigned init_done; unsigned step; unsigned replica; unsigned part; int single_repl; int single_part; struct pool_set *set; int is_dev_dax; struct pool_hdr *hdrp; /* copy of the pool header in host byte order */ struct pool_hdr hdr; int hdr_valid; /* * If pool header has been modified this field indicates that * the pool parameters structure requires refresh. */ int pool_hdr_modified; unsigned healthy_replicas; struct pool_hdr *next_part_hdrp; struct pool_hdr *prev_part_hdrp; struct pool_hdr *next_repl_hdrp; struct pool_hdr *prev_repl_hdrp; int next_part_hdr_valid; int prev_part_hdr_valid; int next_repl_hdr_valid; int prev_repl_hdr_valid; /* valid poolset uuid */ uuid_t *valid_puuid; /* valid part uuid */ uuid_t *valid_uuid; /* valid part pool header */ struct pool_hdr *valid_part_hdrp; int valid_part_done; unsigned valid_part_replica; char prefix[PREFIX_MAX_SIZE]; struct arena *arenap; uint64_t offset; uint32_t narena; uint8_t *bitmap; uint8_t *dup_bitmap; uint8_t *fbitmap; struct list *list_inval; struct list *list_flog_inval; struct list *list_unmap; struct { int btti_header; int btti_backup; } valid; struct { struct btt_info btti; uint64_t btti_offset; } pool_valid; } location; /* check steps */ void check_bad_blocks(PMEMpoolcheck *ppc); void check_backup(PMEMpoolcheck *ppc); void check_pool_hdr(PMEMpoolcheck *ppc); void check_pool_hdr_uuids(PMEMpoolcheck *ppc); void check_sds(PMEMpoolcheck *ppc); void check_log(PMEMpoolcheck *ppc); void check_blk(PMEMpoolcheck *ppc); void check_cto(PMEMpoolcheck *ppc); void check_btt_info(PMEMpoolcheck *ppc); void check_btt_map_flog(PMEMpoolcheck *ppc); void check_write(PMEMpoolcheck *ppc); struct check_data *check_data_alloc(void); void check_data_free(struct check_data *data); uint32_t check_step_get(struct check_data *data); void check_step_inc(struct check_data *data); location *check_get_step_data(struct check_data *data); void check_end(struct check_data *data); int check_is_end_util(struct check_data *data); int check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type, uint32_t arg, const char *fmt, ...) FORMAT_PRINTF(4, 5); void check_status_release(PMEMpoolcheck *ppc, struct check_status *status); void check_clear_status_cache(struct check_data *data); struct check_status *check_pop_question(struct check_data *data); struct check_status *check_pop_error(struct check_data *data); struct check_status *check_pop_info(struct check_data *data); bool check_has_error(struct check_data *data); bool check_has_answer(struct check_data *data); int check_push_answer(PMEMpoolcheck *ppc); struct pmempool_check_status *check_status_get_util( struct check_status *status); int check_status_is(struct check_status *status, enum pmempool_check_msg_type type); /* create info status */ #define CHECK_INFO(ppc, ...)\ check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO, 0, __VA_ARGS__) /* create info status and append error message based on errno */ #define CHECK_INFO_ERRNO(ppc, ...)\ check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO,\ (uint32_t)errno, __VA_ARGS__) /* create error status */ #define CHECK_ERR(ppc, ...)\ check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_ERROR, 0, __VA_ARGS__) /* create question status */ #define CHECK_ASK(ppc, question, ...)\ check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_QUESTION, question,\ __VA_ARGS__) #define CHECK_NOT_COMPLETE(loc, steps)\ ((loc)->step != CHECK_STEP_COMPLETE &&\ ((steps)[(loc)->step].check != NULL ||\ (steps)[(loc)->step].fix != NULL)) int check_answer_loop(PMEMpoolcheck *ppc, location *data, void *ctx, int fail_on_no, int (*callback)(PMEMpoolcheck *, location *, uint32_t, void *ctx)); int check_questions_sequence_validate(PMEMpoolcheck *ppc); const char *check_get_time_str(time_t time); const char *check_get_uuid_str(uuid_t uuid); const char *check_get_pool_type_str(enum pool_type type); void check_insert_arena(PMEMpoolcheck *ppc, struct arena *arenap); #ifdef _WIN32 void cache_to_utf8(struct check_data *data, char *buf, size_t size); #endif #define CHECK_IS(ppc, flag)\ util_flag_isset((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag) #define CHECK_IS_NOT(ppc, flag)\ util_flag_isclr((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag) #define CHECK_WITHOUT_FIXING(ppc)\ CHECK_IS_NOT(ppc, REPAIR) || CHECK_IS(ppc, DRY_RUN) #ifdef __cplusplus } #endif #endif
6,694
28.493392
78
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/pmempool.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmempool.h -- internal definitions for libpmempool */ #ifndef PMEMPOOL_H #define PMEMPOOL_H #ifdef __cplusplus extern "C" { #endif #define PMEMPOOL_LOG_PREFIX "libpmempool" #define PMEMPOOL_LOG_LEVEL_VAR "PMEMPOOL_LOG_LEVEL" #define PMEMPOOL_LOG_FILE_VAR "PMEMPOOL_LOG_FILE" enum check_result { CHECK_RESULT_CONSISTENT, CHECK_RESULT_NOT_CONSISTENT, CHECK_RESULT_ASK_QUESTIONS, CHECK_RESULT_PROCESS_ANSWERS, CHECK_RESULT_REPAIRED, CHECK_RESULT_CANNOT_REPAIR, CHECK_RESULT_ERROR, CHECK_RESULT_INTERNAL_ERROR }; /* * pmempool_check_ctx -- context and arguments for check command */ struct pmempool_check_ctx { struct pmempool_check_args args; char *path; char *backup_path; struct check_data *data; struct pool_data *pool; enum check_result result; unsigned sync_required; }; #ifdef __cplusplus } #endif #endif
2,442
30.320513
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/libpmempool_main.c
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool_main.c -- entry point for libpmempool.dll * * XXX - This is a placeholder. All the library initialization/cleanup * that is done in library ctors/dtors, as well as TLS initialization * should be moved here. */ #include <stdio.h> void libpmempool_init(void); void libpmempool_fini(void); int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH: libpmempool_init(); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: libpmempool_fini(); break; } return TRUE; }
2,210
33.546875
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_bad_blocks.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_bad_blocks.c -- pre-check bad_blocks */ #include <stddef.h> #include <stdint.h> #include <unistd.h> #include "out.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" #include "os_badblock.h" #include "badblock.h" /* * check_bad_blocks -- check poolset for bad_blocks */ void check_bad_blocks(PMEMpoolcheck *ppc) { LOG(3, "ppc %p", ppc); int ret; if (!(ppc->pool->params.features.compat & POOL_FEAT_CHECK_BAD_BLOCKS)) { /* skipping checking poolset for bad blocks */ ppc->result = CHECK_RESULT_CONSISTENT; return; } if (ppc->pool->set_file->poolset) { ret = badblocks_check_poolset(ppc->pool->set_file->poolset, 0); } else { ret = os_badblocks_check_file(ppc->pool->set_file->fname); } if (ret < 0) { ppc->result = CHECK_RESULT_ERROR; CHECK_ERR(ppc, "checking poolset for bad blocks failed -- '%s'", ppc->path); return; } if (ret > 0) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; CHECK_ERR(ppc, "poolset contains bad blocks, use 'pmempool info -k' to print or 'pmempool sync -b' to clear them"); } }
2,701
31.166667
103
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/feature.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * feature.c -- implementation of pmempool_feature_(enable|disable|query)() */ #include <stddef.h> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <sys/mman.h> #include "libpmempool.h" #include "util_pmem.h" #include "pool_hdr.h" #include "pool.h" #define RW 0 #define RDONLY 1 #define FEATURE_INCOMPAT(X) \ (features_t)FEAT_INCOMPAT(X) static const features_t f_singlehdr = FEAT_INCOMPAT(SINGLEHDR); static const features_t f_cksum_2k = FEAT_INCOMPAT(CKSUM_2K); static const features_t f_sds = FEAT_INCOMPAT(SDS); static const features_t f_chkbb = FEAT_COMPAT(CHECK_BAD_BLOCKS); #define FEAT_INVALID \ {UINT32_MAX, UINT32_MAX, UINT32_MAX}; static const features_t f_invalid = FEAT_INVALID; #define FEATURE_MAXPRINT ((size_t)1024) /* * buff_concat -- (internal) concat formatted string to string buffer */ static int buff_concat(char *buff, size_t *pos, const char *fmt, ...) { va_list ap; va_start(ap, fmt); int ret = vsnprintf(buff + *pos, FEATURE_MAXPRINT - *pos - 1, fmt, ap); va_end(ap); if (ret < 0) { ERR("vsprintf"); return ret; } *pos += (size_t)ret; return 0; } /* * buff_concat_features -- (internal) concat features string to string buffer */ static int buff_concat_features(char *buff, size_t *pos, features_t f) { return buff_concat(buff, pos, "{compat 0x%x, incompat 0x%x, ro_compat 0x%x}", f.compat, f.incompat, f.ro_compat); } /* * poolset_close -- (internal) close pool set */ static void poolset_close(struct pool_set *set) { for (unsigned r = 0; r < set->nreplicas; ++r) { struct pool_replica *rep = REP(set, r); ASSERT(!rep->remote); for (unsigned p = 0; p < rep->nparts; ++p) { util_unmap_hdr(PART(rep, p)); } } util_poolset_close(set, DO_NOT_DELETE_PARTS); } /* * features_check -- (internal) check if features are correct */ static int features_check(features_t *features, struct pool_hdr *hdrp) { static char msg[FEATURE_MAXPRINT]; struct pool_hdr hdr; memcpy(&hdr, hdrp, sizeof(hdr)); util_convert2h_hdr_nocheck(&hdr); if (!util_feature_cmp(*features, f_invalid)) { if (!util_feature_cmp(*features, hdr.features)) { size_t pos = 0; if (!buff_concat_features(msg, &pos, hdr.features)) goto err; if (!buff_concat(msg, &pos, "%s", " != ")) goto err; if (!buff_concat_features(msg, &pos, *features)) goto err; ERR("features mismatch detected: %s", msg); return -1; } } features_t unknown = util_get_unknown_features( hdr.features, (features_t)POOL_FEAT_VALID); /* all features are known */ if (util_feature_is_zero(unknown)) { memcpy(features, &hdr.features, sizeof(*features)); return 0; } /* unknown features detected - print error message */ size_t pos = 0; if (buff_concat_features(msg, &pos, unknown)) goto err; ERR("invalid features detected: %s", msg); err: return -1; } /* * get_pool_open_flags -- (internal) generate pool open flags */ static inline unsigned get_pool_open_flags(struct pool_set *set, int rdonly) { unsigned flags = 0; if (rdonly == RDONLY && !util_pool_has_device_dax(set)) flags = POOL_OPEN_COW; flags |= POOL_OPEN_IGNORE_BAD_BLOCKS; return flags; } /* * get_mmap_flags -- (internal) generate mmap flags */ static inline int get_mmap_flags(struct pool_set_part *part, int rdonly) { if (part->is_dev_dax) return MAP_SHARED; else return rdonly ? MAP_PRIVATE : MAP_SHARED; } /* * poolset_open -- (internal) open pool set */ static struct pool_set * poolset_open(const char *path, int rdonly) { struct pool_set *set; features_t features = FEAT_INVALID; /* read poolset */ int ret = util_poolset_create_set(&set, path, 0, 0, true); if (ret < 0) { ERR("cannot open pool set -- '%s'", path); goto err_poolset; } if (set->remote) { ERR("poolsets with remote replicas are not supported"); errno = EINVAL; goto err_open; } /* open a memory pool */ unsigned flags = get_pool_open_flags(set, rdonly); if (util_pool_open_nocheck(set, flags)) goto err_open; /* map all headers and check features */ for (unsigned r = 0; r < set->nreplicas; ++r) { struct pool_replica *rep = REP(set, r); ASSERT(!rep->remote); for (unsigned p = 0; p < rep->nparts; ++p) { struct pool_set_part *part = PART(rep, p); int mmap_flags = get_mmap_flags(part, rdonly); if (util_map_hdr(part, mmap_flags, rdonly)) { part->hdr = NULL; goto err_map_hdr; } if (features_check(&features, HDR(rep, p))) { ERR( "invalid features - replica #%d part #%d", r, p); goto err_open; } } } return set; err_map_hdr: /* unmap all headers */ for (unsigned r = 0; r < set->nreplicas; ++r) { struct pool_replica *rep = REP(set, r); ASSERT(!rep->remote); for (unsigned p = 0; p < rep->nparts; ++p) { util_unmap_hdr(PART(rep, p)); } } err_open: /* close the memory pool and release pool set structure */ util_poolset_close(set, DO_NOT_DELETE_PARTS); err_poolset: return NULL; } /* * get_hdr -- (internal) read header in host byte order */ static struct pool_hdr * get_hdr(struct pool_set *set, unsigned rep, unsigned part) { static struct pool_hdr hdr; /* copy header */ struct pool_hdr *hdrp = HDR(REP(set, rep), part); memcpy(&hdr, hdrp, sizeof(hdr)); /* convert to host byte order and return */ util_convert2h_hdr_nocheck(&hdr); return &hdr; } /* * set_hdr -- (internal) convert header to little-endian, checksum and write */ static void set_hdr(struct pool_set *set, unsigned rep, unsigned part, struct pool_hdr *src) { /* convert to little-endian and set new checksum */ const size_t skip_off = POOL_HDR_CSUM_END_OFF(src); util_convert2le_hdr(src); util_checksum(src, sizeof(*src), &src->checksum, 1, skip_off); /* write header */ struct pool_replica *replica = REP(set, rep); struct pool_hdr *dst = HDR(replica, part); memcpy(dst, src, sizeof(*src)); util_persist_auto(PART(replica, part)->is_dev_dax, dst, sizeof(*src)); } typedef enum { DISABLED, ENABLED } fstate_t; #define FEATURE_IS_ENABLED_STR "feature already enabled: %s" #define FEATURE_IS_DISABLED_STR "feature already disabled: %s" /* * require_feature_is -- (internal) check if required feature is enabled * (or disabled) */ static int require_feature_is(struct pool_set *set, features_t feature, fstate_t req_state) { struct pool_hdr *hdrp = get_hdr((set), 0, 0); fstate_t state = util_feature_is_set(hdrp->features, feature) ? ENABLED : DISABLED; if (state == req_state) return 1; const char *msg = (state == ENABLED) ? FEATURE_IS_ENABLED_STR : FEATURE_IS_DISABLED_STR; LOG(3, msg, util_feature2str(feature, NULL)); return 0; } #define FEATURE_IS_NOT_ENABLED_PRIOR_STR "enable %s prior to %s %s" #define FEATURE_IS_NOT_DISABLED_PRIOR_STR "disable %s prior to %s %s" /* * require_other_feature_is -- (internal) check if other feature is enabled * (or disabled) in case the other feature has to be enabled (or disabled) * prior to the main one */ static int require_other_feature_is(struct pool_set *set, features_t other, fstate_t req_state, features_t feature, const char *cause) { struct pool_hdr *hdrp = get_hdr((set), 0, 0); fstate_t state = util_feature_is_set(hdrp->features, other) ? ENABLED : DISABLED; if (state == req_state) return 1; const char *msg = (req_state == ENABLED) ? FEATURE_IS_NOT_ENABLED_PRIOR_STR : FEATURE_IS_NOT_DISABLED_PRIOR_STR; ERR(msg, util_feature2str(other, NULL), cause, util_feature2str(feature, NULL)); return 0; } /* * feature_set -- (internal) enable (or disable) feature */ static void feature_set(struct pool_set *set, features_t feature, int value) { for (unsigned r = 0; r < set->nreplicas; ++r) { for (unsigned p = 0; p < REP(set, r)->nparts; ++p) { struct pool_hdr *hdrp = get_hdr(set, r, p); if (value == ENABLED) util_feature_enable(&hdrp->features, feature); else util_feature_disable(&hdrp->features, feature); set_hdr(set, r, p, hdrp); } } } /* * query_feature -- (internal) query feature value */ static int query_feature(const char *path, features_t feature) { struct pool_set *set = poolset_open(path, RDONLY); if (!set) goto err_open; struct pool_hdr *hdrp = get_hdr(set, 0, 0); const int query = util_feature_is_set(hdrp->features, feature); poolset_close(set); return query; err_open: return -1; } /* * unsupported_feature -- (internal) report unsupported feature */ static inline int unsupported_feature(features_t feature) { ERR("unsupported feature: %s", util_feature2str(feature, NULL)); errno = EINVAL; return -1; } /* * enable_singlehdr -- (internal) enable POOL_FEAT_SINGLEHDR */ static int enable_singlehdr(const char *path) { return unsupported_feature(f_singlehdr); } /* * disable_singlehdr -- (internal) disable POOL_FEAT_SINGLEHDR */ static int disable_singlehdr(const char *path) { return unsupported_feature(f_singlehdr); } /* * query_singlehdr -- (internal) query POOL_FEAT_SINGLEHDR */ static int query_singlehdr(const char *path) { return query_feature(path, f_singlehdr); } /* * enable_checksum_2k -- (internal) enable POOL_FEAT_CKSUM_2K */ static int enable_checksum_2k(const char *path) { struct pool_set *set = poolset_open(path, RW); if (!set) return -1; if (require_feature_is(set, f_cksum_2k, DISABLED)) feature_set(set, f_cksum_2k, ENABLED); poolset_close(set); return 0; } /* * disable_checksum_2k -- (internal) disable POOL_FEAT_CKSUM_2K */ static int disable_checksum_2k(const char *path) { struct pool_set *set = poolset_open(path, RW); if (!set) return -1; int ret = 0; if (!require_feature_is(set, f_cksum_2k, ENABLED)) goto exit; /* check if POOL_FEAT_SDS is disabled */ if (!require_other_feature_is(set, f_sds, DISABLED, f_cksum_2k, "disabling")) { ret = -1; goto exit; } feature_set(set, f_cksum_2k, DISABLED); exit: poolset_close(set); return ret; } /* * query_checksum_2k -- (internal) query POOL_FEAT_CKSUM_2K */ static int query_checksum_2k(const char *path) { return query_feature(path, f_cksum_2k); } /* * enable_shutdown_state -- (internal) enable POOL_FEAT_SDS */ static int enable_shutdown_state(const char *path) { struct pool_set *set = poolset_open(path, RW); if (!set) return -1; int ret = 0; if (!require_feature_is(set, f_sds, DISABLED)) goto exit; /* check if POOL_FEAT_CKSUM_2K is enabled */ if (!require_other_feature_is(set, f_cksum_2k, ENABLED, f_sds, "enabling")) { ret = -1; goto exit; } feature_set(set, f_sds, ENABLED); exit: poolset_close(set); return ret; } /* * reset_shutdown_state -- zero all shutdown structures */ static void reset_shutdown_state(struct pool_set *set) { for (unsigned rep = 0; rep < set->nreplicas; ++rep) { for (unsigned part = 0; part < REP(set, rep)->nparts; ++part) { struct pool_hdr *hdrp = HDR(REP(set, rep), part); shutdown_state_init(&hdrp->sds, REP(set, rep)); } } } /* * disable_shutdown_state -- (internal) disable POOL_FEAT_SDS */ static int disable_shutdown_state(const char *path) { struct pool_set *set = poolset_open(path, RW); if (!set) return -1; if (require_feature_is(set, f_sds, ENABLED)) { feature_set(set, f_sds, DISABLED); reset_shutdown_state(set); } poolset_close(set); return 0; } /* * query_shutdown_state -- (internal) query POOL_FEAT_SDS */ static int query_shutdown_state(const char *path) { return query_feature(path, f_sds); } /* * enable_badblocks_checking -- (internal) enable POOL_FEAT_CHECK_BAD_BLOCKS */ static int enable_badblocks_checking(const char *path) { #ifdef _WIN32 ERR("bad blocks checking is not supported on Windows"); return -1; #else struct pool_set *set = poolset_open(path, RW); if (!set) return -1; if (require_feature_is(set, f_chkbb, DISABLED)) feature_set(set, f_chkbb, ENABLED); poolset_close(set); return 0; #endif } /* * disable_badblocks_checking -- (internal) disable POOL_FEAT_CHECK_BAD_BLOCKS */ static int disable_badblocks_checking(const char *path) { struct pool_set *set = poolset_open(path, RW); if (!set) return -1; int ret = 0; if (!require_feature_is(set, f_chkbb, ENABLED)) goto exit; feature_set(set, f_chkbb, DISABLED); exit: poolset_close(set); return ret; } /* * query_badblocks_checking -- (internal) query POOL_FEAT_CHECK_BAD_BLOCKS */ static int query_badblocks_checking(const char *path) { return query_feature(path, f_chkbb); } struct feature_funcs { int (*enable)(const char *); int (*disable)(const char *); int (*query)(const char *); }; static struct feature_funcs features[] = { { .enable = enable_singlehdr, .disable = disable_singlehdr, .query = query_singlehdr }, { .enable = enable_checksum_2k, .disable = disable_checksum_2k, .query = query_checksum_2k }, { .enable = enable_shutdown_state, .disable = disable_shutdown_state, .query = query_shutdown_state }, { .enable = enable_badblocks_checking, .disable = disable_badblocks_checking, .query = query_badblocks_checking }, }; #define FEATURE_FUNCS_MAX ARRAY_SIZE(features) /* * are_flags_valid -- (internal) check if flags are valid */ static inline int are_flags_valid(unsigned flags) { if (flags != 0) { ERR("invalid flags: 0x%x", flags); errno = EINVAL; return 0; } return 1; } /* * is_feature_valid -- (internal) check if feature is valid */ static inline int is_feature_valid(uint32_t feature) { if (feature >= FEATURE_FUNCS_MAX) { ERR("invalid feature: 0x%x", feature); errno = EINVAL; return 0; } return 1; } /* * pmempool_feature_enableU -- enable pool set feature */ #ifndef _WIN32 static inline #endif int pmempool_feature_enableU(const char *path, enum pmempool_feature feature, unsigned flags) { LOG(3, "path %s feature %x flags %x", path, feature, flags); if (!is_feature_valid(feature)) return -1; if (!are_flags_valid(flags)) return -1; return features[feature].enable(path); } /* * pmempool_feature_disableU -- disable pool set feature */ #ifndef _WIN32 static inline #endif int pmempool_feature_disableU(const char *path, enum pmempool_feature feature, unsigned flags) { LOG(3, "path %s feature %x flags %x", path, feature, flags); if (!is_feature_valid(feature)) return -1; if (!are_flags_valid(flags)) return -1; return features[feature].disable(path); } /* * pmempool_feature_queryU -- query pool set feature */ #ifndef _WIN32 static inline #endif int pmempool_feature_queryU(const char *path, enum pmempool_feature feature, unsigned flags) { LOG(3, "path %s feature %x flags %x", path, feature, flags); /* * XXX: Windows does not allow function call in a constant expressions */ #ifndef _WIN32 #define CHECK_INCOMPAT_MAPPING(FEAT, ENUM) \ COMPILE_ERROR_ON( \ util_feature2pmempool_feature(FEATURE_INCOMPAT(FEAT)) != ENUM) CHECK_INCOMPAT_MAPPING(SINGLEHDR, PMEMPOOL_FEAT_SINGLEHDR); CHECK_INCOMPAT_MAPPING(CKSUM_2K, PMEMPOOL_FEAT_CKSUM_2K); CHECK_INCOMPAT_MAPPING(SDS, PMEMPOOL_FEAT_SHUTDOWN_STATE); #undef CHECK_INCOMPAT_MAPPING #endif if (!is_feature_valid(feature)) return -1; if (!are_flags_valid(flags)) return -1; return features[feature].query(path); } #ifndef _WIN32 /* * pmempool_feature_enable -- enable pool set feature */ int pmempool_feature_enable(const char *path, enum pmempool_feature feature, unsigned flags) { return pmempool_feature_enableU(path, feature, flags); } #else /* * pmempool_feature_enableW -- enable pool set feature as widechar */ int pmempool_feature_enableW(const wchar_t *path, enum pmempool_feature feature, unsigned flags) { char *upath = util_toUTF8(path); if (upath == NULL) { ERR("Invalid poolest/pool file path."); return -1; } int ret = pmempool_feature_enableU(upath, feature, flags); util_free_UTF8(upath); return ret; } #endif #ifndef _WIN32 /* * pmempool_feature_disable -- disable pool set feature */ int pmempool_feature_disable(const char *path, enum pmempool_feature feature, unsigned flags) { return pmempool_feature_disableU(path, feature, flags); } #else /* * pmempool_feature_disableW -- disable pool set feature as widechar */ int pmempool_feature_disableW(const wchar_t *path, enum pmempool_feature feature, unsigned flags) { char *upath = util_toUTF8(path); if (upath == NULL) { ERR("Invalid poolest/pool file path."); return -1; } int ret = pmempool_feature_disableU(upath, feature, flags); util_free_UTF8(upath); return ret; } #endif #ifndef _WIN32 /* * pmempool_feature_query -- query pool set feature */ int pmempool_feature_query(const char *path, enum pmempool_feature feature, unsigned flags) { return pmempool_feature_queryU(path, feature, flags); } #else /* * pmempool_feature_queryW -- query pool set feature as widechar */ int pmempool_feature_queryW(const wchar_t *path, enum pmempool_feature feature, unsigned flags) { char *upath = util_toUTF8(path); if (upath == NULL) { ERR("Invalid poolest/pool file path."); return -1; } int ret = pmempool_feature_queryU(upath, feature, flags); util_free_UTF8(upath); return ret; } #endif
18,602
21.995056
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check.c -- functions performing checks in proper order */ #include <stdint.h> #include "out.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check.h" #include "check_util.h" #define CHECK_RESULT_IS_STOP(result)\ ((result) == CHECK_RESULT_ERROR ||\ (result) == CHECK_RESULT_INTERNAL_ERROR ||\ ((result) == CHECK_RESULT_CANNOT_REPAIR) ||\ ((result) == CHECK_RESULT_NOT_CONSISTENT)) struct step { void (*func)(PMEMpoolcheck *); enum pool_type type; bool part; }; static const struct step steps[] = { { .type = POOL_TYPE_ANY, .func = check_bad_blocks, .part = true, }, { .type = POOL_TYPE_ANY, .func = check_backup, .part = true, }, { .type = POOL_TYPE_BLK | POOL_TYPE_LOG | POOL_TYPE_OBJ | POOL_TYPE_CTO, .func = check_sds, .part = true, }, { .type = POOL_TYPE_BLK | POOL_TYPE_LOG | POOL_TYPE_OBJ | POOL_TYPE_CTO | POOL_TYPE_UNKNOWN, .func = check_pool_hdr, .part = true, }, { .type = POOL_TYPE_BLK | POOL_TYPE_LOG | POOL_TYPE_OBJ | POOL_TYPE_CTO | POOL_TYPE_UNKNOWN, .func = check_pool_hdr_uuids, .part = true, }, { .type = POOL_TYPE_LOG, .func = check_log, .part = false, }, { .type = POOL_TYPE_BLK, .func = check_blk, .part = false, }, { .type = POOL_TYPE_CTO, .func = check_cto, .part = false, }, { .type = POOL_TYPE_BLK | POOL_TYPE_BTT, .func = check_btt_info, .part = false, }, { .type = POOL_TYPE_BLK | POOL_TYPE_BTT, .func = check_btt_map_flog, .part = false, }, { .type = POOL_TYPE_BLK | POOL_TYPE_LOG | POOL_TYPE_BTT | POOL_TYPE_CTO, .func = check_write, .part = false, }, { .func = NULL, }, }; /* * check_init -- initialize check process */ int check_init(PMEMpoolcheck *ppc) { LOG(3, NULL); if (!(ppc->data = check_data_alloc())) goto error_data_malloc; if (!(ppc->pool = pool_data_alloc(ppc))) goto error_pool_malloc; return 0; error_pool_malloc: check_data_free(ppc->data); error_data_malloc: return -1; } #ifdef _WIN32 void convert_status_cache(PMEMpoolcheck *ppc, char *buf, size_t size) { cache_to_utf8(ppc->data, buf, size); } #endif /* * status_get -- (internal) get next check_status * * The assumed order of check_statuses is: all info messages, error or question. */ static struct check_status * status_get(PMEMpoolcheck *ppc) { struct check_status *status = NULL; /* clear cache if exists */ check_clear_status_cache(ppc->data); /* return next info if exists */ if ((status = check_pop_info(ppc->data))) return status; /* return error if exists */ if ((status = check_pop_error(ppc->data))) return status; if (ppc->result == CHECK_RESULT_ASK_QUESTIONS) { /* * push answer for previous question and return info if answer * is not valid */ if (check_push_answer(ppc)) if ((status = check_pop_info(ppc->data))) return status; /* if has next question ask it */ if ((status = check_pop_question(ppc->data))) return status; /* process answers otherwise */ ppc->result = CHECK_RESULT_PROCESS_ANSWERS; } else if (CHECK_RESULT_IS_STOP(ppc->result)) check_end(ppc->data); return NULL; } /* * check_step -- perform single check step */ struct check_status * check_step(PMEMpoolcheck *ppc) { LOG(3, NULL); struct check_status *status = NULL; /* return if we have information or questions to ask or check ended */ if ((status = status_get(ppc)) || check_is_end(ppc->data)) return status; /* get next step and check if exists */ const struct step *step = &steps[check_step_get(ppc->data)]; if (step->func == NULL) { check_end(ppc->data); return status; } /* * step would be performed if pool type is one of the required pool type * and it is not part if parts are excluded from current step */ if (!(step->type & ppc->pool->params.type) || (ppc->pool->params.is_part && !step->part)) { /* skip test */ check_step_inc(ppc->data); return NULL; } /* perform step */ step->func(ppc); /* move on to next step if no questions were generated */ if (ppc->result != CHECK_RESULT_ASK_QUESTIONS) check_step_inc(ppc->data); /* get current status and return */ return status_get(ppc); } /* * check_fini -- stop check process */ void check_fini(PMEMpoolcheck *ppc) { LOG(3, NULL); pool_data_free(ppc->pool); check_data_free(ppc->data); } /* * check_is_end -- return if check has ended */ int check_is_end(struct check_data *data) { return check_is_end_util(data); } /* * check_status_get -- extract pmempool_check_status from check_status */ struct pmempool_check_status * check_status_get(struct check_status *status) { return check_status_get_util(status); }
6,303
22.610487
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_btt_map_flog.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_btt_map_flog.c -- check BTT Map and Flog */ #include <stdint.h> #include <sys/param.h> #include <endian.h> #include "out.h" #include "btt.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum questions { Q_REPAIR_MAP, Q_REPAIR_FLOG, }; /* * flog_read -- (internal) read and convert flog from file */ static int flog_read(PMEMpoolcheck *ppc, struct arena *arenap) { uint64_t flogoff = arenap->offset + arenap->btt_info.flogoff; arenap->flogsize = btt_flog_size(arenap->btt_info.nfree); arenap->flog = malloc(arenap->flogsize); if (!arenap->flog) { ERR("!malloc"); goto error_malloc; } if (pool_read(ppc->pool, arenap->flog, arenap->flogsize, flogoff)) goto error_read; uint8_t *ptr = arenap->flog; uint32_t i; for (i = 0; i < arenap->btt_info.nfree; i++) { struct btt_flog *flog = (struct btt_flog *)ptr; btt_flog_convert2h(&flog[0]); btt_flog_convert2h(&flog[1]); ptr += BTT_FLOG_PAIR_ALIGN; } return 0; error_read: free(arenap->flog); arenap->flog = NULL; error_malloc: return -1; } /* * map_read -- (internal) read and convert map from file */ static int map_read(PMEMpoolcheck *ppc, struct arena *arenap) { uint64_t mapoff = arenap->offset + arenap->btt_info.mapoff; arenap->mapsize = btt_map_size(arenap->btt_info.external_nlba); ASSERT(arenap->mapsize != 0); arenap->map = malloc(arenap->mapsize); if (!arenap->map) { ERR("!malloc"); goto error_malloc; } if (pool_read(ppc->pool, arenap->map, arenap->mapsize, mapoff)) { goto error_read; } uint32_t i; for (i = 0; i < arenap->btt_info.external_nlba; i++) arenap->map[i] = le32toh(arenap->map[i]); return 0; error_read: free(arenap->map); arenap->map = NULL; error_malloc: return -1; } /* * list_item -- item for simple list */ struct list_item { LIST_ENTRY(list_item) next; uint32_t val; }; /* * list -- simple list for storing numbers */ struct list { LIST_HEAD(listhead, list_item) head; uint32_t count; }; /* * list_alloc -- (internal) allocate an empty list */ static struct list * list_alloc(void) { struct list *list = malloc(sizeof(struct list)); if (!list) { ERR("!malloc"); return NULL; } LIST_INIT(&list->head); list->count = 0; return list; } /* * list_push -- (internal) insert new element to the list */ static struct list_item * list_push(struct list *list, uint32_t val) { struct list_item *item = malloc(sizeof(*item)); if (!item) { ERR("!malloc"); return NULL; } item->val = val; list->count++; LIST_INSERT_HEAD(&list->head, item, next); return item; } /* * list_pop -- (internal) pop element from list head */ static int list_pop(struct list *list, uint32_t *valp) { if (!LIST_EMPTY(&list->head)) { struct list_item *i = LIST_FIRST(&list->head); LIST_REMOVE(i, next); if (valp) *valp = i->val; free(i); list->count--; return 1; } return 0; } /* * list_free -- (internal) free the list */ static void list_free(struct list *list) { while (list_pop(list, NULL)) ; free(list); } /* * cleanup -- (internal) prepare resources for map and flog check */ static int cleanup(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (loc->list_unmap) list_free(loc->list_unmap); if (loc->list_flog_inval) list_free(loc->list_flog_inval); if (loc->list_inval) list_free(loc->list_inval); if (loc->fbitmap) free(loc->fbitmap); if (loc->bitmap) free(loc->bitmap); if (loc->dup_bitmap) free(loc->dup_bitmap); return 0; } /* * init -- (internal) initialize map and flog check */ static int init(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); struct arena *arenap = loc->arenap; /* read flog and map entries */ if (flog_read(ppc, arenap)) { CHECK_ERR(ppc, "arena %u: cannot read BTT Flog", arenap->id); goto error; } if (map_read(ppc, arenap)) { CHECK_ERR(ppc, "arena %u: cannot read BTT Map", arenap->id); goto error; } /* create bitmaps for checking duplicated blocks */ uint32_t bitmapsize = howmany(arenap->btt_info.internal_nlba, 8); loc->bitmap = calloc(bitmapsize, 1); if (!loc->bitmap) { ERR("!calloc"); CHECK_ERR(ppc, "arena %u: cannot allocate memory for blocks " "bitmap", arenap->id); goto error; } loc->dup_bitmap = calloc(bitmapsize, 1); if (!loc->dup_bitmap) { ERR("!calloc"); CHECK_ERR(ppc, "arena %u: cannot allocate memory for " "duplicated blocks bitmap", arenap->id); goto error; } loc->fbitmap = calloc(bitmapsize, 1); if (!loc->fbitmap) { ERR("!calloc"); CHECK_ERR(ppc, "arena %u: cannot allocate memory for BTT Flog " "bitmap", arenap->id); goto error; } /* list of invalid map entries */ loc->list_inval = list_alloc(); if (!loc->list_inval) { CHECK_ERR(ppc, "arena %u: cannot allocate memory for invalid BTT map " "entries list", arenap->id); goto error; } /* list of invalid flog entries */ loc->list_flog_inval = list_alloc(); if (!loc->list_flog_inval) { CHECK_ERR(ppc, "arena %u: cannot allocate memory for invalid BTT Flog " "entries list", arenap->id); goto error; } /* list of unmapped blocks */ loc->list_unmap = list_alloc(); if (!loc->list_unmap) { CHECK_ERR(ppc, "arena %u: cannot allocate memory for unmaped blocks " "list", arenap->id); goto error; } return 0; error: ppc->result = CHECK_RESULT_ERROR; cleanup(ppc, loc); return -1; } /* * map_get_postmap_lba -- extract postmap LBA from map entry */ static inline uint32_t map_get_postmap_lba(struct arena *arenap, uint32_t i) { uint32_t entry = arenap->map[i]; /* if map record is in initial state (flags == 0b00) */ if (map_entry_is_initial(entry)) return i; /* read postmap LBA otherwise */ return entry & BTT_MAP_ENTRY_LBA_MASK; } /* * map_entry_check -- (internal) check single map entry */ static int map_entry_check(PMEMpoolcheck *ppc, location *loc, uint32_t i) { struct arena *arenap = loc->arenap; uint32_t lba = map_get_postmap_lba(arenap, i); /* add duplicated and invalid entries to list */ if (lba < arenap->btt_info.internal_nlba) { if (util_isset(loc->bitmap, lba)) { CHECK_INFO(ppc, "arena %u: BTT Map entry %u duplicated " "at %u", arenap->id, lba, i); util_setbit(loc->dup_bitmap, lba); if (!list_push(loc->list_inval, i)) return -1; } else util_setbit(loc->bitmap, lba); } else { CHECK_INFO(ppc, "arena %u: invalid BTT Map entry at %u", arenap->id, i); if (!list_push(loc->list_inval, i)) return -1; } return 0; } /* * flog_entry_check -- (internal) check single flog entry */ static int flog_entry_check(PMEMpoolcheck *ppc, location *loc, uint32_t i, uint8_t **ptr) { struct arena *arenap = loc->arenap; /* flog entry consists of two btt_flog structures */ struct btt_flog *flog = (struct btt_flog *)*ptr; int next; struct btt_flog *flog_cur = btt_flog_get_valid(flog, &next); /* insert invalid and duplicated indexes to list */ if (!flog_cur) { CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at %u", arenap->id, i); if (!list_push(loc->list_flog_inval, i)) return -1; goto next; } uint32_t entry = flog_cur->old_map & BTT_MAP_ENTRY_LBA_MASK; uint32_t new_entry = flog_cur->new_map & BTT_MAP_ENTRY_LBA_MASK; /* * Check if lba is in extranal_nlba range, and check if both old_map and * new_map are in internal_nlba range. */ if (flog_cur->lba >= arenap->btt_info.external_nlba || entry >= arenap->btt_info.internal_nlba || new_entry >= arenap->btt_info.internal_nlba) { CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at %u", arenap->id, i); if (!list_push(loc->list_flog_inval, i)) return -1; goto next; } if (util_isset(loc->fbitmap, entry)) { /* * here we have two flog entries which holds the same free block */ CHECK_INFO(ppc, "arena %u: duplicated BTT Flog entry at %u\n", arenap->id, i); if (!list_push(loc->list_flog_inval, i)) return -1; } else if (util_isset(loc->bitmap, entry)) { /* here we have probably an unfinished write */ if (util_isset(loc->bitmap, new_entry)) { /* Both old_map and new_map are already used in map. */ CHECK_INFO(ppc, "arena %u: duplicated BTT Flog entry " "at %u", arenap->id, i); util_setbit(loc->dup_bitmap, new_entry); if (!list_push(loc->list_flog_inval, i)) return -1; } else { /* * Unfinished write. Next time pool is opened, the map * will be updated to new_map. */ util_setbit(loc->bitmap, new_entry); util_setbit(loc->fbitmap, entry); } } else { int flog_valid = 1; /* * Either flog entry is in its initial state: * - current_btt_flog entry is first one in pair and * - current_btt_flog.old_map == current_btt_flog.new_map and * - current_btt_flog.seq == 0b01 and * - second flog entry in pair is zeroed * or * current_btt_flog.old_map != current_btt_flog.new_map */ if (entry == new_entry) flog_valid = (next == 1) && (flog_cur->seq == 1) && util_is_zeroed((const void *)&flog[1], sizeof(flog[1])); if (flog_valid) { /* totally fine case */ util_setbit(loc->bitmap, entry); util_setbit(loc->fbitmap, entry); } else { CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at " "%u", arenap->id, i); if (!list_push(loc->list_flog_inval, i)) return -1; } } next: *ptr += BTT_FLOG_PAIR_ALIGN; return 0; } /* * arena_map_flog_check -- (internal) check map and flog */ static int arena_map_flog_check(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); struct arena *arenap = loc->arenap; /* check map entries */ uint32_t i; for (i = 0; i < arenap->btt_info.external_nlba; i++) { if (map_entry_check(ppc, loc, i)) goto error_push; } /* check flog entries */ uint8_t *ptr = arenap->flog; for (i = 0; i < arenap->btt_info.nfree; i++) { if (flog_entry_check(ppc, loc, i, &ptr)) goto error_push; } /* check unmapped blocks and insert to list */ for (i = 0; i < arenap->btt_info.internal_nlba; i++) { if (!util_isset(loc->bitmap, i)) { CHECK_INFO(ppc, "arena %u: unmapped block %u", arenap->id, i); if (!list_push(loc->list_unmap, i)) goto error_push; } } if (loc->list_unmap->count) CHECK_INFO(ppc, "arena %u: number of unmapped blocks: %u", arenap->id, loc->list_unmap->count); if (loc->list_inval->count) CHECK_INFO(ppc, "arena %u: number of invalid BTT Map entries: " "%u", arenap->id, loc->list_inval->count); if (loc->list_flog_inval->count) CHECK_INFO(ppc, "arena %u: number of invalid BTT Flog entries: " "%u", arenap->id, loc->list_flog_inval->count); if (CHECK_IS_NOT(ppc, REPAIR) && loc->list_unmap->count > 0) { ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); goto cleanup; } /* * We are able to repair if and only if number of unmapped blocks is * equal to sum of invalid map and flog entries. */ if (loc->list_unmap->count != (loc->list_inval->count + loc->list_flog_inval->count)) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; CHECK_ERR(ppc, "arena %u: cannot repair BTT Map and Flog", arenap->id); goto cleanup; } if (CHECK_IS_NOT(ppc, ADVANCED) && loc->list_inval->count + loc->list_flog_inval->count > 0) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; CHECK_INFO(ppc, REQUIRE_ADVANCED); CHECK_ERR(ppc, "BTT Map and / or BTT Flog contain invalid " "entries"); check_end(ppc->data); goto cleanup; } if (loc->list_inval->count > 0) { CHECK_ASK(ppc, Q_REPAIR_MAP, "Do you want to repair invalid " "BTT Map entries?"); } if (loc->list_flog_inval->count > 0) { CHECK_ASK(ppc, Q_REPAIR_FLOG, "Do you want to repair invalid " "BTT Flog entries?"); } return check_questions_sequence_validate(ppc); error_push: CHECK_ERR(ppc, "arena %u: cannot allocate momory for list item", arenap->id); ppc->result = CHECK_RESULT_ERROR; cleanup: cleanup(ppc, loc); return -1; } /* * arena_map_flog_fix -- (internal) fix map and flog */ static int arena_map_flog_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); ASSERTeq(ctx, NULL); ASSERTne(loc, NULL); struct arena *arenap = loc->arenap; uint32_t inval; uint32_t unmap; switch (question) { case Q_REPAIR_MAP: /* * Cause first of duplicated map entries seems valid till we * find second of them we must find all first map entries * pointing to the postmap LBA's we know are duplicated to mark * them with error flag. */ for (uint32_t i = 0; i < arenap->btt_info.external_nlba; i++) { uint32_t lba = map_get_postmap_lba(arenap, i); if (lba >= arenap->btt_info.internal_nlba) continue; if (!util_isset(loc->dup_bitmap, lba)) continue; arenap->map[i] = BTT_MAP_ENTRY_ERROR | lba; util_clrbit(loc->dup_bitmap, lba); CHECK_INFO(ppc, "arena %u: storing 0x%x at %u BTT Map entry", arenap->id, arenap->map[i], i); } /* * repair invalid or duplicated map entries by using unmapped * blocks */ while (list_pop(loc->list_inval, &inval)) { if (!list_pop(loc->list_unmap, &unmap)) { ppc->result = CHECK_RESULT_ERROR; return -1; } arenap->map[inval] = unmap | BTT_MAP_ENTRY_ERROR; CHECK_INFO(ppc, "arena %u: storing 0x%x at %u BTT Map " "entry", arenap->id, arenap->map[inval], inval); } break; case Q_REPAIR_FLOG: /* repair invalid flog entries using unmapped blocks */ while (list_pop(loc->list_flog_inval, &inval)) { if (!list_pop(loc->list_unmap, &unmap)) { ppc->result = CHECK_RESULT_ERROR; return -1; } struct btt_flog *flog = (struct btt_flog *) (arenap->flog + inval * BTT_FLOG_PAIR_ALIGN); memset(&flog[1], 0, sizeof(flog[1])); uint32_t entry = unmap | BTT_MAP_ENTRY_ERROR; flog[0].lba = inval; flog[0].new_map = entry; flog[0].old_map = entry; flog[0].seq = 1; CHECK_INFO(ppc, "arena %u: repairing BTT Flog at %u " "with free block entry 0x%x", loc->arenap->id, inval, entry); } break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); }; static const struct step steps[] = { { .check = init, }, { .check = arena_map_flog_check, }, { .fix = arena_map_flog_fix, }, { .check = cleanup, }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); const struct step *step = &steps[loc->step++]; if (!step->fix) return step->check(ppc, loc); if (!check_answer_loop(ppc, loc, NULL, 1, step->fix)) return 0; cleanup(ppc, loc); return -1; } /* * check_btt_map_flog -- perform check and fixing of map and flog */ void check_btt_map_flog(PMEMpoolcheck *ppc) { LOG(3, NULL); location *loc = check_get_step_data(ppc->data); if (ppc->pool->blk_no_layout) return; /* initialize check */ if (!loc->arenap && loc->narena == 0 && ppc->result != CHECK_RESULT_PROCESS_ANSWERS) { CHECK_INFO(ppc, "checking BTT Map and Flog"); loc->arenap = TAILQ_FIRST(&ppc->pool->arenas); loc->narena = 0; } while (loc->arenap != NULL) { /* add info about checking next arena */ if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS && loc->step == 0) { CHECK_INFO(ppc, "arena %u: checking BTT Map and Flog", loc->narena); } /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc)) return; } /* jump to next arena */ loc->arenap = TAILQ_NEXT(loc->arenap, next); loc->narena++; loc->step = 0; } }
17,204
23.062937
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/rm.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rm.c -- implementation of pmempool_rm() function */ #include <errno.h> #include <fcntl.h> #include "libpmempool.h" #include "out.h" #include "os.h" #include "util.h" #include "set.h" #include "file.h" #define PMEMPOOL_RM_ALL_FLAGS (\ PMEMPOOL_RM_FORCE |\ PMEMPOOL_RM_POOLSET_LOCAL |\ PMEMPOOL_RM_POOLSET_REMOTE) #define ERR_F(f, ...) do {\ if (CHECK_FLAG((f), FORCE))\ LOG(2, "!(ignored) " __VA_ARGS__);\ else\ ERR(__VA_ARGS__);\ } while (0) #define CHECK_FLAG(f, i) ((f) & PMEMPOOL_RM_##i) struct cb_args { unsigned flags; int error; }; /* * rm_local -- (internal) remove single local file */ static int rm_local(const char *path, unsigned flags, int is_part_file) { int ret = util_unlink_flock(path); if (!ret) { LOG(3, "%s: removed", path); return 0; } int oerrno = errno; os_stat_t buff; ret = os_stat(path, &buff); if (!ret) { if (S_ISDIR(buff.st_mode)) { errno = EISDIR; if (is_part_file) ERR("%s: removing file failed", path); else ERR("removing file failed"); return -1; } } errno = oerrno; if (is_part_file) ERR_F(flags, "%s: removing file failed", path); else ERR_F(flags, "removing file failed"); if (CHECK_FLAG(flags, FORCE)) return 0; return -1; } /* * rm_remote -- (internal) remove remote replica */ static int rm_remote(const char *node, const char *path, unsigned flags) { if (!Rpmem_remove) { ERR_F(flags, "cannot remove remote replica" " -- missing librpmem"); return -1; } int rpmem_flags = 0; if (CHECK_FLAG(flags, FORCE)) rpmem_flags |= RPMEM_REMOVE_FORCE; if (CHECK_FLAG(flags, POOLSET_REMOTE)) rpmem_flags |= RPMEM_REMOVE_POOL_SET; int ret = Rpmem_remove(node, path, rpmem_flags); if (ret) { ERR_F(flags, "%s/%s removing failed", node, path); if (CHECK_FLAG(flags, FORCE)) ret = 0; } else { LOG(3, "%s/%s: removed", node, path); } return ret; } /* * rm_cb -- (internal) foreach part callback */ static int rm_cb(struct part_file *pf, void *arg) { struct cb_args *args = (struct cb_args *)arg; int ret; if (pf->is_remote) { ret = rm_remote(pf->remote->node_addr, pf->remote->pool_desc, args->flags); } else { ret = rm_local(pf->part->path, args->flags, 1); } if (ret) args->error = ret; return 0; } /* * pmempool_rmU -- remove pool files or poolsets */ #ifndef _WIN32 static inline #endif int pmempool_rmU(const char *path, unsigned flags) { LOG(3, "path %s flags %x", path, flags); int ret; if (flags & ~PMEMPOOL_RM_ALL_FLAGS) { ERR("invalid flags specified"); errno = EINVAL; return -1; } int is_poolset = util_is_poolset_file(path); if (is_poolset < 0) { os_stat_t buff; ret = os_stat(path, &buff); if (!ret) { if (S_ISDIR(buff.st_mode)) { errno = EISDIR; ERR("removing file failed"); return -1; } } ERR_F(flags, "removing file failed"); if (CHECK_FLAG(flags, FORCE)) return 0; return -1; } if (!is_poolset) { LOG(2, "%s: not a poolset file", path); return rm_local(path, flags, 0); } LOG(2, "%s: poolset file", path); /* fill up pool_set structure */ struct pool_set *set = NULL; int fd = os_open(path, O_RDONLY); if (fd == -1 || util_poolset_parse(&set, path, fd)) { ERR_F(flags, "parsing poolset file failed"); if (fd != -1) os_close(fd); if (CHECK_FLAG(flags, FORCE)) return 0; return -1; } os_close(fd); if (set->remote) { /* ignore error - it will be handled in rm_remote() */ (void) util_remote_load(); } util_poolset_free(set); struct cb_args args; args.flags = flags; args.error = 0; ret = util_poolset_foreach_part(path, rm_cb, &args); if (ret == -1) { ERR_F(flags, "parsing poolset file failed"); if (CHECK_FLAG(flags, FORCE)) return 0; return ret; } ASSERTeq(ret, 0); if (args.error) return args.error; if (CHECK_FLAG(flags, POOLSET_LOCAL)) { ret = rm_local(path, flags, 0); if (ret) { ERR_F(flags, "removing pool set file failed"); } else { LOG(3, "%s: removed", path); } if (CHECK_FLAG(flags, FORCE)) return 0; return ret; } return 0; } #ifndef _WIN32 /* * pmempool_rm -- remove pool files or poolsets */ int pmempool_rm(const char *path, unsigned flags) { return pmempool_rmU(path, flags); } #else /* * pmempool_rmW -- remove pool files or poolsets in widechar */ int pmempool_rmW(const wchar_t *path, unsigned flags) { char *upath = util_toUTF8(path); if (upath == NULL) { ERR("Invalid poolest/pool file path."); return -1; } int ret = pmempool_rmU(upath, flags); util_free_UTF8(upath); return ret; } #endif
6,151
20.893238
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_backup.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_backup.c -- pre-check backup */ #include <stddef.h> #include <stdint.h> #include <unistd.h> #include "out.h" #include "file.h" #include "os.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum question { Q_OVERWRITE_EXISTING_FILE, Q_OVERWRITE_EXISTING_PARTS }; /* * location_release -- (internal) release poolset structure */ static void location_release(location *loc) { if (loc->set) { util_poolset_free(loc->set); loc->set = NULL; } } /* * backup_nonpoolset_requirements -- (internal) check backup requirements */ static int backup_nonpoolset_requirements(PMEMpoolcheck *ppc, location *loc) { LOG(3, "backup_path %s", ppc->backup_path); int exists = util_file_exists(ppc->backup_path); if (exists < 0) { return CHECK_ERR(ppc, "unable to access the backup destination: %s", ppc->backup_path); } if (!exists) { errno = 0; return 0; } if ((size_t)util_file_get_size(ppc->backup_path) != ppc->pool->set_file->size) { ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "destination of the backup does not match the size of the source pool file: %s", ppc->backup_path); } if (CHECK_WITHOUT_FIXING(ppc)) { location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; } CHECK_ASK(ppc, Q_OVERWRITE_EXISTING_FILE, "destination of the backup already exists.|Do you want to overwrite it?"); return check_questions_sequence_validate(ppc); } /* * backup_nonpoolset_overwrite -- (internal) overwrite pool */ static int backup_nonpoolset_overwrite(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *context) { LOG(3, NULL); ASSERTne(loc, NULL); switch (question) { case Q_OVERWRITE_EXISTING_FILE: if (pool_copy(ppc->pool, ppc->backup_path, 1 /* overwrite */)) { location_release(loc); ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "cannot perform backup"); } location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; default: ERR("not implemented question id: %u", question); } return 0; } /* * backup_nonpoolset_create -- (internal) create backup */ static int backup_nonpoolset_create(PMEMpoolcheck *ppc, location *loc) { CHECK_INFO(ppc, "creating backup file: %s", ppc->backup_path); if (pool_copy(ppc->pool, ppc->backup_path, 0)) { location_release(loc); ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "cannot perform backup"); } location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; } /* * backup_poolset_requirements -- (internal) check backup requirements */ static int backup_poolset_requirements(PMEMpoolcheck *ppc, location *loc) { LOG(3, "backup_path %s", ppc->backup_path); if (ppc->pool->set_file->poolset->nreplicas > 1) { CHECK_INFO(ppc, "backup of a poolset with multiple replicas is not supported"); goto err; } if (pool_set_parse(&loc->set, ppc->backup_path)) { CHECK_INFO_ERRNO(ppc, "invalid poolset backup file: %s", ppc->backup_path); goto err; } if (loc->set->nreplicas > 1) { CHECK_INFO(ppc, "backup to a poolset with multiple replicas is not supported"); goto err_poolset; } ASSERTeq(loc->set->nreplicas, 1); struct pool_replica *srep = ppc->pool->set_file->poolset->replica[0]; struct pool_replica *drep = loc->set->replica[0]; if (srep->nparts != drep->nparts) { CHECK_INFO(ppc, "number of part files in the backup poolset must match number of part files in the source poolset"); goto err_poolset; } int overwrite_required = 0; for (unsigned p = 0; p < srep->nparts; p++) { int exists = util_file_exists(drep->part[p].path); if (exists < 0) { CHECK_INFO(ppc, "unable to access the part of the destination poolset: %s", ppc->backup_path); goto err_poolset; } if (srep->part[p].filesize != drep->part[p].filesize) { CHECK_INFO(ppc, "size of the part %u of the backup poolset does not match source poolset", p); goto err_poolset; } if (!exists) { errno = 0; continue; } overwrite_required = true; if ((size_t)util_file_get_size(drep->part[p].path) != srep->part[p].filesize) { CHECK_INFO(ppc, "destination of the backup part does not match size of the source part file: %s", drep->part[p].path); goto err_poolset; } } if (CHECK_WITHOUT_FIXING(ppc)) { location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; } if (overwrite_required) { CHECK_ASK(ppc, Q_OVERWRITE_EXISTING_PARTS, "part files of the destination poolset of the backup already exist.|" "Do you want to overwrite them?"); } return check_questions_sequence_validate(ppc); err_poolset: location_release(loc); err: ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "unable to backup poolset"); } /* * backup_poolset -- (internal) backup the poolset */ static int backup_poolset(PMEMpoolcheck *ppc, location *loc, int overwrite) { struct pool_replica *srep = ppc->pool->set_file->poolset->replica[0]; struct pool_replica *drep = loc->set->replica[0]; for (unsigned p = 0; p < srep->nparts; p++) { if (overwrite == 0) { CHECK_INFO(ppc, "creating backup file: %s", drep->part[p].path); } if (pool_set_part_copy(&drep->part[p], &srep->part[p], overwrite)) { location_release(loc); ppc->result = CHECK_RESULT_ERROR; CHECK_INFO(ppc, "unable to create backup file"); return CHECK_ERR(ppc, "unable to backup poolset"); } } return 0; } /* * backup_poolset_overwrite -- (internal) backup poolset with overwrite */ static int backup_poolset_overwrite(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *context) { LOG(3, NULL); ASSERTne(loc, NULL); switch (question) { case Q_OVERWRITE_EXISTING_PARTS: if (backup_poolset(ppc, loc, 1 /* overwrite */)) { location_release(loc); ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "cannot perform backup"); } location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; default: ERR("not implemented question id: %u", question); } return 0; } /* * backup_poolset_create -- (internal) backup poolset */ static int backup_poolset_create(PMEMpoolcheck *ppc, location *loc) { if (backup_poolset(ppc, loc, 0)) { location_release(loc); ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "cannot perform backup"); } location_release(loc); loc->step = CHECK_STEP_COMPLETE; return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); int poolset; }; static const struct step steps[] = { { .check = backup_nonpoolset_requirements, .poolset = false, }, { .fix = backup_nonpoolset_overwrite, .poolset = false, }, { .check = backup_nonpoolset_create, .poolset = false }, { .check = backup_poolset_requirements, .poolset = true, }, { .fix = backup_poolset_overwrite, .poolset = true, }, { .check = backup_poolset_create, .poolset = true }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); const struct step *step = &steps[loc->step++]; if (step->poolset == 0 && ppc->pool->params.is_poolset == 1) return 0; if (!step->fix) return step->check(ppc, loc); if (!check_has_answer(ppc->data)) return 0; if (check_answer_loop(ppc, loc, NULL, 1, step->fix)) return -1; ppc->result = CHECK_RESULT_CONSISTENT; return 0; } /* * check_backup -- perform backup if requested and needed */ void check_backup(PMEMpoolcheck *ppc) { LOG(3, "backup_path %s", ppc->backup_path); if (ppc->backup_path == NULL) return; location *loc = check_get_step_data(ppc->data); /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc)) break; } }
9,483
22.889169
103
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_btt_info.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_btt_info.c -- check BTT Info */ #include <stdlib.h> #include <stdint.h> #include <endian.h> #include "out.h" #include "btt.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum question { Q_RESTORE_FROM_BACKUP, Q_REGENERATE, Q_REGENERATE_CHECKSUM, Q_RESTORE_FROM_HEADER }; /* * location_release -- (internal) release check_btt_info_loc allocations */ static void location_release(location *loc) { free(loc->arenap); loc->arenap = NULL; } /* * btt_info_checksum -- (internal) check BTT Info checksum */ static int btt_info_checksum(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); loc->arenap = calloc(1, sizeof(struct arena)); if (!loc->arenap) { ERR("!calloc"); ppc->result = CHECK_RESULT_INTERNAL_ERROR; CHECK_ERR(ppc, "cannot allocate memory for arena"); goto error_cleanup; } /* read the BTT Info header at well known offset */ if (pool_read(ppc->pool, &loc->arenap->btt_info, sizeof(loc->arenap->btt_info), loc->offset)) { CHECK_ERR(ppc, "arena %u: cannot read BTT Info header", loc->arenap->id); ppc->result = CHECK_RESULT_ERROR; goto error_cleanup; } loc->arenap->id = ppc->pool->narenas; /* BLK is consistent even without BTT Layout */ if (ppc->pool->params.type == POOL_TYPE_BLK) { int is_zeroed = util_is_zeroed((const void *) &loc->arenap->btt_info, sizeof(loc->arenap->btt_info)); if (is_zeroed) { CHECK_INFO(ppc, "BTT Layout not written"); loc->step = CHECK_STEP_COMPLETE; ppc->pool->blk_no_layout = 1; location_release(loc); check_end(ppc->data); return 0; } } /* check consistency of BTT Info */ if (pool_btt_info_valid(&loc->arenap->btt_info)) { CHECK_INFO(ppc, "arena %u: BTT Info header checksum correct", loc->arenap->id); loc->valid.btti_header = 1; } else if (CHECK_IS_NOT(ppc, REPAIR)) { CHECK_ERR(ppc, "arena %u: BTT Info header checksum incorrect", loc->arenap->id); ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); goto error_cleanup; } return 0; error_cleanup: location_release(loc); return -1; } /* * btt_info_backup -- (internal) check BTT Info backup */ static int btt_info_backup(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); /* check BTT Info backup consistency */ const size_t btt_info_size = sizeof(ppc->pool->bttc.btt_info); uint64_t btt_info_off = pool_next_arena_offset(ppc->pool, loc->offset) - btt_info_size; if (pool_read(ppc->pool, &ppc->pool->bttc.btt_info, btt_info_size, btt_info_off)) { CHECK_ERR(ppc, "arena %u: cannot read BTT Info backup", loc->arenap->id); goto error; } /* check whether this BTT Info backup is valid */ if (pool_btt_info_valid(&ppc->pool->bttc.btt_info)) { loc->valid.btti_backup = 1; /* restore BTT Info from backup */ if (!loc->valid.btti_header && CHECK_IS(ppc, REPAIR)) CHECK_ASK(ppc, Q_RESTORE_FROM_BACKUP, "arena %u: BTT " "Info header checksum incorrect.|Restore BTT " "Info from backup?", loc->arenap->id); } /* * if BTT Info backup require repairs it will be fixed in further steps */ return check_questions_sequence_validate(ppc); error: ppc->result = CHECK_RESULT_ERROR; location_release(loc); return -1; } /* * btt_info_from_backup_fix -- (internal) fix BTT Info using its backup */ static int btt_info_from_backup_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); ASSERTeq(ctx, NULL); ASSERTne(loc, NULL); switch (question) { case Q_RESTORE_FROM_BACKUP: CHECK_INFO(ppc, "arena %u: restoring BTT Info header from backup", loc->arenap->id); memcpy(&loc->arenap->btt_info, &ppc->pool->bttc.btt_info, sizeof(loc->arenap->btt_info)); loc->valid.btti_header = 1; break; default: ERR("not implemented question id: %u", question); } return 0; } /* * btt_info_gen -- (internal) ask whether try to regenerate BTT Info */ static int btt_info_gen(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (loc->valid.btti_header) return 0; ASSERT(CHECK_IS(ppc, REPAIR)); if (!loc->pool_valid.btti_offset) { ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); return CHECK_ERR(ppc, "can not find any valid BTT Info"); } CHECK_ASK(ppc, Q_REGENERATE, "arena %u: BTT Info header checksum incorrect.|Do you want to " "regenerate BTT Info?", loc->arenap->id); return check_questions_sequence_validate(ppc); } /* * btt_info_gen_fix -- (internal) fix by regenerating BTT Info */ static int btt_info_gen_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); ASSERTeq(ctx, NULL); ASSERTne(loc, NULL); switch (question) { case Q_REGENERATE: CHECK_INFO(ppc, "arena %u: regenerating BTT Info header", loc->arenap->id); /* * We do not have valid BTT Info backup so we get first valid * BTT Info and try to calculate BTT Info for current arena */ uint64_t arena_size = ppc->pool->set_file->size - loc->offset; if (arena_size > BTT_MAX_ARENA) arena_size = BTT_MAX_ARENA; uint64_t space_left = ppc->pool->set_file->size - loc->offset - arena_size; struct btt_info *bttd = &loc->arenap->btt_info; struct btt_info *btts = &loc->pool_valid.btti; btt_info_convert2h(bttd); /* * all valid BTT Info structures have the same signature, UUID, * parent UUID, flags, major, minor, external LBA size, internal * LBA size, nfree, info size and data offset */ memcpy(bttd->sig, btts->sig, BTTINFO_SIG_LEN); memcpy(bttd->uuid, btts->uuid, BTTINFO_UUID_LEN); memcpy(bttd->parent_uuid, btts->parent_uuid, BTTINFO_UUID_LEN); memset(bttd->unused, 0, BTTINFO_UNUSED_LEN); bttd->flags = btts->flags; bttd->major = btts->major; bttd->minor = btts->minor; /* other parameters can be calculated */ if (btt_info_set(bttd, btts->external_lbasize, btts->nfree, arena_size, space_left)) { CHECK_ERR(ppc, "can not restore BTT Info"); return -1; } ASSERTeq(bttd->external_lbasize, btts->external_lbasize); ASSERTeq(bttd->internal_lbasize, btts->internal_lbasize); ASSERTeq(bttd->nfree, btts->nfree); ASSERTeq(bttd->infosize, btts->infosize); ASSERTeq(bttd->dataoff, btts->dataoff); return 0; default: ERR("not implemented question id: %u", question); return -1; } } /* * btt_info_checksum_retry -- (internal) check BTT Info checksum */ static int btt_info_checksum_retry(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (loc->valid.btti_header) return 0; btt_info_convert2le(&loc->arenap->btt_info); /* check consistency of BTT Info */ if (pool_btt_info_valid(&loc->arenap->btt_info)) { CHECK_INFO(ppc, "arena %u: BTT Info header checksum correct", loc->arenap->id); loc->valid.btti_header = 1; return 0; } if (CHECK_IS_NOT(ppc, ADVANCED)) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; CHECK_INFO(ppc, REQUIRE_ADVANCED); CHECK_ERR(ppc, "arena %u: BTT Info header checksum incorrect", loc->arenap->id); check_end(ppc->data); goto error_cleanup; } CHECK_ASK(ppc, Q_REGENERATE_CHECKSUM, "arena %u: BTT Info header checksum incorrect.|Do you want to " "regenerate BTT Info checksum?", loc->arenap->id); return check_questions_sequence_validate(ppc); error_cleanup: location_release(loc); return -1; } /* * btt_info_checksum_fix -- (internal) fix by regenerating BTT Info checksum */ static int btt_info_checksum_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); ASSERTeq(ctx, NULL); ASSERTne(loc, NULL); switch (question) { case Q_REGENERATE_CHECKSUM: util_checksum(&loc->arenap->btt_info, sizeof(struct btt_info), &loc->arenap->btt_info.checksum, 1, 0); loc->valid.btti_header = 1; break; default: ERR("not implemented question id: %u", question); } return 0; } /* * btt_info_backup_checksum -- (internal) check BTT Info backup checksum */ static int btt_info_backup_checksum(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); ASSERT(loc->valid.btti_header); if (loc->valid.btti_backup) return 0; /* BTT Info backup is not valid so it must be fixed */ if (CHECK_IS_NOT(ppc, REPAIR)) { CHECK_ERR(ppc, "arena %u: BTT Info backup checksum incorrect", loc->arenap->id); ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); goto error_cleanup; } CHECK_ASK(ppc, Q_RESTORE_FROM_HEADER, "arena %u: BTT Info backup checksum incorrect.|Do you want to " "restore it from BTT Info header?", loc->arenap->id); return check_questions_sequence_validate(ppc); error_cleanup: location_release(loc); return -1; } /* * btt_info_backup_fix -- (internal) prepare restore BTT Info backup from header */ static int btt_info_backup_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); ASSERTeq(ctx, NULL); ASSERTne(loc, NULL); switch (question) { case Q_RESTORE_FROM_HEADER: /* BTT Info backup would be restored in check_write step */ CHECK_INFO(ppc, "arena %u: restoring BTT Info backup from header", loc->arenap->id); break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); }; static const struct step steps[] = { { .check = btt_info_checksum, }, { .check = btt_info_backup, }, { .fix = btt_info_from_backup_fix, }, { .check = btt_info_gen, }, { .fix = btt_info_gen_fix, }, { .check = btt_info_checksum_retry, }, { .fix = btt_info_checksum_fix, }, { .check = btt_info_backup_checksum, }, { .fix = btt_info_backup_fix, }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); const struct step *step = &steps[loc->step++]; if (!step->fix) return step->check(ppc, loc); if (!check_answer_loop(ppc, loc, NULL, 1, step->fix)) return 0; if (check_has_error(ppc->data)) location_release(loc); return -1; } /* * check_btt_info -- entry point for btt info check */ void check_btt_info(PMEMpoolcheck *ppc) { LOG(3, NULL); location *loc = check_get_step_data(ppc->data); uint64_t nextoff = 0; /* initialize check */ if (!loc->offset) { CHECK_INFO(ppc, "checking BTT Info headers"); loc->offset = BTT_ALIGNMENT; if (ppc->pool->params.type == POOL_TYPE_BLK) loc->offset += BTT_ALIGNMENT; loc->pool_valid.btti_offset = pool_get_first_valid_btt( ppc->pool, &loc->pool_valid.btti, loc->offset, NULL); /* Without valid BTT Info we can not proceed */ if (!loc->pool_valid.btti_offset) { if (ppc->pool->params.type == POOL_TYPE_BTT) { CHECK_ERR(ppc, "can not find any valid BTT Info"); ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); return; } } else btt_info_convert2h(&loc->pool_valid.btti); } do { /* jump to next offset */ if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS) { loc->offset += nextoff; loc->step = 0; loc->valid.btti_header = 0; loc->valid.btti_backup = 0; } /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc) || ppc->pool->blk_no_layout == 1) return; } /* save offset and insert BTT to cache for next steps */ loc->arenap->offset = loc->offset; loc->arenap->valid = true; check_insert_arena(ppc, loc->arenap); nextoff = le64toh(loc->arenap->btt_info.nextoff); } while (nextoff > 0); }
13,144
23.524254
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_util.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_util.c -- check utility functions */ #include <stdio.h> #include <stdint.h> #include "out.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" #define CHECK_END UINT_MAX /* separate info part of message from question part of message */ #define MSG_SEPARATOR '|' /* error part of message must have '.' at the end */ #define MSG_PLACE_OF_SEPARATION '.' #define MAX_MSG_STR_SIZE 8192 #define CHECK_ANSWER_YES "yes" #define CHECK_ANSWER_NO "no" #define STR_MAX 256 #define TIME_STR_FMT "%a %b %d %Y %H:%M:%S" #define UUID_STR_MAX 37 enum check_answer { PMEMPOOL_CHECK_ANSWER_EMPTY, PMEMPOOL_CHECK_ANSWER_YES, PMEMPOOL_CHECK_ANSWER_NO, PMEMPOOL_CHECK_ANSWER_DEFAULT, }; /* queue of check statuses */ struct check_status { TAILQ_ENTRY(check_status) next; struct pmempool_check_status status; unsigned question; enum check_answer answer; char *msg; }; TAILQ_HEAD(check_status_head, check_status); /* check control context */ struct check_data { unsigned step; location step_data; struct check_status *error; struct check_status_head infos; struct check_status_head questions; struct check_status_head answers; struct check_status *check_status_cache; }; /* * check_data_alloc -- allocate and initialize check_data structure */ struct check_data * check_data_alloc(void) { LOG(3, NULL); struct check_data *data = calloc(1, sizeof(*data)); if (data == NULL) { ERR("!calloc"); return NULL; } TAILQ_INIT(&data->infos); TAILQ_INIT(&data->questions); TAILQ_INIT(&data->answers); return data; } /* * check_data_free -- clean and deallocate check_data */ void check_data_free(struct check_data *data) { LOG(3, NULL); if (data->error != NULL) { free(data->error); data->error = NULL; } if (data->check_status_cache != NULL) { free(data->check_status_cache); data->check_status_cache = NULL; } while (!TAILQ_EMPTY(&data->infos)) { struct check_status *statp = TAILQ_FIRST(&data->infos); TAILQ_REMOVE(&data->infos, statp, next); free(statp); } while (!TAILQ_EMPTY(&data->questions)) { struct check_status *statp = TAILQ_FIRST(&data->questions); TAILQ_REMOVE(&data->questions, statp, next); free(statp); } while (!TAILQ_EMPTY(&data->answers)) { struct check_status *statp = TAILQ_FIRST(&data->answers); TAILQ_REMOVE(&data->answers, statp, next); free(statp); } free(data); } /* * check_step_get - return current check step number */ uint32_t check_step_get(struct check_data *data) { return data->step; } /* * check_step_inc -- move to next step number */ void check_step_inc(struct check_data *data) { if (check_is_end_util(data)) return; ++data->step; memset(&data->step_data, 0, sizeof(location)); } /* * check_get_step_data -- return pointer to check step data */ location * check_get_step_data(struct check_data *data) { return &data->step_data; } /* * check_end -- mark check as ended */ void check_end(struct check_data *data) { LOG(3, NULL); data->step = CHECK_END; } /* * check_is_end_util -- return if check has ended */ int check_is_end_util(struct check_data *data) { return data->step == CHECK_END; } /* * status_alloc -- (internal) allocate and initialize check_status */ static inline struct check_status * status_alloc(void) { struct check_status *status = malloc(sizeof(*status)); if (!status) FATAL("!malloc"); status->msg = malloc(sizeof(char) * MAX_MSG_STR_SIZE); if (!status->msg) { free(status); FATAL("!malloc"); } status->status.str.msg = status->msg; status->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; status->question = CHECK_INVALID_QUESTION; return status; } /* * status_release -- (internal) release check_status */ static void status_release(struct check_status *status) { #ifdef _WIN32 /* dealloc duplicate string after conversion */ if (status->status.str.msg != status->msg) free((void *)status->status.str.msg); #endif free(status->msg); free(status); } /* * status_msg_info_only -- (internal) separate info part of the message * * If message is in form of "info.|question" it modifies it as follows * "info\0|question" */ static inline int status_msg_info_only(const char *msg) { char *sep = strchr(msg, MSG_SEPARATOR); if (sep) { ASSERTne(sep, msg); --sep; ASSERTeq(*sep, MSG_PLACE_OF_SEPARATION); *sep = '\0'; return 0; } return -1; } /* * status_msg_info_and_question -- (internal) join info and question * * If message is in form "info.|question" it will replace MSG_SEPARATOR '|' with * space to get "info. question" */ static inline int status_msg_info_and_question(const char *msg) { char *sep = strchr(msg, MSG_SEPARATOR); if (sep) { *sep = ' '; return 0; } return -1; } /* * status_push -- (internal) push single status object */ static int status_push(PMEMpoolcheck *ppc, struct check_status *st, uint32_t question) { if (st->status.type == PMEMPOOL_CHECK_MSG_TYPE_ERROR) { ASSERTeq(ppc->data->error, NULL); ppc->data->error = st; return -1; } else if (st->status.type == PMEMPOOL_CHECK_MSG_TYPE_INFO) { if (CHECK_IS(ppc, VERBOSE)) TAILQ_INSERT_TAIL(&ppc->data->infos, st, next); else check_status_release(ppc, st); return 0; } /* st->status.type == PMEMPOOL_CHECK_MSG_TYPE_QUESTION */ if (CHECK_IS_NOT(ppc, REPAIR)) { /* error status */ if (status_msg_info_only(st->msg)) { ERR("no error message for the user"); st->msg[0] = '\0'; } st->status.type = PMEMPOOL_CHECK_MSG_TYPE_ERROR; return status_push(ppc, st, question); } if (CHECK_IS(ppc, ALWAYS_YES)) { if (!status_msg_info_only(st->msg)) { /* information status */ st->status.type = PMEMPOOL_CHECK_MSG_TYPE_INFO; status_push(ppc, st, question); st = status_alloc(); } /* answer status */ ppc->result = CHECK_RESULT_PROCESS_ANSWERS; st->question = question; st->answer = PMEMPOOL_CHECK_ANSWER_YES; st->status.type = PMEMPOOL_CHECK_MSG_TYPE_QUESTION; TAILQ_INSERT_TAIL(&ppc->data->answers, st, next); } else { /* question message */ status_msg_info_and_question(st->msg); st->question = question; ppc->result = CHECK_RESULT_ASK_QUESTIONS; st->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; TAILQ_INSERT_TAIL(&ppc->data->questions, st, next); } return 0; } /* * check_status_create -- create single status, push it to proper queue * * MSG_SEPARATOR character in fmt is treated as message separator. If creating * question but check arguments do not allow to make any changes (asking any * question is pointless) it takes part of message before MSG_SEPARATOR * character and use it to create error message. Character just before separator * must be a MSG_PLACE_OF_SEPARATION character. Return non 0 value if error * status would be created. * * The arg is an additional argument for specified type of status. */ int check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type, uint32_t arg, const char *fmt, ...) { if (CHECK_IS_NOT(ppc, VERBOSE) && type == PMEMPOOL_CHECK_MSG_TYPE_INFO) return 0; struct check_status *st = status_alloc(); ASSERT(CHECK_IS(ppc, FORMAT_STR)); va_list ap; va_start(ap, fmt); int p = vsnprintf(st->msg, MAX_MSG_STR_SIZE, fmt, ap); va_end(ap); /* append possible strerror at the end of the message */ if (type != PMEMPOOL_CHECK_MSG_TYPE_QUESTION && arg && p > 0) { char buff[UTIL_MAX_ERR_MSG]; util_strerror((int)arg, buff, UTIL_MAX_ERR_MSG); int ret = snprintf(st->msg + p, MAX_MSG_STR_SIZE - (size_t)p, ": %s", buff); if (ret < 0 || ret >= (int)(MAX_MSG_STR_SIZE - (size_t)p)) { ERR("snprintf: %d", ret); free(st); return -1; } } st->status.type = type; return status_push(ppc, st, arg); } /* * check_status_release -- release single status object */ void check_status_release(PMEMpoolcheck *ppc, struct check_status *status) { if (status->status.type == PMEMPOOL_CHECK_MSG_TYPE_ERROR) ppc->data->error = NULL; status_release(status); } /* * pop_status -- (internal) pop single message from check_status queue */ static struct check_status * pop_status(struct check_data *data, struct check_status_head *queue) { if (!TAILQ_EMPTY(queue)) { ASSERTeq(data->check_status_cache, NULL); data->check_status_cache = TAILQ_FIRST(queue); TAILQ_REMOVE(queue, data->check_status_cache, next); return data->check_status_cache; } return NULL; } /* * check_pop_question -- pop single question from questions queue */ struct check_status * check_pop_question(struct check_data *data) { return pop_status(data, &data->questions); } /* * check_pop_info -- pop single info from information queue */ struct check_status * check_pop_info(struct check_data *data) { return pop_status(data, &data->infos); } /* * check_pop_error -- pop error from state */ struct check_status * check_pop_error(struct check_data *data) { if (data->error) { ASSERTeq(data->check_status_cache, NULL); data->check_status_cache = data->error; data->error = NULL; return data->check_status_cache; } return NULL; } #ifdef _WIN32 void cache_to_utf8(struct check_data *data, char *buf, size_t size) { if (data->check_status_cache == NULL) return; struct check_status *status = data->check_status_cache; /* if it was a question, convert it and the answer to utf8 */ if (status->status.type == PMEMPOOL_CHECK_MSG_TYPE_QUESTION) { struct pmempool_check_statusW *wstatus = (struct pmempool_check_statusW *)&status->status; wchar_t *wstring = (wchar_t *)wstatus->str.msg; status->status.str.msg = util_toUTF8(wstring); if (status->status.str.msg == NULL) FATAL("!malloc"); util_free_UTF16(wstring); if (util_toUTF8_buff(wstatus->str.answer, buf, size) != 0) FATAL("Invalid answer conversion %s", out_get_errormsg()); status->status.str.answer = buf; } } #endif /* * check_clear_status_cache -- release check_status from cache */ void check_clear_status_cache(struct check_data *data) { if (data->check_status_cache) { switch (data->check_status_cache->status.type) { case PMEMPOOL_CHECK_MSG_TYPE_INFO: case PMEMPOOL_CHECK_MSG_TYPE_ERROR: /* * Info and error statuses are disposable. After showing * them to the user we have to release them. */ status_release(data->check_status_cache); data->check_status_cache = NULL; break; case PMEMPOOL_CHECK_MSG_TYPE_QUESTION: /* * Question status after being showed to the user carry * users answer. It must be kept till answer would be * processed so it can not be released from cache. It * has to be pushed to the answers queue, processed and * released after that. */ break; default: ASSERT(0); } } } /* * status_answer_push -- (internal) push single answer to answers queue */ static void status_answer_push(struct check_data *data, struct check_status *st) { ASSERTeq(st->status.type, PMEMPOOL_CHECK_MSG_TYPE_QUESTION); TAILQ_INSERT_TAIL(&data->answers, st, next); } /* * check_push_answer -- process answer and push it to answers queue */ int check_push_answer(PMEMpoolcheck *ppc) { if (ppc->data->check_status_cache == NULL) return 0; /* check if answer is "yes" or "no" */ struct check_status *status = ppc->data->check_status_cache; if (status->status.str.answer != NULL) { if (strcmp(status->status.str.answer, CHECK_ANSWER_YES) == 0) status->answer = PMEMPOOL_CHECK_ANSWER_YES; else if (strcmp(status->status.str.answer, CHECK_ANSWER_NO) == 0) status->answer = PMEMPOOL_CHECK_ANSWER_NO; } if (status->answer == PMEMPOOL_CHECK_ANSWER_EMPTY) { /* invalid answer provided */ status_answer_push(ppc->data, ppc->data->check_status_cache); ppc->data->check_status_cache = NULL; CHECK_INFO(ppc, "Answer must be either %s or %s", CHECK_ANSWER_YES, CHECK_ANSWER_NO); return -1; } /* push answer */ TAILQ_INSERT_TAIL(&ppc->data->answers, ppc->data->check_status_cache, next); ppc->data->check_status_cache = NULL; return 0; } /* * check_has_error - check if error exists */ bool check_has_error(struct check_data *data) { return data->error != NULL; } /* * check_has_answer - check if any answer exists */ bool check_has_answer(struct check_data *data) { return !TAILQ_EMPTY(&data->answers); } /* * pop_answer -- (internal) pop single answer from answers queue */ static struct check_status * pop_answer(struct check_data *data) { struct check_status *ret = NULL; if (!TAILQ_EMPTY(&data->answers)) { ret = TAILQ_FIRST(&data->answers); TAILQ_REMOVE(&data->answers, ret, next); } return ret; } /* * check_status_get_util -- extract pmempool_check_status from check_status */ struct pmempool_check_status * check_status_get_util(struct check_status *status) { return &status->status; } /* * check_answer_loop -- loop through all available answers and process them */ int check_answer_loop(PMEMpoolcheck *ppc, location *data, void *ctx, int fail_on_no, int (*callback)(PMEMpoolcheck *, location *, uint32_t, void *ctx)) { struct check_status *answer; while ((answer = pop_answer(ppc->data)) != NULL) { /* if answer is "no" we cannot fix an issue */ if (answer->answer != PMEMPOOL_CHECK_ANSWER_YES) { if (fail_on_no || answer->answer != PMEMPOOL_CHECK_ANSWER_NO) { CHECK_ERR(ppc, "cannot complete repair, reverting changes"); ppc->result = CHECK_RESULT_NOT_CONSISTENT; goto error; } ppc->result = CHECK_RESULT_REPAIRED; check_status_release(ppc, answer); continue; } /* perform fix */ if (callback(ppc, data, answer->question, ctx)) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; goto error; } if (ppc->result == CHECK_RESULT_ERROR) goto error; /* fix succeeded */ ppc->result = CHECK_RESULT_REPAIRED; check_status_release(ppc, answer); } return 0; error: check_status_release(ppc, answer); return -1; } /* * check_questions_sequence_validate -- generate return value from result * * Sequence of questions can result in one of the following results: CONSISTENT, * REPAIRED, ASK_QUESTIONS of PROCESS_ANSWERS. If result == ASK_QUESTIONS it * returns -1 to indicate existence of unanswered questions. */ int check_questions_sequence_validate(PMEMpoolcheck *ppc) { ASSERT(ppc->result == CHECK_RESULT_CONSISTENT || ppc->result == CHECK_RESULT_ASK_QUESTIONS || ppc->result == CHECK_RESULT_PROCESS_ANSWERS || ppc->result == CHECK_RESULT_REPAIRED); if (ppc->result == CHECK_RESULT_ASK_QUESTIONS) { ASSERT(!TAILQ_EMPTY(&ppc->data->questions)); return -1; } return 0; } /* * check_get_time_str -- returns time in human-readable format */ const char * check_get_time_str(time_t time) { static char str_buff[STR_MAX] = {0, }; struct tm *tm = util_localtime(&time); if (tm) strftime(str_buff, STR_MAX, TIME_STR_FMT, tm); else { int ret = snprintf(str_buff, STR_MAX, "unknown"); if (ret < 0) { ERR("failed to get time str"); return ""; } } return str_buff; } /* * check_get_uuid_str -- returns uuid in human readable format */ const char * check_get_uuid_str(uuid_t uuid) { static char uuid_str[UUID_STR_MAX] = {0, }; int ret = util_uuid_to_string(uuid, uuid_str); if (ret != 0) { ERR("failed to covert uuid to string"); return ""; } return uuid_str; } /* * pmempool_check_insert_arena -- insert arena to list */ void check_insert_arena(PMEMpoolcheck *ppc, struct arena *arenap) { TAILQ_INSERT_TAIL(&ppc->pool->arenas, arenap, next); ppc->pool->narenas++; }
16,996
23.316166
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/pool.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pool.h -- internal definitions for pool processing functions */ #ifndef POOL_H #define POOL_H #include <stdbool.h> #include <sys/types.h> #include "libpmemobj.h" #include "libpmemcto.h" #include "queue.h" #include "set.h" #include "log.h" #include "blk.h" #include "btt_layout.h" #include "cto.h" #ifdef __cplusplus extern "C" { #endif enum pool_type { POOL_TYPE_UNKNOWN = (1 << 0), POOL_TYPE_LOG = (1 << 1), POOL_TYPE_BLK = (1 << 2), POOL_TYPE_OBJ = (1 << 3), POOL_TYPE_BTT = (1 << 4), POOL_TYPE_CTO = (1 << 5), POOL_TYPE_ANY = POOL_TYPE_UNKNOWN | POOL_TYPE_LOG | POOL_TYPE_BLK | POOL_TYPE_OBJ | POOL_TYPE_BTT | POOL_TYPE_CTO, }; struct pool_params { enum pool_type type; char signature[POOL_HDR_SIG_LEN]; features_t features; size_t size; mode_t mode; int is_poolset; int is_part; int is_dev_dax; int is_pmem; union { struct { uint64_t bsize; } blk; struct { char layout[PMEMOBJ_MAX_LAYOUT]; } obj; struct { char layout[PMEMCTO_MAX_LAYOUT]; } cto; }; }; struct pool_set_file { int fd; char *fname; void *addr; size_t size; struct pool_set *poolset; time_t mtime; mode_t mode; }; struct arena { TAILQ_ENTRY(arena) next; struct btt_info btt_info; uint32_t id; bool valid; bool zeroed; uint64_t offset; uint8_t *flog; size_t flogsize; uint32_t *map; size_t mapsize; }; struct pool_data { struct pool_params params; struct pool_set_file *set_file; int blk_no_layout; union { struct pool_hdr pool; struct pmemlog log; struct pmemblk blk; struct pmemcto cto; } hdr; enum { UUID_NOP = 0, UUID_FROM_BTT, UUID_NOT_FROM_BTT, } uuid_op; struct arena bttc; TAILQ_HEAD(arenashead, arena) arenas; uint32_t narenas; }; struct pool_data *pool_data_alloc(PMEMpoolcheck *ppc); void pool_data_free(struct pool_data *pool); void pool_params_from_header(struct pool_params *params, const struct pool_hdr *hdr); int pool_set_parse(struct pool_set **setp, const char *path); void *pool_set_file_map(struct pool_set_file *file, uint64_t offset); int pool_read(struct pool_data *pool, void *buff, size_t nbytes, uint64_t off); int pool_write(struct pool_data *pool, const void *buff, size_t nbytes, uint64_t off); int pool_copy(struct pool_data *pool, const char *dst_path, int overwrite); int pool_set_part_copy(struct pool_set_part *dpart, struct pool_set_part *spart, int overwrite); int pool_memset(struct pool_data *pool, uint64_t off, int c, size_t count); unsigned pool_set_files_count(struct pool_set_file *file); int pool_set_file_map_headers(struct pool_set_file *file, int rdonly, int prv); void pool_set_file_unmap_headers(struct pool_set_file *file); void pool_hdr_default(enum pool_type type, struct pool_hdr *hdrp); enum pool_type pool_hdr_get_type(const struct pool_hdr *hdrp); enum pool_type pool_set_type(struct pool_set *set); const char *pool_get_pool_type_str(enum pool_type type); int pool_btt_info_valid(struct btt_info *infop); int pool_blk_get_first_valid_arena(struct pool_data *pool, struct arena *arenap); int pool_blk_bsize_valid(uint32_t bsize, uint64_t fsize); uint64_t pool_next_arena_offset(struct pool_data *pool, uint64_t header_offset); uint64_t pool_get_first_valid_btt(struct pool_data *pool, struct btt_info *infop, uint64_t offset, bool *zeroed); size_t pool_get_min_size(enum pool_type); #ifdef __cplusplus } #endif #endif
4,963
27.365714
80
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_write.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_write.c -- write fixed data back */ #include <stdint.h> #include <endian.h> #include "out.h" #include "btt.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum questions { Q_REPAIR_MAP, Q_REPAIR_FLOG, }; /* * log_write -- (internal) write all structures for log pool */ static int log_write(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (CHECK_WITHOUT_FIXING(ppc)) return 0; /* endianness conversion */ struct pmemlog *log = &ppc->pool->hdr.log; log_convert2le(log); if (pool_write(ppc->pool, log, sizeof(*log), 0)) { ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "writing pmemlog structure failed"); } return 0; } /* * blk_write_flog -- (internal) convert and write flog to file */ static int blk_write_flog(PMEMpoolcheck *ppc, struct arena *arenap) { if (!arenap->flog) { ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "flog is missing"); } uint64_t flogoff = arenap->offset + arenap->btt_info.flogoff; uint8_t *ptr = arenap->flog; uint32_t i; for (i = 0; i < arenap->btt_info.nfree; i++) { struct btt_flog *flog = (struct btt_flog *)ptr; btt_flog_convert2le(&flog[0]); btt_flog_convert2le(&flog[1]); ptr += BTT_FLOG_PAIR_ALIGN; } if (pool_write(ppc->pool, arenap->flog, arenap->flogsize, flogoff)) { CHECK_INFO(ppc, "%s", ppc->path); ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "arena %u: writing BTT FLOG failed\n", arenap->id); } return 0; } /* * blk_write_map -- (internal) convert and write map to file */ static int blk_write_map(PMEMpoolcheck *ppc, struct arena *arenap) { if (!arenap->map) { ppc->result = CHECK_RESULT_ERROR; return CHECK_ERR(ppc, "map is missing"); } uint64_t mapoff = arenap->offset + arenap->btt_info.mapoff; uint32_t i; for (i = 0; i < arenap->btt_info.external_nlba; i++) arenap->map[i] = htole32(arenap->map[i]); if (pool_write(ppc->pool, arenap->map, arenap->mapsize, mapoff)) { CHECK_INFO(ppc, "%s", ppc->path); ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "arena %u: writing BTT map failed\n", arenap->id); } return 0; } /* * blk_write -- (internal) write all structures for blk pool */ static int blk_write(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (CHECK_WITHOUT_FIXING(ppc)) return 0; /* endianness conversion */ ppc->pool->hdr.blk.bsize = htole32(ppc->pool->hdr.blk.bsize); if (pool_write(ppc->pool, &ppc->pool->hdr.blk, sizeof(ppc->pool->hdr.blk), 0)) { CHECK_INFO(ppc, "%s", ppc->path); ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "writing pmemblk structure failed"); } return 0; } /* * btt_data_write -- (internal) write BTT data */ static int btt_data_write(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); struct arena *arenap; TAILQ_FOREACH(arenap, &ppc->pool->arenas, next) { if (ppc->pool->uuid_op == UUID_NOT_FROM_BTT) { memcpy(arenap->btt_info.parent_uuid, ppc->pool->hdr.pool.poolset_uuid, sizeof(arenap->btt_info.parent_uuid)); util_checksum(&arenap->btt_info, sizeof(arenap->btt_info), &arenap->btt_info.checksum, 1, 0); } if (pool_write(ppc->pool, &arenap->btt_info, sizeof(arenap->btt_info), arenap->offset)) { CHECK_INFO(ppc, "%s", ppc->path); CHECK_ERR(ppc, "arena %u: writing BTT Info failed", arenap->id); goto error; } if (pool_write(ppc->pool, &arenap->btt_info, sizeof(arenap->btt_info), arenap->offset + le64toh(arenap->btt_info.infooff))) { CHECK_INFO(ppc, "%s", ppc->path); CHECK_ERR(ppc, "arena %u: writing BTT Info backup failed", arenap->id); goto error; } if (blk_write_flog(ppc, arenap)) goto error; if (blk_write_map(ppc, arenap)) goto error; } return 0; error: ppc->result = CHECK_RESULT_CANNOT_REPAIR; return -1; } /* * cto_write -- (internal) write all structures for pmemcto pool */ static int cto_write(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); if (CHECK_WITHOUT_FIXING(ppc)) return 0; if (pool_write(ppc->pool, &ppc->pool->hdr.cto, sizeof(ppc->pool->hdr.cto), 0)) { CHECK_INFO(ppc, "%s", ppc->path); ppc->result = CHECK_RESULT_CANNOT_REPAIR; return CHECK_ERR(ppc, "writing pmemcto structure failed"); } return 0; } struct step { int (*func)(PMEMpoolcheck *, location *loc); enum pool_type type; }; static const struct step steps[] = { { .func = log_write, .type = POOL_TYPE_LOG, }, { .func = blk_write, .type = POOL_TYPE_BLK, }, { .func = cto_write, .type = POOL_TYPE_CTO, }, { .func = btt_data_write, .type = POOL_TYPE_BLK | POOL_TYPE_BTT, }, { .func = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); const struct step *step = &steps[loc->step++]; /* check step conditions */ if (!(step->type & ppc->pool->params.type)) return 0; return step->func(ppc, loc); } /* * check_write -- write fixed data back */ void check_write(PMEMpoolcheck *ppc) { /* * XXX: Disabling individual checks based on type should be done in the * step structure. This however requires refactor of the step * processing code. */ if (CHECK_IS_NOT(ppc, REPAIR)) return; location *loc = (location *)check_get_step_data(ppc->data); /* do all steps */ while (loc->step != CHECK_STEP_COMPLETE && steps[loc->step].func != NULL) { if (step_exe(ppc, loc)) return; } }
7,165
22.728477
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmempool/check_cto.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check_cto.c -- check pmemcto */ #include <inttypes.h> #include <sys/param.h> #include <endian.h> #include "out.h" #include "libpmempool.h" #include "pmempool.h" #include "pool.h" #include "check_util.h" enum question { Q_CTO_CONSISTENT, Q_CTO_ADDR, Q_CTO_SIZE, Q_CTO_ROOT }; /* * cto_read -- (internal) read pmemcto header */ static int cto_read(PMEMpoolcheck *ppc) { /* * Here we want to read the pmemcto header without the pool_hdr as we've * already done it before. * * Take the pointer to fields right after pool_hdr, compute the size and * offset of remaining fields. */ uint8_t *ptr = (uint8_t *)&ppc->pool->hdr.cto; ptr += sizeof(ppc->pool->hdr.cto.hdr); size_t size = sizeof(ppc->pool->hdr.cto) - sizeof(ppc->pool->hdr.cto.hdr); uint64_t offset = sizeof(ppc->pool->hdr.log.hdr); if (pool_read(ppc->pool, ptr, size, offset)) return CHECK_ERR(ppc, "cannot read pmemcto structure"); return 0; } /* * cto_hdr_check -- (internal) check pmemcto header */ static int cto_hdr_check(PMEMpoolcheck *ppc, location *loc) { LOG(3, NULL); CHECK_INFO(ppc, "checking pmemcto header"); if (cto_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } if (ppc->pool->hdr.cto.consistent == 0) { if (CHECK_ASK(ppc, Q_CTO_CONSISTENT, "pmemcto.consistent flag is not set.|Do you want to set pmemcto.consistent flag?")) goto error; } if ((void *)ppc->pool->hdr.cto.addr == NULL) { if (CHECK_ASK(ppc, Q_CTO_ADDR, "invalid pmemcto.addr: %p.|Do you want to recover pmemcto.addr?", (void *)ppc->pool->hdr.cto.addr)) goto error; } if (ppc->pool->hdr.cto.size < PMEMCTO_MIN_POOL) { CHECK_INFO(ppc, "pmemcto.size is less than minimum: %zu < %zu.", ppc->pool->hdr.cto.size, PMEMCTO_MIN_POOL); } if (ppc->pool->hdr.cto.size != ppc->pool->params.size) { if (CHECK_ASK(ppc, Q_CTO_SIZE, "pmemcto.size is different than pool size: %zu != %zu.|Do you want to set pmemlog.size to the actual pool size?", ppc->pool->hdr.cto.size, ppc->pool->params.size)) goto error; } char *valid_addr_begin = (char *)ppc->pool->hdr.cto.addr + CTO_DSC_SIZE_ALIGNED; char *valid_addr_end = (char *)ppc->pool->hdr.cto.addr + ppc->pool->hdr.cto.size; if ((void *)ppc->pool->hdr.cto.root != NULL && ((char *)ppc->pool->hdr.cto.root < valid_addr_begin || (char *)ppc->pool->hdr.cto.root >= valid_addr_end)) { if (CHECK_ASK(ppc, Q_CTO_ROOT, "invalid pmemcto.root: %p.|Do you want to recover pmemcto.root?", (void *)ppc->pool->hdr.cto.root)) goto error; } if (ppc->result == CHECK_RESULT_CONSISTENT || ppc->result == CHECK_RESULT_REPAIRED) CHECK_INFO(ppc, "pmemcto header correct"); return check_questions_sequence_validate(ppc); error: ppc->result = CHECK_RESULT_NOT_CONSISTENT; check_end(ppc->data); return -1; } /* * cto_hdr_fix -- (internal) fix pmemcto header */ static int cto_hdr_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx) { LOG(3, NULL); switch (question) { case Q_CTO_CONSISTENT: CHECK_INFO(ppc, "setting pmemcto.consistent flag"); ppc->pool->hdr.cto.consistent = 1; break; case Q_CTO_ADDR: CHECK_INFO(ppc, "recovering pmemcto.addr"); ppc->pool->hdr.cto.addr = 0; break; case Q_CTO_SIZE: CHECK_INFO(ppc, "setting pmemcto.size to the actual pool size %zu", ppc->pool->params.size); ppc->pool->hdr.cto.size = ppc->pool->params.size; break; case Q_CTO_ROOT: CHECK_INFO(ppc, "recovering pmemcto.root pointer"); ppc->pool->hdr.cto.root = 0; break; default: ERR("not implemented question id: %u", question); } return 0; } struct step { int (*check)(PMEMpoolcheck *, location *); int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *); enum pool_type type; }; static const struct step steps[] = { { .check = cto_hdr_check, .type = POOL_TYPE_CTO }, { .fix = cto_hdr_fix, .type = POOL_TYPE_CTO }, { .check = NULL, .fix = NULL, }, }; /* * step_exe -- (internal) perform single step according to its parameters */ static inline int step_exe(PMEMpoolcheck *ppc, location *loc) { ASSERT(loc->step < ARRAY_SIZE(steps)); ASSERTeq(ppc->pool->params.type, POOL_TYPE_CTO); const struct step *step = &steps[loc->step++]; if (!(step->type & ppc->pool->params.type)) return 0; if (!step->fix) return step->check(ppc, loc); if (cto_read(ppc)) { ppc->result = CHECK_RESULT_ERROR; return -1; } return check_answer_loop(ppc, loc, NULL, 1, step->fix); } /* * check_ctok -- entry point for pmemcto checks */ void check_cto(PMEMpoolcheck *ppc) { LOG(3, NULL); location *loc = check_get_step_data(ppc->data); /* do all checks */ while (CHECK_NOT_COMPLETE(loc, steps)) { if (step_exe(ppc, loc)) break; } }
6,338
24.873469
117
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/pmem_posix.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem_posix.c -- pmem utilities with Posix implementation */ #include <stddef.h> #include <sys/mman.h> #include "pmem.h" #include "out.h" #include "mmap.h" /* * is_pmem_detect -- implement pmem_is_pmem() * * This function returns true only if the entire range can be confirmed * as being direct access persistent memory. Finding any part of the * range is not direct access, or failing to look up the information * because it is unmapped or because any sort of error happens, just * results in returning false. */ int is_pmem_detect(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); if (len == 0) return 0; int retval = util_range_is_pmem(addr, len); LOG(4, "returning %d", retval); return retval; } /* * pmem_map_register -- memory map file and register mapping */ void * pmem_map_register(int fd, size_t len, const char *path, int is_dev_dax) { LOG(3, "fd %d len %zu path %s id_dev_dax %d", fd, len, path, is_dev_dax); void *addr; int map_sync; addr = util_map(fd, len, MAP_SHARED, 0, 0, &map_sync); if (!addr) return NULL; enum pmem_map_type type = MAX_PMEM_TYPE; if (is_dev_dax) type = PMEM_DEV_DAX; else if (map_sync) type = PMEM_MAP_SYNC; if (type != MAX_PMEM_TYPE) { if (util_range_register(addr, len, path, type)) { LOG(1, "can't track mapped region"); goto err_unmap; } } return addr; err_unmap: util_unmap(addr, len); return NULL; } /* * pmem_os_init -- os-dependent part of pmem initialization */ void pmem_os_init(void) { LOG(3, NULL); }
3,143
27.844037
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/libpmem.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmem.c -- pmem entry points for libpmem */ #include <stdio.h> #include <stdint.h> #include "libpmem.h" #include "pmem.h" #include "pmemcommon.h" /* * libpmem_init -- load-time initialization for libpmem * * Called automatically by the run-time loader. */ ATTR_CONSTRUCTOR void libpmem_init(void) { common_init(PMEM_LOG_PREFIX, PMEM_LOG_LEVEL_VAR, PMEM_LOG_FILE_VAR, PMEM_MAJOR_VERSION, PMEM_MINOR_VERSION); LOG(3, NULL); pmem_init(); } /* * libpmem_fini -- libpmem cleanup routine * * Called automatically when the process terminates. */ ATTR_DESTRUCTOR void libpmem_fini(void) { LOG(3, NULL); common_fini(); } /* * pmem_check_versionU -- see if library meets application version requirements */ #ifndef _WIN32 static inline #endif const char * pmem_check_versionU(unsigned major_required, unsigned minor_required) { LOG(3, "major_required %u minor_required %u", major_required, minor_required); if (major_required != PMEM_MAJOR_VERSION) { ERR("libpmem major version mismatch (need %u, found %u)", major_required, PMEM_MAJOR_VERSION); return out_get_errormsg(); } if (minor_required > PMEM_MINOR_VERSION) { ERR("libpmem minor version mismatch (need %u, found %u)", minor_required, PMEM_MINOR_VERSION); return out_get_errormsg(); } return NULL; } #ifndef _WIN32 /* * pmem_check_version -- see if library meets application version requirements */ const char * pmem_check_version(unsigned major_required, unsigned minor_required) { return pmem_check_versionU(major_required, minor_required); } #else /* * pmem_check_versionW -- see if library meets application version requirements */ const wchar_t * pmem_check_versionW(unsigned major_required, unsigned minor_required) { if (pmem_check_versionU(major_required, minor_required) != NULL) return out_get_errormsgW(); else return NULL; } #endif /* * pmem_errormsgU -- return last error message */ #ifndef _WIN32 static inline #endif const char * pmem_errormsgU(void) { return out_get_errormsg(); } #ifndef _WIN32 /* * pmem_errormsg -- return last error message */ const char * pmem_errormsg(void) { return pmem_errormsgU(); } #else /* * pmem_errormsgW -- return last error message as wchar_t */ const wchar_t * pmem_errormsgW(void) { return out_get_errormsgW(); } #endif
3,902
24.180645
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/memops_generic.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memops_generic.c -- architecture-independent memmove & memset fallback * * This fallback is needed to fulfill guarantee that pmem_mem[cpy|set|move] * will use at least 8-byte stores (for 8-byte aligned buffers and sizes), * even when accelerated implementation is missing or disabled. * This guarantee is needed to maintain correctness eg in pmemobj. * Libc may do the same, but this behavior is not documented, so we can't rely * on that. */ #include <stddef.h> #include "out.h" #include "pmem.h" #include "libpmem.h" #include "util.h" /* * cpy64 -- (internal) copy 64 bytes from src to dst */ static force_inline void cpy64(uint64_t *dst, const uint64_t *src) { /* * We use atomics here just to be sure compiler will not split stores. * Order of stores doesn't matter. */ uint64_t tmp[8]; util_atomic_load_explicit64(&src[0], &tmp[0], memory_order_relaxed); util_atomic_load_explicit64(&src[1], &tmp[1], memory_order_relaxed); util_atomic_load_explicit64(&src[2], &tmp[2], memory_order_relaxed); util_atomic_load_explicit64(&src[3], &tmp[3], memory_order_relaxed); util_atomic_load_explicit64(&src[4], &tmp[4], memory_order_relaxed); util_atomic_load_explicit64(&src[5], &tmp[5], memory_order_relaxed); util_atomic_load_explicit64(&src[6], &tmp[6], memory_order_relaxed); util_atomic_load_explicit64(&src[7], &tmp[7], memory_order_relaxed); util_atomic_store_explicit64(&dst[0], tmp[0], memory_order_relaxed); util_atomic_store_explicit64(&dst[1], tmp[1], memory_order_relaxed); util_atomic_store_explicit64(&dst[2], tmp[2], memory_order_relaxed); util_atomic_store_explicit64(&dst[3], tmp[3], memory_order_relaxed); util_atomic_store_explicit64(&dst[4], tmp[4], memory_order_relaxed); util_atomic_store_explicit64(&dst[5], tmp[5], memory_order_relaxed); util_atomic_store_explicit64(&dst[6], tmp[6], memory_order_relaxed); util_atomic_store_explicit64(&dst[7], tmp[7], memory_order_relaxed); } /* * cpy8 -- (internal) copy 8 bytes from src to dst */ static force_inline void cpy8(uint64_t *dst, const uint64_t *src) { uint64_t tmp; util_atomic_load_explicit64(src, &tmp, memory_order_relaxed); util_atomic_store_explicit64(dst, tmp, memory_order_relaxed); } /* * store8 -- (internal) store 8 bytes */ static force_inline void store8(uint64_t *dst, uint64_t c) { util_atomic_store_explicit64(dst, c, memory_order_relaxed); } /* * memmove_nodrain_generic -- generic memmove to pmem without hw drain */ void * memmove_nodrain_generic(void *dst, const void *src, size_t len, unsigned flags) { LOG(15, "pmemdest %p src %p len %zu flags 0x%x", dst, src, len, flags); char *cdst = dst; const char *csrc = src; size_t remaining; (void) flags; if ((uintptr_t)cdst - (uintptr_t)csrc >= len) { size_t cnt = (uint64_t)cdst & 7; if (cnt > 0) { cnt = 8 - cnt; if (cnt > len) cnt = len; for (size_t i = 0; i < cnt; ++i) cdst[i] = csrc[i]; pmem_flush_flags(cdst, cnt, flags); cdst += cnt; csrc += cnt; len -= cnt; } uint64_t *dst8 = (uint64_t *)cdst; const uint64_t *src8 = (const uint64_t *)csrc; while (len >= 64) { cpy64(dst8, src8); pmem_flush_flags(dst8, 64, flags); len -= 64; dst8 += 8; src8 += 8; } remaining = len; while (len >= 8) { cpy8(dst8, src8); len -= 8; dst8++; src8++; } cdst = (char *)dst8; csrc = (const char *)src8; for (size_t i = 0; i < len; ++i) *cdst++ = *csrc++; if (remaining) pmem_flush_flags(cdst - remaining, remaining, flags); } else { cdst += len; csrc += len; size_t cnt = (uint64_t)cdst & 7; if (cnt > 0) { if (cnt > len) cnt = len; cdst -= cnt; csrc -= cnt; len -= cnt; for (size_t i = cnt; i > 0; --i) cdst[i - 1] = csrc[i - 1]; pmem_flush_flags(cdst, cnt, flags); } uint64_t *dst8 = (uint64_t *)cdst; const uint64_t *src8 = (const uint64_t *)csrc; while (len >= 64) { dst8 -= 8; src8 -= 8; cpy64(dst8, src8); pmem_flush_flags(dst8, 64, flags); len -= 64; } remaining = len; while (len >= 8) { --dst8; --src8; cpy8(dst8, src8); len -= 8; } cdst = (char *)dst8; csrc = (const char *)src8; for (size_t i = len; i > 0; --i) *--cdst = *--csrc; if (remaining) pmem_flush_flags(cdst, remaining, flags); } return dst; } /* * memset_nodrain_generic -- generic memset to pmem without hw drain */ void * memset_nodrain_generic(void *dst, int c, size_t len, unsigned flags) { LOG(15, "pmemdest %p c 0x%x len %zu flags 0x%x", dst, c, len, flags); (void) flags; char *cdst = dst; size_t cnt = (uint64_t)cdst & 7; if (cnt > 0) { cnt = 8 - cnt; if (cnt > len) cnt = len; for (size_t i = 0; i < cnt; ++i) cdst[i] = (char)c; pmem_flush_flags(cdst, cnt, flags); cdst += cnt; len -= cnt; } uint64_t *dst8 = (uint64_t *)cdst; uint64_t u = (unsigned char)c; uint64_t tmp = (u << 56) | (u << 48) | (u << 40) | (u << 32) | (u << 24) | (u << 16) | (u << 8) | u; while (len >= 64) { store8(&dst8[0], tmp); store8(&dst8[1], tmp); store8(&dst8[2], tmp); store8(&dst8[3], tmp); store8(&dst8[4], tmp); store8(&dst8[5], tmp); store8(&dst8[6], tmp); store8(&dst8[7], tmp); pmem_flush_flags(dst8, 64, flags); len -= 64; dst8 += 8; } size_t remaining = len; while (len >= 8) { store8(dst8, tmp); len -= 8; dst8++; } cdst = (char *)dst8; for (size_t i = 0; i < len; ++i) *cdst++ = (char)c; if (remaining) pmem_flush_flags(cdst - remaining, remaining, flags); return dst; }
7,120
25.180147
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/libpmem_main.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmem_main.c -- entry point for libpmem.dll * * XXX - This is a placeholder. All the library initialization/cleanup * that is done in library ctors/dtors, as well as TLS initialization * should be moved here. */ #include "win_mmap.h" void libpmem_init(void); void libpmem_fini(void); int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH: libpmem_init(); win_mmap_init(); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: win_mmap_fini(); libpmem_fini(); break; } return TRUE; }
2,227
32.757576
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/pmem.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem.c -- pmem entry points for libpmem * * * PERSISTENT MEMORY INSTRUCTIONS ON X86 * * The primary feature of this library is to provide a way to flush * changes to persistent memory as outlined below (note that many * of the decisions below are made at initialization time, and not * repeated every time a flush is requested). * * To flush a range to pmem when CLWB is available: * * CLWB for each cache line in the given range. * * SFENCE to ensure the CLWBs above have completed. * * To flush a range to pmem when CLFLUSHOPT is available and CLWB is not * (same as above but issue CLFLUSHOPT instead of CLWB): * * CLFLUSHOPT for each cache line in the given range. * * SFENCE to ensure the CLWBs above have completed. * * To flush a range to pmem when neither CLFLUSHOPT or CLWB are available * (same as above but fences surrounding CLFLUSH are not required): * * CLFLUSH for each cache line in the given range. * * To memcpy a range of memory to pmem when MOVNT is available: * * Copy any non-64-byte portion of the destination using MOV. * * Use the flush flow above without the fence for the copied portion. * * Copy using MOVNTDQ, up to any non-64-byte aligned end portion. * (The MOVNT instructions bypass the cache, so no flush is required.) * * Copy any unaligned end portion using MOV. * * Use the flush flow above for the copied portion (including fence). * * To memcpy a range of memory to pmem when MOVNT is not available: * * Just pass the call to the normal memcpy() followed by pmem_persist(). * * To memset a non-trivial sized range of memory to pmem: * * Same as the memcpy cases above but store the given value instead * of reading values from the source. * * These features are supported for ARM AARCH64 using equivalent ARM * assembly instruction. Please refer to (arm_cacheops.h) for more details. * * INTERFACES FOR FLUSHING TO PERSISTENT MEMORY * * Given the flows above, three interfaces are provided for flushing a range * so that the caller has the ability to separate the steps when necessary, * but otherwise leaves the detection of available instructions to the libpmem: * * pmem_persist(addr, len) * * This is the common case, which just calls the two other functions: * * pmem_flush(addr, len); * pmem_drain(); * * pmem_flush(addr, len) * * CLWB or CLFLUSHOPT or CLFLUSH for each cache line * * pmem_drain() * * SFENCE unless using CLFLUSH * * * INTERFACES FOR COPYING/SETTING RANGES OF MEMORY * * Given the flows above, the following interfaces are provided for the * memmove/memcpy/memset operations to persistent memory: * * pmem_memmove_nodrain() * * Checks for overlapped ranges to determine whether to copy from * the beginning of the range or from the end. If MOVNT instructions * are available, uses the memory copy flow described above, otherwise * calls the libc memmove() followed by pmem_flush(). Since no conditional * compilation and/or architecture specific CFLAGS are in use at the * moment, SSE2 ( thus movnt ) is just assumed to be available. * * pmem_memcpy_nodrain() * * Just calls pmem_memmove_nodrain(). * * pmem_memset_nodrain() * * If MOVNT instructions are available, uses the memset flow described * above, otherwise calls the libc memset() followed by pmem_flush(). * * pmem_memmove_persist() * pmem_memcpy_persist() * pmem_memset_persist() * * Calls the appropriate _nodrain() function followed by pmem_drain(). * * * DECISIONS MADE AT INITIALIZATION TIME * * As much as possible, all decisions described above are made at library * initialization time. This is achieved using function pointers that are * setup by pmem_init() when the library loads. * * Func_predrain_fence is used by pmem_drain() to call one of: * predrain_fence_empty() * predrain_memory_barrier() * * Func_flush is used by pmem_flush() to call one of: * flush_dcache() * flush_dcache_invalidate_opt() * flush_dcache_invalidate() * * Func_memmove_nodrain is used by memmove_nodrain() to call one of: * memmove_nodrain_libc() * memmove_nodrain_movnt() * * Func_memset_nodrain is used by memset_nodrain() to call one of: * memset_nodrain_libc() * memset_nodrain_movnt() * * DEBUG LOGGING * * Many of the functions here get called hundreds of times from loops * iterating over ranges, making the usual LOG() calls at level 3 * impractical. The call tracing log for those functions is set at 15. */ #include <sys/mman.h> #include <sys/stat.h> #include <errno.h> #include <fcntl.h> #include "libpmem.h" #include "pmem.h" #include "out.h" #include "os.h" #include "mmap.h" #include "file.h" #include "valgrind_internal.h" #include "os_deep.h" #include "os_auto_flush.h" static struct pmem_funcs Funcs; /* * pmem_has_hw_drain -- return whether or not HW drain was found * * Always false for x86: HW drain is done by HW with no SW involvement. */ int pmem_has_hw_drain(void) { LOG(3, NULL); return 0; } /* * pmem_drain -- wait for any PM stores to drain from HW buffers */ void pmem_drain(void) { LOG(15, NULL); Funcs.predrain_fence(); } /* * pmem_has_auto_flush -- check if platform supports eADR */ int pmem_has_auto_flush() { LOG(3, NULL); return os_auto_flush(); } /* * pmem_deep_flush -- flush processor cache for the given range * regardless of eADR support on platform */ void pmem_deep_flush(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len); Funcs.deep_flush(addr, len); } /* * pmem_flush -- flush processor cache for the given range */ void pmem_flush(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len); Funcs.flush(addr, len); } /* * pmem_persist -- make any cached changes to a range of pmem persistent */ void pmem_persist(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); pmem_flush(addr, len); pmem_drain(); } /* * pmem_msync -- flush to persistence via msync * * Using msync() means this routine is less optimal for pmem (but it * still works) but it also works for any memory mapped file, unlike * pmem_persist() which is only safe where pmem_is_pmem() returns true. */ int pmem_msync(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len); /* * msync requires len to be a multiple of pagesize, so * adjust addr and len to represent the full 4k chunks * covering the given range. */ /* increase len by the amount we gain when we round addr down */ len += (uintptr_t)addr & (Pagesize - 1); /* round addr down to page boundary */ uintptr_t uptr = (uintptr_t)addr & ~((uintptr_t)Pagesize - 1); /* * msync accepts addresses aligned to page boundary, so we may sync * more and part of it may have been marked as undefined/inaccessible * Msyncing such memory is not a bug, so as a workaround temporarily * disable error reporting. */ VALGRIND_DO_DISABLE_ERROR_REPORTING; int ret; if ((ret = msync((void *)uptr, len, MS_SYNC)) < 0) ERR("!msync"); VALGRIND_DO_ENABLE_ERROR_REPORTING; /* full flush */ VALGRIND_DO_PERSIST(uptr, len); return ret; } /* * is_pmem_always -- (internal) always true (for meaningful parameters) version * of pmem_is_pmem() */ static int is_pmem_always(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); if (len == 0) return 0; return 1; } /* * is_pmem_never -- (internal) never true version of pmem_is_pmem() */ static int is_pmem_never(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); return 0; } /* * pmem_is_pmem_init -- (internal) initialize Func_is_pmem pointer * * This should be done only once - on the first call to pmem_is_pmem(). * If PMEM_IS_PMEM_FORCE is set, it would override the default behavior * of pmem_is_pmem(). */ static void pmem_is_pmem_init(void) { LOG(3, NULL); static volatile unsigned init; while (init != 2) { if (!util_bool_compare_and_swap32(&init, 0, 1)) continue; /* * For debugging/testing, allow pmem_is_pmem() to be forced * to always true or never true using environment variable * PMEM_IS_PMEM_FORCE values of zero or one. * * This isn't #ifdef DEBUG because it has a trivial performance * impact and it may turn out to be useful as a "chicken bit" * for systems where pmem_is_pmem() isn't correctly detecting * true persistent memory. */ char *ptr = os_getenv("PMEM_IS_PMEM_FORCE"); if (ptr) { int val = atoi(ptr); if (val == 0) Funcs.is_pmem = is_pmem_never; else if (val == 1) Funcs.is_pmem = is_pmem_always; VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Funcs.is_pmem); LOG(4, "PMEM_IS_PMEM_FORCE=%d", val); } if (Funcs.is_pmem == NULL) Funcs.is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) FATAL("util_bool_compare_and_swap32"); } } /* * pmem_is_pmem -- return true if entire range is persistent memory */ int pmem_is_pmem(const void *addr, size_t len) { LOG(10, "addr %p len %zu", addr, len); static int once; /* This is not thread-safe, but pmem_is_pmem_init() is. */ if (once == 0) { pmem_is_pmem_init(); util_fetch_and_add32(&once, 1); } VALGRIND_ANNOTATE_HAPPENS_AFTER(&Funcs.is_pmem); return Funcs.is_pmem(addr, len); } #define PMEM_FILE_ALL_FLAGS\ (PMEM_FILE_CREATE|PMEM_FILE_EXCL|PMEM_FILE_SPARSE|PMEM_FILE_TMPFILE) #define PMEM_DAX_VALID_FLAGS\ (PMEM_FILE_CREATE|PMEM_FILE_SPARSE) /* * pmem_map_fileU -- create or open the file and map it to memory */ #ifndef _WIN32 static inline #endif void * pmem_map_fileU(const char *path, size_t len, int flags, mode_t mode, size_t *mapped_lenp, int *is_pmemp) { LOG(3, "path \"%s\" size %zu flags %x mode %o mapped_lenp %p " "is_pmemp %p", path, len, flags, mode, mapped_lenp, is_pmemp); int oerrno; int fd; int open_flags = O_RDWR; int delete_on_err = 0; int file_type = util_file_get_type(path); if (file_type == OTHER_ERROR) return NULL; if (flags & ~(PMEM_FILE_ALL_FLAGS)) { ERR("invalid flag specified %x", flags); errno = EINVAL; return NULL; } if (file_type == TYPE_DEVDAX) { if (flags & ~(PMEM_DAX_VALID_FLAGS)) { ERR("flag unsupported for Device DAX %x", flags); errno = EINVAL; return NULL; } else { /* we are ignoring all of the flags */ flags = 0; ssize_t actual_len = util_file_get_size(path); if (actual_len < 0) { ERR("unable to read Device DAX size"); errno = EINVAL; return NULL; } if (len != 0 && len != (size_t)actual_len) { ERR("Device DAX length must be either 0 or " "the exact size of the device %zu", len); errno = EINVAL; return NULL; } len = 0; } } if (flags & PMEM_FILE_CREATE) { if ((os_off_t)len < 0) { ERR("invalid file length %zu", len); errno = EINVAL; return NULL; } open_flags |= O_CREAT; } if (flags & PMEM_FILE_EXCL) open_flags |= O_EXCL; if ((len != 0) && !(flags & PMEM_FILE_CREATE)) { ERR("non-zero 'len' not allowed without PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } if ((len == 0) && (flags & PMEM_FILE_CREATE)) { ERR("zero 'len' not allowed with PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } if ((flags & PMEM_FILE_TMPFILE) && !(flags & PMEM_FILE_CREATE)) { ERR("PMEM_FILE_TMPFILE not allowed without PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } if (flags & PMEM_FILE_TMPFILE) { if ((fd = util_tmpfile(path, OS_DIR_SEP_STR"pmem.XXXXXX", open_flags & O_EXCL)) < 0) { LOG(2, "failed to create temporary file at \"%s\"", path); return NULL; } } else { if ((fd = os_open(path, open_flags, mode)) < 0) { ERR("!open %s", path); return NULL; } if ((flags & PMEM_FILE_CREATE) && (flags & PMEM_FILE_EXCL)) delete_on_err = 1; } if (flags & PMEM_FILE_CREATE) { /* * Always set length of file to 'len'. * (May either extend or truncate existing file.) */ if (os_ftruncate(fd, (os_off_t)len) != 0) { ERR("!ftruncate"); goto err; } if ((flags & PMEM_FILE_SPARSE) == 0) { if ((errno = os_posix_fallocate(fd, 0, (os_off_t)len)) != 0) { ERR("!posix_fallocate"); goto err; } } } else { ssize_t actual_size = util_file_get_size(path); if (actual_size < 0) { ERR("stat %s: negative size", path); errno = EINVAL; goto err; } len = (size_t)actual_size; } void *addr = pmem_map_register(fd, len, path, file_type == TYPE_DEVDAX); if (addr == NULL) goto err; if (mapped_lenp != NULL) *mapped_lenp = len; if (is_pmemp != NULL) *is_pmemp = pmem_is_pmem(addr, len); LOG(3, "returning %p", addr); VALGRIND_REGISTER_PMEM_MAPPING(addr, len); VALGRIND_REGISTER_PMEM_FILE(fd, addr, len, 0); (void) os_close(fd); return addr; err: oerrno = errno; (void) os_close(fd); if (delete_on_err) (void) os_unlink(path); errno = oerrno; return NULL; } #ifndef _WIN32 /* * pmem_map_file -- create or open the file and map it to memory */ void * pmem_map_file(const char *path, size_t len, int flags, mode_t mode, size_t *mapped_lenp, int *is_pmemp) { return pmem_map_fileU(path, len, flags, mode, mapped_lenp, is_pmemp); } #else /* * pmem_map_fileW -- create or open the file and map it to memory */ void * pmem_map_fileW(const wchar_t *path, size_t len, int flags, mode_t mode, size_t *mapped_lenp, int *is_pmemp) { char *upath = util_toUTF8(path); if (upath == NULL) return NULL; void *ret = pmem_map_fileU(upath, len, flags, mode, mapped_lenp, is_pmemp); util_free_UTF8(upath); return ret; } #endif /* * pmem_unmap -- unmap the specified region */ int pmem_unmap(void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); #ifndef _WIN32 util_range_unregister(addr, len); #endif VALGRIND_REMOVE_PMEM_MAPPING(addr, len); return util_unmap(addr, len); } /* * pmem_memmove -- memmove to pmem */ void * pmem_memmove(void *pmemdest, const void *src, size_t len, unsigned flags) { LOG(15, "pmemdest %p src %p len %zu flags 0x%x", pmemdest, src, len, flags); #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) ERR("invalid flags 0x%x", flags); #endif Funcs.memmove_nodrain(pmemdest, src, len, flags & ~PMEM_F_MEM_NODRAIN); if ((flags & (PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH)) == 0) pmem_drain(); return pmemdest; } /* * pmem_memcpy -- memcpy to pmem */ void * pmem_memcpy(void *pmemdest, const void *src, size_t len, unsigned flags) { return pmem_memmove(pmemdest, src, len, flags); } /* * pmem_memset -- memset to pmem */ void * pmem_memset(void *pmemdest, int c, size_t len, unsigned flags) { LOG(15, "pmemdest %p c 0x%x len %zu flags 0x%x", pmemdest, c, len, flags); #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) ERR("invalid flags 0x%x", flags); #endif Funcs.memset_nodrain(pmemdest, c, len, flags & ~PMEM_F_MEM_NODRAIN); if ((flags & (PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH)) == 0) pmem_drain(); return pmemdest; } /* * pmem_memmove_nodrain -- memmove to pmem without hw drain */ void * pmem_memmove_nodrain(void *pmemdest, const void *src, size_t len) { return pmem_memmove(pmemdest, src, len, PMEM_F_MEM_NODRAIN); } /* * pmem_memcpy_nodrain -- memcpy to pmem without hw drain */ void * pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len) { return pmem_memcpy(pmemdest, src, len, PMEM_F_MEM_NODRAIN); } /* * pmem_memmove_persist -- memmove to pmem */ void * pmem_memmove_persist(void *pmemdest, const void *src, size_t len) { return pmem_memmove(pmemdest, src, len, 0); } /* * pmem_memcpy_persist -- memcpy to pmem */ void * pmem_memcpy_persist(void *pmemdest, const void *src, size_t len) { return pmem_memcpy(pmemdest, src, len, 0); } /* * pmem_memset_nodrain -- memset to pmem without hw drain */ void * pmem_memset_nodrain(void *pmemdest, int c, size_t len) { return pmem_memset(pmemdest, c, len, PMEM_F_MEM_NODRAIN); } /* * pmem_memset_persist -- memset to pmem */ void * pmem_memset_persist(void *pmemdest, int c, size_t len) { return pmem_memset(pmemdest, c, len, 0); } /* * pmem_init -- load-time initialization for pmem.c */ void pmem_init(void) { LOG(3, NULL); pmem_init_funcs(&Funcs); pmem_os_init(); } /* * pmem_deep_persist -- perform deep persist on a memory range * * It merely acts as wrapper around an msync call in most cases, the only * exception is the case of an mmap'ed DAX device on Linux. */ int pmem_deep_persist(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); pmem_deep_flush(addr, len); return pmem_deep_drain(addr, len); } /* * pmem_deep_drain -- perform deep drain on a memory range */ int pmem_deep_drain(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); return os_range_deep_common((uintptr_t)addr, len); }
18,443
23.592
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/pmem_windows.c
/* * Copyright 2016-2018, Intel Corporation * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem_windows.c -- pmem utilities with OS-specific implementation */ #include <memoryapi.h> #include "pmem.h" #include "out.h" #include "mmap.h" #include "win_mmap.h" #include "sys/mman.h" #if (NTDDI_VERSION >= NTDDI_WIN10_RS1) typedef BOOL (WINAPI *PQVM)( HANDLE, const void *, enum WIN32_MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); static PQVM Func_qvmi = NULL; #endif /* * is_direct_mapped -- (internal) for each page in the given region * checks with MM, if it's direct mapped. */ static int is_direct_mapped(const void *begin, const void *end) { LOG(3, "begin %p end %p", begin, end); #if (NTDDI_VERSION >= NTDDI_WIN10_RS1) int retval = 1; WIN32_MEMORY_REGION_INFORMATION region_info; SIZE_T bytes_returned; if (Func_qvmi == NULL) { LOG(4, "QueryVirtualMemoryInformation not supported, " "assuming non-DAX."); return 0; } const void *begin_aligned = (const void *)rounddown((intptr_t)begin, Pagesize); const void *end_aligned = (const void *)roundup((intptr_t)end, Pagesize); for (const void *page = begin_aligned; page < end_aligned; page = (const void *)((char *)page + Pagesize)) { if (Func_qvmi(GetCurrentProcess(), page, MemoryRegionInfo, &region_info, sizeof(region_info), &bytes_returned)) { retval = region_info.DirectMapped; } else { LOG(4, "QueryVirtualMemoryInformation failed, assuming " "non-DAX. Last error: %08x", GetLastError()); retval = 0; } if (retval == 0) { LOG(4, "page %p is not direct mapped", page); break; } } return retval; #else /* if the MM API is not available the safest answer is NO */ return 0; #endif /* NTDDI_VERSION >= NTDDI_WIN10_RS1 */ } /* * is_pmem_detect -- implement pmem_is_pmem() * * This function returns true only if the entire range can be confirmed * as being direct access persistent memory. Finding any part of the * range is not direct access, or failing to look up the information * because it is unmapped or because any sort of error happens, just * results in returning false. */ int is_pmem_detect(const void *addr, size_t len) { LOG(3, "addr %p len %zu", addr, len); if (len == 0) return 0; if (len > UINTPTR_MAX - (uintptr_t)addr) { len = UINTPTR_MAX - (uintptr_t)addr; LOG(4, "limit len to %zu to not get beyond address space", len); } int retval = 1; const void *begin = addr; const void *end = (const void *)((char *)addr + len); LOG(4, "begin %p end %p", begin, end); AcquireSRWLockShared(&FileMappingQLock); PFILE_MAPPING_TRACKER mt; SORTEDQ_FOREACH(mt, &FileMappingQHead, ListEntry) { if (mt->BaseAddress >= end) { LOG(4, "ignoring all mapped ranges beyond given range"); break; } if (mt->EndAddress <= begin) { LOG(4, "skipping all mapped ranges before given range"); continue; } if (!(mt->Flags & FILE_MAPPING_TRACKER_FLAG_DIRECT_MAPPED)) { LOG(4, "tracked range [%p, %p) is not direct mapped", mt->BaseAddress, mt->EndAddress); retval = 0; break; } /* * If there is a gap between the given region that we process * currently and the mapped region in our tracking list, we * need to process the gap by taking the long route of asking * MM for each page in that range. */ if (begin < mt->BaseAddress && !is_direct_mapped(begin, mt->BaseAddress)) { LOG(4, "untracked range [%p, %p) is not direct mapped", begin, mt->BaseAddress); retval = 0; break; } /* push our begin to reflect what we have already processed */ begin = mt->EndAddress; } /* * If we still have a range to verify, check with MM if the entire * region is direct mapped. */ if (begin < end && !is_direct_mapped(begin, end)) { LOG(4, "untracked end range [%p, %p) is not direct mapped", begin, end); retval = 0; } ReleaseSRWLockShared(&FileMappingQLock); LOG(4, "returning %d", retval); return retval; } /* * pmem_map_register -- memory map file and register mapping */ void * pmem_map_register(int fd, size_t len, const char *path, int is_dev_dax) { /* there is no device dax on windows */ ASSERTeq(is_dev_dax, 0); return util_map(fd, len, MAP_SHARED, 0, 0, NULL); } /* * pmem_os_init -- os-dependent part of pmem initialization */ void pmem_os_init(void) { LOG(3, NULL); #if NTDDI_VERSION >= NTDDI_WIN10_RS1 Func_qvmi = (PQVM)GetProcAddress( GetModuleHandle(TEXT("KernelBase.dll")), "QueryVirtualMemoryInformation"); #endif }
6,094
27.615023
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/pmem.h
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem.h -- internal definitions for libpmem */ #ifndef PMEM_H #define PMEM_H #include <stddef.h> #include "libpmem.h" #include "util.h" #ifdef __cplusplus extern "C" { #endif #define PMEM_LOG_PREFIX "libpmem" #define PMEM_LOG_LEVEL_VAR "PMEM_LOG_LEVEL" #define PMEM_LOG_FILE_VAR "PMEM_LOG_FILE" typedef void (*predrain_fence_func)(void); typedef void (*flush_func)(const void *, size_t); typedef int (*is_pmem_func)(const void *addr, size_t len); typedef void *(*memmove_nodrain_func)(void *pmemdest, const void *src, size_t len, unsigned flags); typedef void *(*memset_nodrain_func)(void *pmemdest, int c, size_t len, unsigned flags); struct pmem_funcs { predrain_fence_func predrain_fence; flush_func flush; is_pmem_func is_pmem; memmove_nodrain_func memmove_nodrain; memset_nodrain_func memset_nodrain; flush_func deep_flush; }; void pmem_init(void); void pmem_os_init(void); void pmem_init_funcs(struct pmem_funcs *funcs); int is_pmem_detect(const void *addr, size_t len); void *pmem_map_register(int fd, size_t len, const char *path, int is_dev_dax); /* * flush_empty_nolog -- (internal) do not flush the CPU cache */ static force_inline void flush_empty_nolog(const void *addr, size_t len) { /* NOP */ } /* * flush64b_empty -- (internal) do not flush the CPU cache */ static force_inline void flush64b_empty(const char *addr) { } /* * pmem_flush_flags -- internal wrapper around pmem_flush */ static inline void pmem_flush_flags(const void *addr, size_t len, unsigned flags) { if (!(flags & PMEM_F_MEM_NOFLUSH)) pmem_flush(addr, len); } void *memmove_nodrain_generic(void *pmemdest, const void *src, size_t len, unsigned flags); void *memset_nodrain_generic(void *pmemdest, int c, size_t len, unsigned flags); #ifdef __cplusplus } #endif #endif
3,394
29.585586
80
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/flush.h
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef X86_64_FLUSH_H #define X86_64_FLUSH_H #include <emmintrin.h> #include <stddef.h> #include <stdint.h> #include "util.h" #define FLUSH_ALIGN ((uintptr_t)64) #ifdef _MSC_VER #define pmem_clflushopt _mm_clflushopt #define pmem_clwb _mm_clwb #else /* * The x86 memory instructions are new enough that the compiler * intrinsic functions are not always available. The intrinsic * functions are defined here in terms of asm statements for now. */ #define pmem_clflushopt(addr)\ asm volatile(".byte 0x66; clflush %0" : "+m" \ (*(volatile char *)(addr))); #define pmem_clwb(addr)\ asm volatile(".byte 0x66; xsaveopt %0" : "+m" \ (*(volatile char *)(addr))); #endif /* _MSC_VER */ /* * flush_clflush_nolog -- flush the CPU cache, using clflush */ static force_inline void flush_clflush_nolog(const void *addr, size_t len) { uintptr_t uptr; /* * Loop through cache-line-size (typically 64B) aligned chunks * covering the given range. */ for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1); uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN) _mm_clflush((char *)uptr); } /* * flush_clflushopt_nolog -- flush the CPU cache, using clflushopt */ static force_inline void flush_clflushopt_nolog(const void *addr, size_t len) { uintptr_t uptr; /* * Loop through cache-line-size (typically 64B) aligned chunks * covering the given range. */ for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1); uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN) { pmem_clflushopt((char *)uptr); } } /* * flush_clwb_nolog -- flush the CPU cache, using clwb */ static force_inline void flush_clwb_nolog(const void *addr, size_t len) { uintptr_t uptr; /* * Loop through cache-line-size (typically 64B) aligned chunks * covering the given range. */ for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1); uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN) { pmem_clwb((char *)uptr); } } #endif
3,520
29.885965
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/cpu.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cpu.c -- CPU features detection * * These routines do not work AARCH64 platforms, and need new detection * routiones to be added. Currently to ensure msync is not used and ARM * FLUSH instructions are used PMEM_IS_PMEM_FORCE=1 needs to be used. */ /* * Reference: * http://www.intel.com/content/www/us/en/processors/ * architectures-software-developer-manuals.html * * https://support.amd.com/TechDocs/24594.pdf */ #include <string.h> #include "out.h" #include "cpu.h" #define EAX_IDX 0 #define EBX_IDX 1 #define ECX_IDX 2 #define EDX_IDX 3 #if defined(__x86_64__) || defined(__amd64__) #include <cpuid.h> static inline void cpuid(unsigned func, unsigned subfunc, unsigned cpuinfo[4]) { __cpuid_count(func, subfunc, cpuinfo[EAX_IDX], cpuinfo[EBX_IDX], cpuinfo[ECX_IDX], cpuinfo[EDX_IDX]); } #elif defined(_M_X64) || defined(_M_AMD64) #include <intrin.h> static inline void cpuid(unsigned func, unsigned subfunc, unsigned cpuinfo[4]) { __cpuidex(cpuinfo, func, subfunc); } #else /* not x86_64 */ #define cpuid(func, subfunc, cpuinfo)\ do { (void)(func); (void)(subfunc); (void)(cpuinfo); } while (0) #endif #ifndef bit_CLFLUSH #define bit_CLFLUSH (1 << 19) #endif #ifndef bit_CLFLUSHOPT #define bit_CLFLUSHOPT (1 << 23) #endif #ifndef bit_CLWB #define bit_CLWB (1 << 24) #endif #ifndef bit_AVX #define bit_AVX (1 << 28) #endif #ifndef bit_AVX512F #define bit_AVX512F (1 << 16) #endif /* * is_cpu_feature_present -- (internal) checks if CPU feature is supported */ static int is_cpu_feature_present(unsigned func, unsigned reg, unsigned bit) { unsigned cpuinfo[4] = { 0 }; /* check CPUID level first */ cpuid(0x0, 0x0, cpuinfo); if (cpuinfo[EAX_IDX] < func) return 0; cpuid(func, 0x0, cpuinfo); return (cpuinfo[reg] & bit) != 0; } /* * is_cpu_genuine_intel -- checks for genuine Intel CPU */ int is_cpu_genuine_intel(void) { unsigned cpuinfo[4] = { 0 }; union { char name[0x20]; unsigned cpuinfo[3]; } vendor; memset(&vendor, 0, sizeof(vendor)); cpuid(0x0, 0x0, cpuinfo); vendor.cpuinfo[0] = cpuinfo[EBX_IDX]; vendor.cpuinfo[1] = cpuinfo[EDX_IDX]; vendor.cpuinfo[2] = cpuinfo[ECX_IDX]; LOG(4, "CPU vendor: %s", vendor.name); return (strncmp(vendor.name, "GenuineIntel", sizeof(vendor.name))) == 0; } /* * is_cpu_clflush_present -- checks if CLFLUSH instruction is supported */ int is_cpu_clflush_present(void) { int ret = is_cpu_feature_present(0x1, EDX_IDX, bit_CLFLUSH); LOG(4, "CLFLUSH %ssupported", ret == 0 ? "not " : ""); return ret; } /* * is_cpu_clflushopt_present -- checks if CLFLUSHOPT instruction is supported */ int is_cpu_clflushopt_present(void) { int ret = is_cpu_feature_present(0x7, EBX_IDX, bit_CLFLUSHOPT); LOG(4, "CLFLUSHOPT %ssupported", ret == 0 ? "not " : ""); return ret; } /* * is_cpu_clwb_present -- checks if CLWB instruction is supported */ int is_cpu_clwb_present(void) { if (!is_cpu_genuine_intel()) return 0; int ret = is_cpu_feature_present(0x7, EBX_IDX, bit_CLWB); LOG(4, "CLWB %ssupported", ret == 0 ? "not " : ""); return ret; } /* * is_cpu_avx_present -- checks if AVX instructions are supported */ int is_cpu_avx_present(void) { int ret = is_cpu_feature_present(0x1, ECX_IDX, bit_AVX); LOG(4, "AVX %ssupported", ret == 0 ? "not " : ""); return ret; } /* * is_cpu_avx512f_present -- checks if AVX-512f instructions are supported */ int is_cpu_avx512f_present(void) { int ret = is_cpu_feature_present(0x7, EBX_IDX, bit_AVX512F); LOG(4, "AVX512f %ssupported", ret == 0 ? "not " : ""); return ret; }
5,154
23.316038
77
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/cpu.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMDK_CPU_H #define PMDK_CPU_H 1 /* * cpu.h -- definitions for "cpu" module */ int is_cpu_genuine_intel(void); int is_cpu_clflush_present(void); int is_cpu_clflushopt_present(void); int is_cpu_clwb_present(void); int is_cpu_avx_present(void); int is_cpu_avx512f_present(void); #endif
1,898
38.5625
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/init.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <string.h> #include <xmmintrin.h> #include "libpmem.h" #include "cpu.h" #include "flush.h" #include "memcpy_memset.h" #include "os.h" #include "out.h" #include "pmem.h" #include "valgrind_internal.h" #define MOVNT_THRESHOLD 256 size_t Movnt_threshold = MOVNT_THRESHOLD; /* * predrain_fence_empty -- (internal) issue the pre-drain fence instruction */ static void predrain_fence_empty(void) { LOG(15, NULL); VALGRIND_DO_FENCE; /* nothing to do (because CLFLUSH did it for us) */ } /* * predrain_memory_barrier -- (internal) issue the pre-drain fence instruction */ static void predrain_memory_barrier(void) { LOG(15, NULL); _mm_sfence(); /* ensure CLWB or CLFLUSHOPT completes */ } /* * flush_clflush -- (internal) flush the CPU cache, using clflush */ static void flush_clflush(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); flush_clflush_nolog(addr, len); } /* * flush_clflushopt -- (internal) flush the CPU cache, using clflushopt */ static void flush_clflushopt(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); flush_clflushopt_nolog(addr, len); } /* * flush_clwb -- (internal) flush the CPU cache, using clwb */ static void flush_clwb(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); flush_clwb_nolog(addr, len); } /* * flush_empty -- (internal) do not flush the CPU cache */ static void flush_empty(const void *addr, size_t len) { LOG(15, "addr %p len %zu", addr, len); flush_empty_nolog(addr, len); } #if SSE2_AVAILABLE || AVX_AVAILABLE || AVX512F_AVAILABLE #define PMEM_F_MEM_MOVNT (PMEM_F_MEM_WC | PMEM_F_MEM_NONTEMPORAL) #define PMEM_F_MEM_MOV (PMEM_F_MEM_WB | PMEM_F_MEM_TEMPORAL) #define MEMCPY_TEMPLATE(isa, flush) \ static void *\ memmove_nodrain_##isa##_##flush(void *dest, const void *src, size_t len, \ unsigned flags)\ {\ if (len == 0 || src == dest)\ return dest;\ \ if (flags & PMEM_F_MEM_NOFLUSH) \ memmove_mov_##isa##_empty(dest, src, len); \ else if (flags & PMEM_F_MEM_MOVNT)\ memmove_movnt_##isa ##_##flush(dest, src, len);\ else if (flags & PMEM_F_MEM_MOV)\ memmove_mov_##isa##_##flush(dest, src, len);\ else if (len < Movnt_threshold)\ memmove_mov_##isa##_##flush(dest, src, len);\ else\ memmove_movnt_##isa##_##flush(dest, src, len);\ \ return dest;\ } #define MEMSET_TEMPLATE(isa, flush)\ static void *\ memset_nodrain_##isa##_##flush(void *dest, int c, size_t len, unsigned flags)\ {\ if (len == 0)\ return dest;\ \ if (flags & PMEM_F_MEM_NOFLUSH) \ memset_mov_##isa##_empty(dest, c, len); \ else if (flags & PMEM_F_MEM_MOVNT)\ memset_movnt_##isa##_##flush(dest, c, len);\ else if (flags & PMEM_F_MEM_MOV)\ memset_mov_##isa##_##flush(dest, c, len);\ else if (len < Movnt_threshold)\ memset_mov_##isa##_##flush(dest, c, len);\ else\ memset_movnt_##isa##_##flush(dest, c, len);\ \ return dest;\ } #endif #if SSE2_AVAILABLE MEMCPY_TEMPLATE(sse2, clflush) MEMCPY_TEMPLATE(sse2, clflushopt) MEMCPY_TEMPLATE(sse2, clwb) MEMCPY_TEMPLATE(sse2, empty) MEMSET_TEMPLATE(sse2, clflush) MEMSET_TEMPLATE(sse2, clflushopt) MEMSET_TEMPLATE(sse2, clwb) MEMSET_TEMPLATE(sse2, empty) #endif #if AVX_AVAILABLE MEMCPY_TEMPLATE(avx, clflush) MEMCPY_TEMPLATE(avx, clflushopt) MEMCPY_TEMPLATE(avx, clwb) MEMCPY_TEMPLATE(avx, empty) MEMSET_TEMPLATE(avx, clflush) MEMSET_TEMPLATE(avx, clflushopt) MEMSET_TEMPLATE(avx, clwb) MEMSET_TEMPLATE(avx, empty) #endif #if AVX512F_AVAILABLE MEMCPY_TEMPLATE(avx512f, clflush) MEMCPY_TEMPLATE(avx512f, clflushopt) MEMCPY_TEMPLATE(avx512f, clwb) MEMCPY_TEMPLATE(avx512f, empty) MEMSET_TEMPLATE(avx512f, clflush) MEMSET_TEMPLATE(avx512f, clflushopt) MEMSET_TEMPLATE(avx512f, clwb) MEMSET_TEMPLATE(avx512f, empty) #endif /* * memmove_nodrain_libc -- (internal) memmove to pmem using libc */ static void * memmove_nodrain_libc(void *pmemdest, const void *src, size_t len, unsigned flags) { LOG(15, "pmemdest %p src %p len %zu flags 0x%x", pmemdest, src, len, flags); (void) flags; memmove(pmemdest, src, len); pmem_flush_flags(pmemdest, len, flags); return pmemdest; } /* * memset_nodrain_libc -- (internal) memset to pmem using libc */ static void * memset_nodrain_libc(void *pmemdest, int c, size_t len, unsigned flags) { LOG(15, "pmemdest %p c 0x%x len %zu flags 0x%x", pmemdest, c, len, flags); (void) flags; memset(pmemdest, c, len); pmem_flush_flags(pmemdest, len, flags); return pmemdest; } enum memcpy_impl { MEMCPY_INVALID, MEMCPY_LIBC, MEMCPY_GENERIC, MEMCPY_SSE2, MEMCPY_AVX, MEMCPY_AVX512F }; /* * use_sse2_memcpy_memset -- (internal) SSE2 detected, use it if possible */ static void use_sse2_memcpy_memset(struct pmem_funcs *funcs, enum memcpy_impl *impl) { #if SSE2_AVAILABLE *impl = MEMCPY_SSE2; if (funcs->deep_flush == flush_clflush) funcs->memmove_nodrain = memmove_nodrain_sse2_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memmove_nodrain = memmove_nodrain_sse2_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memmove_nodrain = memmove_nodrain_sse2_clwb; else if (funcs->deep_flush == flush_empty) funcs->memmove_nodrain = memmove_nodrain_sse2_empty; else ASSERT(0); if (funcs->deep_flush == flush_clflush) funcs->memset_nodrain = memset_nodrain_sse2_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memset_nodrain = memset_nodrain_sse2_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memset_nodrain = memset_nodrain_sse2_clwb; else if (funcs->deep_flush == flush_empty) funcs->memset_nodrain = memset_nodrain_sse2_empty; else ASSERT(0); #else LOG(3, "sse2 disabled at build time"); #endif } /* * use_avx_memcpy_memset -- (internal) AVX detected, use it if possible */ static void use_avx_memcpy_memset(struct pmem_funcs *funcs, enum memcpy_impl *impl) { #if AVX_AVAILABLE LOG(3, "avx supported"); char *e = os_getenv("PMEM_AVX"); if (e == NULL || strcmp(e, "1") != 0) { LOG(3, "PMEM_AVX not set or not == 1"); return; } LOG(3, "PMEM_AVX enabled"); *impl = MEMCPY_AVX; if (funcs->deep_flush == flush_clflush) funcs->memmove_nodrain = memmove_nodrain_avx_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memmove_nodrain = memmove_nodrain_avx_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memmove_nodrain = memmove_nodrain_avx_clwb; else if (funcs->deep_flush == flush_empty) funcs->memmove_nodrain = memmove_nodrain_avx_empty; else ASSERT(0); if (funcs->deep_flush == flush_clflush) funcs->memset_nodrain = memset_nodrain_avx_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memset_nodrain = memset_nodrain_avx_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memset_nodrain = memset_nodrain_avx_clwb; else if (funcs->deep_flush == flush_empty) funcs->memset_nodrain = memset_nodrain_avx_empty; else ASSERT(0); #else LOG(3, "avx supported, but disabled at build time"); #endif } /* * use_avx512f_memcpy_memset -- (internal) AVX512F detected, use it if possible */ static void use_avx512f_memcpy_memset(struct pmem_funcs *funcs, enum memcpy_impl *impl) { #if AVX512F_AVAILABLE LOG(3, "avx512f supported"); char *e = os_getenv("PMEM_AVX512F"); if (e == NULL || strcmp(e, "1") != 0) { LOG(3, "PMEM_AVX512F not set or not == 1"); return; } LOG(3, "PMEM_AVX512F enabled"); *impl = MEMCPY_AVX512F; if (funcs->deep_flush == flush_clflush) funcs->memmove_nodrain = memmove_nodrain_avx512f_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memmove_nodrain = memmove_nodrain_avx512f_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memmove_nodrain = memmove_nodrain_avx512f_clwb; else if (funcs->deep_flush == flush_empty) funcs->memmove_nodrain = memmove_nodrain_avx512f_empty; else ASSERT(0); if (funcs->deep_flush == flush_clflush) funcs->memset_nodrain = memset_nodrain_avx512f_clflush; else if (funcs->deep_flush == flush_clflushopt) funcs->memset_nodrain = memset_nodrain_avx512f_clflushopt; else if (funcs->deep_flush == flush_clwb) funcs->memset_nodrain = memset_nodrain_avx512f_clwb; else if (funcs->deep_flush == flush_empty) funcs->memset_nodrain = memset_nodrain_avx512f_empty; else ASSERT(0); #else LOG(3, "avx512f supported, but disabled at build time"); #endif } /* * pmem_get_cpuinfo -- configure libpmem based on CPUID */ static void pmem_cpuinfo_to_funcs(struct pmem_funcs *funcs, enum memcpy_impl *impl) { LOG(3, NULL); if (is_cpu_clflush_present()) { funcs->is_pmem = is_pmem_detect; LOG(3, "clflush supported"); } if (is_cpu_clflushopt_present()) { LOG(3, "clflushopt supported"); char *e = os_getenv("PMEM_NO_CLFLUSHOPT"); if (e && strcmp(e, "1") == 0) { LOG(3, "PMEM_NO_CLFLUSHOPT forced no clflushopt"); } else { funcs->deep_flush = flush_clflushopt; funcs->predrain_fence = predrain_memory_barrier; } } if (is_cpu_clwb_present()) { LOG(3, "clwb supported"); char *e = os_getenv("PMEM_NO_CLWB"); if (e && strcmp(e, "1") == 0) { LOG(3, "PMEM_NO_CLWB forced no clwb"); } else { funcs->deep_flush = flush_clwb; funcs->predrain_fence = predrain_memory_barrier; } } char *ptr = os_getenv("PMEM_NO_MOVNT"); if (ptr && strcmp(ptr, "1") == 0) { LOG(3, "PMEM_NO_MOVNT forced no movnt"); } else { use_sse2_memcpy_memset(funcs, impl); if (is_cpu_avx_present()) use_avx_memcpy_memset(funcs, impl); if (is_cpu_avx512f_present()) use_avx512f_memcpy_memset(funcs, impl); } } /* * pmem_init_funcs -- initialize architecture-specific list of pmem operations */ void pmem_init_funcs(struct pmem_funcs *funcs) { LOG(3, NULL); funcs->predrain_fence = predrain_fence_empty; funcs->deep_flush = flush_clflush; funcs->is_pmem = NULL; funcs->memmove_nodrain = memmove_nodrain_generic; funcs->memset_nodrain = memset_nodrain_generic; enum memcpy_impl impl = MEMCPY_GENERIC; char *ptr = os_getenv("PMEM_NO_GENERIC_MEMCPY"); if (ptr) { long long val = atoll(ptr); if (val) { funcs->memmove_nodrain = memmove_nodrain_libc; funcs->memset_nodrain = memset_nodrain_libc; impl = MEMCPY_LIBC; } } pmem_cpuinfo_to_funcs(funcs, &impl); /* * For testing, allow overriding the default threshold * for using non-temporal stores in pmem_memcpy_*(), pmem_memmove_*() * and pmem_memset_*(). * It has no effect if movnt is not supported or disabled. */ ptr = os_getenv("PMEM_MOVNT_THRESHOLD"); if (ptr) { long long val = atoll(ptr); if (val < 0) { LOG(3, "Invalid PMEM_MOVNT_THRESHOLD"); } else { LOG(3, "PMEM_MOVNT_THRESHOLD set to %zu", (size_t)val); Movnt_threshold = (size_t)val; } } int flush; char *e = os_getenv("PMEM_NO_FLUSH"); if (e && (strcmp(e, "1") == 0)) { flush = 0; LOG(3, "Forced not flushing CPU_cache"); } else if (e && (strcmp(e, "0") == 0)) { flush = 1; LOG(3, "Forced flushing CPU_cache"); } else if (pmem_has_auto_flush() == 1) { flush = 0; LOG(3, "Not flushing CPU_cache, eADR detected"); } else { flush = 1; LOG(3, "Flushing CPU cache"); } if (flush) { funcs->flush = funcs->deep_flush; } else { funcs->flush = flush_empty; funcs->predrain_fence = predrain_memory_barrier; } if (funcs->deep_flush == flush_clwb) LOG(3, "using clwb"); else if (funcs->deep_flush == flush_clflushopt) LOG(3, "using clflushopt"); else if (funcs->deep_flush == flush_clflush) LOG(3, "using clflush"); else FATAL("invalid deep flush function address"); if (funcs->flush == flush_empty) LOG(3, "not flushing CPU cache"); else if (funcs->flush != funcs->deep_flush) FATAL("invalid flush function address"); if (impl == MEMCPY_AVX512F) LOG(3, "using movnt AVX512F"); else if (impl == MEMCPY_AVX) LOG(3, "using movnt AVX"); else if (impl == MEMCPY_SSE2) LOG(3, "using movnt SSE2"); else if (impl == MEMCPY_LIBC) LOG(3, "using libc memmove"); else if (impl == MEMCPY_GENERIC) LOG(3, "using generic memmove"); else FATAL("invalid memcpy impl"); }
13,566
25.654224
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/avx.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_AVX_H #define PMEM_AVX_H #include <immintrin.h> #include "util.h" /* * avx_zeroupper -- _mm256_zeroupper wrapper * * _mm256_zeroupper clears upper parts of avx registers. * * It's needed for 2 reasons: * - it improves performance of non-avx code after avx * - it works around problem discovered by Valgrind * * In optimized builds gcc inserts VZEROUPPER automatically before * calling non-avx code (or at the end of the function). But in release * builds it doesn't, so if we don't do this by ourselves, then when * someone memcpy'ies uninitialized data, Valgrind complains whenever * someone reads those registers. * * One notable example is loader, which tries to detect whether it * needs to save whole ymm registers by looking at their current * (possibly uninitialized) value. * * Valgrind complains like that: * Conditional jump or move depends on uninitialised value(s) * at 0x4015CC9: _dl_runtime_resolve_avx_slow * (in /lib/x86_64-linux-gnu/ld-2.24.so) * by 0x10B531: test_realloc_api (obj_basic_integration.c:185) * by 0x10F1EE: main (obj_basic_integration.c:594) * * Note: We have to be careful to not read AVX registers after this * intrinsic, because of this stupid gcc bug: * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82735 */ static force_inline void avx_zeroupper(void) { _mm256_zeroupper(); } static force_inline __m128i m256_get16b(__m256i ymm) { return _mm256_extractf128_si256(ymm, 0); } #ifdef _MSC_VER static force_inline uint64_t m256_get8b(__m256i ymm) { return (uint64_t)_mm_extract_epi64(m256_get16b(ymm), 0); } static force_inline uint32_t m256_get4b(__m256i ymm) { return (uint32_t)m256_get8b(ymm); } static force_inline uint16_t m256_get2b(__m256i ymm) { return (uint16_t)m256_get8b(ymm); } #else static force_inline uint64_t m256_get8b(__m256i ymm) { return (uint64_t)_mm256_extract_epi64(ymm, 0); } static force_inline uint32_t m256_get4b(__m256i ymm) { return (uint32_t)_mm256_extract_epi32(ymm, 0); } static force_inline uint16_t m256_get2b(__m256i ymm) { return (uint16_t)_mm256_extract_epi16(ymm, 0); } #endif #endif
3,753
31.362069
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy_memset.h
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MEMCPY_MEMSET_H #define MEMCPY_MEMSET_H #include <stddef.h> #include <xmmintrin.h> #include "pmem.h" static inline void barrier_after_ntstores(void) { /* * In this configuration pmem_drain does not contain sfence, so we have * to serialize non-temporal store instructions. */ _mm_sfence(); } static inline void no_barrier_after_ntstores(void) { /* * In this configuration pmem_drain contains sfence, so we don't have * to serialize non-temporal store instructions */ } #ifndef AVX512F_AVAILABLE /* XXX not supported in MSVC version we currently use */ #ifdef _MSC_VER #define AVX512F_AVAILABLE 0 #else #define AVX512F_AVAILABLE 1 #endif #endif #ifndef AVX_AVAILABLE #define AVX_AVAILABLE 1 #endif #ifndef SSE2_AVAILABLE #define SSE2_AVAILABLE 1 #endif #if SSE2_AVAILABLE void memmove_mov_sse2_clflush(char *dest, const char *src, size_t len); void memmove_mov_sse2_clflushopt(char *dest, const char *src, size_t len); void memmove_mov_sse2_clwb(char *dest, const char *src, size_t len); void memmove_mov_sse2_empty(char *dest, const char *src, size_t len); void memmove_movnt_sse2_clflush(char *dest, const char *src, size_t len); void memmove_movnt_sse2_clflushopt(char *dest, const char *src, size_t len); void memmove_movnt_sse2_clwb(char *dest, const char *src, size_t len); void memmove_movnt_sse2_empty(char *dest, const char *src, size_t len); void memset_mov_sse2_clflush(char *dest, int c, size_t len); void memset_mov_sse2_clflushopt(char *dest, int c, size_t len); void memset_mov_sse2_clwb(char *dest, int c, size_t len); void memset_mov_sse2_empty(char *dest, int c, size_t len); void memset_movnt_sse2_clflush(char *dest, int c, size_t len); void memset_movnt_sse2_clflushopt(char *dest, int c, size_t len); void memset_movnt_sse2_clwb(char *dest, int c, size_t len); void memset_movnt_sse2_empty(char *dest, int c, size_t len); #endif #if AVX_AVAILABLE void memmove_mov_avx_clflush(char *dest, const char *src, size_t len); void memmove_mov_avx_clflushopt(char *dest, const char *src, size_t len); void memmove_mov_avx_clwb(char *dest, const char *src, size_t len); void memmove_mov_avx_empty(char *dest, const char *src, size_t len); void memmove_movnt_avx_clflush(char *dest, const char *src, size_t len); void memmove_movnt_avx_clflushopt(char *dest, const char *src, size_t len); void memmove_movnt_avx_clwb(char *dest, const char *src, size_t len); void memmove_movnt_avx_empty(char *dest, const char *src, size_t len); void memset_mov_avx_clflush(char *dest, int c, size_t len); void memset_mov_avx_clflushopt(char *dest, int c, size_t len); void memset_mov_avx_clwb(char *dest, int c, size_t len); void memset_mov_avx_empty(char *dest, int c, size_t len); void memset_movnt_avx_clflush(char *dest, int c, size_t len); void memset_movnt_avx_clflushopt(char *dest, int c, size_t len); void memset_movnt_avx_clwb(char *dest, int c, size_t len); void memset_movnt_avx_empty(char *dest, int c, size_t len); #endif #if AVX512F_AVAILABLE void memmove_mov_avx512f_clflush(char *dest, const char *src, size_t len); void memmove_mov_avx512f_clflushopt(char *dest, const char *src, size_t len); void memmove_mov_avx512f_clwb(char *dest, const char *src, size_t len); void memmove_mov_avx512f_empty(char *dest, const char *src, size_t len); void memmove_movnt_avx512f_clflush(char *dest, const char *src, size_t len); void memmove_movnt_avx512f_clflushopt(char *dest, const char *src, size_t len); void memmove_movnt_avx512f_clwb(char *dest, const char *src, size_t len); void memmove_movnt_avx512f_empty(char *dest, const char *src, size_t len); void memset_mov_avx512f_clflush(char *dest, int c, size_t len); void memset_mov_avx512f_clflushopt(char *dest, int c, size_t len); void memset_mov_avx512f_clwb(char *dest, int c, size_t len); void memset_mov_avx512f_empty(char *dest, int c, size_t len); void memset_movnt_avx512f_clflush(char *dest, int c, size_t len); void memset_movnt_avx512f_clflushopt(char *dest, int c, size_t len); void memset_movnt_avx512f_clwb(char *dest, int c, size_t len); void memset_movnt_avx512f_empty(char *dest, int c, size_t len); #endif extern size_t Movnt_threshold; #endif
5,754
41.316176
79
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_movnt_avx_clflush #define maybe_barrier barrier_after_ntstores #include "memset_nt_avx.h"
1,757
46.513514
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_avx512f.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_MEMSET_AVX512F_H #define PMEM_MEMSET_AVX512F_H #include <stddef.h> #include "memset_avx.h" static force_inline void memset_small_avx512f(char *dest, __m256i ymm, size_t len) { /* We can't do better than AVX here. */ memset_small_avx(dest, ymm, len); } #endif
1,880
38.1875
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b _mm_clflush #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_mov_avx_clflush #include "memset_t_avx.h"
1,738
46
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_sse2_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b flush64b_empty #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_mov_sse2_empty #include "memset_t_sse2.h"
1,739
46.027027
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_sse2_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clwb #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_mov_sse2_clwb #include "memset_t_sse2.h"
1,732
45.837838
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_movnt_avx_clwb #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_avx.h"
1,754
46.432432
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clwb #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_mov_avx_clwb #include "memset_t_avx.h"
1,730
45.783784
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_sse2.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "flush.h" #include "libpmem.h" #include "memcpy_memset.h" #include "memset_sse2.h" #include "out.h" #include "valgrind_internal.h" static force_inline void memset_movnt4x64b(char *dest, __m128i xmm) { _mm_stream_si128((__m128i *)dest + 0, xmm); _mm_stream_si128((__m128i *)dest + 1, xmm); _mm_stream_si128((__m128i *)dest + 2, xmm); _mm_stream_si128((__m128i *)dest + 3, xmm); _mm_stream_si128((__m128i *)dest + 4, xmm); _mm_stream_si128((__m128i *)dest + 5, xmm); _mm_stream_si128((__m128i *)dest + 6, xmm); _mm_stream_si128((__m128i *)dest + 7, xmm); _mm_stream_si128((__m128i *)dest + 8, xmm); _mm_stream_si128((__m128i *)dest + 9, xmm); _mm_stream_si128((__m128i *)dest + 10, xmm); _mm_stream_si128((__m128i *)dest + 11, xmm); _mm_stream_si128((__m128i *)dest + 12, xmm); _mm_stream_si128((__m128i *)dest + 13, xmm); _mm_stream_si128((__m128i *)dest + 14, xmm); _mm_stream_si128((__m128i *)dest + 15, xmm); VALGRIND_DO_FLUSH(dest, 4 * 64); } static force_inline void memset_movnt2x64b(char *dest, __m128i xmm) { _mm_stream_si128((__m128i *)dest + 0, xmm); _mm_stream_si128((__m128i *)dest + 1, xmm); _mm_stream_si128((__m128i *)dest + 2, xmm); _mm_stream_si128((__m128i *)dest + 3, xmm); _mm_stream_si128((__m128i *)dest + 4, xmm); _mm_stream_si128((__m128i *)dest + 5, xmm); _mm_stream_si128((__m128i *)dest + 6, xmm); _mm_stream_si128((__m128i *)dest + 7, xmm); VALGRIND_DO_FLUSH(dest, 2 * 64); } static force_inline void memset_movnt1x64b(char *dest, __m128i xmm) { _mm_stream_si128((__m128i *)dest + 0, xmm); _mm_stream_si128((__m128i *)dest + 1, xmm); _mm_stream_si128((__m128i *)dest + 2, xmm); _mm_stream_si128((__m128i *)dest + 3, xmm); VALGRIND_DO_FLUSH(dest, 64); } static force_inline void memset_movnt1x32b(char *dest, __m128i xmm) { _mm_stream_si128((__m128i *)dest + 0, xmm); _mm_stream_si128((__m128i *)dest + 1, xmm); VALGRIND_DO_FLUSH(dest, 32); } static force_inline void memset_movnt1x16b(char *dest, __m128i xmm) { _mm_stream_si128((__m128i *)dest, xmm); VALGRIND_DO_FLUSH(dest, 16); } static force_inline void memset_movnt1x8b(char *dest, __m128i xmm) { uint64_t x = (uint64_t)_mm_cvtsi128_si64(xmm); _mm_stream_si64((long long *)dest, (long long)x); VALGRIND_DO_FLUSH(dest, 8); } static force_inline void memset_movnt1x4b(char *dest, __m128i xmm) { uint32_t x = (uint32_t)_mm_cvtsi128_si32(xmm); _mm_stream_si32((int *)dest, (int)x); VALGRIND_DO_FLUSH(dest, 4); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m128i xmm = _mm_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_sse2(dest, xmm, cnt); dest += cnt; len -= cnt; } while (len >= 4 * 64) { memset_movnt4x64b(dest, xmm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_movnt2x64b(dest, xmm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_movnt1x64b(dest, xmm); dest += 1 * 64; len -= 1 * 64; } if (len == 0) goto end; /* There's no point in using more than 1 nt store for 1 cache line. */ if (util_is_pow2(len)) { if (len == 32) memset_movnt1x32b(dest, xmm); else if (len == 16) memset_movnt1x16b(dest, xmm); else if (len == 8) memset_movnt1x8b(dest, xmm); else if (len == 4) memset_movnt1x4b(dest, xmm); else goto nonnt; goto end; } nonnt: memset_small_sse2(dest, xmm, len); end: maybe_barrier(); }
5,136
25.755208
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_sse2.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "flush.h" #include "memcpy_memset.h" #include "memset_sse2.h" static force_inline void memset_mov4x64b(char *dest, __m128i xmm) { _mm_store_si128((__m128i *)dest + 0, xmm); _mm_store_si128((__m128i *)dest + 1, xmm); _mm_store_si128((__m128i *)dest + 2, xmm); _mm_store_si128((__m128i *)dest + 3, xmm); _mm_store_si128((__m128i *)dest + 4, xmm); _mm_store_si128((__m128i *)dest + 5, xmm); _mm_store_si128((__m128i *)dest + 6, xmm); _mm_store_si128((__m128i *)dest + 7, xmm); _mm_store_si128((__m128i *)dest + 8, xmm); _mm_store_si128((__m128i *)dest + 9, xmm); _mm_store_si128((__m128i *)dest + 10, xmm); _mm_store_si128((__m128i *)dest + 11, xmm); _mm_store_si128((__m128i *)dest + 12, xmm); _mm_store_si128((__m128i *)dest + 13, xmm); _mm_store_si128((__m128i *)dest + 14, xmm); _mm_store_si128((__m128i *)dest + 15, xmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); } static force_inline void memset_mov2x64b(char *dest, __m128i xmm) { _mm_store_si128((__m128i *)dest + 0, xmm); _mm_store_si128((__m128i *)dest + 1, xmm); _mm_store_si128((__m128i *)dest + 2, xmm); _mm_store_si128((__m128i *)dest + 3, xmm); _mm_store_si128((__m128i *)dest + 4, xmm); _mm_store_si128((__m128i *)dest + 5, xmm); _mm_store_si128((__m128i *)dest + 6, xmm); _mm_store_si128((__m128i *)dest + 7, xmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); } static force_inline void memset_mov1x64b(char *dest, __m128i xmm) { _mm_store_si128((__m128i *)dest + 0, xmm); _mm_store_si128((__m128i *)dest + 1, xmm); _mm_store_si128((__m128i *)dest + 2, xmm); _mm_store_si128((__m128i *)dest + 3, xmm); flush64b(dest + 0 * 64); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m128i xmm = _mm_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_sse2(dest, xmm, cnt); dest += cnt; len -= cnt; } while (len >= 4 * 64) { memset_mov4x64b(dest, xmm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_mov2x64b(dest, xmm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_mov1x64b(dest, xmm); dest += 1 * 64; len -= 1 * 64; } if (len) memset_small_sse2(dest, xmm, len); }
3,985
28.525926
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_sse2_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_movnt_sse2_clflush #define maybe_barrier barrier_after_ntstores #include "memset_nt_sse2.h"
1,759
46.567568
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "avx.h" #include "flush.h" #include "libpmem.h" #include "memset_avx.h" #include "memcpy_memset.h" #include "out.h" #include "valgrind_internal.h" static force_inline void memset_movnt8x64b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest + 0, ymm); _mm256_stream_si256((__m256i *)dest + 1, ymm); _mm256_stream_si256((__m256i *)dest + 2, ymm); _mm256_stream_si256((__m256i *)dest + 3, ymm); _mm256_stream_si256((__m256i *)dest + 4, ymm); _mm256_stream_si256((__m256i *)dest + 5, ymm); _mm256_stream_si256((__m256i *)dest + 6, ymm); _mm256_stream_si256((__m256i *)dest + 7, ymm); _mm256_stream_si256((__m256i *)dest + 8, ymm); _mm256_stream_si256((__m256i *)dest + 9, ymm); _mm256_stream_si256((__m256i *)dest + 10, ymm); _mm256_stream_si256((__m256i *)dest + 11, ymm); _mm256_stream_si256((__m256i *)dest + 12, ymm); _mm256_stream_si256((__m256i *)dest + 13, ymm); _mm256_stream_si256((__m256i *)dest + 14, ymm); _mm256_stream_si256((__m256i *)dest + 15, ymm); VALGRIND_DO_FLUSH(dest, 8 * 64); } static force_inline void memset_movnt4x64b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest + 0, ymm); _mm256_stream_si256((__m256i *)dest + 1, ymm); _mm256_stream_si256((__m256i *)dest + 2, ymm); _mm256_stream_si256((__m256i *)dest + 3, ymm); _mm256_stream_si256((__m256i *)dest + 4, ymm); _mm256_stream_si256((__m256i *)dest + 5, ymm); _mm256_stream_si256((__m256i *)dest + 6, ymm); _mm256_stream_si256((__m256i *)dest + 7, ymm); VALGRIND_DO_FLUSH(dest, 4 * 64); } static force_inline void memset_movnt2x64b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest + 0, ymm); _mm256_stream_si256((__m256i *)dest + 1, ymm); _mm256_stream_si256((__m256i *)dest + 2, ymm); _mm256_stream_si256((__m256i *)dest + 3, ymm); VALGRIND_DO_FLUSH(dest, 2 * 64); } static force_inline void memset_movnt1x64b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest + 0, ymm); _mm256_stream_si256((__m256i *)dest + 1, ymm); VALGRIND_DO_FLUSH(dest, 64); } static force_inline void memset_movnt1x32b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest, ymm); VALGRIND_DO_FLUSH(dest, 32); } static force_inline void memset_movnt1x16b(char *dest, __m256i ymm) { __m128i xmm0 = m256_get16b(ymm); _mm_stream_si128((__m128i *)dest, xmm0); VALGRIND_DO_FLUSH(dest - 16, 16); } static force_inline void memset_movnt1x8b(char *dest, __m256i ymm) { uint64_t x = m256_get8b(ymm); _mm_stream_si64((long long *)dest, (long long)x); VALGRIND_DO_FLUSH(dest, 8); } static force_inline void memset_movnt1x4b(char *dest, __m256i ymm) { uint32_t x = m256_get4b(ymm); _mm_stream_si32((int *)dest, (int)x); VALGRIND_DO_FLUSH(dest, 4); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m256i ymm = _mm256_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_avx(dest, ymm, cnt); dest += cnt; len -= cnt; } while (len >= 8 * 64) { memset_movnt8x64b(dest, ymm); dest += 8 * 64; len -= 8 * 64; } if (len >= 4 * 64) { memset_movnt4x64b(dest, ymm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_movnt2x64b(dest, ymm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_movnt1x64b(dest, ymm); dest += 1 * 64; len -= 1 * 64; } if (len == 0) goto end; /* There's no point in using more than 1 nt store for 1 cache line. */ if (util_is_pow2(len)) { if (len == 32) memset_movnt1x32b(dest, ymm); else if (len == 16) memset_movnt1x16b(dest, ymm); else if (len == 8) memset_movnt1x8b(dest, ymm); else if (len == 4) memset_movnt1x4b(dest, ymm); else goto nonnt; goto end; } nonnt: memset_small_avx(dest, ymm, len); end: avx_zeroupper(); maybe_barrier(); }
5,514
25.137441
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_avx.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_MEMSET_AVX_H #define PMEM_MEMSET_AVX_H #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include <string.h> #include "avx.h" #include "libpmem.h" #include "out.h" static force_inline void memset_small_avx_noflush(char *dest, __m256i ymm, size_t len) { ASSERT(len <= 64); if (len <= 8) goto le8; if (len <= 32) goto le32; /* 33..64 */ _mm256_storeu_si256((__m256i *)dest, ymm); _mm256_storeu_si256((__m256i *)(dest + len - 32), ymm); return; le32: if (len > 16) { /* 17..32 */ __m128i xmm = m256_get16b(ymm); _mm_storeu_si128((__m128i *)dest, xmm); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm); return; } /* 9..16 */ uint64_t d8 = m256_get8b(ymm); *(uint64_t *)dest = d8; *(uint64_t *)(dest + len - 8) = d8; return; le8: if (len <= 2) goto le2; if (len > 4) { /* 5..8 */ uint32_t d = m256_get4b(ymm); *(uint32_t *)dest = d; *(uint32_t *)(dest + len - 4) = d; return; } /* 3..4 */ uint16_t d2 = m256_get2b(ymm); *(uint16_t *)dest = d2; *(uint16_t *)(dest + len - 2) = d2; return; le2: if (len == 2) { uint16_t d2 = m256_get2b(ymm); *(uint16_t *)dest = d2; return; } *(uint8_t *)dest = (uint8_t)m256_get2b(ymm); } static force_inline void memset_small_avx(char *dest, __m256i ymm, size_t len) { memset_small_avx_noflush(dest, ymm, len); flush(dest, len); } #endif
2,975
24.655172
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx512f_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_movnt_avx512f_clwb #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_avx512f.h"
1,762
46.648649
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_movnt_avx_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_avx.h"
1,766
46.756757
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_sse2_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_movnt_sse2_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_sse2.h"
1,768
46.810811
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "avx.h" #include "flush.h" #include "memset_avx.h" #include "memcpy_memset.h" static force_inline void memset_mov8x64b(char *dest, __m256i ymm) { _mm256_store_si256((__m256i *)dest + 0, ymm); _mm256_store_si256((__m256i *)dest + 1, ymm); _mm256_store_si256((__m256i *)dest + 2, ymm); _mm256_store_si256((__m256i *)dest + 3, ymm); _mm256_store_si256((__m256i *)dest + 4, ymm); _mm256_store_si256((__m256i *)dest + 5, ymm); _mm256_store_si256((__m256i *)dest + 6, ymm); _mm256_store_si256((__m256i *)dest + 7, ymm); _mm256_store_si256((__m256i *)dest + 8, ymm); _mm256_store_si256((__m256i *)dest + 9, ymm); _mm256_store_si256((__m256i *)dest + 10, ymm); _mm256_store_si256((__m256i *)dest + 11, ymm); _mm256_store_si256((__m256i *)dest + 12, ymm); _mm256_store_si256((__m256i *)dest + 13, ymm); _mm256_store_si256((__m256i *)dest + 14, ymm); _mm256_store_si256((__m256i *)dest + 15, ymm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); } static force_inline void memset_mov4x64b(char *dest, __m256i ymm) { _mm256_store_si256((__m256i *)dest + 0, ymm); _mm256_store_si256((__m256i *)dest + 1, ymm); _mm256_store_si256((__m256i *)dest + 2, ymm); _mm256_store_si256((__m256i *)dest + 3, ymm); _mm256_store_si256((__m256i *)dest + 4, ymm); _mm256_store_si256((__m256i *)dest + 5, ymm); _mm256_store_si256((__m256i *)dest + 6, ymm); _mm256_store_si256((__m256i *)dest + 7, ymm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); } static force_inline void memset_mov2x64b(char *dest, __m256i ymm) { _mm256_store_si256((__m256i *)dest + 0, ymm); _mm256_store_si256((__m256i *)dest + 1, ymm); _mm256_store_si256((__m256i *)dest + 2, ymm); _mm256_store_si256((__m256i *)dest + 3, ymm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); } static force_inline void memset_mov1x64b(char *dest, __m256i ymm) { _mm256_store_si256((__m256i *)dest + 0, ymm); _mm256_store_si256((__m256i *)dest + 1, ymm); flush64b(dest + 0 * 64); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m256i ymm = _mm256_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_avx(dest, ymm, cnt); dest += cnt; len -= cnt; } while (len >= 8 * 64) { memset_mov8x64b(dest, ymm); dest += 8 * 64; len -= 8 * 64; } if (len >= 4 * 64) { memset_mov4x64b(dest, ymm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_mov2x64b(dest, ymm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_mov1x64b(dest, ymm); dest += 1 * 64; len -= 1 * 64; } if (len) memset_small_avx(dest, ymm, len); avx_zeroupper(); }
4,570
27.56875
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx512f_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_movnt_avx512f_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_avx512f.h"
1,774
46.972973
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx512f_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clflushopt #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_mov_avx512f_clflushopt #include "memset_t_avx512f.h"
1,756
46.486486
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx512f.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "avx.h" #include "flush.h" #include "memset_avx512f.h" #include "memcpy_memset.h" static force_inline void memset_mov32x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); _mm512_store_si512((__m512i *)dest + 1, zmm); _mm512_store_si512((__m512i *)dest + 2, zmm); _mm512_store_si512((__m512i *)dest + 3, zmm); _mm512_store_si512((__m512i *)dest + 4, zmm); _mm512_store_si512((__m512i *)dest + 5, zmm); _mm512_store_si512((__m512i *)dest + 6, zmm); _mm512_store_si512((__m512i *)dest + 7, zmm); _mm512_store_si512((__m512i *)dest + 8, zmm); _mm512_store_si512((__m512i *)dest + 9, zmm); _mm512_store_si512((__m512i *)dest + 10, zmm); _mm512_store_si512((__m512i *)dest + 11, zmm); _mm512_store_si512((__m512i *)dest + 12, zmm); _mm512_store_si512((__m512i *)dest + 13, zmm); _mm512_store_si512((__m512i *)dest + 14, zmm); _mm512_store_si512((__m512i *)dest + 15, zmm); _mm512_store_si512((__m512i *)dest + 16, zmm); _mm512_store_si512((__m512i *)dest + 17, zmm); _mm512_store_si512((__m512i *)dest + 18, zmm); _mm512_store_si512((__m512i *)dest + 19, zmm); _mm512_store_si512((__m512i *)dest + 20, zmm); _mm512_store_si512((__m512i *)dest + 21, zmm); _mm512_store_si512((__m512i *)dest + 22, zmm); _mm512_store_si512((__m512i *)dest + 23, zmm); _mm512_store_si512((__m512i *)dest + 24, zmm); _mm512_store_si512((__m512i *)dest + 25, zmm); _mm512_store_si512((__m512i *)dest + 26, zmm); _mm512_store_si512((__m512i *)dest + 27, zmm); _mm512_store_si512((__m512i *)dest + 28, zmm); _mm512_store_si512((__m512i *)dest + 29, zmm); _mm512_store_si512((__m512i *)dest + 30, zmm); _mm512_store_si512((__m512i *)dest + 31, zmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); flush64b(dest + 8 * 64); flush64b(dest + 9 * 64); flush64b(dest + 10 * 64); flush64b(dest + 11 * 64); flush64b(dest + 12 * 64); flush64b(dest + 13 * 64); flush64b(dest + 14 * 64); flush64b(dest + 15 * 64); flush64b(dest + 16 * 64); flush64b(dest + 17 * 64); flush64b(dest + 18 * 64); flush64b(dest + 19 * 64); flush64b(dest + 20 * 64); flush64b(dest + 21 * 64); flush64b(dest + 22 * 64); flush64b(dest + 23 * 64); flush64b(dest + 24 * 64); flush64b(dest + 25 * 64); flush64b(dest + 26 * 64); flush64b(dest + 27 * 64); flush64b(dest + 28 * 64); flush64b(dest + 29 * 64); flush64b(dest + 30 * 64); flush64b(dest + 31 * 64); } static force_inline void memset_mov16x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); _mm512_store_si512((__m512i *)dest + 1, zmm); _mm512_store_si512((__m512i *)dest + 2, zmm); _mm512_store_si512((__m512i *)dest + 3, zmm); _mm512_store_si512((__m512i *)dest + 4, zmm); _mm512_store_si512((__m512i *)dest + 5, zmm); _mm512_store_si512((__m512i *)dest + 6, zmm); _mm512_store_si512((__m512i *)dest + 7, zmm); _mm512_store_si512((__m512i *)dest + 8, zmm); _mm512_store_si512((__m512i *)dest + 9, zmm); _mm512_store_si512((__m512i *)dest + 10, zmm); _mm512_store_si512((__m512i *)dest + 11, zmm); _mm512_store_si512((__m512i *)dest + 12, zmm); _mm512_store_si512((__m512i *)dest + 13, zmm); _mm512_store_si512((__m512i *)dest + 14, zmm); _mm512_store_si512((__m512i *)dest + 15, zmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); flush64b(dest + 8 * 64); flush64b(dest + 9 * 64); flush64b(dest + 10 * 64); flush64b(dest + 11 * 64); flush64b(dest + 12 * 64); flush64b(dest + 13 * 64); flush64b(dest + 14 * 64); flush64b(dest + 15 * 64); } static force_inline void memset_mov8x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); _mm512_store_si512((__m512i *)dest + 1, zmm); _mm512_store_si512((__m512i *)dest + 2, zmm); _mm512_store_si512((__m512i *)dest + 3, zmm); _mm512_store_si512((__m512i *)dest + 4, zmm); _mm512_store_si512((__m512i *)dest + 5, zmm); _mm512_store_si512((__m512i *)dest + 6, zmm); _mm512_store_si512((__m512i *)dest + 7, zmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); } static force_inline void memset_mov4x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); _mm512_store_si512((__m512i *)dest + 1, zmm); _mm512_store_si512((__m512i *)dest + 2, zmm); _mm512_store_si512((__m512i *)dest + 3, zmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); } static force_inline void memset_mov2x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); _mm512_store_si512((__m512i *)dest + 1, zmm); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); } static force_inline void memset_mov1x64b(char *dest, __m512i zmm) { _mm512_store_si512((__m512i *)dest + 0, zmm); flush64b(dest + 0 * 64); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m512i zmm = _mm512_set1_epi8((char)c); /* See comment in memset_movnt_avx512f */ __m256i ymm = _mm256_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_avx512f(dest, ymm, cnt); dest += cnt; len -= cnt; } while (len >= 32 * 64) { memset_mov32x64b(dest, zmm); dest += 32 * 64; len -= 32 * 64; } if (len >= 16 * 64) { memset_mov16x64b(dest, zmm); dest += 16 * 64; len -= 16 * 64; } if (len >= 8 * 64) { memset_mov8x64b(dest, zmm); dest += 8 * 64; len -= 8 * 64; } if (len >= 4 * 64) { memset_mov4x64b(dest, zmm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_mov2x64b(dest, zmm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_mov1x64b(dest, zmm); dest += 1 * 64; len -= 1 * 64; } if (len) memset_small_avx512f(dest, ymm, len); avx_zeroupper(); }
7,852
28.411985
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_sse2_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b _mm_clflush #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_mov_sse2_clflush #include "memset_t_sse2.h"
1,740
46.054054
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx512f_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_movnt_avx512f_clflush #define maybe_barrier barrier_after_ntstores #include "memset_nt_avx512f.h"
1,765
46.72973
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clflushopt #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_mov_avx_clflushopt #include "memset_t_avx.h"
1,748
46.27027
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_sse2_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_movnt_sse2_empty #define maybe_barrier barrier_after_ntstores #include "memset_nt_sse2.h"
1,755
46.459459
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx512f_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b _mm_clflush #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memset_mov_avx512f_clflush #include "memset_t_avx512f.h"
1,746
46.216216
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx512f_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clwb #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_mov_avx512f_clwb #include "memset_t_avx512f.h"
1,738
46
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b flush64b_empty #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_mov_avx_empty #include "memset_t_avx.h"
1,737
45.972973
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_movnt_avx_empty #define maybe_barrier barrier_after_ntstores #include "memset_nt_avx.h"
1,753
46.405405
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_sse2.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_MEMSET_SSE2_H #define PMEM_MEMSET_SSE2_H #include <xmmintrin.h> #include <stddef.h> #include <stdint.h> #include <string.h> #include "libpmem.h" #include "out.h" static force_inline void memset_small_sse2_noflush(char *dest, __m128i xmm, size_t len) { ASSERT(len <= 64); if (len <= 8) goto le8; if (len <= 32) goto le32; if (len > 48) { /* 49..64 */ _mm_storeu_si128((__m128i *)(dest + 0), xmm); _mm_storeu_si128((__m128i *)(dest + 16), xmm); _mm_storeu_si128((__m128i *)(dest + 32), xmm); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm); return; } /* 33..48 */ _mm_storeu_si128((__m128i *)(dest + 0), xmm); _mm_storeu_si128((__m128i *)(dest + 16), xmm); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm); return; le32: if (len > 16) { /* 17..32 */ _mm_storeu_si128((__m128i *)(dest + 0), xmm); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm); return; } /* 9..16 */ uint64_t d8 = (uint64_t)_mm_cvtsi128_si64(xmm); *(uint64_t *)dest = d8; *(uint64_t *)(dest + len - 8) = d8; return; le8: if (len <= 2) goto le2; if (len > 4) { /* 5..8 */ uint32_t d4 = (uint32_t)_mm_cvtsi128_si32(xmm); *(uint32_t *)dest = d4; *(uint32_t *)(dest + len - 4) = d4; return; } /* 3..4 */ uint16_t d2 = (uint16_t)(uint32_t)_mm_cvtsi128_si32(xmm); *(uint16_t *)dest = d2; *(uint16_t *)(dest + len - 2) = d2; return; le2: if (len == 2) { uint16_t d2 = (uint16_t)(uint32_t)_mm_cvtsi128_si32(xmm); *(uint16_t *)dest = d2; return; } *(uint8_t *)dest = (uint8_t)_mm_cvtsi128_si32(xmm); } static force_inline void memset_small_sse2(char *dest, __m128i xmm, size_t len) { memset_small_sse2_noflush(dest, xmm, len); flush(dest, len); } #endif
3,327
26.056911
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_sse2_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memset_movnt_sse2_clwb #define maybe_barrier no_barrier_after_ntstores #include "memset_nt_sse2.h"
1,756
46.486486
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_sse2_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clflushopt #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memset_mov_sse2_clflushopt #include "memset_t_sse2.h"
1,750
46.324324
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_t_avx512f_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b flush64b_empty #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_mov_avx512f_empty #include "memset_t_avx512f.h"
1,745
46.189189
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx512f.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "avx.h" #include "flush.h" #include "libpmem.h" #include "memcpy_memset.h" #include "memset_avx512f.h" #include "out.h" #include "util.h" #include "valgrind_internal.h" static force_inline void memset_movnt32x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); _mm512_stream_si512((__m512i *)dest + 1, zmm); _mm512_stream_si512((__m512i *)dest + 2, zmm); _mm512_stream_si512((__m512i *)dest + 3, zmm); _mm512_stream_si512((__m512i *)dest + 4, zmm); _mm512_stream_si512((__m512i *)dest + 5, zmm); _mm512_stream_si512((__m512i *)dest + 6, zmm); _mm512_stream_si512((__m512i *)dest + 7, zmm); _mm512_stream_si512((__m512i *)dest + 8, zmm); _mm512_stream_si512((__m512i *)dest + 9, zmm); _mm512_stream_si512((__m512i *)dest + 10, zmm); _mm512_stream_si512((__m512i *)dest + 11, zmm); _mm512_stream_si512((__m512i *)dest + 12, zmm); _mm512_stream_si512((__m512i *)dest + 13, zmm); _mm512_stream_si512((__m512i *)dest + 14, zmm); _mm512_stream_si512((__m512i *)dest + 15, zmm); _mm512_stream_si512((__m512i *)dest + 16, zmm); _mm512_stream_si512((__m512i *)dest + 17, zmm); _mm512_stream_si512((__m512i *)dest + 18, zmm); _mm512_stream_si512((__m512i *)dest + 19, zmm); _mm512_stream_si512((__m512i *)dest + 20, zmm); _mm512_stream_si512((__m512i *)dest + 21, zmm); _mm512_stream_si512((__m512i *)dest + 22, zmm); _mm512_stream_si512((__m512i *)dest + 23, zmm); _mm512_stream_si512((__m512i *)dest + 24, zmm); _mm512_stream_si512((__m512i *)dest + 25, zmm); _mm512_stream_si512((__m512i *)dest + 26, zmm); _mm512_stream_si512((__m512i *)dest + 27, zmm); _mm512_stream_si512((__m512i *)dest + 28, zmm); _mm512_stream_si512((__m512i *)dest + 29, zmm); _mm512_stream_si512((__m512i *)dest + 30, zmm); _mm512_stream_si512((__m512i *)dest + 31, zmm); VALGRIND_DO_FLUSH(dest, 32 * 64); } static force_inline void memset_movnt16x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); _mm512_stream_si512((__m512i *)dest + 1, zmm); _mm512_stream_si512((__m512i *)dest + 2, zmm); _mm512_stream_si512((__m512i *)dest + 3, zmm); _mm512_stream_si512((__m512i *)dest + 4, zmm); _mm512_stream_si512((__m512i *)dest + 5, zmm); _mm512_stream_si512((__m512i *)dest + 6, zmm); _mm512_stream_si512((__m512i *)dest + 7, zmm); _mm512_stream_si512((__m512i *)dest + 8, zmm); _mm512_stream_si512((__m512i *)dest + 9, zmm); _mm512_stream_si512((__m512i *)dest + 10, zmm); _mm512_stream_si512((__m512i *)dest + 11, zmm); _mm512_stream_si512((__m512i *)dest + 12, zmm); _mm512_stream_si512((__m512i *)dest + 13, zmm); _mm512_stream_si512((__m512i *)dest + 14, zmm); _mm512_stream_si512((__m512i *)dest + 15, zmm); VALGRIND_DO_FLUSH(dest, 16 * 64); } static force_inline void memset_movnt8x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); _mm512_stream_si512((__m512i *)dest + 1, zmm); _mm512_stream_si512((__m512i *)dest + 2, zmm); _mm512_stream_si512((__m512i *)dest + 3, zmm); _mm512_stream_si512((__m512i *)dest + 4, zmm); _mm512_stream_si512((__m512i *)dest + 5, zmm); _mm512_stream_si512((__m512i *)dest + 6, zmm); _mm512_stream_si512((__m512i *)dest + 7, zmm); VALGRIND_DO_FLUSH(dest, 8 * 64); } static force_inline void memset_movnt4x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); _mm512_stream_si512((__m512i *)dest + 1, zmm); _mm512_stream_si512((__m512i *)dest + 2, zmm); _mm512_stream_si512((__m512i *)dest + 3, zmm); VALGRIND_DO_FLUSH(dest, 4 * 64); } static force_inline void memset_movnt2x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); _mm512_stream_si512((__m512i *)dest + 1, zmm); VALGRIND_DO_FLUSH(dest, 2 * 64); } static force_inline void memset_movnt1x64b(char *dest, __m512i zmm) { _mm512_stream_si512((__m512i *)dest + 0, zmm); VALGRIND_DO_FLUSH(dest, 64); } static force_inline void memset_movnt1x32b(char *dest, __m256i ymm) { _mm256_stream_si256((__m256i *)dest, ymm); VALGRIND_DO_FLUSH(dest, 32); } static force_inline void memset_movnt1x16b(char *dest, __m256i ymm) { __m128i xmm = _mm256_extracti128_si256(ymm, 0); _mm_stream_si128((__m128i *)dest, xmm); VALGRIND_DO_FLUSH(dest, 16); } static force_inline void memset_movnt1x8b(char *dest, __m256i ymm) { uint64_t x = m256_get8b(ymm); _mm_stream_si64((long long *)dest, (long long)x); VALGRIND_DO_FLUSH(dest, 8); } static force_inline void memset_movnt1x4b(char *dest, __m256i ymm) { uint32_t x = m256_get4b(ymm); _mm_stream_si32((int *)dest, (int)x); VALGRIND_DO_FLUSH(dest, 4); } void EXPORTED_SYMBOL(char *dest, int c, size_t len) { __m512i zmm = _mm512_set1_epi8((char)c); /* * Can't use _mm512_extracti64x4_epi64, because some versions of gcc * crash. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82887 */ __m256i ymm = _mm256_set1_epi8((char)c); size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memset_small_avx512f(dest, ymm, cnt); dest += cnt; len -= cnt; } while (len >= 32 * 64) { memset_movnt32x64b(dest, zmm); dest += 32 * 64; len -= 32 * 64; } if (len >= 16 * 64) { memset_movnt16x64b(dest, zmm); dest += 16 * 64; len -= 16 * 64; } if (len >= 8 * 64) { memset_movnt8x64b(dest, zmm); dest += 8 * 64; len -= 8 * 64; } if (len >= 4 * 64) { memset_movnt4x64b(dest, zmm); dest += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memset_movnt2x64b(dest, zmm); dest += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memset_movnt1x64b(dest, zmm); dest += 1 * 64; len -= 1 * 64; } if (len == 0) goto end; /* There's no point in using more than 1 nt store for 1 cache line. */ if (util_is_pow2(len)) { if (len == 32) memset_movnt1x32b(dest, ymm); else if (len == 16) memset_movnt1x16b(dest, ymm); else if (len == 8) memset_movnt1x8b(dest, ymm); else if (len == 4) memset_movnt1x4b(dest, ymm); else goto nonnt; goto end; } nonnt: memset_small_avx512f(dest, ymm, len); end: avx_zeroupper(); maybe_barrier(); }
7,756
27.105072
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memset/memset_nt_avx512f_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_empty_nolog #define EXPORTED_SYMBOL memset_movnt_avx512f_empty #define maybe_barrier barrier_after_ntstores #include "memset_nt_avx512f.h"
1,761
46.621622
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_t_avx512f_clwb.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b pmem_clwb #define flush flush_clwb_nolog #define EXPORTED_SYMBOL memmove_mov_avx512f_clwb #include "memcpy_t_avx512f.h"
1,739
46.027027
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_avx512f_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memmove_movnt_avx512f_clflush #define maybe_barrier barrier_after_ntstores #include "memcpy_nt_avx512f.h"
1,766
46.756757
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_avx512f_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memmove_movnt_avx512f_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memcpy_nt_avx512f.h"
1,775
47
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_t_avx_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b _mm_clflush #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memmove_mov_avx_clflush #include "memcpy_t_avx.h"
1,739
46.027027
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_sse2_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memmove_movnt_sse2_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memcpy_nt_sse2.h"
1,769
46.837838
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_avx_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memmove_movnt_avx_clflush #define maybe_barrier barrier_after_ntstores #include "memcpy_nt_avx.h"
1,758
46.540541
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_avx.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_MEMCPY_AVX_H #define PMEM_MEMCPY_AVX_H #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "libpmem.h" #include "out.h" static force_inline void memmove_small_avx_noflush(char *dest, const char *src, size_t len) { ASSERT(len <= 64); if (len <= 8) goto le8; if (len <= 32) goto le32; /* 33..64 */ __m256i ymm0 = _mm256_loadu_si256((__m256i *)src); __m256i ymm1 = _mm256_loadu_si256((__m256i *)(src + len - 32)); _mm256_storeu_si256((__m256i *)dest, ymm0); _mm256_storeu_si256((__m256i *)(dest + len - 32), ymm1); return; le32: if (len > 16) { /* 17..32 */ __m128i xmm0 = _mm_loadu_si128((__m128i *)src); __m128i xmm1 = _mm_loadu_si128((__m128i *)(src + len - 16)); _mm_storeu_si128((__m128i *)dest, xmm0); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm1); return; } /* 9..16 */ uint64_t d80 = *(uint64_t *)src; uint64_t d81 = *(uint64_t *)(src + len - 8); *(uint64_t *)dest = d80; *(uint64_t *)(dest + len - 8) = d81; return; le8: if (len <= 2) goto le2; if (len > 4) { /* 5..8 */ uint32_t d40 = *(uint32_t *)src; uint32_t d41 = *(uint32_t *)(src + len - 4); *(uint32_t *)dest = d40; *(uint32_t *)(dest + len - 4) = d41; return; } /* 3..4 */ uint16_t d20 = *(uint16_t *)src; uint16_t d21 = *(uint16_t *)(src + len - 2); *(uint16_t *)dest = d20; *(uint16_t *)(dest + len - 2) = d21; return; le2: if (len == 2) { *(uint16_t *)dest = *(uint16_t *)src; return; } *(uint8_t *)dest = *(uint8_t *)src; } static force_inline void memmove_small_avx(char *dest, const char *src, size_t len) { memmove_small_avx_noflush(dest, src, len); flush(dest, len); } #endif
3,275
26.529412
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_sse2.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PMEM_MEMCPY_SSE2_H #define PMEM_MEMCPY_SSE2_H #include <xmmintrin.h> #include <stddef.h> #include <stdint.h> #include "libpmem.h" #include "out.h" static force_inline void memmove_small_sse2_noflush(char *dest, const char *src, size_t len) { ASSERT(len <= 64); if (len <= 8) goto le8; if (len <= 32) goto le32; if (len > 48) { /* 49..64 */ __m128i xmm0 = _mm_loadu_si128((__m128i *)src); __m128i xmm1 = _mm_loadu_si128((__m128i *)(src + 16)); __m128i xmm2 = _mm_loadu_si128((__m128i *)(src + 32)); __m128i xmm3 = _mm_loadu_si128((__m128i *)(src + len - 16)); _mm_storeu_si128((__m128i *)dest, xmm0); _mm_storeu_si128((__m128i *)(dest + 16), xmm1); _mm_storeu_si128((__m128i *)(dest + 32), xmm2); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm3); return; } /* 33..48 */ __m128i xmm0 = _mm_loadu_si128((__m128i *)src); __m128i xmm1 = _mm_loadu_si128((__m128i *)(src + 16)); __m128i xmm2 = _mm_loadu_si128((__m128i *)(src + len - 16)); _mm_storeu_si128((__m128i *)dest, xmm0); _mm_storeu_si128((__m128i *)(dest + 16), xmm1); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm2); return; le32: if (len > 16) { /* 17..32 */ __m128i xmm0 = _mm_loadu_si128((__m128i *)src); __m128i xmm1 = _mm_loadu_si128((__m128i *)(src + len - 16)); _mm_storeu_si128((__m128i *)dest, xmm0); _mm_storeu_si128((__m128i *)(dest + len - 16), xmm1); return; } /* 9..16 */ uint64_t d80 = *(uint64_t *)src; uint64_t d81 = *(uint64_t *)(src + len - 8); *(uint64_t *)dest = d80; *(uint64_t *)(dest + len - 8) = d81; return; le8: if (len <= 2) goto le2; if (len > 4) { /* 5..8 */ uint32_t d40 = *(uint32_t *)src; uint32_t d41 = *(uint32_t *)(src + len - 4); *(uint32_t *)dest = d40; *(uint32_t *)(dest + len - 4) = d41; return; } /* 3..4 */ uint16_t d20 = *(uint16_t *)src; uint16_t d21 = *(uint16_t *)(src + len - 2); *(uint16_t *)dest = d20; *(uint16_t *)(dest + len - 2) = d21; return; le2: if (len == 2) { *(uint16_t *)dest = *(uint16_t *)src; return; } *(uint8_t *)dest = *(uint8_t *)src; } static force_inline void memmove_small_sse2(char *dest, const char *src, size_t len) { memmove_small_sse2_noflush(dest, src, len); flush(dest, len); } #endif
3,846
27.496296
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_t_sse2.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "flush.h" #include "memcpy_memset.h" #include "memcpy_sse2.h" static force_inline void memmove_mov4x64b(char *dest, const char *src) { __m128i xmm0 = _mm_loadu_si128((__m128i *)src + 0); __m128i xmm1 = _mm_loadu_si128((__m128i *)src + 1); __m128i xmm2 = _mm_loadu_si128((__m128i *)src + 2); __m128i xmm3 = _mm_loadu_si128((__m128i *)src + 3); __m128i xmm4 = _mm_loadu_si128((__m128i *)src + 4); __m128i xmm5 = _mm_loadu_si128((__m128i *)src + 5); __m128i xmm6 = _mm_loadu_si128((__m128i *)src + 6); __m128i xmm7 = _mm_loadu_si128((__m128i *)src + 7); __m128i xmm8 = _mm_loadu_si128((__m128i *)src + 8); __m128i xmm9 = _mm_loadu_si128((__m128i *)src + 9); __m128i xmm10 = _mm_loadu_si128((__m128i *)src + 10); __m128i xmm11 = _mm_loadu_si128((__m128i *)src + 11); __m128i xmm12 = _mm_loadu_si128((__m128i *)src + 12); __m128i xmm13 = _mm_loadu_si128((__m128i *)src + 13); __m128i xmm14 = _mm_loadu_si128((__m128i *)src + 14); __m128i xmm15 = _mm_loadu_si128((__m128i *)src + 15); _mm_store_si128((__m128i *)dest + 0, xmm0); _mm_store_si128((__m128i *)dest + 1, xmm1); _mm_store_si128((__m128i *)dest + 2, xmm2); _mm_store_si128((__m128i *)dest + 3, xmm3); _mm_store_si128((__m128i *)dest + 4, xmm4); _mm_store_si128((__m128i *)dest + 5, xmm5); _mm_store_si128((__m128i *)dest + 6, xmm6); _mm_store_si128((__m128i *)dest + 7, xmm7); _mm_store_si128((__m128i *)dest + 8, xmm8); _mm_store_si128((__m128i *)dest + 9, xmm9); _mm_store_si128((__m128i *)dest + 10, xmm10); _mm_store_si128((__m128i *)dest + 11, xmm11); _mm_store_si128((__m128i *)dest + 12, xmm12); _mm_store_si128((__m128i *)dest + 13, xmm13); _mm_store_si128((__m128i *)dest + 14, xmm14); _mm_store_si128((__m128i *)dest + 15, xmm15); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); } static force_inline void memmove_mov2x64b(char *dest, const char *src) { __m128i xmm0 = _mm_loadu_si128((__m128i *)src + 0); __m128i xmm1 = _mm_loadu_si128((__m128i *)src + 1); __m128i xmm2 = _mm_loadu_si128((__m128i *)src + 2); __m128i xmm3 = _mm_loadu_si128((__m128i *)src + 3); __m128i xmm4 = _mm_loadu_si128((__m128i *)src + 4); __m128i xmm5 = _mm_loadu_si128((__m128i *)src + 5); __m128i xmm6 = _mm_loadu_si128((__m128i *)src + 6); __m128i xmm7 = _mm_loadu_si128((__m128i *)src + 7); _mm_store_si128((__m128i *)dest + 0, xmm0); _mm_store_si128((__m128i *)dest + 1, xmm1); _mm_store_si128((__m128i *)dest + 2, xmm2); _mm_store_si128((__m128i *)dest + 3, xmm3); _mm_store_si128((__m128i *)dest + 4, xmm4); _mm_store_si128((__m128i *)dest + 5, xmm5); _mm_store_si128((__m128i *)dest + 6, xmm6); _mm_store_si128((__m128i *)dest + 7, xmm7); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); } static force_inline void memmove_mov1x64b(char *dest, const char *src) { __m128i xmm0 = _mm_loadu_si128((__m128i *)src + 0); __m128i xmm1 = _mm_loadu_si128((__m128i *)src + 1); __m128i xmm2 = _mm_loadu_si128((__m128i *)src + 2); __m128i xmm3 = _mm_loadu_si128((__m128i *)src + 3); _mm_store_si128((__m128i *)dest + 0, xmm0); _mm_store_si128((__m128i *)dest + 1, xmm1); _mm_store_si128((__m128i *)dest + 2, xmm2); _mm_store_si128((__m128i *)dest + 3, xmm3); flush64b(dest + 0 * 64); } static force_inline void memmove_mov_sse_fw(char *dest, const char *src, size_t len) { size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memmove_small_sse2(dest, src, cnt); dest += cnt; src += cnt; len -= cnt; } while (len >= 4 * 64) { memmove_mov4x64b(dest, src); dest += 4 * 64; src += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memmove_mov2x64b(dest, src); dest += 2 * 64; src += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memmove_mov1x64b(dest, src); dest += 1 * 64; src += 1 * 64; len -= 1 * 64; } if (len) memmove_small_sse2(dest, src, len); } static force_inline void memmove_mov_sse_bw(char *dest, const char *src, size_t len) { dest += len; src += len; size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { if (cnt > len) cnt = len; dest -= cnt; src -= cnt; len -= cnt; memmove_small_sse2(dest, src, cnt); } while (len >= 4 * 64) { dest -= 4 * 64; src -= 4 * 64; len -= 4 * 64; memmove_mov4x64b(dest, src); } if (len >= 2 * 64) { dest -= 2 * 64; src -= 2 * 64; len -= 2 * 64; memmove_mov2x64b(dest, src); } if (len >= 1 * 64) { dest -= 1 * 64; src -= 1 * 64; len -= 1 * 64; memmove_mov1x64b(dest, src); } if (len) memmove_small_sse2(dest - len, src - len, len); } void EXPORTED_SYMBOL(char *dest, const char *src, size_t len) { if ((uintptr_t)dest - (uintptr_t)src >= len) memmove_mov_sse_fw(dest, src, len); else memmove_mov_sse_bw(dest, src, len); }
6,467
28.534247
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_sse2_clflush.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflush_nolog #define EXPORTED_SYMBOL memmove_movnt_sse2_clflush #define maybe_barrier barrier_after_ntstores #include "memcpy_nt_sse2.h"
1,760
46.594595
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_t_avx512f_empty.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush64b flush64b_empty #define flush flush_empty_nolog #define EXPORTED_SYMBOL memmove_mov_avx512f_empty #include "memcpy_t_avx512f.h"
1,746
46.216216
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_nt_avx_clflushopt.c
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define flush flush_clflushopt_nolog #define EXPORTED_SYMBOL memmove_movnt_avx_clflushopt #define maybe_barrier no_barrier_after_ntstores #include "memcpy_nt_avx.h"
1,767
46.783784
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/libpmem/x86_64/memcpy/memcpy_t_avx512f.h
/* * Copyright 2017-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <immintrin.h> #include <stddef.h> #include <stdint.h> #include "pmem.h" #include "avx.h" #include "flush.h" #include "memcpy_avx512f.h" #include "memcpy_memset.h" static force_inline void memmove_mov32x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); __m512i zmm1 = _mm512_loadu_si512((__m512i *)src + 1); __m512i zmm2 = _mm512_loadu_si512((__m512i *)src + 2); __m512i zmm3 = _mm512_loadu_si512((__m512i *)src + 3); __m512i zmm4 = _mm512_loadu_si512((__m512i *)src + 4); __m512i zmm5 = _mm512_loadu_si512((__m512i *)src + 5); __m512i zmm6 = _mm512_loadu_si512((__m512i *)src + 6); __m512i zmm7 = _mm512_loadu_si512((__m512i *)src + 7); __m512i zmm8 = _mm512_loadu_si512((__m512i *)src + 8); __m512i zmm9 = _mm512_loadu_si512((__m512i *)src + 9); __m512i zmm10 = _mm512_loadu_si512((__m512i *)src + 10); __m512i zmm11 = _mm512_loadu_si512((__m512i *)src + 11); __m512i zmm12 = _mm512_loadu_si512((__m512i *)src + 12); __m512i zmm13 = _mm512_loadu_si512((__m512i *)src + 13); __m512i zmm14 = _mm512_loadu_si512((__m512i *)src + 14); __m512i zmm15 = _mm512_loadu_si512((__m512i *)src + 15); __m512i zmm16 = _mm512_loadu_si512((__m512i *)src + 16); __m512i zmm17 = _mm512_loadu_si512((__m512i *)src + 17); __m512i zmm18 = _mm512_loadu_si512((__m512i *)src + 18); __m512i zmm19 = _mm512_loadu_si512((__m512i *)src + 19); __m512i zmm20 = _mm512_loadu_si512((__m512i *)src + 20); __m512i zmm21 = _mm512_loadu_si512((__m512i *)src + 21); __m512i zmm22 = _mm512_loadu_si512((__m512i *)src + 22); __m512i zmm23 = _mm512_loadu_si512((__m512i *)src + 23); __m512i zmm24 = _mm512_loadu_si512((__m512i *)src + 24); __m512i zmm25 = _mm512_loadu_si512((__m512i *)src + 25); __m512i zmm26 = _mm512_loadu_si512((__m512i *)src + 26); __m512i zmm27 = _mm512_loadu_si512((__m512i *)src + 27); __m512i zmm28 = _mm512_loadu_si512((__m512i *)src + 28); __m512i zmm29 = _mm512_loadu_si512((__m512i *)src + 29); __m512i zmm30 = _mm512_loadu_si512((__m512i *)src + 30); __m512i zmm31 = _mm512_loadu_si512((__m512i *)src + 31); _mm512_store_si512((__m512i *)dest + 0, zmm0); _mm512_store_si512((__m512i *)dest + 1, zmm1); _mm512_store_si512((__m512i *)dest + 2, zmm2); _mm512_store_si512((__m512i *)dest + 3, zmm3); _mm512_store_si512((__m512i *)dest + 4, zmm4); _mm512_store_si512((__m512i *)dest + 5, zmm5); _mm512_store_si512((__m512i *)dest + 6, zmm6); _mm512_store_si512((__m512i *)dest + 7, zmm7); _mm512_store_si512((__m512i *)dest + 8, zmm8); _mm512_store_si512((__m512i *)dest + 9, zmm9); _mm512_store_si512((__m512i *)dest + 10, zmm10); _mm512_store_si512((__m512i *)dest + 11, zmm11); _mm512_store_si512((__m512i *)dest + 12, zmm12); _mm512_store_si512((__m512i *)dest + 13, zmm13); _mm512_store_si512((__m512i *)dest + 14, zmm14); _mm512_store_si512((__m512i *)dest + 15, zmm15); _mm512_store_si512((__m512i *)dest + 16, zmm16); _mm512_store_si512((__m512i *)dest + 17, zmm17); _mm512_store_si512((__m512i *)dest + 18, zmm18); _mm512_store_si512((__m512i *)dest + 19, zmm19); _mm512_store_si512((__m512i *)dest + 20, zmm20); _mm512_store_si512((__m512i *)dest + 21, zmm21); _mm512_store_si512((__m512i *)dest + 22, zmm22); _mm512_store_si512((__m512i *)dest + 23, zmm23); _mm512_store_si512((__m512i *)dest + 24, zmm24); _mm512_store_si512((__m512i *)dest + 25, zmm25); _mm512_store_si512((__m512i *)dest + 26, zmm26); _mm512_store_si512((__m512i *)dest + 27, zmm27); _mm512_store_si512((__m512i *)dest + 28, zmm28); _mm512_store_si512((__m512i *)dest + 29, zmm29); _mm512_store_si512((__m512i *)dest + 30, zmm30); _mm512_store_si512((__m512i *)dest + 31, zmm31); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); flush64b(dest + 8 * 64); flush64b(dest + 9 * 64); flush64b(dest + 10 * 64); flush64b(dest + 11 * 64); flush64b(dest + 12 * 64); flush64b(dest + 13 * 64); flush64b(dest + 14 * 64); flush64b(dest + 15 * 64); flush64b(dest + 16 * 64); flush64b(dest + 17 * 64); flush64b(dest + 18 * 64); flush64b(dest + 19 * 64); flush64b(dest + 20 * 64); flush64b(dest + 21 * 64); flush64b(dest + 22 * 64); flush64b(dest + 23 * 64); flush64b(dest + 24 * 64); flush64b(dest + 25 * 64); flush64b(dest + 26 * 64); flush64b(dest + 27 * 64); flush64b(dest + 28 * 64); flush64b(dest + 29 * 64); flush64b(dest + 30 * 64); flush64b(dest + 31 * 64); } static force_inline void memmove_mov16x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); __m512i zmm1 = _mm512_loadu_si512((__m512i *)src + 1); __m512i zmm2 = _mm512_loadu_si512((__m512i *)src + 2); __m512i zmm3 = _mm512_loadu_si512((__m512i *)src + 3); __m512i zmm4 = _mm512_loadu_si512((__m512i *)src + 4); __m512i zmm5 = _mm512_loadu_si512((__m512i *)src + 5); __m512i zmm6 = _mm512_loadu_si512((__m512i *)src + 6); __m512i zmm7 = _mm512_loadu_si512((__m512i *)src + 7); __m512i zmm8 = _mm512_loadu_si512((__m512i *)src + 8); __m512i zmm9 = _mm512_loadu_si512((__m512i *)src + 9); __m512i zmm10 = _mm512_loadu_si512((__m512i *)src + 10); __m512i zmm11 = _mm512_loadu_si512((__m512i *)src + 11); __m512i zmm12 = _mm512_loadu_si512((__m512i *)src + 12); __m512i zmm13 = _mm512_loadu_si512((__m512i *)src + 13); __m512i zmm14 = _mm512_loadu_si512((__m512i *)src + 14); __m512i zmm15 = _mm512_loadu_si512((__m512i *)src + 15); _mm512_store_si512((__m512i *)dest + 0, zmm0); _mm512_store_si512((__m512i *)dest + 1, zmm1); _mm512_store_si512((__m512i *)dest + 2, zmm2); _mm512_store_si512((__m512i *)dest + 3, zmm3); _mm512_store_si512((__m512i *)dest + 4, zmm4); _mm512_store_si512((__m512i *)dest + 5, zmm5); _mm512_store_si512((__m512i *)dest + 6, zmm6); _mm512_store_si512((__m512i *)dest + 7, zmm7); _mm512_store_si512((__m512i *)dest + 8, zmm8); _mm512_store_si512((__m512i *)dest + 9, zmm9); _mm512_store_si512((__m512i *)dest + 10, zmm10); _mm512_store_si512((__m512i *)dest + 11, zmm11); _mm512_store_si512((__m512i *)dest + 12, zmm12); _mm512_store_si512((__m512i *)dest + 13, zmm13); _mm512_store_si512((__m512i *)dest + 14, zmm14); _mm512_store_si512((__m512i *)dest + 15, zmm15); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); flush64b(dest + 8 * 64); flush64b(dest + 9 * 64); flush64b(dest + 10 * 64); flush64b(dest + 11 * 64); flush64b(dest + 12 * 64); flush64b(dest + 13 * 64); flush64b(dest + 14 * 64); flush64b(dest + 15 * 64); } static force_inline void memmove_mov8x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); __m512i zmm1 = _mm512_loadu_si512((__m512i *)src + 1); __m512i zmm2 = _mm512_loadu_si512((__m512i *)src + 2); __m512i zmm3 = _mm512_loadu_si512((__m512i *)src + 3); __m512i zmm4 = _mm512_loadu_si512((__m512i *)src + 4); __m512i zmm5 = _mm512_loadu_si512((__m512i *)src + 5); __m512i zmm6 = _mm512_loadu_si512((__m512i *)src + 6); __m512i zmm7 = _mm512_loadu_si512((__m512i *)src + 7); _mm512_store_si512((__m512i *)dest + 0, zmm0); _mm512_store_si512((__m512i *)dest + 1, zmm1); _mm512_store_si512((__m512i *)dest + 2, zmm2); _mm512_store_si512((__m512i *)dest + 3, zmm3); _mm512_store_si512((__m512i *)dest + 4, zmm4); _mm512_store_si512((__m512i *)dest + 5, zmm5); _mm512_store_si512((__m512i *)dest + 6, zmm6); _mm512_store_si512((__m512i *)dest + 7, zmm7); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); flush64b(dest + 4 * 64); flush64b(dest + 5 * 64); flush64b(dest + 6 * 64); flush64b(dest + 7 * 64); } static force_inline void memmove_mov4x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); __m512i zmm1 = _mm512_loadu_si512((__m512i *)src + 1); __m512i zmm2 = _mm512_loadu_si512((__m512i *)src + 2); __m512i zmm3 = _mm512_loadu_si512((__m512i *)src + 3); _mm512_store_si512((__m512i *)dest + 0, zmm0); _mm512_store_si512((__m512i *)dest + 1, zmm1); _mm512_store_si512((__m512i *)dest + 2, zmm2); _mm512_store_si512((__m512i *)dest + 3, zmm3); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); flush64b(dest + 2 * 64); flush64b(dest + 3 * 64); } static force_inline void memmove_mov2x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); __m512i zmm1 = _mm512_loadu_si512((__m512i *)src + 1); _mm512_store_si512((__m512i *)dest + 0, zmm0); _mm512_store_si512((__m512i *)dest + 1, zmm1); flush64b(dest + 0 * 64); flush64b(dest + 1 * 64); } static force_inline void memmove_mov1x64b(char *dest, const char *src) { __m512i zmm0 = _mm512_loadu_si512((__m512i *)src + 0); _mm512_store_si512((__m512i *)dest + 0, zmm0); flush64b(dest + 0 * 64); } static force_inline void memmove_mov_avx512f_fw(char *dest, const char *src, size_t len) { size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { cnt = 64 - cnt; if (cnt > len) cnt = len; memmove_small_avx512f(dest, src, cnt); dest += cnt; src += cnt; len -= cnt; } while (len >= 32 * 64) { memmove_mov32x64b(dest, src); dest += 32 * 64; src += 32 * 64; len -= 32 * 64; } if (len >= 16 * 64) { memmove_mov16x64b(dest, src); dest += 16 * 64; src += 16 * 64; len -= 16 * 64; } if (len >= 8 * 64) { memmove_mov8x64b(dest, src); dest += 8 * 64; src += 8 * 64; len -= 8 * 64; } if (len >= 4 * 64) { memmove_mov4x64b(dest, src); dest += 4 * 64; src += 4 * 64; len -= 4 * 64; } if (len >= 2 * 64) { memmove_mov2x64b(dest, src); dest += 2 * 64; src += 2 * 64; len -= 2 * 64; } if (len >= 1 * 64) { memmove_mov1x64b(dest, src); dest += 1 * 64; src += 1 * 64; len -= 1 * 64; } if (len) memmove_small_avx512f(dest, src, len); } static force_inline void memmove_mov_avx512f_bw(char *dest, const char *src, size_t len) { dest += len; src += len; size_t cnt = (uint64_t)dest & 63; if (cnt > 0) { if (cnt > len) cnt = len; dest -= cnt; src -= cnt; len -= cnt; memmove_small_avx512f(dest, src, cnt); } while (len >= 32 * 64) { dest -= 32 * 64; src -= 32 * 64; len -= 32 * 64; memmove_mov32x64b(dest, src); } if (len >= 16 * 64) { dest -= 16 * 64; src -= 16 * 64; len -= 16 * 64; memmove_mov16x64b(dest, src); } if (len >= 8 * 64) { dest -= 8 * 64; src -= 8 * 64; len -= 8 * 64; memmove_mov8x64b(dest, src); } if (len >= 4 * 64) { dest -= 4 * 64; src -= 4 * 64; len -= 4 * 64; memmove_mov4x64b(dest, src); } if (len >= 2 * 64) { dest -= 2 * 64; src -= 2 * 64; len -= 2 * 64; memmove_mov2x64b(dest, src); } if (len >= 1 * 64) { dest -= 1 * 64; src -= 1 * 64; len -= 1 * 64; memmove_mov1x64b(dest, src); } if (len) memmove_small_avx512f(dest - len, src - len, len); } void EXPORTED_SYMBOL(char *dest, const char *src, size_t len) { if ((uintptr_t)dest - (uintptr_t)src >= len) memmove_mov_avx512f_fw(dest, src, len); else memmove_mov_avx512f_bw(dest, src, len); avx_zeroupper(); }
12,825
30.131068
74
h