Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/105163/?format=api
http://patches.dpdk.org/api/patches/105163/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20211216152107.725239-1-bruce.richardson@intel.com/", "project": { "id": 1, "url": "http://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": "<20211216152107.725239-1-bruce.richardson@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20211216152107.725239-1-bruce.richardson@intel.com", "date": "2021-12-16T15:21:07", "name": "[v2] build/eal: add OS defines for C conditional checks", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "4ef1429f0b3c398d4a883661d7e836df9a6c66f2", "submitter": { "id": 20, "url": "http://patches.dpdk.org/api/people/20/?format=api", "name": "Bruce Richardson", "email": "bruce.richardson@intel.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20211216152107.725239-1-bruce.richardson@intel.com/mbox/", "series": [ { "id": 20955, "url": "http://patches.dpdk.org/api/series/20955/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=20955", "date": "2021-12-16T15:21:07", "name": "[v2] build/eal: add OS defines for C conditional checks", "version": 2, "mbox": "http://patches.dpdk.org/series/20955/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/105163/comments/", "check": "fail", "checks": "http://patches.dpdk.org/api/patches/105163/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id D7147A0032;\n\tThu, 16 Dec 2021 16:21:44 +0100 (CET)", "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 5D6F340696;\n\tThu, 16 Dec 2021 16:21:44 +0100 (CET)", "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n by mails.dpdk.org (Postfix) with ESMTP id 2C8C640143\n for <dev@dpdk.org>; Thu, 16 Dec 2021 16:21:42 +0100 (CET)", "from orsmga007.jf.intel.com ([10.7.209.58])\n by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 16 Dec 2021 07:21:25 -0800", "from silpixa00399126.ir.intel.com ([10.237.223.86])\n by orsmga007.jf.intel.com with ESMTP; 16 Dec 2021 07:21:23 -0800" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1639668103; x=1671204103;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=rwHNg6LwLHKrUBjZT6z66yeLmliKhs+EQnPRMQhhUqw=;\n b=DGLxPRthkLhdEdu4gijPUprURNd+OECMoWGw2qhoEtUUOuu/8YtYGaLs\n Qen4z9+bECSj0Uo4fTwDF0+/6hAmNjRosUxrti/uPnhYNzJiXI0MJcPYF\n ify5LSMfIIhjjyvg1rURbCT1lEdWMbZRTjQpy7ImcXmkAa2U7h+/z49S5\n wQsl2xjKci4MsnP1NX7ae8MNDG2w3m+QtWTIWkwmQN1QZtH5ee50Psy2I\n U38Tu4jmwvk2Swl3dMv96+/cK1i+ZKH31VEvPj4MjzV/6oklxUzrQG2BY\n Q30Y8uBMI36W8E8j0ZCZ1BsFyQsHhspFwTUE8joX83rqQZpLBEzoB4fiY w==;", "X-IronPort-AV": [ "E=McAfee;i=\"6200,9189,10199\"; a=\"239468831\"", "E=Sophos;i=\"5.88,211,1635231600\"; d=\"scan'208\";a=\"239468831\"", "E=Sophos;i=\"5.88,211,1635231600\"; d=\"scan'208\";a=\"506326710\"" ], "X-ExtLoop1": "1", "From": "Bruce Richardson <bruce.richardson@intel.com>", "To": "dev@dpdk.org", "Cc": "Bruce Richardson <bruce.richardson@intel.com>,\n Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>, Jerin Jacob <jerinj@marvell.com>", "Subject": "[PATCH v2] build/eal: add OS defines for C conditional checks", "Date": "Thu, 16 Dec 2021 15:21:07 +0000", "Message-Id": "<20211216152107.725239-1-bruce.richardson@intel.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20211210145330.108256-1-bruce.richardson@intel.com>", "References": "<20211210145330.108256-1-bruce.richardson@intel.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Define a set of macros in the build configuration to allow C runtime\ncode to check the current OS environment. This saves the user having to\nuse ifdefs for e.g. disabling particular tests on Windows. See included\ndocumentation changes for usage examples.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\nAcked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>\nAcked-by: Jerin Jacob <jerinj@marvell.com>\n\n---\nV2: Included feedback from Dmitry to expand on documentation to include\nguidelines on when to use conditional compilation.\n---\n doc/guides/contributing/coding_style.rst | 53 +++++++++++++++++++++++-\n lib/eal/meson.build | 7 ++++\n 2 files changed, 58 insertions(+), 2 deletions(-)", "diff": "diff --git a/doc/guides/contributing/coding_style.rst b/doc/guides/contributing/coding_style.rst\nindex 0ec37c019b..66803dcccd 100644\n--- a/doc/guides/contributing/coding_style.rst\n+++ b/doc/guides/contributing/coding_style.rst\n@@ -136,6 +136,24 @@ For example:\n Conditional Compilation\n ~~~~~~~~~~~~~~~~~~~~~~~\n \n+.. note::\n+\n+ Conditional compilation should be used only when absolutely necessary, as it increases the number of target binaries that need to be built and tested.\n+ See below for details of some utility macros/defines available to allow ifdefs/macros to be replaced by C conditional in some cases.\n+\n+Some high-level guidelines on the use of conditional compilation:\n+\n+* If code can compile on all platforms/systems, but cannot run on some due to lack of support,\n+ then regular C conditionals, as described in the next section, should be used instead of conditional compilation.\n+* If the code in question cannot compile on all systems, but constitutes only a small fragment of\n+ a file, then conditional complication should be used, as described in this section.\n+* If the code for conditional compilation implements an interface in an OS or platform-specific way,\n+ then create a file for each OS or platform and select the appropriate file using the meson build system.\n+ In most cases, these environment-specific files should be created inside the EAL library,\n+ rather than having each library implement its own abstraction layer.\n+\n+Additional style guidance for the use of conditional compilation macros:\n+\n * When code is conditionally compiled using ``#ifdef`` or ``#if``, a comment may be added following the matching\n ``#endif`` or ``#else`` to permit the reader to easily discern where conditionally compiled code regions end.\n * This comment should be used only for (subjectively) long regions, regions greater than 20 lines, or where a series of nested ``#ifdef``'s may be confusing to the reader.\n@@ -165,9 +183,40 @@ Conditional Compilation\n /* Or here. */\n #endif /* !COMPAT_43 */\n \n-.. note::\n+Defines to Avoid Conditional Compilation\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+In many cases in DPDK, one wants to run code based on the target platform, or runtime environment.\n+While this can be done using the conditional compilation directives,\n+e.g. ``#ifdef RTE_EXEC_ENV_LINUX``, present in DPDK for many releases,\n+this can also be done in many cases using regular ``if`` statements and the following defines:\n+\n+* ``RTE_ENV_FREEBSD``, ``RTE_ENV_LINUX``, ``RTE_ENV_WINDOWS`` - these define ids for each operating system environment.\n+* ``RTE_EXEC_ENV`` - this defines the id of the current environment, i.e. one of the items in list above.\n+* ``RTE_EXEC_ENV_IS_FREEBSD``, ``RTE_EXEC_ENV_IS_LINUX``, ``RTE_EXEC_ENV_IS_WINDOWS`` - 0/1 values indicating if the current environment is that specified,\n+ shortcuts for checking e.g. ``RTE_EXEC_ENV == RTE_ENV_WINDOWS``\n+\n+Examples of use:\n+\n+.. code-block:: c\n+\n+ /* report a unit tests as unsupported on Windows */\n+ if (RTE_EXEC_ENV_IS_WINDOWS)\n+ return TEST_SKIPPED;\n+\n+ /* set different default values depending on OS Environment */\n+ switch (RTE_EXEC_ENV) {\n+ case RTE_ENV_FREEBSD:\n+ default = x;\n+ break;\n+ case RTE_ENV_LINUX:\n+ default = y;\n+ break;\n+ case RTE_ENV_WINDOWS:\n+ default = z;\n+ break;\n+ }\n \n- Conditional compilation should be used only when absolutely necessary, as it increases the number of target binaries that need to be built and tested.\n \n C Types\n -------\ndiff --git a/lib/eal/meson.build b/lib/eal/meson.build\nindex 1722924f67..056beb9461 100644\n--- a/lib/eal/meson.build\n+++ b/lib/eal/meson.build\n@@ -10,6 +10,13 @@ if not is_windows\n subdir('unix')\n endif\n \n+exec_envs = {'freebsd': 0, 'linux': 1, 'windows': 2}\n+foreach env, id:exec_envs\n+ dpdk_conf.set('RTE_ENV_' + env.to_upper(), id)\n+ dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))\n+endforeach\n+dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])\n+\n dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)\n subdir(exec_env)\n \n", "prefixes": [ "v2" ] }{ "id": 105163, "url": "