get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2205,
    "url": "https://patches.dpdk.org/api/patches/2205/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1420565213-17429-3-git-send-email-rkerur@gmail.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": "<1420565213-17429-3-git-send-email-rkerur@gmail.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1420565213-17429-3-git-send-email-rkerur@gmail.com",
    "date": "2015-01-06T17:26:49",
    "name": "[dpdk-dev,v4,3/7] Move common functions in eal.c",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "87e9b5fe52741b694ae9dfb570496972e9255e89",
    "submitter": {
        "id": 134,
        "url": "https://patches.dpdk.org/api/people/134/?format=api",
        "name": "Ravi Kerur",
        "email": "rkerur@gmail.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1420565213-17429-3-git-send-email-rkerur@gmail.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2205/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2205/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 369195A42;\n\tTue,  6 Jan 2015 18:27:23 +0100 (CET)",
            "from mail-pd0-f176.google.com (mail-pd0-f176.google.com\n\t[209.85.192.176]) by dpdk.org (Postfix) with ESMTP id 06E625938\n\tfor <dev@dpdk.org>; Tue,  6 Jan 2015 18:27:17 +0100 (CET)",
            "by mail-pd0-f176.google.com with SMTP id r10so30742949pdi.7\n\tfor <dev@dpdk.org>; Tue, 06 Jan 2015 09:27:16 -0800 (PST)",
            "from iaas-l305162.englab.brocade.com ([144.49.130.148])\n\tby mx.google.com with ESMTPSA id\n\tnl14sm46887340pdb.81.2015.01.06.09.27.15\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tTue, 06 Jan 2015 09:27:15 -0800 (PST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=4YLaQ1HsRXtd1cFjgqeKucZM/QXUURcQ5f9vIj0dLOw=;\n\tb=v5Wc4I7jRAUf8qm1pDvSqm7MdKhw/8QQ01lcaB9eN+iA/1zwRJcLrrEyVlYghSkmOi\n\tWkyZNC+3xEep7PQ1AW3R+gotTCu26pUucLwMAaF9cQaGzW+ffFjmgp9mdSHam1tDjDk5\n\tSE4DjAxrYLFTPSZxRQZyWVcCQdDlIbSUTgFbpGlFB+HXqUcroVktiRvLclnZWinkzgLt\n\tPXubs/cs7Uej6rZwE4qW/5XFs3eQdpgja9mr3gKjBTCyZmywYUEH3t058arIy7kL2/bW\n\tePvxLT3p/oxMc4XHrKVqYTiIAeVOWy245gHOQg4gEZY20XOZcWOe84h42SbDaYALawux\n\t5/Hw==",
        "X-Received": "by 10.68.141.204 with SMTP id rq12mr155511614pbb.7.1420565236339;\n\tTue, 06 Jan 2015 09:27:16 -0800 (PST)",
        "From": "Ravi Kerur <rkerur@gmail.com>",
        "To": "dev@dpdk.org",
        "Date": "Tue,  6 Jan 2015 12:26:49 -0500",
        "Message-Id": "<1420565213-17429-3-git-send-email-rkerur@gmail.com>",
        "X-Mailer": "git-send-email 1.9.1",
        "In-Reply-To": "<1420565213-17429-1-git-send-email-rkerur@gmail.com>",
        "References": "<1420565170-17365-1-git-send-email-rkerur@gmail.com>\n\t<1420565213-17429-1-git-send-email-rkerur@gmail.com>",
        "Subject": "[dpdk-dev] [PATCH v4 3/7] Move common functions in eal.c",
        "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": "Changes in v4\nRemove eal_externs.h file, instead use  _get_ and _set_ APIS\nto access those variables.\nSplit eal_common.c into eal_common_system.c and\nand eal_common_runtime.c\nrte_eal prefix functions are moved to _runtime_ and\neal prefix functions are moved to _system_ files respectively\n\nChanges in v3\nChanged subject to be more explicit on file name inclusion.\n\nChanges in v2\nIn function rte_eal_config_create remove #ifdef _BSDAPP_\nand initialize mem_cfg_addr unconditionally.\n\nChanges in v1\nMove common functions in eal.c to librte_eal/common/eal_common.c.\n\nFollowing functions are moved to eal_common.c file.\n\nstruct rte_config *rte_eal_get_configuration(void);\nint eal_parse_sysfs_value(const char *filename, unsigned long *val);\nstatic void rte_eal_config_create(void);\nenum rte_proc_type_t eal_proc_type_detect(void);\nvoid rte_eal_config_init(void);\nrte_usage_hook_t rte_set_application_usage_hook(rte_usage_hook_t usage_func);\ninline size_t eal_get_hugepage_mem_size(void);\nvoid eal_check_mem_on_local_socket(void);\nint sync_func(__attribute__((unused)) void *arg);\ninline void rte_eal_mcfg_complete(void);\nint rte_eal_has_hugepages(void);\nenum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id);\nenum rte_proc_type_t rte_eal_process_type(void);\n\nMakefile changes to reflect new files added.\nFix checkpatch warnings and errors.\n\nSigned-off-by: Ravi Kerur <rkerur@gmail.com>\n---\n lib/librte_eal/bsdapp/eal/Makefile         |   2 +\n lib/librte_eal/bsdapp/eal/eal.c            | 269 ++++----------------------\n lib/librte_eal/common/eal_common_runtime.c | 201 ++++++++++++++++++++\n lib/librte_eal/common/eal_common_system.c  | 203 ++++++++++++++++++++\n lib/librte_eal/common/eal_hugepages.h      |   1 +\n lib/librte_eal/common/eal_private.h        |  78 ++++++++\n lib/librte_eal/linuxapp/eal/Makefile       |   2 +\n lib/librte_eal/linuxapp/eal/eal.c          | 290 +++++------------------------\n 8 files changed, 563 insertions(+), 483 deletions(-)\n create mode 100644 lib/librte_eal/common/eal_common_runtime.c\n create mode 100644 lib/librte_eal/common/eal_common_system.c",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile\nindex 92dd9a6..c0b73e9 100644\n--- a/lib/librte_eal/bsdapp/eal/Makefile\n+++ b/lib/librte_eal/bsdapp/eal/Makefile\n@@ -58,6 +58,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c\n \n # from common dir\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_system.c\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_runtime.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c\ndiff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c\nindex 69f3c03..4bba352 100644\n--- a/lib/librte_eal/bsdapp/eal/eal.c\n+++ b/lib/librte_eal/bsdapp/eal/eal.c\n@@ -83,27 +83,6 @@\n \n #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)\n \n-/* Allow the application to print its usage message too if set */\n-static rte_usage_hook_t\trte_application_usage_hook = NULL;\n-/* early configuration structure, when memory config is not mmapped */\n-static struct rte_mem_config early_mem_config;\n-\n-/* define fd variable here, because file needs to be kept open for the\n- * duration of the program, as we hold a write lock on it in the primary proc */\n-static int mem_cfg_fd = -1;\n-\n-static struct flock wr_lock = {\n-\t\t.l_type = F_WRLCK,\n-\t\t.l_whence = SEEK_SET,\n-\t\t.l_start = offsetof(struct rte_mem_config, memseg),\n-\t\t.l_len = sizeof(early_mem_config.memseg),\n-};\n-\n-/* Address of global and public configuration */\n-static struct rte_config rte_config = {\n-\t\t.mem_config = &early_mem_config,\n-};\n-\n /* internal configuration (per-core) */\n struct lcore_config lcore_config[RTE_MAX_LCORE];\n \n@@ -113,160 +92,58 @@ struct internal_config internal_config;\n /* used by rte_rdtsc() */\n int rte_cycles_vmware_tsc_map;\n \n-/* Return a pointer to the configuration structure */\n-struct rte_config *\n-rte_eal_get_configuration(void)\n-{\n-\treturn &rte_config;\n-}\n-\n-/* parse a sysfs (or other) file containing one integer value */\n-int\n-eal_parse_sysfs_value(const char *filename, unsigned long *val)\n+inline void *\n+rte_eal_get_mem_cfg_addr(void)\n {\n-\tFILE *f;\n-\tchar buf[BUFSIZ];\n-\tchar *end = NULL;\n-\n-\tif ((f = fopen(filename, \"r\")) == NULL) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot open sysfs value %s\\n\",\n-\t\t\t__func__, filename);\n-\t\treturn -1;\n-\t}\n-\n-\tif (fgets(buf, sizeof(buf), f) == NULL) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot read sysfs value %s\\n\",\n-\t\t\t__func__, filename);\n-\t\tfclose(f);\n-\t\treturn -1;\n-\t}\n-\t*val = strtoul(buf, &end, 0);\n-\tif ((buf[0] == '\\0') || (end == NULL) || (*end != '\\n')) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot parse sysfs value %s\\n\",\n-\t\t\t\t__func__, filename);\n-\t\tfclose(f);\n-\t\treturn -1;\n-\t}\n-\tfclose(f);\n-\treturn 0;\n-}\n-\n-\n-/* create memory configuration in shared/mmap memory. Take out\n- * a write lock on the memsegs, so we can auto-detect primary/secondary.\n- * This means we never close the file while running (auto-close on exit).\n- * We also don't lock the whole file, so that in future we can use read-locks\n- * on other parts, e.g. memzones, to detect if there are running secondary\n- * processes. */\n-static void\n-rte_eal_config_create(void)\n-{\n-\tvoid *rte_mem_cfg_addr;\n-\tint retval;\n-\n-\tconst char *pathname = eal_runtime_config_path();\n-\n-\tif (internal_config.no_shconf)\n-\t\treturn;\n-\n-\tif (mem_cfg_fd < 0){\n-\t\tmem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);\n-\t\tif (mem_cfg_fd < 0)\n-\t\t\trte_panic(\"Cannot open '%s' for rte_mem_config\\n\", pathname);\n-\t}\n-\n-\tretval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));\n-\tif (retval < 0){\n-\t\tclose(mem_cfg_fd);\n-\t\trte_panic(\"Cannot resize '%s' for rte_mem_config\\n\", pathname);\n-\t}\n-\n-\tretval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);\n-\tif (retval < 0){\n-\t\tclose(mem_cfg_fd);\n-\t\trte_exit(EXIT_FAILURE, \"Cannot create lock on '%s'. Is another primary \"\n-\t\t\t\t\"process running?\\n\", pathname);\n-\t}\n-\n-\trte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),\n-\t\t\t\tPROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);\n-\n-\tif (rte_mem_cfg_addr == MAP_FAILED){\n-\t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n-\t}\n-\tmemcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));\n-\trte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;\n+\treturn NULL;\n }\n \n /* attach to an existing shared memory config */\n-static void\n+void\n rte_eal_config_attach(void)\n {\n-\tvoid *rte_mem_cfg_addr;\n+\tstruct rte_mem_config *mem_config;\n+\tstruct rte_config *rte_config;\n \tconst char *pathname = eal_runtime_config_path();\n+\tint *mem_cfg_fd = eal_get_mem_cfg_fd();\n \n \tif (internal_config.no_shconf)\n \t\treturn;\n \n-\tif (mem_cfg_fd < 0){\n-\t\tmem_cfg_fd = open(pathname, O_RDWR);\n-\t\tif (mem_cfg_fd < 0)\n+\trte_config = rte_eal_get_configuration();\n+\tif (rte_config == NULL)\n+\t\treturn;\n+\n+\tif (*mem_cfg_fd < 0) {\n+\t\t*mem_cfg_fd = open(pathname, O_RDWR);\n+\t\tif (*mem_cfg_fd < 0)\n \t\t\trte_panic(\"Cannot open '%s' for rte_mem_config\\n\", pathname);\n \t}\n \n-\trte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),\n-\t\t\t\tPROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);\n-\tclose(mem_cfg_fd);\n-\tif (rte_mem_cfg_addr == MAP_FAILED)\n+\tmem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),\n+\t\t\t\tPROT_READ | PROT_WRITE,\n+\t\t\t\tMAP_SHARED, *mem_cfg_fd, 0);\n+\tclose(*mem_cfg_fd);\n+\tif (mem_config == MAP_FAILED)\n \t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n \n-\trte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;\n+\trte_config->mem_config = mem_config;\n }\n \n-/* Detect if we are a primary or a secondary process */\n-enum rte_proc_type_t\n-eal_proc_type_detect(void)\n+/* NOP for BSD */\n+void\n+rte_eal_config_reattach(void)\n {\n-\tenum rte_proc_type_t ptype = RTE_PROC_PRIMARY;\n-\tconst char *pathname = eal_runtime_config_path();\n-\n-\t/* if we can open the file but not get a write-lock we are a secondary\n-\t * process. NOTE: if we get a file handle back, we keep that open\n-\t * and don't close it to prevent a race condition between multiple opens */\n-\tif (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&\n-\t\t\t(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))\n-\t\tptype = RTE_PROC_SECONDARY;\n-\n-\tRTE_LOG(INFO, EAL, \"Auto-detected process type: %s\\n\",\n-\t\t\tptype == RTE_PROC_PRIMARY ? \"PRIMARY\" : \"SECONDARY\");\n-\n-\treturn ptype;\n-}\n \n-/* Sets up rte_config structure with the pointer to shared memory config.*/\n-static void\n-rte_config_init(void)\n-{\n-\trte_config.process_type = internal_config.process_type;\n-\n-\tswitch (rte_config.process_type){\n-\tcase RTE_PROC_PRIMARY:\n-\t\trte_eal_config_create();\n-\t\tbreak;\n-\tcase RTE_PROC_SECONDARY:\n-\t\trte_eal_config_attach();\n-\t\trte_eal_mcfg_wait_complete(rte_config.mem_config);\n-\t\tbreak;\n-\tcase RTE_PROC_AUTO:\n-\tcase RTE_PROC_INVALID:\n-\t\trte_panic(\"Invalid process type\\n\");\n-\t}\n }\n \n /* display usage */\n static void\n eal_usage(const char *prgname)\n {\n+\trte_usage_hook_t rte_application_usage_hook =\n+\t\t\trte_get_application_usage_hook();\n+\n \tprintf(\"\\nUsage: %s \", prgname);\n \teal_common_usage();\n \t/* Allow the application to print its usage message too if hook is set */\n@@ -276,37 +153,6 @@ eal_usage(const char *prgname)\n \t}\n }\n \n-/* Set a per-application usage message */\n-rte_usage_hook_t\n-rte_set_application_usage_hook( rte_usage_hook_t usage_func )\n-{\n-\trte_usage_hook_t\told_func;\n-\n-\t/* Will be NULL on the first call to denote the last usage routine. */\n-\told_func\t\t\t\t\t= rte_application_usage_hook;\n-\trte_application_usage_hook\t= usage_func;\n-\n-\treturn old_func;\n-}\n-\n-static inline size_t\n-eal_get_hugepage_mem_size(void)\n-{\n-\tuint64_t size = 0;\n-\tunsigned i, j;\n-\n-\tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n-\t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n-\t\tif (hpi->hugedir != NULL) {\n-\t\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++) {\n-\t\t\t\tsize += hpi->hugepage_sz * hpi->num_pages[j];\n-\t\t\t}\n-\t\t}\n-\t}\n-\n-\treturn (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;\n-}\n-\n /* Parse the argument given in the command line of the application */\n static int\n eal_parse_args(int argc, char **argv)\n@@ -374,45 +220,6 @@ eal_parse_args(int argc, char **argv)\n \treturn ret;\n }\n \n-static void\n-eal_check_mem_on_local_socket(void)\n-{\n-\tconst struct rte_memseg *ms;\n-\tint i, socket_id;\n-\n-\tsocket_id = rte_lcore_to_socket_id(rte_config.master_lcore);\n-\n-\tms = rte_eal_get_physmem_layout();\n-\n-\tfor (i = 0; i < RTE_MAX_MEMSEG; i++)\n-\t\tif (ms[i].socket_id == socket_id &&\n-\t\t\t\tms[i].len > 0)\n-\t\t\treturn;\n-\n-\tRTE_LOG(WARNING, EAL, \"WARNING: Master core has no \"\n-\t\t\t\"memory on local socket!\\n\");\n-}\n-\n-static int\n-sync_func(__attribute__((unused)) void *arg)\n-{\n-\treturn 0;\n-}\n-\n-inline static void\n-rte_eal_mcfg_complete(void)\n-{\n-\t/* ALL shared mem_config related INIT DONE */\n-\tif (rte_config.process_type == RTE_PROC_PRIMARY)\n-\t\trte_config.mem_config->magic = RTE_MAGIC;\n-}\n-\n-/* return non-zero if hugepages are enabled. */\n-int rte_eal_has_hugepages(void)\n-{\n-\treturn !internal_config.no_hugetlbfs;\n-}\n-\n /* Abstraction for port I/0 privilege */\n int\n rte_eal_iopl_init(void)\n@@ -431,8 +238,13 @@ rte_eal_init(int argc, char **argv)\n {\n \tint i, fctret, ret;\n \tpthread_t thread_id;\n+\tstruct rte_config *rte_config;\n \tstatic rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);\n \n+\trte_config = rte_eal_get_configuration();\n+\tif (rte_config == NULL)\n+\t\treturn -1;\n+\n \tif (!rte_atomic32_test_and_set(&run_once))\n \t\treturn -1;\n \n@@ -476,7 +288,7 @@ rte_eal_init(int argc, char **argv)\n \n \trte_srand(rte_rdtsc());\n \n-\trte_config_init();\n+\trte_eal_config_init();\n \n \tif (rte_eal_memory_init() < 0)\n \t\trte_panic(\"Cannot init memory\\n\");\n@@ -503,7 +315,7 @@ rte_eal_init(int argc, char **argv)\n \t\trte_panic(\"Cannot init PCI\\n\");\n \n \tRTE_LOG(DEBUG, EAL, \"Master core %u is ready (tid=%p)\\n\",\n-\t\trte_config.master_lcore, thread_id);\n+\t\trte_config->master_lcore, thread_id);\n \n \teal_check_mem_on_local_socket();\n \n@@ -532,7 +344,7 @@ rte_eal_init(int argc, char **argv)\n \t\t\trte_panic(\"Cannot create thread\\n\");\n \t}\n \n-\teal_thread_init_master(rte_config.master_lcore);\n+\teal_thread_init_master(rte_config->master_lcore);\n \n \t/*\n \t * Launch a dummy function on all slave lcores, so that master lcore\n@@ -548,16 +360,3 @@ rte_eal_init(int argc, char **argv)\n \treturn fctret;\n }\n \n-/* get core role */\n-enum rte_lcore_role_t\n-rte_eal_lcore_role(unsigned lcore_id)\n-{\n-\treturn (rte_config.lcore_role[lcore_id]);\n-}\n-\n-enum rte_proc_type_t\n-rte_eal_process_type(void)\n-{\n-\treturn (rte_config.process_type);\n-}\n-\ndiff --git a/lib/librte_eal/common/eal_common_runtime.c b/lib/librte_eal/common/eal_common_runtime.c\nnew file mode 100644\nindex 0000000..a7f8c8e\n--- /dev/null\n+++ b/lib/librte_eal/common/eal_common_runtime.c\n@@ -0,0 +1,201 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   Copyright(c) 2014 6WIND S.A.\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 <stdio.h>\n+#include <stdlib.h>\n+#include <stdint.h>\n+#include <string.h>\n+#include <stdarg.h>\n+#include <unistd.h>\n+#include <pthread.h>\n+#include <syslog.h>\n+#include <getopt.h>\n+#include <sys/file.h>\n+#include <stddef.h>\n+#include <errno.h>\n+#include <limits.h>\n+#include <errno.h>\n+#include <sys/mman.h>\n+#include <sys/queue.h>\n+\n+#include <rte_debug.h>\n+#include <rte_eal_memconfig.h>\n+\n+#include \"eal_private.h\"\n+#include \"eal_thread.h\"\n+#include \"eal_internal_cfg.h\"\n+#include \"eal_filesystem.h\"\n+#include \"eal_hugepages.h\"\n+#include \"eal_options.h\"\n+\n+/* Allow the application to print its usage message too if set */\n+rte_usage_hook_t rte_application_usage_hook = NULL;\n+\n+/* early configuration structure, when memory config is not mmapped */\n+static struct rte_mem_config early_mem_config;\n+\n+/* Address of global and public configuration */\n+struct rte_config rte_config = {\n+\t\t.mem_config = &early_mem_config,\n+};\n+\n+/* Return a pointer to the configuration structure */\n+struct rte_config *\n+rte_eal_get_configuration(void)\n+{\n+\treturn &rte_config;\n+}\n+\n+/* create memory configuration in shared/mmap memory. Take out\n+ * a write lock on the memsegs, so we can auto-detect primary/secondary.\n+ * This means we never close the file while running (auto-close on exit).\n+ * We also don't lock the whole file, so that in future we can use read-locks\n+ * on other parts, e.g. memzones, to detect if there are running secondary\n+ * processes. */\n+static void\n+rte_eal_config_create(void)\n+{\n+\tvoid *rte_mem_cfg_addr;\n+\tint retval;\n+\tint *mem_cfg_fd = eal_get_mem_cfg_fd();\n+\n+\tconst char *pathname = eal_runtime_config_path();\n+\n+\tif (internal_config.no_shconf)\n+\t\treturn;\n+\n+\trte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();\n+\n+\tif (*mem_cfg_fd < 0) {\n+\t\t*mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);\n+\t\tif (*mem_cfg_fd < 0)\n+\t\t\trte_panic(\"Cannot open '%s' for rte_mem_config\\n\",\n+\t\t\t\t\tpathname);\n+\t}\n+\n+\tretval = eal_ftruncate_and_fcntl(mem_cfg_fd,\n+\t\t\t\tsizeof(*rte_config.mem_config));\n+\n+\tif (retval == -1) {\n+\t\tclose(*mem_cfg_fd);\n+\t\trte_panic(\"Cannot resize '%s' for rte_mem_config\\n\", pathname);\n+\t} else if (retval == -2) {\n+\t\tclose(*mem_cfg_fd);\n+\t\trte_exit(EXIT_FAILURE, \"Cannot create lock on '%s'. \"\n+\t\t\t\"Is another primary process running?\\n\", pathname);\n+\t}\n+\n+\trte_mem_cfg_addr = mmap(rte_mem_cfg_addr,\n+\t\t\tsizeof(*rte_config.mem_config), PROT_READ | PROT_WRITE,\n+\t\t\tMAP_SHARED, *mem_cfg_fd, 0);\n+\n+\tif (rte_mem_cfg_addr == MAP_FAILED)\n+\t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n+\n+\tmemcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));\n+\trte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;\n+\n+\t/* store address of the config in the config itself so that secondary\n+\t * processes could later map the config into this exact location\n+\t */\n+\trte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;\n+}\n+\n+/* Sets up rte_config structure with the pointer to shared memory config.*/\n+void\n+rte_eal_config_init(void)\n+{\n+\trte_config.process_type = internal_config.process_type;\n+\n+\tswitch (rte_config.process_type) {\n+\tcase RTE_PROC_PRIMARY:\n+\t\trte_eal_config_create();\n+\t\tbreak;\n+\tcase RTE_PROC_SECONDARY:\n+\t\trte_eal_config_attach();\n+\t\trte_eal_mcfg_wait_complete(rte_config.mem_config);\n+\t\trte_eal_config_reattach();\n+\t\tbreak;\n+\tcase RTE_PROC_AUTO:\n+\tcase RTE_PROC_INVALID:\n+\t\trte_panic(\"Invalid process type\\n\");\n+\t}\n+}\n+\n+/* Get per-application usage message */\n+rte_usage_hook_t\n+rte_get_application_usage_hook(void)\n+{\n+\treturn rte_application_usage_hook;\n+}\n+\n+/* Set a per-application usage message */\n+rte_usage_hook_t\n+rte_set_application_usage_hook(rte_usage_hook_t usage_func)\n+{\n+\trte_usage_hook_t\told_func;\n+\n+\t/* Will be NULL on the first call to denote the last usage routine. */\n+\told_func\t= rte_application_usage_hook;\n+\trte_application_usage_hook\t= usage_func;\n+\n+\treturn old_func;\n+}\n+\n+inline void\n+rte_eal_mcfg_complete(void)\n+{\n+\t/* ALL shared mem_config related INIT DONE */\n+\tif (rte_config.process_type == RTE_PROC_PRIMARY)\n+\t\trte_config.mem_config->magic = RTE_MAGIC;\n+}\n+\n+/* return non-zero if hugepages are enabled. */\n+int rte_eal_has_hugepages(void)\n+{\n+\treturn !internal_config.no_hugetlbfs;\n+}\n+\n+/* get core role */\n+enum rte_lcore_role_t\n+rte_eal_lcore_role(unsigned lcore_id)\n+{\n+\treturn rte_config.lcore_role[lcore_id];\n+}\n+\n+enum rte_proc_type_t\n+rte_eal_process_type(void)\n+{\n+\treturn rte_config.process_type;\n+}\ndiff --git a/lib/librte_eal/common/eal_common_system.c b/lib/librte_eal/common/eal_common_system.c\nnew file mode 100644\nindex 0000000..1fd48cc\n--- /dev/null\n+++ b/lib/librte_eal/common/eal_common_system.c\n@@ -0,0 +1,203 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   Copyright(c) 2014 6WIND S.A.\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 <stdio.h>\n+#include <stdlib.h>\n+#include <stdint.h>\n+#include <string.h>\n+#include <stdarg.h>\n+#include <unistd.h>\n+#include <pthread.h>\n+#include <syslog.h>\n+#include <getopt.h>\n+#include <sys/file.h>\n+#include <stddef.h>\n+#include <errno.h>\n+#include <limits.h>\n+#include <errno.h>\n+#include <sys/mman.h>\n+#include <sys/queue.h>\n+\n+#include \"eal_private.h\"\n+#include \"eal_thread.h\"\n+#include \"eal_internal_cfg.h\"\n+#include \"eal_filesystem.h\"\n+#include \"eal_hugepages.h\"\n+#include \"eal_options.h\"\n+\n+#include <rte_memory.h>\n+#include <rte_eal_memconfig.h>\n+#include <rte_log.h>\n+\n+/* define fd variable here, because file needs to be kept open for the\n+ * duration of the program, as we hold a write lock on it in the primary proc */\n+int mem_cfg_fd = -1;\n+\n+static struct flock wr_lock = {\n+\t\t.l_type = F_WRLCK,\n+\t\t.l_whence = SEEK_SET,\n+\t\t.l_start = offsetof(struct rte_mem_config, memseg),\n+\t\t.l_len = sizeof(((struct rte_mem_config *)0)->memseg),\n+};\n+\n+/* Return memory config file descriptor */\n+int*\n+eal_get_mem_cfg_fd(void)\n+{\n+\treturn &mem_cfg_fd;\n+}\n+\n+/* parse a sysfs (or other) file containing one integer value */\n+int\n+eal_parse_sysfs_value(const char *filename, unsigned long *val)\n+{\n+\tFILE *f;\n+\tchar buf[BUFSIZ];\n+\tchar *end = NULL;\n+\n+\tf = fopen(filename, \"r\");\n+\tif (f == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"%s(): cannot open sysfs value %s\\n\",\n+\t\t\t__func__, filename);\n+\t\treturn -1;\n+\t}\n+\n+\tif (fgets(buf, sizeof(buf), f) == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"%s(): cannot read sysfs value %s\\n\",\n+\t\t\t__func__, filename);\n+\t\tfclose(f);\n+\t\treturn -1;\n+\t}\n+\t*val = strtoul(buf, &end, 0);\n+\tif ((buf[0] == '\\0') || (end == NULL) || (*end != '\\n')) {\n+\t\tRTE_LOG(ERR, EAL, \"%s(): cannot parse sysfs value %s\\n\",\n+\t\t\t\t__func__, filename);\n+\t\tfclose(f);\n+\t\treturn -1;\n+\t}\n+\tfclose(f);\n+\treturn 0;\n+}\n+\n+/* Detect if we are a primary or a secondary process */\n+enum rte_proc_type_t\n+eal_proc_type_detect(void)\n+{\n+\tenum rte_proc_type_t ptype = RTE_PROC_PRIMARY;\n+\tconst char *pathname = eal_runtime_config_path();\n+\n+\t/* if we can open the file but not get a write-lock we are\n+\t * a secondary process. NOTE: if we get a file handle back,\n+\t * we keep that open and don't close it to prevent a race\n+\t * condition between multiple opens\n+\t */\n+\tmem_cfg_fd = open(pathname, O_RDWR);\n+\tif ((mem_cfg_fd >= 0) &&\n+\t\t\t(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))\n+\t\tptype = RTE_PROC_SECONDARY;\n+\n+\tRTE_LOG(INFO, EAL, \"Auto-detected process type: %s\\n\",\n+\t\t\tptype == RTE_PROC_PRIMARY ? \"PRIMARY\" : \"SECONDARY\");\n+\n+\treturn ptype;\n+}\n+\n+inline size_t\n+eal_get_hugepage_mem_size(void)\n+{\n+\tuint64_t size = 0;\n+\tunsigned i, j;\n+\n+\tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n+\t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n+\n+\t\tif (hpi->hugedir != NULL) {\n+\t\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++)\n+\t\t\t\tsize += hpi->hugepage_sz * hpi->num_pages[j];\n+\t\t}\n+\t}\n+\n+\treturn (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;\n+}\n+\n+void\n+eal_check_mem_on_local_socket(void)\n+{\n+\tconst struct rte_memseg *ms;\n+\tint i, socket_id;\n+\tstruct rte_config *rte_config =\n+\t\trte_eal_get_configuration();\n+\n+\tif (rte_config == NULL) {\n+\t\tRTE_LOG(WARNING, EAL, \"WARNING: rte_config NULL!\\n\");\n+\t\treturn;\n+\t}\n+\n+\tsocket_id = rte_lcore_to_socket_id(rte_config->master_lcore);\n+\n+\tms = rte_eal_get_physmem_layout();\n+\n+\tfor (i = 0; i < RTE_MAX_MEMSEG; i++)\n+\t\tif (ms[i].socket_id == socket_id &&\n+\t\t\t\tms[i].len > 0)\n+\t\t\treturn;\n+\n+\tRTE_LOG(WARNING, EAL, \"WARNING: Master core has no \"\n+\t\t\t\"memory on local socket!\\n\");\n+}\n+\n+int\n+sync_func(__attribute__((unused)) void *arg)\n+{\n+\treturn 0;\n+}\n+\n+/*\n+ * Perform ftruncate and fcntl operations on\n+ * memory config file descriptor.\n+ */\n+int\n+eal_ftruncate_and_fcntl(int *mem_cfg_fd, size_t size)\n+{\n+\tint retval;\n+\n+\tretval = ftruncate(*mem_cfg_fd, size);\n+\tif (retval < 0)\n+\t\treturn -1;\n+\n+\tretval = fcntl(*mem_cfg_fd, F_SETLK, &wr_lock);\n+\tif (retval < 0)\n+\t\treturn -2;\n+\treturn 0;\n+}\ndiff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h\nindex 38edac0..0b4d7a2 100644\n--- a/lib/librte_eal/common/eal_hugepages.h\n+++ b/lib/librte_eal/common/eal_hugepages.h\n@@ -63,5 +63,6 @@ struct hugepage_file {\n  * for the EAL to use\n  */\n int eal_hugepage_info_init(void);\n+inline size_t eal_get_hugepage_mem_size(void);\n \n #endif /* EAL_HUGEPAGES_H */\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex 232fcec..6675bc4 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -36,6 +36,8 @@\n \n #include <stdio.h>\n \n+#include <rte_eal.h>\n+\n /**\n  * Initialize the memzone subsystem (private to eal).\n  *\n@@ -203,4 +205,80 @@ int rte_eal_alarm_init(void);\n  */\n int rte_eal_dev_init(void);\n \n+/**\n+ * This function sets up rte_config structure\n+ *\n+ * This function is private to the EAL.\n+ */\n+void rte_eal_config_init(void);\n+\n+/**\n+ * This function checks memory on local socket(NUMA)\n+ *\n+ * This function is private to the EAL.\n+ */\n+void eal_check_mem_on_local_socket(void);\n+\n+/**\n+ * This function updates shared mem_config INIT DONE\n+ *\n+ * This function is private to the EAL.\n+ */\n+inline void rte_eal_mcfg_complete(void);\n+\n+/**\n+ *\n+ * This function is private to the EAL.\n+ */\n+int sync_func(__attribute__((unused)) void *arg);\n+\n+/**\n+ *\n+ * This function is private to the EAL.\n+ */\n+inline void *rte_eal_get_mem_cfg_addr(void);\n+\n+/**\n+ * Return a pointer to the configuration structure\n+ *\n+ * This function is private to the EAL.\n+ */\n+struct rte_config *rte_eal_get_configuration(void);\n+\n+/**\n+ * Return memory config file descriptor\n+ *\n+ * This function is private to the EAL.\n+ */\n+int *eal_get_mem_cfg_fd(void);\n+\n+/**\n+ * Perform ftruncate and fcntl operations on\n+ * memory config file descriptor.\n+ *\n+ * This function is private to the EAL.\n+ */\n+int eal_ftruncate_and_fcntl(int *mem_cfg_fd, size_t size);\n+\n+/**\n+ * Get per-application usage message\n+ *\n+ * This function is private to the EAL.\n+ */\n+rte_usage_hook_t rte_get_application_usage_hook(void);\n+\n+/**\n+ * This function attaches shared memory config\n+ *\n+ * This function is private to the EAL.\n+ */\n+void rte_eal_config_attach(void);\n+\n+/**\n+ * This function reattaches shared memory config\n+ *\n+ * This function is private to the EAL.\n+ */\n+void rte_eal_config_reattach(void);\n+\n #endif /* _EAL_PRIVATE_H_ */\ndiff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile\nindex 9252333..f3600d8 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -70,6 +70,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_ivshmem.c\n endif\n \n # from common dir\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_system.c\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_runtime.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c\ndiff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c\nindex 2fb1acc..677ccf1 100644\n--- a/lib/librte_eal/linuxapp/eal/eal.c\n+++ b/lib/librte_eal/linuxapp/eal/eal.c\n@@ -89,9 +89,6 @@\n \n #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)\n \n-/* Allow the application to print its usage message too if set */\n-static rte_usage_hook_t\trte_application_usage_hook = NULL;\n-\n TAILQ_HEAD(shared_driver_list, shared_driver);\n \n /* Definition for shared object drivers. */\n@@ -106,25 +103,6 @@ struct shared_driver {\n static struct shared_driver_list solib_list =\n TAILQ_HEAD_INITIALIZER(solib_list);\n \n-/* early configuration structure, when memory config is not mmapped */\n-static struct rte_mem_config early_mem_config;\n-\n-/* define fd variable here, because file needs to be kept open for the\n- * duration of the program, as we hold a write lock on it in the primary proc */\n-static int mem_cfg_fd = -1;\n-\n-static struct flock wr_lock = {\n-\t\t.l_type = F_WRLCK,\n-\t\t.l_whence = SEEK_SET,\n-\t\t.l_start = offsetof(struct rte_mem_config, memseg),\n-\t\t.l_len = sizeof(early_mem_config.memseg),\n-};\n-\n-/* Address of global and public configuration */\n-static struct rte_config rte_config = {\n-\t\t.mem_config = &early_mem_config,\n-};\n-\n /* internal configuration (per-core) */\n struct lcore_config lcore_config[RTE_MAX_LCORE];\n \n@@ -134,196 +112,85 @@ struct internal_config internal_config;\n /* used by rte_rdtsc() */\n int rte_cycles_vmware_tsc_map;\n \n-/* Return a pointer to the configuration structure */\n-struct rte_config *\n-rte_eal_get_configuration(void)\n-{\n-\treturn &rte_config;\n-}\n-\n-/* parse a sysfs (or other) file containing one integer value */\n-int\n-eal_parse_sysfs_value(const char *filename, unsigned long *val)\n-{\n-\tFILE *f;\n-\tchar buf[BUFSIZ];\n-\tchar *end = NULL;\n-\n-\tif ((f = fopen(filename, \"r\")) == NULL) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot open sysfs value %s\\n\",\n-\t\t\t__func__, filename);\n-\t\treturn -1;\n-\t}\n-\n-\tif (fgets(buf, sizeof(buf), f) == NULL) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot read sysfs value %s\\n\",\n-\t\t\t__func__, filename);\n-\t\tfclose(f);\n-\t\treturn -1;\n-\t}\n-\t*val = strtoul(buf, &end, 0);\n-\tif ((buf[0] == '\\0') || (end == NULL) || (*end != '\\n')) {\n-\t\tRTE_LOG(ERR, EAL, \"%s(): cannot parse sysfs value %s\\n\",\n-\t\t\t\t__func__, filename);\n-\t\tfclose(f);\n-\t\treturn -1;\n-\t}\n-\tfclose(f);\n-\treturn 0;\n-}\n-\n-\n-/* create memory configuration in shared/mmap memory. Take out\n- * a write lock on the memsegs, so we can auto-detect primary/secondary.\n- * This means we never close the file while running (auto-close on exit).\n- * We also don't lock the whole file, so that in future we can use read-locks\n- * on other parts, e.g. memzones, to detect if there are running secondary\n- * processes. */\n-static void\n-rte_eal_config_create(void)\n+inline void *\n+rte_eal_get_mem_cfg_addr(void)\n {\n-\tvoid *rte_mem_cfg_addr;\n-\tint retval;\n-\n-\tconst char *pathname = eal_runtime_config_path();\n+\tvoid *mem_cfg_addr;\n \n-\tif (internal_config.no_shconf)\n-\t\treturn;\n-\n-\t/* map the config before hugepage address so that we don't waste a page */\n \tif (internal_config.base_virtaddr != 0)\n-\t\trte_mem_cfg_addr = (void *)\n+\t\tmem_cfg_addr = (void *)\n \t\t\tRTE_ALIGN_FLOOR(internal_config.base_virtaddr -\n \t\t\tsizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));\n \telse\n-\t\trte_mem_cfg_addr = NULL;\n-\n-\tif (mem_cfg_fd < 0){\n-\t\tmem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);\n-\t\tif (mem_cfg_fd < 0)\n-\t\t\trte_panic(\"Cannot open '%s' for rte_mem_config\\n\", pathname);\n-\t}\n-\n-\tretval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));\n-\tif (retval < 0){\n-\t\tclose(mem_cfg_fd);\n-\t\trte_panic(\"Cannot resize '%s' for rte_mem_config\\n\", pathname);\n-\t}\n-\n-\tretval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);\n-\tif (retval < 0){\n-\t\tclose(mem_cfg_fd);\n-\t\trte_exit(EXIT_FAILURE, \"Cannot create lock on '%s'. Is another primary \"\n-\t\t\t\t\"process running?\\n\", pathname);\n-\t}\n-\n-\trte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),\n-\t\t\t\tPROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);\n-\n-\tif (rte_mem_cfg_addr == MAP_FAILED){\n-\t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n-\t}\n-\tmemcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));\n-\trte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;\n-\n-\t/* store address of the config in the config itself so that secondary\n-\t * processes could later map the config into this exact location */\n-\trte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;\n+\t\tmem_cfg_addr = NULL;\n \n+\treturn mem_cfg_addr;\n }\n \n /* attach to an existing shared memory config */\n-static void\n+void\n rte_eal_config_attach(void)\n {\n \tstruct rte_mem_config *mem_config;\n+\tstruct rte_config *rte_config;\n+\tint *mem_cfg_fd = eal_get_mem_cfg_fd();\n \n \tconst char *pathname = eal_runtime_config_path();\n \n \tif (internal_config.no_shconf)\n \t\treturn;\n \n-\tif (mem_cfg_fd < 0){\n-\t\tmem_cfg_fd = open(pathname, O_RDWR);\n-\t\tif (mem_cfg_fd < 0)\n+\trte_config = rte_eal_get_configuration();\n+\tif (rte_config == NULL)\n+\t\treturn;\n+\n+\tif (*mem_cfg_fd < 0) {\n+\t\t*mem_cfg_fd = open(pathname, O_RDWR);\n+\t\tif (*mem_cfg_fd < 0)\n \t\t\trte_panic(\"Cannot open '%s' for rte_mem_config\\n\", pathname);\n \t}\n \n \t/* map it as read-only first */\n \tmem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),\n-\t\t\tPROT_READ, MAP_SHARED, mem_cfg_fd, 0);\n+\t\t\tPROT_READ, MAP_SHARED, *mem_cfg_fd, 0);\n \tif (mem_config == MAP_FAILED)\n \t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n \n-\trte_config.mem_config = mem_config;\n+\trte_config->mem_config = mem_config;\n }\n \n /* reattach the shared config at exact memory location primary process has it */\n-static void\n+void\n rte_eal_config_reattach(void)\n {\n \tstruct rte_mem_config *mem_config;\n \tvoid *rte_mem_cfg_addr;\n+\tstruct rte_config *rte_config;\n+\tint *mem_cfg_fd = eal_get_mem_cfg_fd();\n \n \tif (internal_config.no_shconf)\n \t\treturn;\n \n+\trte_config = rte_eal_get_configuration();\n+\tif (rte_config == NULL)\n+\t\treturn;\n+\n \t/* save the address primary process has mapped shared config to */\n-\trte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;\n+\trte_mem_cfg_addr =\n+\t\t(void *) (uintptr_t) rte_config->mem_config->mem_cfg_addr;\n \n \t/* unmap original config */\n-\tmunmap(rte_config.mem_config, sizeof(struct rte_mem_config));\n+\tmunmap(rte_config->mem_config, sizeof(struct rte_mem_config));\n \n \t/* remap the config at proper address */\n \tmem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,\n \t\t\tsizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,\n-\t\t\tmem_cfg_fd, 0);\n-\tclose(mem_cfg_fd);\n+\t\t\t*mem_cfg_fd, 0);\n+\tclose(*mem_cfg_fd);\n \tif (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr)\n \t\trte_panic(\"Cannot mmap memory for rte_config\\n\");\n \n-\trte_config.mem_config = mem_config;\n-}\n-\n-/* Detect if we are a primary or a secondary process */\n-enum rte_proc_type_t\n-eal_proc_type_detect(void)\n-{\n-\tenum rte_proc_type_t ptype = RTE_PROC_PRIMARY;\n-\tconst char *pathname = eal_runtime_config_path();\n-\n-\t/* if we can open the file but not get a write-lock we are a secondary\n-\t * process. NOTE: if we get a file handle back, we keep that open\n-\t * and don't close it to prevent a race condition between multiple opens */\n-\tif (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&\n-\t\t\t(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))\n-\t\tptype = RTE_PROC_SECONDARY;\n-\n-\tRTE_LOG(INFO, EAL, \"Auto-detected process type: %s\\n\",\n-\t\t\tptype == RTE_PROC_PRIMARY ? \"PRIMARY\" : \"SECONDARY\");\n-\n-\treturn ptype;\n-}\n-\n-/* Sets up rte_config structure with the pointer to shared memory config.*/\n-static void\n-rte_config_init(void)\n-{\n-\trte_config.process_type = internal_config.process_type;\n-\n-\tswitch (rte_config.process_type){\n-\tcase RTE_PROC_PRIMARY:\n-\t\trte_eal_config_create();\n-\t\tbreak;\n-\tcase RTE_PROC_SECONDARY:\n-\t\trte_eal_config_attach();\n-\t\trte_eal_mcfg_wait_complete(rte_config.mem_config);\n-\t\trte_eal_config_reattach();\n-\t\tbreak;\n-\tcase RTE_PROC_AUTO:\n-\tcase RTE_PROC_INVALID:\n-\t\trte_panic(\"Invalid process type\\n\");\n-\t}\n+\trte_config->mem_config = mem_config;\n }\n \n /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */\n@@ -349,6 +216,9 @@ eal_hugedirs_unlock(void)\n static void\n eal_usage(const char *prgname)\n {\n+\trte_usage_hook_t rte_application_usage_hook =\n+\t\t\trte_get_application_usage_hook();\n+\n \tprintf(\"\\nUsage: %s \", prgname);\n \teal_common_usage();\n \tprintf(\"EAL Linux options:\\n\"\n@@ -371,19 +241,6 @@ eal_usage(const char *prgname)\n \t}\n }\n \n-/* Set a per-application usage message */\n-rte_usage_hook_t\n-rte_set_application_usage_hook( rte_usage_hook_t usage_func )\n-{\n-\trte_usage_hook_t\told_func;\n-\n-\t/* Will be NULL on the first call to denote the last usage routine. */\n-\told_func\t\t\t\t\t= rte_application_usage_hook;\n-\trte_application_usage_hook\t= usage_func;\n-\n-\treturn old_func;\n-}\n-\n static int\n eal_parse_socket_mem(char *socket_mem)\n {\n@@ -485,24 +342,6 @@ eal_parse_vfio_intr(const char *mode)\n \treturn -1;\n }\n \n-static inline size_t\n-eal_get_hugepage_mem_size(void)\n-{\n-\tuint64_t size = 0;\n-\tunsigned i, j;\n-\n-\tfor (i = 0; i < internal_config.num_hugepage_sizes; i++) {\n-\t\tstruct hugepage_info *hpi = &internal_config.hugepage_info[i];\n-\t\tif (hpi->hugedir != NULL) {\n-\t\t\tfor (j = 0; j < RTE_MAX_NUMA_NODES; j++) {\n-\t\t\t\tsize += hpi->hugepage_sz * hpi->num_pages[j];\n-\t\t\t}\n-\t\t}\n-\t}\n-\n-\treturn (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;\n-}\n-\n /* Parse the argument given in the command line of the application */\n static int\n eal_parse_args(int argc, char **argv)\n@@ -643,39 +482,6 @@ eal_parse_args(int argc, char **argv)\n \treturn ret;\n }\n \n-static void\n-eal_check_mem_on_local_socket(void)\n-{\n-\tconst struct rte_memseg *ms;\n-\tint i, socket_id;\n-\n-\tsocket_id = rte_lcore_to_socket_id(rte_config.master_lcore);\n-\n-\tms = rte_eal_get_physmem_layout();\n-\n-\tfor (i = 0; i < RTE_MAX_MEMSEG; i++)\n-\t\tif (ms[i].socket_id == socket_id &&\n-\t\t\t\tms[i].len > 0)\n-\t\t\treturn;\n-\n-\tRTE_LOG(WARNING, EAL, \"WARNING: Master core has no \"\n-\t\t\t\"memory on local socket!\\n\");\n-}\n-\n-static int\n-sync_func(__attribute__((unused)) void *arg)\n-{\n-\treturn 0;\n-}\n-\n-inline static void\n-rte_eal_mcfg_complete(void)\n-{\n-\t/* ALL shared mem_config related INIT DONE */\n-\tif (rte_config.process_type == RTE_PROC_PRIMARY)\n-\t\trte_config.mem_config->magic = RTE_MAGIC;\n-}\n-\n /*\n  * Request iopl privilege for all RPL, returns 0 on success\n  * iopl() call is mostly for the i386 architecture. For other architectures,\n@@ -702,10 +508,15 @@ rte_eal_init(int argc, char **argv)\n \tstatic rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);\n \tstruct shared_driver *solib = NULL;\n \tconst char *logid;\n+\tstruct rte_config *rte_config;\n \n \tif (!rte_atomic32_test_and_set(&run_once))\n \t\treturn -1;\n \n+\trte_config = rte_eal_get_configuration();\n+\tif (rte_config == NULL)\n+\t\treturn -1;\n+\n \tlogid = strrchr(argv[0], '/');\n \tlogid = strdup(logid ? logid + 1: argv[0]);\n \n@@ -750,7 +561,7 @@ rte_eal_init(int argc, char **argv)\n \n \trte_srand(rte_rdtsc());\n \n-\trte_config_init();\n+\trte_eal_config_init();\n \n \tif (rte_eal_pci_init() < 0)\n \t\trte_panic(\"Cannot init PCI\\n\");\n@@ -800,10 +611,10 @@ rte_eal_init(int argc, char **argv)\n \t\t\tRTE_LOG(WARNING, EAL, \"%s\\n\", dlerror());\n \t}\n \n-\teal_thread_init_master(rte_config.master_lcore);\n+\teal_thread_init_master(rte_config->master_lcore);\n \n \tRTE_LOG(DEBUG, EAL, \"Master core %u is ready (tid=%x)\\n\",\n-\t\trte_config.master_lcore, (int)thread_id);\n+\t\trte_config->master_lcore, (int)thread_id);\n \n \tif (rte_eal_dev_init() < 0)\n \t\trte_panic(\"Cannot init pmd devices\\n\");\n@@ -842,20 +653,3 @@ rte_eal_init(int argc, char **argv)\n \treturn fctret;\n }\n \n-/* get core role */\n-enum rte_lcore_role_t\n-rte_eal_lcore_role(unsigned lcore_id)\n-{\n-\treturn (rte_config.lcore_role[lcore_id]);\n-}\n-\n-enum rte_proc_type_t\n-rte_eal_process_type(void)\n-{\n-\treturn (rte_config.process_type);\n-}\n-\n-int rte_eal_has_hugepages(void)\n-{\n-\treturn ! internal_config.no_hugetlbfs;\n-}\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "3/7"
    ]
}