From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0057.outbound.protection.outlook.com [104.47.34.57]) by dpdk.org (Postfix) with ESMTP id 14BD569A5 for ; Wed, 22 Mar 2017 15:12:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xgEG8jMMIq0njqOBUHc+VfRWHfG/AkkkLXo+h2zKmSw=; b=ERoo0Zh0u82O0sXtLNmFfkAt6tusbzv3V81djqElxXnUhTd1bwIdocjpXMgF7l/1awT9kQY4hiwgzt/Dcbm81EG9Nh9bT/NX5/5IuC2OQPmHP7dMFUnwKULBoiNQiBN9P3yMYSpaP09kLIvR8RFtKxDBT8CSzNd2xOCpaUgoshg= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost.caveonetworks.com (111.93.218.67) by BLUPR0701MB1714.namprd07.prod.outlook.com (10.163.85.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Wed, 22 Mar 2017 14:12:10 +0000 From: Jerin Jacob To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, ferruh.yigit@intel.com, gprathyusha@caviumnetworks.com, Jerin Jacob Date: Wed, 22 Mar 2017 19:41:29 +0530 Message-Id: <1490191892-10396-5-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1490191892-10396-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1490191892-10396-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MAXPR01CA0061.INDPRD01.PROD.OUTLOOK.COM (10.164.146.161) To BLUPR0701MB1714.namprd07.prod.outlook.com (10.163.85.140) X-MS-Office365-Filtering-Correlation-Id: 9a8b5e76-60b1-486a-e494-08d4712d6f78 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR0701MB1714; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 3:U6qBTLK8aS4CVtGwNOIeiAqrGT/FpDn9XfxeW7PF+muca3q5DaVSTa2EBEWJNJdC1oioWu4CaKLf9+vttcUD/Qjra3sXI+XOwhCjg/t88Jsm5O9a0FrvIm5rnfhKjvntKgMIh46jbtIb2uD8RcyvxWd59wxXmqvtpIj5o32zriRKDIdCdVNHeIsDX+3lTGG2t/rGer/ALUIJv69X/oH4VjqUTBjDhHBQC1i3F9u6krmw9S4r4GGYiv8OWcLc+IN82/Smj/vLdMaH443DlnWvgw==; 25:GMiYwiDgvcC8BWhDMaw3WuN2DgD5dVJUxu5l1EtGsWYpL+B+nZzwrkX5bN9QnHZEHmm/fPPMBk4fozbJLZWnZVm3rfdETw5tYBGSVbWZgl79pJy9iSnI3HU2CFtyyXr3zod17WIyonWrgUDlGEiTWQrL/C4qrRGLt9AiPsTbQncl/OA3x10c0ci9i/B2ZyIz1C+oxLhJiCT9Nek870h15YcyF3MTylxBT5gx6+hJD7bWFJ9HNG52V3vKJdJ1K7UJfJOlx7hKBkvhthonhtb2Hke+RikJCjy//BP3QsP7I9jDxbXvSYtMMqa/xY4lK/5ZhnD04cV77ZDVXnoxhAED4yhcxwT+9U2FnYXCE2WTf/FQzQXyEEtti/JRjGvHfrW5Kaqy+azudPTmCV6A6qjBxmle2LYsJdZmikbjWVyD67iLOIJ9+PbIYMrMmpTv3VvddMi6C4E2RYdpfnAi/kzVJQ== X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 31:vKg99Ah3fXBe9FKMZuZcjoX6lhXXrJp4BbfjbC/D0zkslNSmikRMAgS5cCH93dOlPdIEVyc6uA6sId6kGBnyw8biQqeSn7if/+lkUkOKQrnKjUTQewyDgccGJuf+ZKDYkJxfBSvGmULzU1GOiFuBez3D9QENdJFNmhFVH3/UXoOouCjl7WGyKcFMEzxpJfdUbUmfpMuCbzj6uO9qztQma2RO5yoUJ9ZoTviUi2pSlBE=; 20:ucJd9Zd5kMyOnzXbUN9iF4kmy8sRaqZzonpo8ov9VfmgVzH4UGc2o8PH5EAJPsCMpiOKMAr8eS4ILsHm10y63dz5r9xyf/5PT8RaKLMaPnbvIyavmh/sAQds/C0VRifOHyoH40bHe0P6caz64neuKs5DRGNXJdYWRxgd5xLwF1Jj60rRAnXDE8Ra/p+2Q7C0mphFTnxxN1jnnOBZBkO1u2dsX+wBZOoQ/6YHZKunYUltgzyBDTXML8b3nkzExNrtkG6kP3u5M3D+1FmO4aQ9ZpjZKvsoZDImCTJpuc6tK1RU0mSTNkRXCMd+eS9A4okZf9NEWkmj8Gaq0QBRZGPMzq188BeIlfUoGwwKQU8Pn++DfrEtX+glNmHnGRtarJFBZi7wfmqXSAO4gku+QWAhRokb0B8AHrqucQViSpHnNs4wYJWsrfZV5tjPe/orIljBaBtj40J7Djzs1goGJRFMg/EwVNu57aUsVPwqJQbTdCnu1pxwX/xFT43jCgT4d2HVVmttjzsD9gFY/GxEwQ5DK+0WSbtF/NqERliuRgRQxoiXvSRn6KCWkPbrXVWPPLVUub3lYpA3+TosK2Z40ifkM5fG1m6jw9MebaOJ+ub/4l8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123555025)(20161123558025)(20161123560025)(20161123562025)(6072148); SRVR:BLUPR0701MB1714; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0701MB1714; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 4:vrwJZf41EQdk+CJzWWcrrBNJwMZr1cE0ahHQ1kUdjAfeQHxEhB3sGGQsxzp4L51ssFFRxwkRLwL2kvXC9RH4sh4WXYV62jk0FvQYca0FHaZYu6Ba+k39mRCDRmkkuKXJ12Ntq3tjdDlCxlBjcooL6As7wbc6nlgqnLVvU3lqCF/KPf6/ngZOMWFh8AS7kJlWKrUT80TQT0QL/7NVMFzdORShTOhkVZJYMCMg8k54h+mk2Bq3koSJWjguoT4EG52q2PS/o/dKpntvWE8JjFM642+/bAAD9AVsoEZ6CXdnle9ct3JvkitPfWlZo/L7h9bMtZ4SFOpU4sqmsPpJIqsnDI0M3puei9SGY1LMnhYoZ5jvBotVPeOmSqyPEy7S/ir+chHfOvkZD+ls1D4JrDZrPBaPFwJXEwvbWcWGhIdqVQzaA2Ny7qJ2zcEzOQhSZyXeEpAjqFx/x7DCArxpSq8+dvyLudlwWkDDt9tC5uuq2ytUNnZ/0F5VneM50QWLwPgEGXd17GyelqA+S/t/RgTyQ46tt7YG2HVpiJsu8Konr584prKcQl4BwrSIgGSbi0Intc8pWvja/5SqcZl1BPkROvwUZ2aJrTT738rvpgH7MPk= X-Forefront-PRVS: 02543CD7CD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(6486002)(53936002)(4326008)(6506006)(50466002)(48376002)(189998001)(36756003)(25786009)(6512007)(33646002)(53416004)(2906002)(6666003)(2950100002)(42882006)(47776003)(66066001)(6916009)(76506005)(42186005)(38730400002)(107886003)(110136004)(5660300001)(5009440100003)(50226002)(305945005)(7736002)(2361001)(3846002)(6116002)(81166006)(2351001)(8676002)(50986999)(76176999)(5003940100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1714; H:localhost.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0701MB1714; 23:wLaAMtihH8XaCp7nSSpetQnHSqSGuN+xGJrofI8?= =?us-ascii?Q?cGpQPl9CzkRpaI80loOd0pNfb/Jg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tzKHZztzYsESo3pmASWMjsk/TqXa920UOJ2N/p2znVKXqzutkHCn2tliR+p6?= =?us-ascii?Q?GS6FeID7itjVSj9MBnmTwe6x5YgTMKchzvFPlPmxWIvWkJw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 6:gf9+NgnCIq9Zw1bUyaeAmJ1SZw2NwMFKXBy4v8pCMl0SlYAXh4+nqEnw+MWPYTPcxIKGP77Bfud1D/IMuCE7AtxPEc+jfeSxz6TN/hj5rVClzNKGFJg508HmYGmxuqFNcq563EHKt3xW4TaQgLnMhhmUqPLzM0K/AWcHovWBIpz90EFrl8qcXKp7BNuQtVKkkejthdb7U157kTZIhV6JQmcrFhAZfhNkql9D1h6WoSMcNmGAAjRd28oYKoEkffA+lgeeUUyYV1QrnzelP10nEsrOrcR8KBwHOjOE+XAujKG8Ezp9qGLMRQKIUIXP+BPNdUyvTiirlr9lEuuBlsdcucvWvwQGMkuqP7gwQUQnXwz4hlSmFutUAkCEp4b8+qWttu0ZfjEal/cr7aEoTwhwlw==; 5:mvT2vQd/SaBFKctjWD7zUseV227awYKDUCpbPN9DATFCgtBU+o4TGPWPSSEueKHO69PT8vfl0wXaXmthD1WOenminwgO7ujsWQkpSlAQtrIQm8V/iClP8tSATXYYnP7/9VS+PHt4KAa03jh2J72FgA==; 24:008o9DAGsYfnq/ZL+T5lQpqv5mGT6kuWAdI1Jp3jUPtA3b2cX8xBL43NEVzUCVoHYBZZ6sCtk5WMFFip2cXx2FiWkVzE5uFjLiEvjvbr7E0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1714; 7:dMtnis5bFGjdX2ZoN0s0fRcR82gxm4XuRz0tnSbouYx8N2ilwrislEhwiGhPTjZUHKxk+XWH9vPxRdOzhJ0xGk1mTgeLA0vCfS7aPy48sCv4Cy1s36CUfUfwzzGbN6d0fl8K5I5JM+dF9VhBU4+5zu2CCzZmWi+wvAGso+I1KsUQe5MdDY5zeNvAY12H+W6pb0h1KPOK9IwZkTKQjb0TrMfBqIeEEN0NfvTANYtbOznpiJ2VoCxezG8L0HLjWanixnPWH/WiePP7plXZKLJe3aayUYbCCD3ZPfKcJcjfK7MZ/DasrhFhIzGWRzrgFm4BBoowJO3AJ84gB/zAMWhDhA== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2017 14:12:10.5846 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1714 Subject: [dpdk-dev] [PATCH 4/7] usertools: use optimized driver override scheme to bind X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Mar 2017 14:12:14 -0000 From: Guduri Prathyusha The current device bind model uses /sys/bus/pci/driver/new_id scheme to bind devices to the driver. This scheme has following operations to bind a device to the driver. 1) Write device ID and vendor ID to /sys/bus/pci/driver/new_id 2) Write PCI BDF number to /sys/bus/pci/driver/bind 3) On step (1), _All_ the devices that match the device ID and vendor ID get bound to the driver 4) Except for requested devices, Unbind the remaining devices In kernels >= 3.15, An alternative scheme driver_override can be used to bind a device to driver.This scheme has following operations to bind a device to driver. 1) Write driver to /sys/bus/pci/device/driver_override 2) Write PCI BDF number to /sys/bus/pci/driver/bind This script detects the presence of /sys/bus/pci/device/driver_override, if available use optimized bind scheme to bind it Signed-off-by: Guduri Prathyusha Signed-off-by: Jerin Jacob --- usertools/dpdk-devbind.py | 109 +++++++++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 34 deletions(-) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 9beadde..4dc6a66 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -355,6 +355,25 @@ def unbind_one(dev_id, force): "Skipping unbind" % (dev_id)) return + # For kernels > 3.15 driver_override is used to bind a device to a driver. + # Before unbinding it, overwrite driver_override with empty string so that + # the device can be bound to any other driver + filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id + if os.path.exists(filename): + try: + f = open(filename, "w") + except: + print("Error: unbind failed for %s - Cannot open %s" + % (dev_id, filename)) + sys.exit(1) + try: + f.write("\00") + f.close() + except: + print("Error: unbind failed for %s - Cannot open %s" + % (dev_id, filename)) + sys.exit(1) + # write to /sys to unbind filename = "/sys/bus/pci/drivers/%s/unbind" % dev["Driver_str"] try: @@ -390,22 +409,44 @@ def bind_one(dev_id, driver, force): unbind_one(dev_id, force) dev["Driver_str"] = "" # clear driver string - # if we are binding to one of DPDK drivers, add PCI id's to that driver + # For kernels >= 3.15 driver_override can be used to specify the driver + # for a device rather than relying on the driver to provide a positive + # match of the device. The existing process of looking up + # the vendor and device ID, adding them to the driver new_id, + # will erroneously bind other devices too which has the additional burden + # of unbinding those devices if driver in dpdk_drivers: - filename = "/sys/bus/pci/drivers/%s/new_id" % driver - try: - f = open(filename, "w") - except: - print("Error: bind failed for %s - Cannot open %s" - % (dev_id, filename)) - return - try: - f.write("%04x %04x" % (dev["Vendor"], dev["Device"])) - f.close() - except: - print("Error: bind failed for %s - Cannot write new PCI ID to " - "driver %s" % (dev_id, driver)) - return + filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id + if os.path.exists(filename): + try: + f = open(filename, "w") + except: + print("Error: bind failed for %s - Cannot open %s" + % (dev_id, filename)) + return + try: + f.write("%s" % driver) + f.close() + except: + print("Error: bind failed for %s - Cannot write driver %s to " + "PCI ID " % (dev_id, driver)) + return + # For kernels < 3.15 use new_id to add PCI id's to the driver + else: + filename = "/sys/bus/pci/drivers/%s/new_id" % driver + try: + f = open(filename, "w") + except: + print("Error: bind failed for %s - Cannot open %s" + % (dev_id, filename)) + return + try: + f.write("%04x %04x" % (dev["Vendor"], dev["Device"])) + f.close() + except: + print("Error: bind failed for %s - Cannot write new PCI ID to " + "driver %s" % (dev_id, driver)) + return # do the bind by writing to /sys filename = "/sys/bus/pci/drivers/%s/bind" % driver @@ -450,23 +491,24 @@ def bind_all(dev_list, driver, force=False): for d in dev_list: bind_one(d, driver, force) - # when binding devices to a generic driver (i.e. one that doesn't have a - # PCI ID table), some devices that are not bound to any other driver could - # be bound even if no one has asked them to. hence, we check the list of - # drivers again, and see if some of the previously-unbound devices were - # erroneously bound. - for d in devices.keys(): - # skip devices that were already bound or that we know should be bound - if "Driver_str" in devices[d] or d in dev_list: - continue + # For kenels < 3.15 when binding devices to a generic driver + # (i.e. one that doesn't have a PCI ID table) using new_id, some devices + # that are not bound to any other driver could be bound even if no one has + # asked them to. hence, we check the list of drivers again, and see if + # some of the previously-unbound devices were erroneously bound. + if not os.path.exists("/sys/bus/pci/devices/%s/driver_override" % d): + for d in devices.keys(): + # skip devices that were already bound or that we know should be bound + if "Driver_str" in devices[d] or d in dev_list: + continue - # update information about this device - devices[d] = dict(devices[d].items() + - get_pci_device_details(d, True).items()) + # update information about this device + devices[d] = dict(devices[d].items() + + get_pci_device_details(d, True).items()) - # check if updated information indicates that the device was bound - if "Driver_str" in devices[d]: - unbind_one(d, force) + # check if updated information indicates that the device was bound + if "Driver_str" in devices[d]: + unbind_one(d, force) def display_devices(title, dev_list, extra_params=None): @@ -510,13 +552,12 @@ def show_device_status(devices_type, device_name): kernel_drv.append(devices[d]) # print each category separately, so we can clearly see what's used by DPDK - display_devices("%s devices using DPDK-compatible driver" % device_name, - dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s") + display_devices("%s devices using DPDK-compatible driver" % device_name, dpdk_drv, + "drv=%(Driver_str)s unused=%(Module_str)s") display_devices("%s devices using kernel driver" % device_name, kernel_drv, "if=%(Interface)s drv=%(Driver_str)s " "unused=%(Module_str)s %(Active)s") - display_devices("Other %s devices" % device_name, no_drv, - "unused=%(Module_str)s") + display_devices("Other %s devices" % device_name, no_drv, "unused=%(Module_str)s") def show_status(): '''Function called when the script is passed the "--status" option. -- 2.5.5