Skip to content

Commit

Permalink
run as utest instead of ftest
Browse files Browse the repository at this point in the history
Required-githooks: true
Skipped-githooks: codespell

Signed-off-by: Lei Huang <[email protected]>
  • Loading branch information
wiliamhuang committed Jan 9, 2025
1 parent c1acb9d commit 989be37
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 231 deletions.
1 change: 1 addition & 0 deletions ci/test_files_to_stash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/*/*/src/tests/ftest/cart/utest/utest_swim,
build/*/*/src/gurt/tests/test_gurt,
build/*/*/src/gurt/tests/test_gurt_telem_producer,
build/*/*/src/gurt/tests/test_gurt_telem_consumer,
build/*/*/src/gurt/tests/test_shm,
build/*/*/src/rdb/raft/src/tests_main,
build/*/*/src/common/tests/btree_direct,
build/*/*/src/common/tests/btree,
Expand Down
1 change: 0 additions & 1 deletion debian/daos-client-tests.install
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ usr/bin/daos_perf
usr/bin/daos_racer
usr/bin/daos_test
usr/bin/dfs_test
usr/bin/shm_test
usr/bin/jobtest
usr/bin/crt_launch
usr/bin/daos_gen_io_conf
Expand Down
145 changes: 86 additions & 59 deletions src/gurt/shm_alloc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright 2024 Intel Corporation.
* (C) Copyright 2024-2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -44,6 +44,82 @@ pthread_mutexattr_t d_shm_mutex_attr;
*/
static int pid_shm_creator;

static uint64_t page_size;

static int
create_shm_region(uint64_t shm_size, uint64_t shm_pool_size)
{
int i;
int shm_ht_fd;
int shmopen_perm = 0600;
void *shm_addr;
char daos_shm_name_buf[64];

/* the shared memory only accessible for individual user for now */
sprintf(daos_shm_name_buf, "%s_%d", daos_shm_name, getuid());
shm_ht_fd = shm_open(daos_shm_name_buf, O_RDWR | O_CREAT | O_EXCL, shmopen_perm);
/* failed to create */
if (shm_ht_fd == -1) {
if (errno == EEXIST)
return errno;
DS_ERROR(errno, "shm_open() failed to create shared memory");
return errno;
}
/* set the size of shared memory region */
if (ftruncate(shm_ht_fd, shm_size) != 0) {
DS_ERROR(errno, "ftruncate() failed for shm_ht_fd");
goto err;
}
/* map the shared memory at a fixed address for now. We will remove this limit later. */
shm_addr = mmap(FIXED_SHM_ADDR, shm_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED, shm_ht_fd, 0);
if (shm_addr != FIXED_SHM_ADDR) {
DS_ERROR(errno, "mmap() failed to map at desired address");
goto err;
}
d_shm_head = (struct d_shm_hdr *)shm_addr;
d_shm_head->magic = 0;
/* initialize memory allocators */
for (i = 0; i < N_SHM_POOL; i++) {
d_shm_head->tlsf[i] = tlsf_create_with_pool(
shm_addr + sizeof(struct d_shm_hdr) + (i * shm_pool_size), shm_pool_size);
}

if (shm_mutex_init(&(d_shm_head->g_lock)) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}
for (i = 0; i < N_SHM_POOL; i++) {
if (shm_mutex_init(&(d_shm_head->mem_lock[i])) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}
}
if (shm_mutex_init(&(d_shm_head->ht_lock)) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}

pid_shm_creator = pid;
d_shm_head->off_ht_head = INVALID_OFFSET;

atomic_store_relaxed(&(d_shm_head->ref_count), 1);
atomic_store_relaxed(&(d_shm_head->large_mem_count), 0);
d_shm_head->size = shm_size;
d_shm_head->shm_pool_size = shm_pool_size;
d_shm_head->magic = DSM_MAGIC;
/* initialization is finished now. */
return 0;

err_unmap:
d_shm_head = NULL;
munmap(shm_addr, shm_size);

err:
close(shm_ht_fd);
return errno;
}

