This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, master has been updated via 2541e8688750f2a045aff3dbf544868be3ebf787 (commit) via b2b516c03ae6eb57e0055c98b33e946e9529f215 (commit) via d5d52b65d262698694a5fab0b3d9bd12fa4a6460 (commit) via 6e594990575df83dcbb70f5f86ad52f7c5a0f96d (commit) via c50d47bd420c675552dd0b82638a073b67b2ae4f (commit) via 933fd66f5b7230a00ee0ef7acde5cc1c9af63b45 (commit) via 8ae6373c8844408ad080b58fb3083b30e8dc7ea6 (commit) from 96b36df87f23bf32ab218321f1fc35703f092eb4 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 2541e8688750f2a045aff3dbf544868be3ebf787 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Jul 4 19:31:06 2017 +0300
linux-gen: shm: user can define place for shm files
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index 6545bfce..cde2dbc3 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -71,6 +71,8 @@ #include <inttypes.h> #include <sys/wait.h> #include <libgen.h> +#include <sys/types.h> +#include <dirent.h>
/* * Maximum number of internal shared memory blocks. @@ -99,6 +101,7 @@ #define ISHM_FILENAME_MAXLEN (ISHM_NAME_MAXLEN + 64) #define ISHM_FILENAME_FORMAT "%s/odp-%d-ishm-%s" #define ISHM_FILENAME_NORMAL_PAGE_DIR "/dev/shm" +#define _ODP_FILES_FMT "odp-%d-"
/* * when the memory is to be shared with an external entity (such as another @@ -106,7 +109,7 @@ * export file is created describing the exported memory: this defines the * location and the filename format of this description file */ -#define ISHM_EXPTNAME_FORMAT "/dev/shm/%s/odp-%d-shm-%s" +#define ISHM_EXPTNAME_FORMAT "%s/%s/odp-%d-shm-%s"
/* * At worse case the virtual space gets so fragmented that there is @@ -437,7 +440,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, odp_global_data.uid); else snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", - ISHM_FILENAME_NORMAL_PAGE_DIR, + odp_global_data.shm_dir, odp_global_data.uid);
snprintf(filename, ISHM_FILENAME_MAXLEN, @@ -476,6 +479,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, ISHM_FILENAME_MAXLEN - 1); snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, + odp_global_data.shm_dir, odp_global_data.uid, odp_global_data.main_pid, (name && name[0]) ? name : seq_string); @@ -955,6 +959,7 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, /* try to read the block description file: */ snprintf(export_filename, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, + odp_global_data.shm_dir, odp_global_data.uid, external_odp_pid, remote_name); @@ -1383,22 +1388,86 @@ static int do_odp_ishm_init_local(void) return 0; }
+/* remove all files staring with "odp-<pid>" from a directory "dir" */ +int _odp_ishm_cleanup_files(const char *dirpath) +{ + struct dirent *e; + DIR *dir; + char userdir[PATH_MAX]; + char prefix[PATH_MAX]; + char *fullpath; + int d_len = strlen(dirpath); + int p_len; + int f_len; + + snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_data.uid); + + dir = opendir(userdir); + if (!dir) { + /* ok if the dir does not exist. no much to delete then! */ + ODP_DBG("opendir failed for %s: %s\n", + dirpath, strerror(errno)); + return 0; + } + snprintf(prefix, PATH_MAX, _ODP_FILES_FMT, odp_global_data.main_pid); + p_len = strlen(prefix); + while ((e = readdir(dir)) != NULL) { + if (strncmp(e->d_name, prefix, p_len) == 0) { + f_len = strlen(e->d_name); + fullpath = malloc(d_len + f_len + 2); + if (fullpath == NULL) { + closedir(dir); + return -1; + } + snprintf(fullpath, PATH_MAX, "%s/%s", + dirpath, e->d_name); + ODP_DBG("deleting obsolete file: %s\n", fullpath); + if (unlink(fullpath)) + ODP_ERR("unlink failed for %s: %s\n", + fullpath, strerror(errno)); + free(fullpath); + } + } + closedir(dir); + + return 0; +} + int _odp_ishm_init_global(void) { void *addr; void *spce_addr; int i; + uid_t uid;
- if ((getpid() != odp_global_data.main_pid) || - (syscall(SYS_gettid) != getpid())) - ODP_ERR("odp_init_global() must be performed by the main " + odp_global_data.main_pid = getpid(); + odp_global_data.shm_dir = getenv("ODP_SHM_DIR"); + odp_global_data.shm_dir = + calloc(1, sizeof(ISHM_FILENAME_NORMAL_PAGE_DIR)); + sprintf(odp_global_data.shm_dir, "%s", ISHM_FILENAME_NORMAL_PAGE_DIR); + + ODP_DBG("ishm: using dir %s\n", odp_global_data.shm_dir); + + uid = getuid(); + snprintf(odp_global_data.uid, UID_MAXLEN, "%d", + uid); + + if ((syscall(SYS_gettid)) != odp_global_data.main_pid) { + ODP_ERR("ishm init must be performed by the main " "ODP process!\n."); + return -1; + }
if (!odp_global_data.hugepage_info.default_huge_page_dir) ODP_DBG("NOTE: No support for huge pages\n"); - else + else { ODP_DBG("Huge pages mount point is: %s\n", odp_global_data.hugepage_info.default_huge_page_dir); + _odp_ishm_cleanup_files( + odp_global_data.hugepage_info.default_huge_page_dir); + } + + _odp_ishm_cleanup_files(odp_global_data.shm_dir);
/* allocate space for the internal shared mem block table: */ addr = mmap(NULL, sizeof(ishm_table_t), @@ -1592,6 +1661,8 @@ int _odp_ishm_term_global(void) if (_odp_ishmphy_unbook_va()) ret |= -1;
+ free(odp_global_data.shm_dir); + return ret; }
diff --git a/platform/linux-generic/include/_ishm_internal.h b/platform/linux-generic/include/_ishm_internal.h index c7c33077..005d6b55 100644 --- a/platform/linux-generic/include/_ishm_internal.h +++ b/platform/linux-generic/include/_ishm_internal.h @@ -44,6 +44,7 @@ int _odp_ishm_find_exported(const char *remote_name, void *_odp_ishm_address(int block_index); int _odp_ishm_info(int block_index, _odp_ishm_info_t *info); int _odp_ishm_status(const char *title); +int _odp_ishm_cleanup_files(const char *dirpath);
#ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 7e6811f3..dd3374b7 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -42,6 +42,7 @@ typedef struct { } hugepage_info_t;
struct odp_global_data_s { + char *shm_dir; /*< directory for odp mmaped files */ pid_t main_pid; char uid[UID_MAXLEN]; odp_log_func_t log_fn; diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index f62ccec0..ab2d6fb0 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -20,70 +20,15 @@ #include <sys/types.h> #include <pwd.h>
-#define _ODP_FILES_FMT "odp-%d-" -#define _ODP_TMPDIR "/dev/shm" - struct odp_global_data_s odp_global_data;
-/* remove all files staring with "odp-<pid>" from a directory "dir" */ -static int cleanup_files(const char *dirpath, int odp_pid) -{ - struct dirent *e; - DIR *dir; - char userdir[PATH_MAX]; - char prefix[PATH_MAX]; - char *fullpath; - int d_len = strlen(dirpath); - int p_len; - int f_len; - - snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_data.uid); - - dir = opendir(userdir); - if (!dir) { - /* ok if the dir does not exist. no much to delete then! */ - ODP_DBG("opendir failed for %s: %s\n", - dirpath, strerror(errno)); - return 0; - } - snprintf(prefix, PATH_MAX, _ODP_FILES_FMT, odp_pid); - p_len = strlen(prefix); - while ((e = readdir(dir)) != NULL) { - if (strncmp(e->d_name, prefix, p_len) == 0) { - f_len = strlen(e->d_name); - fullpath = malloc(d_len + f_len + 2); - if (fullpath == NULL) { - closedir(dir); - return -1; - } - snprintf(fullpath, PATH_MAX, "%s/%s", - dirpath, e->d_name); - ODP_DBG("deleting obsolete file: %s\n", fullpath); - if (unlink(fullpath)) - ODP_ERR("unlink failed for %s: %s\n", - fullpath, strerror(errno)); - free(fullpath); - } - } - closedir(dir); - - return 0; -} - int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params ODP_UNUSED) { - char *hpdir; - uid_t uid; - memset(&odp_global_data, 0, sizeof(struct odp_global_data_s)); odp_global_data.main_pid = getpid();
- uid = getuid(); - snprintf(odp_global_data.uid, UID_MAXLEN, "%d", - uid); - enum init_stage stage = NO_INIT; odp_global_data.log_fn = odp_override_log; odp_global_data.abort_fn = odp_override_abort; @@ -95,8 +40,6 @@ int odp_init_global(odp_instance_t *instance, odp_global_data.abort_fn = params->abort_fn; }
- cleanup_files(_ODP_TMPDIR, odp_global_data.main_pid); - if (odp_cpumask_init_global(params)) { ODP_ERR("ODP cpumask init failed.\n"); goto init_failed; @@ -113,23 +56,20 @@ int odp_init_global(odp_instance_t *instance, ODP_ERR("ODP system_info init failed.\n"); goto init_failed; } - hpdir = odp_global_data.hugepage_info.default_huge_page_dir; - /* cleanup obsolete huge page files, if any */ - if (hpdir) - cleanup_files(hpdir, odp_global_data.main_pid); stage = SYSINFO_INIT;
+ if (_odp_ishm_init_global()) { + ODP_ERR("ODP ishm init failed.\n"); + goto init_failed; + } + stage = ISHM_INIT; + if (_odp_fdserver_init_global()) { ODP_ERR("ODP fdserver init failed.\n"); goto init_failed; } stage = FDSERVER_INIT;
- if (_odp_ishm_init_global()) { - ODP_ERR("ODP ishm init failed.\n"); - goto init_failed; - } - stage = ISHM_INIT;
if (odp_thread_init_global()) { ODP_ERR("ODP thread init failed.\n"); diff --git a/test/linux-generic/validation/api/shmem/shmem_common.h b/test/linux-generic/validation/api/shmem/shmem_common.h index 621e3431..e6c04d81 100644 --- a/test/linux-generic/validation/api/shmem/shmem_common.h +++ b/test/linux-generic/validation/api/shmem/shmem_common.h @@ -7,8 +7,9 @@ #ifndef _COMMON_TEST_SHMEM_H_ #define _COMMON_TEST_SHMEM_H_
-#define ODP_SHM_NAME "odp_linux_shared_mem" -#define FIFO_NAME_FMT "/dev/shm/%d/shmem_test_fifo-%d" +#define SHM_NAME "odp_linux_shared_mem" +#define DEFAULT_SHM_DIR "/dev/shm" +#define FIFO_NAME_FMT "/%s/%d/shmem_test_fifo-%d" #define ALIGN_SIZE (128) #define TEST_SHARE_FOO (0xf0f0f0f0) #define TEST_SHARE_BAR (0xf0f0f0f) diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c index d5931447..e7e699e7 100644 --- a/test/linux-generic/validation/api/shmem/shmem_linux.c +++ b/test/linux-generic/validation/api/shmem/shmem_linux.c @@ -79,6 +79,7 @@ #include <linux/limits.h> #include <inttypes.h> #include <pwd.h> +#include <stdlib.h> #include "shmem_linux.h" #include "shmem_common.h"
@@ -210,6 +211,7 @@ int main(int argc __attribute__((unused)), char *argv[]) test_shared_linux_data_t *addr; int app2_status; uid_t uid = getuid(); + char *shm_dir = getenv("ODP_SHM_DIR");
/* odp_app1 is in the same directory as this file: */ strncpy(prg_name, argv[0], PATH_MAX - 1); @@ -228,7 +230,9 @@ int main(int argc __attribute__((unused)), char *argv[]) /* wait max 30 sec for the fifo to be created by the ODP side. * Just die if time expire as there is no fifo to communicate * through... */ - sprintf(fifo_name, FIFO_NAME_FMT, uid, odp_app1); + sprintf(fifo_name, FIFO_NAME_FMT, + shm_dir ? shm_dir : DEFAULT_SHM_DIR, + uid, odp_app1); for (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) { fifo_fd = open(fifo_name, O_WRONLY); if (fifo_fd >= 0) @@ -244,7 +248,7 @@ int main(int argc __attribute__((unused)), char *argv[]) * check to see if linux can see the created shared memory: */
/* read the shared memory attributes (includes the shm filename): */ - if (read_shmem_attribues(odp_app1, ODP_SHM_NAME, + if (read_shmem_attribues(odp_app1, SHM_NAME, shm_filename, &len, &flags, &user_len, &user_flags, &align) != 0) test_failure(fifo_name, fifo_fd, odp_app1); diff --git a/test/linux-generic/validation/api/shmem/shmem_odp1.c b/test/linux-generic/validation/api/shmem/shmem_odp1.c index c402365a..26abc94b 100644 --- a/test/linux-generic/validation/api/shmem/shmem_odp1.c +++ b/test/linux-generic/validation/api/shmem/shmem_odp1.c @@ -11,6 +11,7 @@ #include <stdio.h> #include <sys/stat.h> #include <fcntl.h> +#include <stdlib.h>
#include <odp_cunit_common.h> #include "shmem_odp1.h" @@ -26,9 +27,10 @@ void shmem_test_odp_shm_proc(void) odp_shm_t shm; test_shared_data_t *test_shared_data; char test_result; + char *shm_dir = getenv("ODP_SHM_DIR");
/* reminder: ODP_SHM_PROC => export to linux, ODP_SHM_EXPORT=>to odp */ - shm = odp_shm_reserve(ODP_SHM_NAME, + shm = odp_shm_reserve(SHM_NAME, sizeof(test_shared_data_t), ALIGN_SIZE, ODP_SHM_PROC | ODP_SHM_EXPORT); CU_ASSERT_FATAL(ODP_SHM_INVALID != shm); @@ -41,7 +43,9 @@ void shmem_test_odp_shm_proc(void)
/* open the fifo: this will indicate to linux process that it can * start the shmem lookups and check if it sees the data */ - sprintf(fifo_name, FIFO_NAME_FMT, getuid(), getpid()); + sprintf(fifo_name, FIFO_NAME_FMT, + shm_dir ? shm_dir : DEFAULT_SHM_DIR, + getuid(), getpid()); CU_ASSERT_FATAL(mkfifo(fifo_name, 0666) == 0);
/* read from the fifo: the linux process result: */ diff --git a/test/linux-generic/validation/api/shmem/shmem_odp2.c b/test/linux-generic/validation/api/shmem/shmem_odp2.c index 7d8c682b..2a4b67d7 100644 --- a/test/linux-generic/validation/api/shmem/shmem_odp2.c +++ b/test/linux-generic/validation/api/shmem/shmem_odp2.c @@ -53,8 +53,8 @@ int main(int argc, char *argv[]) odp1 = (odp_instance_t)atoi(argv[1]);
printf("shmem_odp2: trying to grab %s from pid %d\n", - ODP_SHM_NAME, (int)odp1); - shm = odp_shm_import(ODP_SHM_NAME, odp1, ODP_SHM_NAME); + SHM_NAME, (int)odp1); + shm = odp_shm_import(SHM_NAME, odp1, SHM_NAME); if (shm == ODP_SHM_INVALID) { fprintf(stderr, "error: odp_shm_lookup_external failed.\n"); return 1;
commit b2b516c03ae6eb57e0055c98b33e946e9529f215 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Fri Jun 23 19:16:52 2017 +0300
linux-gen: shm: add uid to shm files
new processes can get some earliar pid numbers which processes can be already dead. Because of previous process can be from other user it can have different access right to that file. To avoid that place shm files to /dev/shm/uid/odp- files
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/_fdserver.c b/platform/linux-generic/_fdserver.c index 20d6e233..7ed5e7a6 100644 --- a/platform/linux-generic/_fdserver.c +++ b/platform/linux-generic/_fdserver.c @@ -48,6 +48,7 @@ #include <stdlib.h> #include <errno.h> #include <string.h> +#include <sys/stat.h> #include <sys/types.h> #include <signal.h> #include <sys/socket.h> @@ -57,8 +58,9 @@ #include <sys/mman.h> #include <sys/wait.h>
-#define FDSERVER_SOCKPATH_MAXLEN 32 -#define FDSERVER_SOCKPATH_FORMAT "/dev/shm/odp-%d-fdserver" +#define FDSERVER_SOCKPATH_MAXLEN 255 +#define FDSERVER_SOCK_FORMAT "/dev/shm/%s/odp-%d-fdserver" +#define FDSERVER_SOCKDIR_FORMAT "/dev/shm/%s" #define FDSERVER_BACKLOG 5
#ifndef MAP_ANONYMOUS @@ -238,7 +240,8 @@ static int get_socket(void) int len;
/* construct the named socket path: */ - snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT, + snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, + odp_global_data.uid, odp_global_data.main_pid);
s_sock = socket(AF_UNIX, SOCK_STREAM, 0); @@ -581,8 +584,14 @@ int _odp_fdserver_init_global(void)
odp_spinlock_init(client_lock);
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT, + odp_global_data.uid); + + mkdir(sockpath, 0744); + /* construct the server named socket path: */ - snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT, + snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, + odp_global_data.uid, odp_global_data.main_pid);
/* create UNIX domain socket: */ @@ -663,11 +672,17 @@ int _odp_fdserver_term_global(void) wait(&status);
/* construct the server named socket path: */ - snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT, + snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, + odp_global_data.uid, odp_global_data.main_pid);
/* delete the UNIX domain socket: */ unlink(sockpath);
+ /* delete shm files directory */ + snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT, + odp_global_data.uid); + unlink(sockpath); + return 0; } diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index c0623f18..6545bfce 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -86,7 +86,7 @@ * Maximum internal shared memory block name length in chars * probably taking the same number as SHM name size make sense at this stage */ -#define ISHM_NAME_MAXLEN 32 +#define ISHM_NAME_MAXLEN 128
/* * Linux underlying file name: <directory>/odp-<odp_pid>-ishm-<name> @@ -106,7 +106,7 @@ * export file is created describing the exported memory: this defines the * location and the filename format of this description file */ -#define ISHM_EXPTNAME_FORMAT "/dev/shm/odp-%d-shm-%s" +#define ISHM_EXPTNAME_FORMAT "/dev/shm/%s/odp-%d-shm-%s"
/* * At worse case the virtual space gets so fragmented that there is @@ -417,6 +417,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, * /mnt/huge */ int oflag = O_RDWR | O_CREAT | O_TRUNC; /* flags for open */ FILE *export_file; + char dir[ISHM_FILENAME_MAXLEN];
new_block = &ishm_tbl->block[block_index]; name = new_block->name; @@ -431,17 +432,21 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, return -1;
if (huge == HUGE) - snprintf(filename, ISHM_FILENAME_MAXLEN, - ISHM_FILENAME_FORMAT, + snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", odp_global_data.hugepage_info.default_huge_page_dir, - odp_global_data.main_pid, - (name && name[0]) ? name : seq_string); + odp_global_data.uid); else - snprintf(filename, ISHM_FILENAME_MAXLEN, - ISHM_FILENAME_FORMAT, + snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", ISHM_FILENAME_NORMAL_PAGE_DIR, - odp_global_data.main_pid, - (name && name[0]) ? name : seq_string); + odp_global_data.uid); + + snprintf(filename, ISHM_FILENAME_MAXLEN, + ISHM_FILENAME_FORMAT, + dir, + odp_global_data.main_pid, + (name && name[0]) ? name : seq_string); + + mkdir(dir, 0744);
fd = open(filename, oflag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { @@ -471,6 +476,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, ISHM_FILENAME_MAXLEN - 1); snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, + odp_global_data.uid, odp_global_data.main_pid, (name && name[0]) ? name : seq_string); export_file = fopen(new_block->exptname, "w"); @@ -949,6 +955,7 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, /* try to read the block description file: */ snprintf(export_filename, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, + odp_global_data.uid, external_odp_pid, remote_name);
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 8bae028d..7e6811f3 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -25,6 +25,7 @@ extern "C" { #include <sys/types.h>
#define MAX_CPU_NUMBER 128 +#define UID_MAXLEN 30
typedef struct { uint64_t cpu_hz_max[MAX_CPU_NUMBER]; @@ -42,6 +43,7 @@ typedef struct {
struct odp_global_data_s { pid_t main_pid; + char uid[UID_MAXLEN]; odp_log_func_t log_fn; odp_abort_func_t abort_fn; system_info_t system_info; diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index b4abb181..f62ccec0 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -17,6 +17,8 @@ #include <string.h> #include <stdlib.h> #include <errno.h> +#include <sys/types.h> +#include <pwd.h>
#define _ODP_FILES_FMT "odp-%d-" #define _ODP_TMPDIR "/dev/shm" @@ -28,13 +30,16 @@ static int cleanup_files(const char *dirpath, int odp_pid) { struct dirent *e; DIR *dir; + char userdir[PATH_MAX]; char prefix[PATH_MAX]; char *fullpath; int d_len = strlen(dirpath); int p_len; int f_len;
- dir = opendir(dirpath); + snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_data.uid); + + dir = opendir(userdir); if (!dir) { /* ok if the dir does not exist. no much to delete then! */ ODP_DBG("opendir failed for %s: %s\n", @@ -70,10 +75,15 @@ int odp_init_global(odp_instance_t *instance, const odp_platform_init_t *platform_params ODP_UNUSED) { char *hpdir; + uid_t uid;
memset(&odp_global_data, 0, sizeof(struct odp_global_data_s)); odp_global_data.main_pid = getpid();
+ uid = getuid(); + snprintf(odp_global_data.uid, UID_MAXLEN, "%d", + uid); + enum init_stage stage = NO_INIT; odp_global_data.log_fn = odp_override_log; odp_global_data.abort_fn = odp_override_abort; diff --git a/test/linux-generic/validation/api/shmem/shmem_common.h b/test/linux-generic/validation/api/shmem/shmem_common.h index 16227ecd..621e3431 100644 --- a/test/linux-generic/validation/api/shmem/shmem_common.h +++ b/test/linux-generic/validation/api/shmem/shmem_common.h @@ -8,7 +8,7 @@ #define _COMMON_TEST_SHMEM_H_
#define ODP_SHM_NAME "odp_linux_shared_mem" -#define FIFO_NAME_FMT "/tmp/shmem_test_fifo-%d" +#define FIFO_NAME_FMT "/dev/shm/%d/shmem_test_fifo-%d" #define ALIGN_SIZE (128) #define TEST_SHARE_FOO (0xf0f0f0f0) #define TEST_SHARE_BAR (0xf0f0f0f) diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c index 2f4c7628..d5931447 100644 --- a/test/linux-generic/validation/api/shmem/shmem_linux.c +++ b/test/linux-generic/validation/api/shmem/shmem_linux.c @@ -8,7 +8,7 @@ * flag is visible under linux, and checks that memory created with the * ODP_SHM_EXPORT flag is visible by other ODP instances. * It therefore checks both that the link - * name under /tmp is correct, and also checks that the memory contents + * name under /dev/shm is correct, and also checks that the memory contents * is indeed shared. * we want: * -the odp test to run using C UNIT @@ -69,6 +69,7 @@ #include <string.h> #include <fcntl.h> #include <sys/stat.h> +#include <sys/types.h> #include <sys/wait.h> #include <linux/limits.h> #include <stdio.h> @@ -77,12 +78,14 @@ #include <libgen.h> #include <linux/limits.h> #include <inttypes.h> +#include <pwd.h> #include "shmem_linux.h" #include "shmem_common.h"
#define ODP_APP1_NAME "shmem_odp1" /* name of the odp1 program, in this dir */ #define ODP_APP2_NAME "shmem_odp2" /* name of the odp2 program, in this dir */ -#define DEVNAME_FMT "/tmp/odp-%" PRIu64 "-shm-%s" /* odp-<pid>-shm-<name> */ +/* odp-<pid>-shm-<name> */ +#define DEVNAME_FMT "/dev/shm/%d/odp-%" PRIu64 "-shm-%s" #define MAX_FIFO_WAIT 30 /* Max time waiting for the fifo (sec) */
/* @@ -108,7 +111,8 @@ static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname, char shm_attr_filename[PATH_MAX]; FILE *export_file;
- sprintf(shm_attr_filename, DEVNAME_FMT, ext_odp_pid, blockname); + sprintf(shm_attr_filename, DEVNAME_FMT, getuid(), + ext_odp_pid, blockname);
/* O_CREAT flag not given => failure if shm_attr_filename does not * already exist */ @@ -205,6 +209,7 @@ int main(int argc __attribute__((unused)), char *argv[]) int shm_fd; test_shared_linux_data_t *addr; int app2_status; + uid_t uid = getuid();
/* odp_app1 is in the same directory as this file: */ strncpy(prg_name, argv[0], PATH_MAX - 1); @@ -223,7 +228,7 @@ int main(int argc __attribute__((unused)), char *argv[]) /* wait max 30 sec for the fifo to be created by the ODP side. * Just die if time expire as there is no fifo to communicate * through... */ - sprintf(fifo_name, FIFO_NAME_FMT, odp_app1); + sprintf(fifo_name, FIFO_NAME_FMT, uid, odp_app1); for (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) { fifo_fd = open(fifo_name, O_WRONLY); if (fifo_fd >= 0) @@ -244,7 +249,7 @@ int main(int argc __attribute__((unused)), char *argv[]) &user_len, &user_flags, &align) != 0) test_failure(fifo_name, fifo_fd, odp_app1);
- /* open the shm filename (which is either on /tmp or on hugetlbfs) + /* open the shm filename (which is either on /dev/shm/ or on hugetlbfs) * O_CREAT flag not given => failure if shm_devname does not already * exist */ shm_fd = open(shm_filename, O_RDONLY, diff --git a/test/linux-generic/validation/api/shmem/shmem_odp1.c b/test/linux-generic/validation/api/shmem/shmem_odp1.c index 3869c2e1..c402365a 100644 --- a/test/linux-generic/validation/api/shmem/shmem_odp1.c +++ b/test/linux-generic/validation/api/shmem/shmem_odp1.c @@ -41,7 +41,7 @@ void shmem_test_odp_shm_proc(void)
/* open the fifo: this will indicate to linux process that it can * start the shmem lookups and check if it sees the data */ - sprintf(fifo_name, FIFO_NAME_FMT, getpid()); + sprintf(fifo_name, FIFO_NAME_FMT, getuid(), getpid()); CU_ASSERT_FATAL(mkfifo(fifo_name, 0666) == 0);
/* read from the fifo: the linux process result: */
commit d5d52b65d262698694a5fab0b3d9bd12fa4a6460 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Jun 20 12:03:39 2017 +0300
linux-gen: shm: use shm in /dev/shm instead of /tmp
/tmp might be mounted to tmpfs or not mounted. If it's disk then some writes are loss there. At least ipc test shows missing packets in shm ring on 4.10.0-rc8+ kernel. Which is more likely kernel bug.
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/_fdserver.c b/platform/linux-generic/_fdserver.c index 9aed7a9f..20d6e233 100644 --- a/platform/linux-generic/_fdserver.c +++ b/platform/linux-generic/_fdserver.c @@ -58,7 +58,7 @@ #include <sys/wait.h>
#define FDSERVER_SOCKPATH_MAXLEN 32 -#define FDSERVER_SOCKPATH_FORMAT "/tmp/odp-%d-fdserver" +#define FDSERVER_SOCKPATH_FORMAT "/dev/shm/odp-%d-fdserver" #define FDSERVER_BACKLOG 5
#ifndef MAP_ANONYMOUS diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index c1efd7d2..c0623f18 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -92,12 +92,13 @@ * Linux underlying file name: <directory>/odp-<odp_pid>-ishm-<name> * The <name> part may be replaced by a sequence number if no specific * name is given at reserve time - * <directory> is either /tmp or the hugepagefs mount point for default size. + * <directory> is either /dev/shm or the hugepagefs mount point for default + * size. * (searched at init time) */ #define ISHM_FILENAME_MAXLEN (ISHM_NAME_MAXLEN + 64) #define ISHM_FILENAME_FORMAT "%s/odp-%d-ishm-%s" -#define ISHM_FILENAME_NORMAL_PAGE_DIR "/tmp" +#define ISHM_FILENAME_NORMAL_PAGE_DIR "/dev/shm"
/* * when the memory is to be shared with an external entity (such as another @@ -105,7 +106,7 @@ * export file is created describing the exported memory: this defines the * location and the filename format of this description file */ -#define ISHM_EXPTNAME_FORMAT "/tmp/odp-%d-shm-%s" +#define ISHM_EXPTNAME_FORMAT "/dev/shm/odp-%d-shm-%s"
/* * At worse case the virtual space gets so fragmented that there is @@ -117,7 +118,7 @@
/* * when a memory block is to be exported outside its ODP instance, - * an block 'attribute file' is created in /tmp/odp-<pid>-shm-<name>. + * an block 'attribute file' is created in /dev/shm/odp-<pid>-shm-<name>. * The information given in this file is according to the following: */ #define EXPORT_FILE_LINE1_FMT "ODP exported shm block info:" @@ -401,7 +402,7 @@ static void free_fragment(ishm_fragment_t *fragmnt)
/* * Create file with size len. returns -1 on error - * Creates a file to /tmp/odp-<pid>-<sequence_or_name> (for normal pages) + * Creates a file to /dev/shm/odp-<pid>-<sequence_or_name> (for normal pages) * or /mnt/huge/odp-<pid>-<sequence_or_name> (for huge pages) * Return the new file descriptor, or -1 on error. */ @@ -412,7 +413,8 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, int fd; ishm_block_t *new_block; /* entry in the main block table */ char seq_string[ISHM_FILENAME_MAXLEN]; /* used to construct filename*/ - char filename[ISHM_FILENAME_MAXLEN];/* filename in /tmp/ or /mnt/huge */ + char filename[ISHM_FILENAME_MAXLEN]; /* filename in /dev/shm or + * /mnt/huge */ int oflag = O_RDWR | O_CREAT | O_TRUNC; /* flags for open */ FILE *export_file;
@@ -530,7 +532,7 @@ static void *do_map(int block_index, uint64_t len, uint32_t align, new_block = &ishm_tbl->block[block_index];
/* - * Creates a file to /tmp/odp-<pid>-<sequence> (for normal pages) + * Creates a file to /dev/shm/odp-<pid>-<sequence> (for normal pages) * or /mnt/huge/odp-<pid>-<sequence> (for huge pages) * unless a fd was already given */ @@ -761,7 +763,7 @@ static void procsync(void) * If ok, allocate a new shared memory block and map the * provided fd in it (if fd >=0 was given). * If no fd is provided, a shared memory file desc named - * /tmp/odp-<pid>-ishm-<name_or_sequence> is created and mapped. + * /dev/shm/odp-<pid>-ishm-<name_or_sequence> is created and mapped. * (the name is different for huge page file as they must be on hugepagefs) * The function returns the index of the newly created block in the * main block table (>=0) or -1 on error. diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 06c61435..b4abb181 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -19,7 +19,7 @@ #include <errno.h>
#define _ODP_FILES_FMT "odp-%d-" -#define _ODP_TMPDIR "/tmp" +#define _ODP_TMPDIR "/dev/shm"
struct odp_global_data_s odp_global_data;
commit 6e594990575df83dcbb70f5f86ad52f7c5a0f96d Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Sat Jun 24 00:20:43 2017 +0300
linux-gen: ipc remove base_addr_offset
base_addr_offset is not used in this version, remove it.
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/include/odp_packet_io_ipc_internal.h b/platform/linux-generic/include/odp_packet_io_ipc_internal.h index 7cd29488..9d8943a6 100644 --- a/platform/linux-generic/include/odp_packet_io_ipc_internal.h +++ b/platform/linux-generic/include/odp_packet_io_ipc_internal.h @@ -30,19 +30,11 @@ struct pktio_info { int num; /* size of packet/segment in remote pool */ uint32_t block_size; - /* offset from shared memory block start - * to pool *base_addr in remote process. - * (odp-linux pool specific) */ - size_t base_addr_offset; char pool_name[ODP_POOL_NAME_LEN]; /* 1 if master finished creation of all shared objects */ int init_done; } master; struct { - /* offset from shared memory block start - * to pool *base_addr in remote process. - * (odp-linux pool specific) */ - size_t base_addr_offset; void *base_addr; uint32_t block_size; char pool_name[ODP_POOL_NAME_LEN]; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 6b631098..54e42227 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -59,8 +59,7 @@ static int _ipc_master_start(pktio_entry_t *pktio_entry)
pktio_entry->s.ipc.remote_pool_shm = shm; pktio_entry->s.ipc.pool_base = odp_shm_addr(shm); - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm) + - pinfo->slave.base_addr_offset; + pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm);
odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1);
@@ -153,7 +152,6 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, }
memcpy(pinfo->master.pool_name, pool_name, strlen(pool_name)); - pinfo->slave.base_addr_offset = 0; pinfo->slave.base_addr = 0; pinfo->slave.pid = 0; pinfo->slave.init_done = 0; @@ -297,8 +295,7 @@ static int _ipc_slave_start(pktio_entry_t *pktio_entry) shm = _ipc_map_remote_pool(pinfo->master.pool_name, pid); pktio_entry->s.ipc.remote_pool_shm = shm; - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm) + - pinfo->master.base_addr_offset; + pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm); pktio_entry->s.ipc.pkt_size = pinfo->master.block_size;
_ipc_export_pool(pinfo, pktio_entry->s.ipc.pool);
commit c50d47bd420c675552dd0b82638a073b67b2ae4f Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Jun 20 11:37:07 2017 +0300
linux-gen: pktio: ipc: rx: push back not processed packets
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 7a054962..6b631098 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -498,12 +498,24 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, pkt_table[i] = pkt; }
+ /* put back to rx ring dequed but not processed packets*/ + if (pkts != i) { + r_p = pktio_entry->s.ipc.rx.recv; + ipcbufs_p = (void *)&offsets[i]; + pkts_ring = _ring_mp_enqueue_burst(r_p, ipcbufs_p, pkts - i); + if (pkts_ring != (pkts - i)) + ODP_ERR("bug to enqueue packets\n"); + } + + /*num of actually received packets*/ + pkts = i; + /* Now tell other process that we no longer need that buffers.*/ r_p = pktio_entry->s.ipc.rx.free;
repeat: pkts_ring = _ring_mp_enqueue_burst(r_p, ipcbufs_p, pkts); - if (odp_unlikely(pkts < 0)) + if (odp_unlikely(pkts_ring < 0)) ODP_ABORT("ipc: odp_ring_mp_enqueue_bulk r_p fail\n"); if (odp_unlikely(pkts != pkts_ring)) { IPC_ODP_DBG("odp_ring_full: %d, odp_ring_count %d,"
commit 933fd66f5b7230a00ee0ef7acde5cc1c9af63b45 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Jun 20 11:24:25 2017 +0300
linux-gen: pktio: ipc fix error check
Code clean up, break before entering to for loop.
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 1a2a37f2..7a054962 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -401,7 +401,7 @@ static void _ipc_free_ring_packets(pktio_entry_t *pktio_entry, _ring_t *r) while (1) { ret = _ring_mc_dequeue_burst(r, rbuf_p, PKTIO_IPC_ENTRIES); - if (0 == ret) + if (ret <= 0) break; for (i = 0; i < ret; i++) { odp_packet_hdr_t *phdr;
commit 8ae6373c8844408ad080b58fb3083b30e8dc7ea6 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Jun 20 11:24:25 2017 +0300
linux-gen: pktio: ipc fix send return code on tx
Return number on sent packets, but not succesuful return code.
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 06175e5a..1a2a37f2 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -609,7 +609,7 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, ODP_ABORT("Unexpected!\n"); }
- return ret; + return len; }
static int ipc_pktio_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED,
-----------------------------------------------------------------------
Summary of changes: platform/linux-generic/_fdserver.c | 25 ++++- platform/linux-generic/_ishm.c | 124 +++++++++++++++++---- platform/linux-generic/include/_ishm_internal.h | 1 + platform/linux-generic/include/odp_internal.h | 3 + .../include/odp_packet_io_ipc_internal.h | 8 -- platform/linux-generic/odp_init.c | 66 ++--------- platform/linux-generic/pktio/ipc.c | 25 +++-- .../validation/api/shmem/shmem_common.h | 5 +- .../validation/api/shmem/shmem_linux.c | 21 +++- .../validation/api/shmem/shmem_odp1.c | 8 +- .../validation/api/shmem/shmem_odp2.c | 4 +- 11 files changed, 177 insertions(+), 113 deletions(-)
hooks/post-receive