From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0073.outbound.protection.outlook.com [104.47.37.73]) by dpdk.org (Postfix) with ESMTP id D20DB58C8 for ; Sat, 24 Sep 2016 15:13:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmonic.onmicrosoft.com; s=selector1-harmonicinc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=nMR8lZcbsps43M+a0N72q3b3r/kdvgjL3Ab1TwtEoGQ=; b=cRwNl3ms7OdtKJqd3eWnncVd+b3MNzx/W9ibxF5dlS+b3KhT/mDoiWEaJYr7jtPVc86jgVZWI7UdMpvGRn1ooT0TPxYSjlUeV1LDxnDWETsFzNHF4hBawkdX6raH5VPr0YEkrDbBZ+TD7ddn332Fm/DGZIQkBA6czJq9fKPyMSg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Vladyslav.Buslov@harmonicinc.com; Received: from kms.harmonicinc.com (62.205.135.152) by DM5PR11MB1353.namprd11.prod.outlook.com (10.168.108.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8; Sat, 24 Sep 2016 13:13:31 +0000 From: Vladyslav Buslov To: CC: Date: Sat, 24 Sep 2016 16:13:02 +0300 Message-ID: <20160924131302.26014-1-vladyslav.buslov@harmonicinc.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160920181637.26778-1-vladyslav.buslov@harmonicinc.com> References: <20160920181637.26778-1-vladyslav.buslov@harmonicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [62.205.135.152] X-ClientProxiedBy: DB4PR03CA0022.eurprd03.prod.outlook.com (10.160.39.160) To DM5PR11MB1353.namprd11.prod.outlook.com (10.168.108.145) X-MS-Office365-Filtering-Correlation-Id: 46b63adc-1425-4396-64b6-08d3e47c956d X-Microsoft-Exchange-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KtK1hrU5+7XnKzdpTAtf6I8YThTehzkGk0dEVZCKeE/lEUYUITB7X0JFvUqi+CzHqfB788i; 31:JHfmInY+PWWnfWyAQV0NWFZgHTD8C9i8OF8TO22/0HGpgsylMZ/WpOAL59AGU5BAy37xBp/2y5NztgvgrPE5p98tSj8BC8O26mm/pIQTAJBP7q2bsanGA6vbAzZE871NY5l4CSI+iu4wftotXMFo/Lmd6Bp9qt6MGGzMayTm6Y26iGfwOpYX2O9g+ZX6nAbgdhlfVoEHEIIhKKi8AlAtEyi1lTuSGz7/gLlZNdAOPRk= X-Microsoft-Exchange-Diagnostics: 1; DM5PR11MB1353; 20:CzSQKKVZRAs8lrYP0pU0owTF4oefGe92B/1qSoTCqbcO7DIkSqh9iBdq+euf0Tovkmf1/HsUQQqmlmOERkQdgWeEmnYO9Ukq4FAOsoYo8Z9yIANIFAZq/DpdbBzY9HUCzUaZev7OXuA3UfRVknNSP6tBbiRRPApAGOwSLHbbgbfZ9Ez28QSNPG+V240NGxtvlEbGMOROB7cu/nc1Sc9CtJCRiyxGLuPk8IAZXn2YVULdC3x2YmslBDxPGLU3TvaccM9loJM0g6m55/MkCx+x1UEp60oEo8uD+HtVQXch7GtAqEMUWmf8n0EEKu6iukxDjiKv5jnymQH2yJWx7LnmNqBB3SKDxHD/Se+odQ7oC5xwnxwhH+YmVQmqIolKFFt/3FQ/r5PXJTa53SfFBMeAc0LAZocoLJCTObPLjmleVOi+tNFNx0WIk7KW9IRUYSUaKEhAPb1F4iMw1SFG8Z6ccdYVVa0PXvDl2e1zvJaxMmb0VhG1JRTib7JPn3WeJXvV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(209352067349851)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:DM5PR11MB1353; BCL:0; PCL:0; RULEID:; SRVR:DM5PR11MB1353; X-Microsoft-Exchange-Diagnostics: 1; DM5PR11MB1353; 4:rJk2qo16CSsSi44rxejdJ0YbDPgiZP9RyJw94obmbSkUIzYQ0qcVQoq6DbHIJFaU2UN0E71tg1iu1zMkHratx6aixTCcaka6qVk7tCUeeSSC1kLwRrJvKlvdS/m3/CDh35RN57Y1aM7H4fQA6POccq3SPkbpWRoBCJaA3vE9ierceKZoSJVxhGsNUXiIad4EhCHHzXcG+p0I3d5PYZLkrxkxasfRge1kKqjGGJfI7gIY+xqiAgFStJH14EsA7NuSV89ZX0y+R9lig49ukln3JwlCA4fPc3XEKO6Xc/SHS5ik7WOOFivIEjfKVfkG4DCJL6omrF0xs9fStVbtckEq712gSS8LCgoWG0M1m4uAh1TLHajGnP0JhAZ0Kk3Cdxw+8haAKG62UyOqTl41NZg4waMyXXJqcyNB8U13GjCl2AcmbUZjtFr3Hn6CfKlDe7Qdt5NOreILb3171QvX0WGyhprXkWIOZl2YMLMLdTRAtOk= X-Forefront-PRVS: 0075CB064E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(19580395003)(3846002)(5003940100001)(66066001)(1076002)(97736004)(68736007)(7846002)(6916009)(50226002)(189998001)(86362001)(5660300001)(47776003)(7736002)(19580405001)(33646002)(305945005)(586003)(2950100002)(92566002)(69596002)(229853001)(81156014)(76176999)(36756003)(2351001)(6116002)(4326007)(81166006)(42186005)(53416004)(106356001)(101416001)(77096005)(110136003)(8676002)(2906002)(105586002)(50466002)(48376002)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR11MB1353; H:kms.harmonicinc.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: harmonicinc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR11MB1353; 23:6Xa6ATK8wQVF3DlW0QStr8Vh0EY+4bsCRq+GmWDDc?= =?us-ascii?Q?w6yQo+8tlDe0FQj8oVbM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hucwKoqNw8XcnKzMYYVC0KotciPrMggKtEvJXEi6GclRM/0tKrTihJIdpApQOrRc8jLS1m2BgOGfsy1nNWnLnUQ8RCFY0kEOtr3dO8crElT05bQeLM/ASSGXYymyWpPzfzhDbArMtDNVJ5xd8twoFAqh591tS78vTbDBuAx9KHJhuNCXCxFqUCRp8C35fBmAlJvqyth1+zd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR11MB1353; 20:KDJ2iKCrymyyk+gQ9vgLm6qOGkQqbyHtEzaPWx8DM8DnOeOiizXmYOovo6sdMPxnpesava1klq3Ayrhpz9tUx/dNoYuhZ9CgtlBtOIm6+kTjlcnJX5olkcUyO27xADnoQT7hE0oTKCpuNdHBFJFhYu+kjRoVbI7vYhQZnBuB4n8= X-OriginatorOrg: harmonicinc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2016 13:13:31.6448 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1353 Subject: [dpdk-dev] [PATCH] kni: add support for core_id param in single threaded mode X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Sep 2016 13:13:35 -0000 Allow binding KNI thread to specific core in single threaded mode by setting core_id and force_bind config parameters. Signed-off-by: Vladyslav Buslov Acked-by: Ferruh Yigit --- doc/guides/prog_guide/kernel_nic_interface.rst | 3 + lib/librte_eal/linuxapp/kni/kni_misc.c | 103 ++++++++++++++++--------- 2 files changed, 68 insertions(+), 38 deletions(-) diff --git a/doc/guides/prog_guide/kernel_nic_interface.rst b/doc/guides/prog_guide/kernel_nic_interface.rst index fac1960..eb16e2e 100644 --- a/doc/guides/prog_guide/kernel_nic_interface.rst +++ b/doc/guides/prog_guide/kernel_nic_interface.rst @@ -102,6 +102,9 @@ Refer to rte_kni_common.h in the DPDK source code for more details. The physical addresses will be re-mapped into the kernel address space and stored in separate KNI contexts. +The affinity of kernel RX thread (both single and multi-threaded modes) is controlled by force_bind and +core_id config parameters. + The KNI interfaces can be deleted by a DPDK application dynamically after being created. Furthermore, all those KNI interfaces not deleted will be deleted on the release operation of the miscellaneous device (when the DPDK application is closed). diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c index 59d15ca..7ef2d3e 100644 --- a/lib/librte_eal/linuxapp/kni/kni_misc.c +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -100,6 +101,7 @@ static int kni_net_id; struct kni_net { unsigned long device_in_use; /* device in use flag */ + struct mutex kni_kthread_lock; struct task_struct *kni_kthread; struct rw_semaphore kni_list_lock; struct list_head kni_list_head; @@ -109,11 +111,12 @@ static int __net_init kni_init_net(struct net *net) { #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS struct kni_net *knet = net_generic(net, kni_net_id); + memset(knet, 0, sizeof(*knet)); #else struct kni_net *knet; int ret; - knet = kmalloc(sizeof(struct kni_net), GFP_KERNEL); + knet = kzalloc(sizeof(struct kni_net), GFP_KERNEL); if (!knet) { ret = -ENOMEM; return ret; @@ -123,6 +126,8 @@ static int __net_init kni_init_net(struct net *net) /* Clear the bit of device in use */ clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use); + mutex_init(&knet->kni_kthread_lock); + init_rwsem(&knet->kni_list_lock); INIT_LIST_HEAD(&knet->kni_list_head); @@ -139,9 +144,9 @@ static int __net_init kni_init_net(struct net *net) static void __net_exit kni_exit_net(struct net *net) { -#ifndef HAVE_SIMPLIFIED_PERNET_OPERATIONS struct kni_net *knet = net_generic(net, kni_net_id); - + mutex_destroy(&knet->kni_kthread_lock); +#ifndef HAVE_SIMPLIFIED_PERNET_OPERATIONS kfree(knet); #endif } @@ -167,6 +172,11 @@ kni_init(void) return -EINVAL; } + if (multiple_kthread_on == 0) + KNI_PRINT("Single kernel thread for all KNI devices\n"); + else + KNI_PRINT("Multiple kernel thread mode enabled\n"); + #ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS rc = register_pernet_subsys(&kni_net_ops); #else @@ -235,19 +245,6 @@ kni_open(struct inode *inode, struct file *file) if (test_and_set_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use)) return -EBUSY; - /* Create kernel thread for single mode */ - if (multiple_kthread_on == 0) { - KNI_PRINT("Single kernel thread for all KNI devices\n"); - /* Create kernel thread for RX */ - knet->kni_kthread = kthread_run(kni_thread_single, (void *)knet, - "kni_single"); - if (IS_ERR(knet->kni_kthread)) { - KNI_ERR("Unable to create kernel threaed\n"); - return PTR_ERR(knet->kni_kthread); - } - } else - KNI_PRINT("Multiple kernel thread mode enabled\n"); - file->private_data = get_net(net); KNI_PRINT("/dev/kni opened\n"); @@ -263,9 +260,13 @@ kni_release(struct inode *inode, struct file *file) /* Stop kernel thread for single mode */ if (multiple_kthread_on == 0) { + mutex_lock(&knet->kni_kthread_lock); /* Stop kernel thread */ - kthread_stop(knet->kni_kthread); - knet->kni_kthread = NULL; + if (knet->kni_kthread != NULL) { + kthread_stop(knet->kni_kthread); + knet->kni_kthread = NULL; + } + mutex_unlock(&knet->kni_kthread_lock); } down_write(&knet->kni_list_lock); @@ -390,6 +391,47 @@ kni_check_param(struct kni_dev *kni, struct rte_kni_device_info *dev) } static int +kni_run_thread(struct kni_net *knet, struct kni_dev *kni, uint8_t force_bind) +{ + /** + * Create a new kernel thread for multiple mode, set its core affinity, + * and finally wake it up. + */ + if (multiple_kthread_on) { + kni->pthread = kthread_create(kni_thread_multiple, + (void *)kni, "kni_%s", kni->name); + if (IS_ERR(kni->pthread)) { + kni_dev_remove(kni); + return -ECANCELED; + } + + if (force_bind) + kthread_bind(kni->pthread, kni->core_id); + wake_up_process(kni->pthread); + } else { + mutex_lock(&knet->kni_kthread_lock); + + if (knet->kni_kthread == NULL) { + knet->kni_kthread = kthread_create(kni_thread_single, + (void *)knet, "kni_single"); + if (IS_ERR(knet->kni_kthread)) { + mutex_unlock(&knet->kni_kthread_lock); + kni_dev_remove(kni); + return -ECANCELED; + } + + if (force_bind) + kthread_bind(knet->kni_kthread, kni->core_id); + wake_up_process(knet->kni_kthread); + } + + mutex_unlock(&knet->kni_kthread_lock); + } + + return 0; +} + +static int kni_ioctl_create(struct net *net, unsigned int ioctl_num, unsigned long ioctl_param) { @@ -415,11 +457,9 @@ kni_ioctl_create(struct net *net, } /** - * Check if the cpu core id is valid for binding, - * for multiple kernel thread mode. + * Check if the cpu core id is valid for binding. */ - if (multiple_kthread_on && dev_info.force_bind && - !cpu_online(dev_info.core_id)) { + if (dev_info.force_bind && !cpu_online(dev_info.core_id)) { KNI_ERR("cpu %u is not online\n", dev_info.core_id); return -EINVAL; } @@ -566,22 +606,9 @@ kni_ioctl_create(struct net *net, kni_vhost_init(kni); #endif - /** - * Create a new kernel thread for multiple mode, set its core affinity, - * and finally wake it up. - */ - if (multiple_kthread_on) { - kni->pthread = kthread_create(kni_thread_multiple, - (void *)kni, - "kni_%s", kni->name); - if (IS_ERR(kni->pthread)) { - kni_dev_remove(kni); - return -ECANCELED; - } - if (dev_info.force_bind) - kthread_bind(kni->pthread, kni->core_id); - wake_up_process(kni->pthread); - } + ret = kni_run_thread(knet, kni, dev_info.force_bind); + if (ret != 0) + return ret; down_write(&knet->kni_list_lock); list_add(&kni->list, &knet->kni_list_head); -- 2.8.3