int
shm_init(void)
{
Expand All @@ -56,6 +132,8 @@ shm_init(void)
uint64_t shm_size;
uint64_t shm_pool_size;

if (page_size == 0)
page_size = sysconf(_SC_PAGESIZE);
if (pid == 0)
pid = getpid();
if (d_shm_head) {
Expand All @@ -69,9 +147,9 @@ shm_init(void)
if (rc != -DER_NONEXIST) {
/* set parameter from env */
shm_pool_size = shm_size / N_SHM_POOL;
if (shm_pool_size % 4096)
if (shm_pool_size % page_size)
/* make shm_pool_size 4K aligned */
shm_pool_size += (4096 - (shm_pool_size % 4096));
shm_pool_size += (page_size - (shm_pool_size % page_size));
shm_size = shm_pool_size * N_SHM_POOL + sizeof(struct d_shm_hdr);
} else {
shm_pool_size = SHM_POOL_SIZE;
Expand All @@ -94,7 +172,11 @@ shm_init(void)
/* failed to open */
if (shm_ht_fd == -1) {
if (errno == ENOENT) {
goto create_shm;
rc = create_shm_region(shm_size, shm_pool_size);
if (rc == EEXIST)
goto open_rw;
else
return rc;
} else {
DS_ERROR(errno, "unexpected error shm_open()");
for (i = 0; i < RETRY; i++) {
Expand Down Expand Up @@ -133,61 +215,6 @@ shm_init(void)
close(shm_ht_fd);
return 0;

create_shm:
shm_ht_fd = shm_open(daos_shm_name_buf, O_RDWR | O_CREAT | O_EXCL, shmopen_perm);
/* failed to create */
if (shm_ht_fd == -1) {
if (errno == EEXIST)
goto open_rw;
DS_ERROR(errno, "shm_open() failed to create shared memory");
return errno;
}
/* set the size of shared memory region */
if (ftruncate(shm_ht_fd, shm_size) != 0) {
DS_ERROR(errno, "ftruncate() failed for shm_ht_fd");
goto err;
}
/* map the shared memory at a fixed address for now. We will remove this limit later. */
shm_addr = mmap(FIXED_SHM_ADDR, shm_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED, shm_ht_fd, 0);
if (shm_addr != FIXED_SHM_ADDR) {
DS_ERROR(errno, "mmap() failed to map at desired address");
goto err;
}
d_shm_head = (struct d_shm_hdr *)shm_addr;
d_shm_head->magic = 0;
/* initialize memory allocators */
for (i = 0; i < N_SHM_POOL; i++) {
d_shm_head->tlsf[i] = tlsf_create_with_pool(
shm_addr + sizeof(struct d_shm_hdr) + (i * shm_pool_size), shm_pool_size);
}

if (shm_mutex_init(&(d_shm_head->g_lock)) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}
for (i = 0; i < N_SHM_POOL; i++) {
if (shm_mutex_init(&(d_shm_head->mem_lock[i])) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}
}
if (shm_mutex_init(&(d_shm_head->ht_lock)) != 0) {
DS_ERROR(errno, "shm_mutex_init() failed");
goto err_unmap;
}

pid_shm_creator = pid;
d_shm_head->off_ht_head = INVALID_OFFSET;

atomic_store_relaxed(&(d_shm_head->ref_count), 1);
atomic_store_relaxed(&(d_shm_head->large_mem_count), 0);
d_shm_head->size = shm_size;
d_shm_head->shm_pool_size = shm_pool_size;
d_shm_head->magic = DSM_MAGIC;
/* initialization is finished now. */
return 0;

err_unmap:
d_shm_head = NULL;
munmap(shm_addr, shm_size);
Expand Down
2 changes: 1 addition & 1 deletion src/gurt/tests/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os

TEST_SRC = ['test_gurt.c', 'test_gurt_telem_producer.c']
TEST_SRC = ['test_gurt.c', 'test_gurt_telem_producer.c', 'test_shm.c']


def scons():
Expand Down
Loading

0 comments on commit 989be37

Please sign in to comment.