@@ -43,5 +43,6 @@ struct pktio_info {
* (odp-linux pool specific) */
size_t mdata_offset;
char pool_name[ODP_POOL_NAME_LEN];
+ int pid;
} slave;
} ODP_PACKED;
@@ -17,7 +17,7 @@
/* MAC address for the "ipc" interface */
static const char pktio_ipc_mac[] = {0x12, 0x12, 0x12, 0x12, 0x12, 0x12};
-static void *_ipc_map_remote_pool(const char *name, size_t size);
+static void *_ipc_map_remote_pool(const char *name, size_t size, int pid);
static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl)
{
@@ -35,38 +35,6 @@ static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl)
return info.name;
}
-/**
-* Look up for shared memory object.
-*
-* @param name name of shm object
-*
-* @return 0 on success, otherwise non-zero
-*/
-static int _ipc_shm_lookup(const char *name)
-{
- int shm;
- char shm_devname[SHM_DEVNAME_MAXLEN];
-
- if (!odp_global_data.ipc_ns)
- ODP_ABORT("ipc_ns not set\n");
-
- snprintf(shm_devname, SHM_DEVNAME_MAXLEN,
- SHM_DEVNAME_FORMAT,
- odp_global_data.ipc_ns, name);
-
- shm = shm_open(shm_devname, O_RDWR, S_IRUSR | S_IWUSR);
- if (shm == -1) {
- if (errno == ENOENT) {
- ODP_DBG("no file %s\n", shm_devname);
- return -1;
- }
- ODP_ABORT("shm_open for %s err %s\n",
- shm_devname, strerror(errno));
- }
- close(shm);
- return 0;
-}
-
static int _ipc_map_pktio_info(pktio_entry_t *pktio_entry,
const char *dev,
int *slave)
@@ -81,22 +49,21 @@ static int _ipc_map_pktio_info(pktio_entry_t *pktio_entry,
flags = ODP_SHM_PROC | _ODP_SHM_O_EXCL;
- shm = odp_shm_reserve(name, sizeof(struct pktio_info),
- ODP_CACHE_LINE_SIZE,
- flags);
- if (ODP_SHM_INVALID != shm) {
- pinfo = odp_shm_addr(shm);
- pinfo->master.pool_name[0] = 0;
- *slave = 0;
- } else {
- flags = _ODP_SHM_PROC_NOCREAT | _ODP_SHM_O_EXCL;
+ shm = odp_shm_reserve_exported(name, odp_global_data.ipc_ns,
+ name, 4096, 0);
+ if (ODP_SHM_INVALID == shm) {
+ flags = ODP_SHM_EXPORT | ODP_SHM_LOCK;
shm = odp_shm_reserve(name, sizeof(struct pktio_info),
ODP_CACHE_LINE_SIZE,
flags);
if (ODP_SHM_INVALID == shm)
- ODP_ABORT("can not connect to shm\n");
+ ODP_ABORT("can not create shm %s\n", name);
pinfo = odp_shm_addr(shm);
+ pinfo->master.pool_name[0] = 0;
+ *slave = 0;
+ } else {
+ pinfo = odp_shm_addr(shm);
*slave = 1;
}
@@ -109,20 +76,20 @@ static int _ipc_map_pktio_info(pktio_entry_t *pktio_entry,
static int _ipc_master_start(pktio_entry_t *pktio_entry)
{
struct pktio_info *pinfo = pktio_entry->s.ipc.pinfo;
- int ret;
void *ipc_pool_base;
if (pinfo->slave.mdata_offset == 0)
return -1;
- ret = _ipc_shm_lookup(pinfo->slave.pool_name);
- if (ret) {
- ODP_DBG("no pool file %s\n", pinfo->slave.pool_name);
- return -1;
- }
-
ipc_pool_base = _ipc_map_remote_pool(pinfo->slave.pool_name,
- pinfo->master.shm_pkt_pool_size);
+ pinfo->master.shm_pkt_pool_size,
+ pinfo->slave.pid);
+ if (ipc_pool_base == NULL) {
+ ODP_DBG("no pool file %s for pid %d\n",
+ pinfo->slave.pool_name, pinfo->slave.pid);
+ return -1;
+ }
+
pktio_entry->s.ipc.pool_mdata_base = (char *)ipc_pool_base +
pinfo->slave.mdata_offset;
@@ -258,22 +225,24 @@ static void _ipc_export_pool(struct pktio_info *pinfo,
snprintf(pinfo->slave.pool_name, ODP_POOL_NAME_LEN, "%s",
pool_entry->s.name);
+ pinfo->slave.pid = odp_global_data.main_pid;
pinfo->slave.mdata_offset = pool_entry->s.pool_mdata_addr -
pool_entry->s.pool_base_addr;
}
-static void *_ipc_map_remote_pool(const char *name, size_t size)
+static void *_ipc_map_remote_pool(const char *name, size_t size, int pid)
{
odp_shm_t shm;
void *addr;
ODP_DBG("Mapping remote pool %s, size %ld\n", name, size);
- shm = odp_shm_reserve(name,
- size,
- ODP_CACHE_LINE_SIZE,
- _ODP_SHM_PROC_NOCREAT);
- if (shm == ODP_SHM_INVALID)
- ODP_ABORT("unable map %s\n", name);
+
+ shm = odp_shm_reserve_exported(name, pid,
+ name, 4096, 0);
+ if (shm == ODP_SHM_INVALID) {
+ ODP_ERR("unable map %s\n", name);
+ return NULL;
+ }
addr = odp_shm_addr(shm);
ODP_DBG("MAP master: %p - %p size %ld, pool %s\n",
@@ -281,20 +250,16 @@ static void *_ipc_map_remote_pool(const char *name, size_t size)
return addr;
}
-static void *_ipc_shm_map(char *name, size_t size)
+static void *_ipc_shm_map(char *name, size_t size ODP_UNUSED)
{
odp_shm_t shm;
- int ret;
- ret = _ipc_shm_lookup(name);
- if (ret == -1)
+ shm = odp_shm_reserve_exported(name, odp_global_data.ipc_ns,
+ name, 4096, 0);
+ if (ODP_SHM_INVALID == shm) {
+ ODP_ERR("unable to map: %s\n", name);
return NULL;
-
- shm = odp_shm_reserve(name, size,
- ODP_CACHE_LINE_SIZE,
- _ODP_SHM_PROC_NOCREAT);
- if (ODP_SHM_INVALID == shm)
- ODP_ABORT("unable to map: %s\n", name);
+ }
return odp_shm_addr(shm);
}
@@ -368,7 +333,8 @@ static int _ipc_slave_start(pktio_entry_t *pktio_entry)
/* Get info about remote pool */
pinfo = pktio_entry->s.ipc.pinfo;
ipc_pool_base = _ipc_map_remote_pool(pinfo->master.pool_name,
- pinfo->master.shm_pkt_pool_size);
+ pinfo->master.shm_pkt_pool_size,
+ odp_global_data.ipc_ns);
pktio_entry->s.ipc.pool_mdata_base = (char *)ipc_pool_base +
pinfo->master.mdata_offset;
pktio_entry->s.ipc.pkt_size = pinfo->master.shm_pkt_size;
@@ -160,7 +160,7 @@ _ring_create(const char *name, unsigned count, unsigned flags)
odp_shm_t shm;
if (flags & _RING_SHM_PROC)
- shm_flag = ODP_SHM_PROC;
+ shm_flag = ODP_SHM_EXPORT;
else
shm_flag = 0;
Repair ipc after shared memory implementation and keep original logic. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- .../include/odp_packet_io_ipc_internal.h | 1 + platform/linux-generic/pktio/ipc.c | 104 +++++++-------------- platform/linux-generic/pktio/ring.c | 2 +- 3 files changed, 37 insertions(+), 70 deletions(-) -- 2.7.1.250.gff4ea60