get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 76627,
    "url": "http://patches.dpdk.org/api/patches/76627/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20200906034247.25111-1-stephen@networkplumber.org/",
    "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": "<20200906034247.25111-1-stephen@networkplumber.org>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20200906034247.25111-1-stephen@networkplumber.org",
    "date": "2020-09-06T03:42:47",
    "name": "[v5] usertools: add huge page setup script",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "9a04e5b72a16b1e171d3ff74778eeb55816a9870",
    "submitter": {
        "id": 27,
        "url": "http://patches.dpdk.org/api/people/27/?format=api",
        "name": "Stephen Hemminger",
        "email": "stephen@networkplumber.org"
    },
    "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/20200906034247.25111-1-stephen@networkplumber.org/mbox/",
    "series": [
        {
            "id": 11973,
            "url": "http://patches.dpdk.org/api/series/11973/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=11973",
            "date": "2020-09-06T03:42:47",
            "name": "[v5] usertools: add huge page setup script",
            "version": 5,
            "mbox": "http://patches.dpdk.org/series/11973/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/76627/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/76627/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 dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id BDFBCA04BE;\n\tSun,  6 Sep 2020 05:42:54 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id B86C32BF1;\n\tSun,  6 Sep 2020 05:42:53 +0200 (CEST)",
            "from mail-pl1-f171.google.com (mail-pl1-f171.google.com\n [209.85.214.171]) by dpdk.org (Postfix) with ESMTP id E18322BAB\n for <dev@dpdk.org>; Sun,  6 Sep 2020 05:42:51 +0200 (CEST)",
            "by mail-pl1-f171.google.com with SMTP id m15so1817265pls.8\n for <dev@dpdk.org>; Sat, 05 Sep 2020 20:42:51 -0700 (PDT)",
            "from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127])\n by smtp.gmail.com with ESMTPSA id s8sm11874151pfd.153.2020.09.05.20.42.49\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sat, 05 Sep 2020 20:42:49 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20150623.gappssmtp.com; s=20150623;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=Yop7pRKwpPT2iWhHfreLDEfg3W9K61eqtSapXkhZ9Tg=;\n b=CsCOWUl4Fgz6i0TNy9atdkk2fRgV1c13raNw1esoY8tRr0ZfhVSvQTn0+tcpela5TB\n zdS53660civ2L6A3eFw2d3mQ0yor/E3nR+EobXRKPt6SDC8f5PYCt/rVIP3Ihn6SnIgs\n YKZfK2111SDPy+ze5y3q8y/XYRay/xk3HlUpvRInye76uYIK4FV+apGVyqMDiEJqaaev\n O07OXQKjSdgIU9bXCKJ/iEICrW1YpueHmWVG38MdNd9uVXZseavB73s+FqOriQgfizL/\n MBduKqWSamK8lgE/DGp8zV8ZXaMhoK9cnxkU170frwNNwdixPmQt5iU5UmqRWP4TlF6Q\n B40g==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20161025;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=Yop7pRKwpPT2iWhHfreLDEfg3W9K61eqtSapXkhZ9Tg=;\n b=i3tlZDbZKB5ZKni+RmDTBdQMpqhgOOzHeRn2RbNtHrqCUNgwDkJnz8tW9UfnqY7dm5\n uG9D9B351KWNAEcZvZIZv3tDKnvxM8ertPJnS/jHxb4vO5TYJ7pTsc3Qsg6Q7GRxG9DT\n 1v26kLy8DWnKDwhKq+PXQDDhSZB4l+yMxCYJRTKkEsGEOSj87HCxg8ZUGn6iOQ8aaoZP\n MYH7wu6+cO/I6SijLL6Q7HLON1XDpRQQbHbVyYY2W6o2c+M/QjMZ05Dmd7k58/xTUJl4\n CV0bu8u+kYLgCmKxOJQsJWYHMXBeY8KvazP1oGQddT5p6go3BKrbmDCERumJQLsq59aX\n iwfQ==",
        "X-Gm-Message-State": "AOAM530udcezJH1vGPE8G/dsrDRy1qH0xRXGo+L+0xBVEIDAEbsjyxj3\n 7SyMmKAf50q2O8sLMVuPRA6ItTdmCk4kzg==",
        "X-Google-Smtp-Source": "\n ABdhPJyttujPmzIrISLi+R48hnXu5wMOvs/k9pyxdrViWdPIlHNRUkYdNtrSM9tOz+oekz7t1KpOsw==",
        "X-Received": "by 2002:a17:90a:634c:: with SMTP id\n v12mr14660847pjs.57.1599363770488;\n Sat, 05 Sep 2020 20:42:50 -0700 (PDT)",
        "From": "Stephen Hemminger <stephen@networkplumber.org>",
        "To": "dev@dpdk.org",
        "Cc": "Stephen Hemminger <stephen@networkplumber.org>",
        "Date": "Sat,  5 Sep 2020 20:42:47 -0700",
        "Message-Id": "<20200906034247.25111-1-stephen@networkplumber.org>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20200901165643.15668-1-stephen@networkplumber.org>",
        "References": "<20200901165643.15668-1-stephen@networkplumber.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH v5] usertools: add huge page setup script",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "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",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This is an improved version of the setup of huge pages\nbases on earlier DPDK setup. Differences are:\n   * it autodetects NUMA vs non NUMA\n   * it allows setting different page sizes\n     recent kernels support multiple sizes.\n   * it accepts a parameter in bytes (not pages).\n\nIf necessary the steps of clearing old settings and mounting/umounting\ncan be done individually.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\nv5 -- cleanup help messages\n      add documentation and install script\n\nv4 -- more review feedback\n      use argparser rather than getopt (thanks Bruce)\n      silently handle already mounted type errors\n      handle exceptions for permission and file not found\n      fix numa bugs\n      code now passes pylint\n\nv3 -- incorporate review feedback\n      add missing SPDX and env header\n      overengineer the memory prefix string code\n      add numa node argument\n      fix some pylint warnings\n\n doc/guides/tools/hugepagesetup.rst |  79 +++++++++\n doc/guides/tools/index.rst         |   1 +\n usertools/hugepage_setup.py        | 271 +++++++++++++++++++++++++++++\n usertools/meson.build              |   7 +-\n 4 files changed, 357 insertions(+), 1 deletion(-)\n create mode 100644 doc/guides/tools/hugepagesetup.rst\n create mode 100755 usertools/hugepage_setup.py",
    "diff": "diff --git a/doc/guides/tools/hugepagesetup.rst b/doc/guides/tools/hugepagesetup.rst\nnew file mode 100644\nindex 000000000000..b1a5a8993a25\n--- /dev/null\n+++ b/doc/guides/tools/hugepagesetup.rst\n@@ -0,0 +1,79 @@\n+..  SPDX-License-Identifier: BSD-3-Clause\n+    Copyright (c) 2020 Microsoft Corporation\n+\n+hugepage_setup Application\n+==========================\n+\n+The ``hugepage_setup`` tool is a Data Plane Development Kit (DPDK) utility\n+that helps in reserving hugepages.\n+As well as checking for current settings.\n+\n+\n+Running the Application\n+-----------------------\n+\n+The tool has a number of command line options:\n+\n+.. code-block:: console\n+\n+\n+   hugepage_setup [options]\n+\t\t\n+\n+OPTIONS\n+-------\n+\n+* ``-h, --help``\n+\n+        Display usage information and quit\n+\n+* ``-s, --show``\n+\n+        Print the current huge page configuration\n+\n+* ``-c driver, --clear``\n+\n+        Clear existing huge page reservation\n+\n+* ``-m, --mount``\n+\n+        Mount the huge page filesystem\n+\n+* ``-u, --unmount``\n+\n+        Unmount the huge page filesystem\n+\n+* ``-n NODE, --node=NODE``\n+\n+  \tSet NUMA node to reserve pages on\n+\n+* ``-p SIZE, --pagesize=SIZE``\n+\n+  \tSelect hugepage size to use.\n+\tIf not specified the default system huge page size is used.\n+\n+* ``-r SIZE, --reserve=SIZE``\n+\n+  \tReserve huge pages.\n+\tSize is in bytes with K, M or G suffix.\n+\n+* ``--setup SIZE``\n+\n+\tShort cut to clear, unmount, reserve and mount.\n+\n+.. warning::\n+\n+    While any user can run the ``hugepage_setup`` script to view the\n+    status of huge pages, modifying the setup requires root privileges.\n+\n+\n+Examples\n+--------\n+\n+To display current huge page settings::\n+\n+   hugepage_setup -s\n+\n+To a complete setup of with 2 Gigabyte of 1G huge pages::\n+\n+   hugepage_setup -p 1G --setup 2G\ndiff --git a/doc/guides/tools/index.rst b/doc/guides/tools/index.rst\nindex c721943606f9..25c953ab01d4 100644\n--- a/doc/guides/tools/index.rst\n+++ b/doc/guides/tools/index.rst\n@@ -11,6 +11,7 @@ DPDK Tools User Guides\n     proc_info\n     pdump\n     pmdinfo\n+    hugepagesetup\n     devbind\n     flow-perf\n     testbbdev\ndiff --git a/usertools/hugepage_setup.py b/usertools/hugepage_setup.py\nnew file mode 100755\nindex 000000000000..bec010883e63\n--- /dev/null\n+++ b/usertools/hugepage_setup.py\n@@ -0,0 +1,271 @@\n+#! /usr/bin/env python3\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright (c) 2020 Microsoft Corporation\n+\"\"\"Script to query and setup huge pages for DPDK applications.\"\"\"\n+\n+import argparse\n+import glob\n+import os\n+import re\n+import sys\n+from math import log2\n+\n+# Standard binary prefix\n+BINARY_PREFIX = \"KMG\"\n+\n+# systemd mount point for huge pages\n+HUGE_MOUNT = \"/dev/hugepages\"\n+\n+\n+def fmt_memsize(sz_k):\n+    '''Format memory size in kB into conventional format'''\n+    if sz_k.isdigit():\n+        return int(sz_k) / 1024\n+    logk = int(log2(sz_k) / 10)\n+    return '{}{}b'.format(int(sz_k / (2**(logk * 10))), BINARY_PREFIX[logk])\n+\n+\n+def get_memsize(arg):\n+    '''Convert memory size with suffix to kB'''\n+    match = re.match(r'(\\d+)([' + BINARY_PREFIX + r']?)$', arg.upper())\n+    if match is None:\n+        sys.exit('{} is not a valid page size'.format(arg))\n+    num = float(match.group(1))\n+    suffix = match.group(2)\n+    if suffix == \"\":\n+        return int(num / 1024)\n+    idx = BINARY_PREFIX.find(suffix)\n+    return int(num * (2**(idx * 10)))\n+\n+\n+def is_numa():\n+    '''Test if NUMA is necessary on this system'''\n+    return os.path.exists('/sys/devices/system/node')\n+\n+\n+def get_hugepages(path):\n+    '''Read number of reserved pages'''\n+    with open(path + '/nr_hugepages') as nr_hugpages:\n+        return int(nr_hugpages.read())\n+    return 0\n+\n+\n+def set_hugepages(path, pages):\n+    '''Write the number of reserved huge pages'''\n+    filename = path + '/nr_hugepages'\n+    try:\n+        with open(filename, 'w') as nr_hugpages:\n+            nr_hugpages.write('{}\\n'.format(pages))\n+    except PermissionError:\n+        sys.exit('Permission denied: need to be root!')\n+    except FileNotFoundError:\n+        filename = os.path.basename(path)\n+        size = filename[10:]\n+        sys.exit('{} is not a valid system huge page size'.format(size))\n+\n+\n+def show_numa_pages():\n+    '''Show huge page reservations on Numa system'''\n+    print('Node Pages Size')\n+    for numa_path in glob.glob('/sys/devices/system/node/node*'):\n+        node = numa_path[29:]  # slice after /sys/devices/system/node/node\n+        path = numa_path + '/hugepages'\n+        for hdir in os.listdir(path):\n+            pages = get_hugepages(path + '/' + hdir)\n+            if pages > 0:\n+                pg_sz = fmt_memsize(\n+                    hdir[10:-2])  # slice out of hugepages-NNNkB\n+                print('{:<4} {:<5} {}'.format(node, pages, pg_sz))\n+\n+\n+def show_non_numa_pages():\n+    '''Show huge page reservations on non Numa system'''\n+    print('Pages Size')\n+    path = '/sys/kernel/mm/hugepages'\n+    for hdir in os.listdir(path):\n+        pages = get_hugepages(path + '/' + hdir)\n+        if pages > 0:\n+            pg_sz = fmt_memsize(int(hdir[10:-2]))\n+            print('{:<5} {}'.format(pages, pg_sz))\n+\n+\n+def show_pages():\n+    '''Show existing huge page settings'''\n+    if is_numa():\n+        show_numa_pages()\n+    else:\n+        show_non_numa_pages()\n+\n+\n+def clear_pages():\n+    '''Clear all existing huge page mappings'''\n+    if is_numa():\n+        dirs = glob.glob(\n+            '/sys/devices/system/node/node*/hugepages/hugepages-*')\n+    else:\n+        dirs = glob.glob('/sys/kernel/mm/hugepages/hugepages-*')\n+\n+    for path in dirs:\n+        set_hugepages(path, 0)\n+\n+\n+def default_pagesize():\n+    '''Get default huge page size from /proc/meminfo'''\n+    with open('/proc/meminfo') as meminfo:\n+        for line in meminfo:\n+            if line.startswith('Hugepagesize:'):\n+                return int(line.split()[1])\n+    return None\n+\n+\n+def set_numa_pages(pages, hugepgsz, node=None):\n+    '''Set huge page reservation on Numa system'''\n+    if node:\n+        nodes = ['/sys/devices/system/node/node{}/hugepages'.format(node)]\n+    else:\n+        nodes = glob.glob('/sys/devices/system/node/node*/hugepages')\n+\n+    for node_path in nodes:\n+        huge_path = '{}/hugepages-{}kB'.format(node_path, hugepgsz)\n+        set_hugepages(huge_path, pages)\n+\n+\n+def set_non_numa_pages(pages, hugepgsz):\n+    '''Set huge page reservation on non Numa system'''\n+    path = '/sys/kernel/mm/hugepages/hugepages-{}kB'.format(hugepgsz)\n+    set_hugepages(path, pages)\n+\n+\n+def reserve_pages(pages, hugepgsz, node=None):\n+    '''Sets the number of huge pages to be reserved'''\n+    if node or is_numa():\n+        set_numa_pages(pages, hugepgsz, node=node)\n+    else:\n+        set_non_numa_pages(pages, hugepgsz)\n+\n+\n+def get_mountpoints():\n+    '''get list of of where hugepage filesystem is mounted'''\n+    mounted = []\n+    with open('/proc/mounts') as mounts:\n+        for line in mounts:\n+            fields = line.split()\n+            if fields[2] != 'hugetlbfs':\n+                continue\n+            mounted.append(fields[1])\n+    return mounted\n+\n+\n+def mount_huge(pagesize, mountpoint):\n+    '''mount the huge tlb file system'''\n+    if mountpoint in get_mountpoints():\n+        print(mountpoint, \"already mounted\")\n+        return\n+    cmd = \"mount -t hugetlbfs\"\n+    if pagesize:\n+        cmd += ' -o pagesize={}'.format(pagesize * 1024)\n+    cmd += ' nodev ' + mountpoint\n+    os.system(cmd)\n+\n+\n+def umount_huge(mountpoint):\n+    '''unmount the huge tlb file system (if mounted)'''\n+    if mountpoint in get_mountpoints():\n+        os.system(\"umount \" + mountpoint)\n+\n+\n+def show_mount():\n+    '''Show where huge page filesystem is mounted'''\n+    mounted = get_mountpoints()\n+    if mounted:\n+        print(\"Hugepages mounted on\", *mounted)\n+    else:\n+        print(\"Hugepages not mounted\")\n+\n+\n+def main():\n+    '''Process the command line arguments and setup huge pages'''\n+    argv0 = os.path.basename(sys.argv[0])\n+    parser = argparse.ArgumentParser(\n+        formatter_class=argparse.RawDescriptionHelpFormatter,\n+        description=\"Setup huge pages\",\n+        epilog=\"\"\"\n+Examples:\n+\n+To display current huge page settings:\n+    %(prog)s -s\n+\n+To a complete setup of with 2 Gigabyte of 1G huge pages:\n+    %(prog)s -p 1G --setup 2G\n+\"\"\")\n+    parser.add_argument(\n+        '--show',\n+        '-s',\n+        action='store_true',\n+        help=\"print the current huge page configuration\")\n+    parser.add_argument(\n+        '--clear', '-c', action='store_true', help=\"clear existing huge pages\")\n+    parser.add_argument(\n+        '--mount',\n+        '-m',\n+        action='store_true',\n+        help='mount the huge page filesystem')\n+    parser.add_argument(\n+        '--unmount',\n+        '-u',\n+        action='store_true',\n+        help='unmount the system huge page directory')\n+    parser.add_argument(\n+        '--node',\n+        '-n',\n+        help='select numa node to reserve pages on')\n+    parser.add_argument(\n+        '--pagesize',\n+        '-p',\n+        metavar='SIZE',\n+        help='choose huge page size to use')\n+    parser.add_argument(\n+        '--reserve',\n+        '-r',\n+        metavar='SIZE',\n+        help='reserve huge pages. Size is in bytes with K, M, or G suffix')\n+    parser.add_argument(\n+        '--setup',\n+        metavar='SIZE',\n+        help='setup huge pages by doing clear, unmount, reserve and mount')\n+    args = parser.parse_args()\n+\n+    if args.setup:\n+        args.clear = True\n+        args.unmount = True\n+        args.reserve = args.setup\n+        args.mount = True\n+\n+    if args.pagesize:\n+        pagesize_kb = get_memsize(args.pagesize)\n+    else:\n+        pagesize_kb = default_pagesize()\n+\n+    if args.clear:\n+        clear_pages()\n+    if args.unmount:\n+        umount_huge(HUGE_MOUNT)\n+\n+    if args.reserve:\n+        reserve_kb = get_memsize(args.reserve)\n+        if reserve_kb % pagesize_kb != 0:\n+            sys.exit(\n+                'Huge reservation {}kB is not a multiple of page size {}kB'.\n+                format(reserve_kb, pagesize_kb))\n+        reserve_pages(\n+            int(reserve_kb / pagesize_kb), pagesize_kb, node=args.node)\n+    if args.mount:\n+        mount_huge(pagesize_kb, HUGE_MOUNT)\n+    if args.show:\n+        show_pages()\n+        print()\n+        show_mount()\n+\n+\n+if __name__ == \"__main__\":\n+    main()\ndiff --git a/usertools/meson.build b/usertools/meson.build\nindex 64e27238f45b..2bf2aeace5b5 100644\n--- a/usertools/meson.build\n+++ b/usertools/meson.build\n@@ -1,4 +1,9 @@\n # SPDX-License-Identifier: BSD-3-Clause\n # Copyright(c) 2017 Intel Corporation\n \n-install_data(['dpdk-devbind.py', 'dpdk-pmdinfo.py', 'dpdk-telemetry.py'], install_dir: 'bin')\n+install_data([\n+\t'dpdk-devbind.py',\n+\t'dpdk-pmdinfo.py',\n+\t'dpdk-telemetry.py',\n+\t'hugepage_setup.py'\n+],install_dir: 'bin')\n",
    "prefixes": [
        "v5"
    ]
}