get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/12832/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 12832,
    "url": "https://patches.dpdk.org/api/patches/12832/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1463563818-2249-3-git-send-email-remy.horton@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1463563818-2249-3-git-send-email-remy.horton@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1463563818-2249-3-git-send-email-remy.horton@intel.com",
    "date": "2016-05-18T09:30:17",
    "name": "[dpdk-dev,v2,2/3] examples/l2fwd-keepalive: add IPC liveness reporting",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "7cecdf2fe059a666ffe6425f538c0cff1c0ee8c8",
    "submitter": {
        "id": 326,
        "url": "https://patches.dpdk.org/api/people/326/?format=api",
        "name": "Remy Horton",
        "email": "remy.horton@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1463563818-2249-3-git-send-email-remy.horton@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/12832/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/12832/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id CDED36CCC;\n\tWed, 18 May 2016 11:30:27 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 1DC0D6C99\n\tfor <dev@dpdk.org>; Wed, 18 May 2016 11:30:23 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga102.jf.intel.com with ESMTP; 18 May 2016 02:30:23 -0700",
            "from rhorton-mobl.ger.corp.intel.com (HELO VM.ir.intel.com)\n\t([163.33.230.16])\n\tby orsmga002.jf.intel.com with ESMTP; 18 May 2016 02:30:22 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.26,328,1459839600\"; d=\"scan'208\";a=\"979453111\"",
        "From": "Remy Horton <remy.horton@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Wed, 18 May 2016 10:30:17 +0100",
        "Message-Id": "<1463563818-2249-3-git-send-email-remy.horton@intel.com>",
        "X-Mailer": "git-send-email 2.5.5",
        "In-Reply-To": "<1463563818-2249-1-git-send-email-remy.horton@intel.com>",
        "References": "<1463563818-2249-1-git-send-email-remy.horton@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 2/3] examples/l2fwd-keepalive: add IPC\n\tliveness reporting",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Signed-off-by: Remy Horton <remy.horton@intel.com>\n---\n examples/Makefile                          |   1 +\n examples/l2fwd-keepalive/Makefile          |   4 +-\n examples/l2fwd-keepalive/ka-agent/Makefile |  51 ++++++++++\n examples/l2fwd-keepalive/ka-agent/main.c   | 150 +++++++++++++++++++++++++++++\n examples/l2fwd-keepalive/main.c            |  22 ++++-\n examples/l2fwd-keepalive/shm.c             | 128 ++++++++++++++++++++++++\n examples/l2fwd-keepalive/shm.h             |  89 +++++++++++++++++\n 7 files changed, 441 insertions(+), 4 deletions(-)\n create mode 100644 examples/l2fwd-keepalive/ka-agent/Makefile\n create mode 100644 examples/l2fwd-keepalive/ka-agent/main.c\n create mode 100644 examples/l2fwd-keepalive/shm.c\n create mode 100644 examples/l2fwd-keepalive/shm.h",
    "diff": "diff --git a/examples/Makefile b/examples/Makefile\nindex 3bc635a..f650d3e 100644\n--- a/examples/Makefile\n+++ b/examples/Makefile\n@@ -64,6 +64,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += l2fwd-crypto\n DIRS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += l2fwd-ivshmem\n DIRS-$(CONFIG_RTE_LIBRTE_JOBSTATS) += l2fwd-jobstats\n DIRS-y += l2fwd-keepalive\n+DIRS-y += l2fwd-keepalive/ka-agent\n DIRS-$(CONFIG_RTE_LIBRTE_LPM) += l3fwd\n DIRS-$(CONFIG_RTE_LIBRTE_ACL) += l3fwd-acl\n ifeq ($(CONFIG_RTE_LIBRTE_LPM),y)\ndiff --git a/examples/l2fwd-keepalive/Makefile b/examples/l2fwd-keepalive/Makefile\nindex 568edcb..3fcf513 100644\n--- a/examples/l2fwd-keepalive/Makefile\n+++ b/examples/l2fwd-keepalive/Makefile\n@@ -1,6 +1,6 @@\n #   BSD LICENSE\n #\n-#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.\n #   All rights reserved.\n #\n #   Redistribution and use in source and binary forms, with or without\n@@ -42,7 +42,7 @@ include $(RTE_SDK)/mk/rte.vars.mk\n APP = l2fwd-keepalive\n \n # all source are stored in SRCS-y\n-SRCS-y := main.c\n+SRCS-y := main.c shm.c\n \n CFLAGS += -O3\n CFLAGS += $(WERROR_FLAGS)\ndiff --git a/examples/l2fwd-keepalive/ka-agent/Makefile b/examples/l2fwd-keepalive/ka-agent/Makefile\nnew file mode 100644\nindex 0000000..4eaac76\n--- /dev/null\n+++ b/examples/l2fwd-keepalive/ka-agent/Makefile\n@@ -0,0 +1,51 @@\n+#   BSD LICENSE\n+#\n+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.\n+#   All rights reserved.\n+#\n+#   Redistribution and use in source and binary forms, with or without\n+#   modification, are permitted provided that the following conditions\n+#   are met:\n+#\n+#     * Redistributions of source code must retain the above copyright\n+#       notice, this list of conditions and the following disclaimer.\n+#     * Redistributions in binary form must reproduce the above copyright\n+#       notice, this list of conditions and the following disclaimer in\n+#       the documentation and/or other materials provided with the\n+#       distribution.\n+#     * Neither the name of Intel Corporation nor the names of its\n+#       contributors may be used to endorse or promote products derived\n+#       from this software without specific prior written permission.\n+#\n+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+#   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+ifeq ($(RTE_SDK),)\n+$(error \"Please define RTE_SDK environment variable\")\n+endif\n+\n+# Default target, can be overridden by command line or environment\n+RTE_TARGET ?= x86_64-native-linuxapp-gcc\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+# binary name\n+APP = ka-agent\n+\n+# all source are stored in SRCS-y\n+SRCS-y := main.c\n+\n+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)/../\n+\n+EXTRA_CFLAGS += -O3 -g -Wfatal-errors\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\ndiff --git a/examples/l2fwd-keepalive/ka-agent/main.c b/examples/l2fwd-keepalive/ka-agent/main.c\nnew file mode 100644\nindex 0000000..c8c7303\n--- /dev/null\n+++ b/examples/l2fwd-keepalive/ka-agent/main.c\n@@ -0,0 +1,150 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <errno.h>\n+#include <stdio.h>\n+#include <string.h>\n+#include <stdint.h>\n+#include <errno.h>\n+#include <unistd.h>\n+#include <fcntl.h>\n+#include <sys/wait.h>\n+#include <sys/queue.h>\n+#include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <time.h>\n+\n+#include <rte_keepalive.h>\n+\n+#include <shm.h>\n+\n+#define MAX_TIMEOUTS 4\n+#define SEM_TIMEOUT_SECS 2\n+\n+static struct rte_keepalive_shm *ka_shm_create(void)\n+{\n+\tint fd = shm_open(RTE_KEEPALIVE_SHM_NAME, O_RDWR, 0666);\n+\tsize_t size = sizeof(struct rte_keepalive_shm);\n+\tstruct rte_keepalive_shm *shm;\n+\n+\tif (fd < 0)\n+\t\tprintf(\"Failed to open %s as SHM:%s\\n\",\n+\t\t\tRTE_KEEPALIVE_SHM_NAME,\n+\t\tstrerror(errno));\n+\telse {\n+\t\tshm = (struct rte_keepalive_shm *) mmap(\n+\t\t\t0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);\n+\t\tclose(fd);\n+\t\tif (shm == MAP_FAILED)\n+\t\t\tprintf(\"Failed to mmap SHM:%s\\n\", strerror(errno));\n+\t\telse\n+\t\t\treturn shm;\n+\t}\n+\n+\t/* Reset to zero, as it was set to MAP_FAILED aka: (void *)-1 */\n+\tshm = 0;\n+\treturn NULL;\n+}\n+\n+int main(void)\n+{\n+\tstruct rte_keepalive_shm *shm = ka_shm_create();\n+\tstruct timespec timeout = { .tv_nsec = 0 };\n+\tint idx_core;\n+\tint cnt_cores;\n+\tuint64_t last_seen_alive_time = 0;\n+\tuint64_t most_recent_alive_time;\n+\tint cnt_timeouts = 0;\n+\tint sem_errno;\n+\n+\tif (shm == NULL) {\n+\t\tprintf(\"Unable to access shared core state\\n\");\n+\t\treturn 1;\n+\t}\n+\twhile (1) {\n+\t\tmost_recent_alive_time = 0;\n+\t\tfor (idx_core = 0; idx_core < RTE_KEEPALIVE_MAXCORES;\n+\t\t\t\tidx_core++)\n+\t\t\tif (shm->core_last_seen_times[idx_core] >\n+\t\t\t\t\tmost_recent_alive_time)\n+\t\t\t\tmost_recent_alive_time =\n+\t\t\t\t\tshm->core_last_seen_times[idx_core];\n+\n+\t\ttimeout.tv_sec = time(NULL) + SEM_TIMEOUT_SECS;\n+\t\tif (sem_timedwait(&shm->core_died, &timeout) == -1) {\n+\t\t\t/* Assume no core death signals and no change in any\n+\t\t\t * last-seen times is the keepalive monitor itself\n+\t\t\t * failing.\n+\t\t\t */\n+\t\t\tsem_errno = errno;\n+\t\t\tlast_seen_alive_time = most_recent_alive_time;\n+\t\t\tif (sem_errno == ETIMEDOUT) {\n+\t\t\t\tif (last_seen_alive_time ==\n+\t\t\t\t\t\tmost_recent_alive_time &&\n+\t\t\t\t\t\tcnt_timeouts++ >\n+\t\t\t\t\t\tMAX_TIMEOUTS) {\n+\t\t\t\t\tprintf(\"No updates. Exiting..\\n\");\n+\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t} else\n+\t\t\t\tprintf(\"sem_timedwait() error (%s)\\n\",\n+\t\t\t\t\tstrerror(sem_errno));\n+\t\t\tcontinue;\n+\t\t}\n+\t\tcnt_timeouts = 0;\n+\n+\t\tcnt_cores = 0;\n+\t\tfor (idx_core = 0; idx_core < RTE_KEEPALIVE_MAXCORES;\n+\t\t\t\tidx_core++)\n+\t\t\tif (shm->core_state[idx_core] == DEAD)\n+\t\t\t\tcnt_cores++;\n+\t\tif (cnt_cores == 0) {\n+\t\t\t/* Can happen if core was restarted since Semaphore\n+\t\t\t * was sent, due to agent being offline.\n+\t\t\t */\n+\t\t\tprintf(\"Warning: Empty dead core report\\n\");\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tprintf(\"%i dead cores: \", cnt_cores);\n+\t\tfor (idx_core = 0;\n+\t\t\t\tidx_core < RTE_KEEPALIVE_MAXCORES;\n+\t\t\t\tidx_core++)\n+\t\t\tif (shm->core_state[idx_core] == DEAD)\n+\t\t\t\tprintf(\"%d, \", idx_core);\n+\t\tprintf(\"\\b\\b\\n\");\n+\t}\n+\tif (munmap(shm, sizeof(struct rte_keepalive_shm)) != 0)\n+\t\tprintf(\"Warning: munmap() failed\\n\");\n+\treturn 0;\n+}\ndiff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c\nindex 8da89aa..a69cbb9 100644\n--- a/examples/l2fwd-keepalive/main.c\n+++ b/examples/l2fwd-keepalive/main.c\n@@ -72,6 +72,8 @@\n #include <rte_timer.h>\n #include <rte_keepalive.h>\n \n+#include \"shm.h\"\n+\n #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1\n \n #define NB_MBUF   8192\n@@ -523,7 +525,7 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)\n }\n \n static void\n-dead_core(__attribute__((unused)) void *ptr_data, const int id_core)\n+dead_core(__rte_unused void *ptr_data, const int id_core)\n {\n \tprintf(\"Dead core %i - restarting..\\n\", id_core);\n \tif (rte_eal_get_lcore_state(id_core) == FINISHED) {\n@@ -534,6 +536,14 @@ dead_core(__attribute__((unused)) void *ptr_data, const int id_core)\n \t}\n }\n \n+static void\n+relay_core_state(void *ptr_data, const int id_core,\n+\tconst enum rte_keepalive_state core_state, uint64_t last_alive)\n+{\n+\trte_keepalive_relayed_state((struct rte_keepalive_shm *)ptr_data,\n+\t\tid_core, core_state, last_alive);\n+}\n+\n int\n main(int argc, char **argv)\n {\n@@ -725,10 +735,18 @@ main(int argc, char **argv)\n \trte_timer_init(&stats_timer);\n \n \tif (check_period > 0) {\n+\t\tstruct rte_keepalive_shm *ka_shm;\n+\n+\t\tka_shm = rte_keepalive_shm_create();\n+\t\tif (ka_shm == NULL)\n+\t\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t\"rte_keepalive_shm_create() failed\");\n \t\trte_global_keepalive_info =\n-\t\t\trte_keepalive_create(&dead_core, NULL);\n+\t\t\trte_keepalive_create(&dead_core, ka_shm);\n \t\tif (rte_global_keepalive_info == NULL)\n \t\t\trte_exit(EXIT_FAILURE, \"init_keep_alive() failed\");\n+\t\trte_keepalive_register_relay_callback(rte_global_keepalive_info,\n+\t\t\trelay_core_state, ka_shm);\n \t\trte_timer_init(&hb_timer);\n \t\tif (rte_timer_reset(&hb_timer,\n \t\t\t\t(check_period * rte_get_timer_hz()) / 1000,\ndiff --git a/examples/l2fwd-keepalive/shm.c b/examples/l2fwd-keepalive/shm.c\nnew file mode 100644\nindex 0000000..f66bd12\n--- /dev/null\n+++ b/examples/l2fwd-keepalive/shm.c\n@@ -0,0 +1,128 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <time.h>\n+\n+#include <rte_common.h>\n+#include <rte_log.h>\n+#include <rte_keepalive.h>\n+\n+#include \"shm.h\"\n+\n+struct rte_keepalive_shm *rte_keepalive_shm_create(void)\n+{\n+\tint fd;\n+\tint idx_core;\n+\tstruct rte_keepalive_shm *ka_shm;\n+\n+\t/* If any existing object is not unlinked, it makes it all too easy\n+\t * for clients to end up with stale shared memory blocks when\n+\t * restarted. Unlinking makes sure subsequent shm_open by clients\n+\t * will get the new block mapped below.\n+\t */\n+\tif (shm_unlink(RTE_KEEPALIVE_SHM_NAME) == -1 && errno != ENOENT)\n+\t\tprintf(\"Warning: Error unlinking stale %s (%s)\\n\",\n+\t\t\tRTE_KEEPALIVE_SHM_NAME, strerror(errno));\n+\n+\tfd = shm_open(RTE_KEEPALIVE_SHM_NAME,\n+\t\tO_CREAT | O_TRUNC | O_RDWR, 0666);\n+\tif (fd < 0)\n+\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\"Failed to open %s as SHM (%s)\\n\",\n+\t\t\tRTE_KEEPALIVE_SHM_NAME,\n+\t\t\tstrerror(errno));\n+\telse if (ftruncate(fd, sizeof(struct rte_keepalive_shm)) != 0)\n+\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\"Failed to resize SHM (%s)\\n\", strerror(errno));\n+\telse {\n+\t\tka_shm = (struct rte_keepalive_shm *) mmap(\n+\t\t\t0, sizeof(struct rte_keepalive_shm),\n+\t\t\tPROT_READ | PROT_WRITE,\tMAP_SHARED, fd, 0);\n+\t\tclose(fd);\n+\t\tif (ka_shm == MAP_FAILED)\n+\t\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\t\"Failed to mmap SHM (%s)\\n\", strerror(errno));\n+\t\telse {\n+\t\t\tmemset(ka_shm, 0, sizeof(struct rte_keepalive_shm));\n+\n+\t\t\t/* Initialize the semaphores for IPC/SHM use */\n+\t\t\tif (sem_init(&ka_shm->core_died, 1, 0) != 0) {\n+\t\t\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\t\t\"Failed to setup SHM semaphore (%s)\\n\",\n+\t\t\t\t\tstrerror(errno));\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\n+\t\t\t/* Set all cores to 'not present' */\n+\t\t\tfor (idx_core = 0;\n+\t\t\t\t\tidx_core < RTE_KEEPALIVE_MAXCORES;\n+\t\t\t\t\tidx_core++) {\n+\t\t\t\tka_shm->core_state[idx_core] = UNUSED;\n+\t\t\t\tka_shm->core_last_seen_times[idx_core] = 0;\n+\t\t\t}\n+\n+\t\t\treturn ka_shm;\n+\t\t}\n+\t}\n+return NULL;\n+}\n+\n+void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,\n+\tconst int id_core, const enum rte_keepalive_state core_state,\n+\t__rte_unused uint64_t last_alive)\n+{\n+\tint count;\n+\n+\tshm->core_state[id_core] = core_state;\n+\tshm->core_last_seen_times[id_core] = last_alive;\n+\n+\tif (core_state == RTE_KEEPALIVE_SHM_DEAD) {\n+\t\t/* Since core has died, also signal ka_agent.\n+\t\t *\n+\t\t * Limit number of times semaphore can be incremented, in case\n+\t\t * ka_agent is not active.\n+\t\t */\n+\t\tif (sem_getvalue(&shm->core_died, &count) == -1) {\n+\t\t\tRTE_LOG(INFO, EAL, \"Semaphore check failed(%s)\\n\",\n+\t\t\t\tstrerror(errno));\n+\t\t\treturn;\n+\t\t}\n+\t\tif (count > 1)\n+\t\t\treturn;\n+\n+\t\tif (sem_post(&shm->core_died) != 0)\n+\t\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\t\"Failed to increment semaphore (%s)\\n\",\n+\t\t\t\tstrerror(errno));\n+\t}\n+}\ndiff --git a/examples/l2fwd-keepalive/shm.h b/examples/l2fwd-keepalive/shm.h\nnew file mode 100644\nindex 0000000..25e1b61\n--- /dev/null\n+++ b/examples/l2fwd-keepalive/shm.h\n@@ -0,0 +1,89 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#define RTE_KEEPALIVE_SHM_NAME \"/dpdk_keepalive_shm_name\"\n+\n+#define RTE_KEEPALIVE_SHM_ALIVE 1\n+#define RTE_KEEPALIVE_SHM_DEAD 2\n+\n+#include <fcntl.h>\n+#include <string.h>\n+#include <unistd.h>\n+#include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <semaphore.h>\n+#include <rte_keepalive.h>\n+\n+/**\n+ * Keepalive SHM structure.\n+ *\n+ * The shared memory allocated by the primary is this size, and contains the\n+ * information as contained within this struct. A secondary may open the SHM,\n+ * and read the contents.\n+ */\n+struct rte_keepalive_shm {\n+\t/** IPC semaphore. Posted when a core dies */\n+\tsem_t core_died;\n+\n+\t/**\n+\t * Relayed status of each core.\n+\t */\n+\tenum rte_keepalive_state core_state[RTE_KEEPALIVE_MAXCORES];\n+\n+\t/**\n+\t * Last-seen-alive timestamps for the cores\n+\t */\n+\tuint64_t core_last_seen_times[RTE_KEEPALIVE_MAXCORES];\n+};\n+\n+/**\n+ * Create shared host memory keepalive object.\n+ * @return\n+ *  Pointer to SHM keepalive structure, or NULL on failure.\n+ */\n+struct rte_keepalive_shm *rte_keepalive_shm_create(void);\n+\n+/**\n+ * Relays state for given core\n+ * @param *shm\n+ *  Pointer to SHM keepalive structure.\n+ * @param id_core\n+ *  Id of core\n+ * @param core_state\n+ *  State of core\n+ * @param last_alive\n+ *  Last seen timestamp for core\n+ */\n+void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,\n+\tconst int id_core, const enum rte_keepalive_state core_state,\n+\tuint64_t last_alive);\n",
    "prefixes": [
        "dpdk-dev",
        "v2",
        "2/3"
    ]
}