From patchwork Thu Oct 20 20:26:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 78560 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp971766qge; Thu, 20 Oct 2016 13:27:24 -0700 (PDT) X-Received: by 10.233.232.86 with SMTP id a83mr2576206qkg.208.1476995244119; Thu, 20 Oct 2016 13:27:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y2si624202qtb.15.2016.10.20.13.27.23; Thu, 20 Oct 2016 13:27:24 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A809060AEF; Thu, 20 Oct 2016 20:27:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 50FE560F3B; Thu, 20 Oct 2016 20:27:05 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5B1D2617AC; Thu, 20 Oct 2016 20:27:00 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id 8C9B760F3B for ; Thu, 20 Oct 2016 20:26:54 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id b81so99057017lfe.1 for ; Thu, 20 Oct 2016 13:26:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Dsl5JmMOKCQBpR3aa0abz+Ys451CvuPhECjiyl88/Qo=; b=OpYez+k2RWV2anXxuTktJOmTPcdrYbekl7YMF9X/CsMRmVlElgdlHpJYBISxJbO7l5 dJiY7PxhfxrUm/2+m97cJC0HHnwPrhhPNk2LWO5ahXjyFXPwRhQayu9RblyLhgYIDQO5 D07ZSlM5EuMkPWPUf+Q5HV/WVidZFXVpS6yao3n8msfrzSesOdcZjG/5If0s6H/nbju1 ENf/BFBJO1fdzOWrNEUd+QPQ4ywza7pPHtbryQ9WorHq83kvnKKTyOhIi/1DCUkGieCS WEk6pc6+pS1T633iCM3E33uYJ5lP10BFVy8m1CgwqLcGvRcsa3RUeSo0zv1eq0t+ZY5r xYSw== X-Gm-Message-State: ABUngvfholObSXOwENxn3LxFUKZhNUeKP7YqeVN1Iy/wYZO+FCOl8Tat0PSlJZAZs51FrrTF3t8= X-Received: by 10.25.165.144 with SMTP id o138mr2478572lfe.80.1476995211550; Thu, 20 Oct 2016 13:26:51 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-163-48.pppoe.mtu-net.ru. [91.77.163.48]) by smtp.gmail.com with ESMTPSA id 78sm466282ljj.7.2016.10.20.13.26.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 13:26:50 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 20 Oct 2016 23:26:27 +0300 Message-Id: <1476995190-7548-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1476995190-7548-1-git-send-email-maxim.uvarov@linaro.org> References: <1476995190-7548-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/4] linux-gen: pktio ipc: repair ipc pktio X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Repair ipc after shared memory implementation and keep original logic. Signed-off-by: Maxim Uvarov --- .../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 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 851114d..1b81e2c 100644 --- a/platform/linux-generic/include/odp_packet_io_ipc_internal.h +++ b/platform/linux-generic/include/odp_packet_io_ipc_internal.h @@ -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; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index b779ab7..9b064dd 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -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; diff --git a/platform/linux-generic/pktio/ring.c b/platform/linux-generic/pktio/ring.c index cc84e8a..fe27815 100644 --- a/platform/linux-generic/pktio/ring.c +++ b/platform/linux-generic/pktio/ring.c @@ -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;