From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 77457429E4; Tue, 25 Apr 2023 04:11:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0DB5E40A7E; Tue, 25 Apr 2023 04:11:55 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 710DC400D7 for ; Tue, 25 Apr 2023 04:11:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Q554b34n5zpT4J; Tue, 25 Apr 2023 10:07:59 +0800 (CST) Received: from [10.67.100.224] (10.67.100.224) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 25 Apr 2023 10:11:50 +0800 Subject: Re: [RFC 0/3] introduce coroutine library To: Stephen Hemminger , , CC: References: <20230424130208.9517-1-fengchengwen@huawei.com> <20230424090836.0550e14b@hermes.local> From: fengchengwen Message-ID: Date: Tue, 25 Apr 2023 10:11:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20230424090836.0550e14b@hermes.local> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.100.224] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 2023/4/25 0:08, Stephen Hemminger wrote: > On Mon, 24 Apr 2023 13:02:05 +0000 > Chengwen Feng wrote: > >> This patchset introduces the coroutine library which will help refactor >> the hns3 PMD's reset process. >> >> The hns3 single function reset process consists of the following steps: >> 1.stop_service(); >> 2.prepare_reset(); >> 3.delay(100ms); >> 4.notify_hw(); >> 5.wait_hw_reset_done(); // multiple sleep waits are involved. >> 6.reinit(); >> 7.restore_conf(); >> >> If the DPDK process take over multiple hns3 functions (e.g. 100), >> it's impractical to reset and restore functions in sequence: >> 1.proc_func(001); // will completed in 100+ms range. >> 2.proc_func(002); // will completed in 100~200+ms range. >> ... >> x.proc_func(100); // will completed in 9900~10000+ms range. >> The later functions will process fail because it's too late to deal with. >> >> One solution is that create a reset thread for each function, and it >> will lead to large number of threads if the DPDK process take over >> multiple hns3 functions. >> >> So the current hns3 driver uses asynchronous mechanism, for examples, it >> use rte_eal_alarm_set() when process delay(100ms), it splits a serial >> process into multiple asynchronous processes, and the code is complex >> and difficult to understand. >> >> The coroutine is a good mechanism to provide programmers with the >> simplicity of keeping serial processes within a limited number of >> threads. >> >> This patchset use to build the coroutine framework, and it >> just provides a demo. More APIs maybe added in the future. >> >> In addition, we would like to ask the community whether it it possible >> to accept the library. If not, whether it is allowed to provide the >> library in hns3 PMD. >> >> Chengwen Feng (3): >> lib/coroutine: add coroutine library >> examples/coroutine: support coroutine examples >> net/hns3: refactor reset process with coroutine > > Interesting, but the DPDK really is not the right place for this. > Also, why so much sleeping. Can't this device be handled with an event based > model. Plus any complexity like this introduces more bugs into already fragile > interaction of DPDK userspace applications and threads. A event base model will function as: event-handler() { for (...) { event = get_next_event(); proc_event(); } } The root cause is that the proc_event() take too many time, and it will lead to other function can't be processed timely. For which proc_event() may wait a lot of time, the coroutine could also used to optimize it. > > Not only that, coroutines add to the pre-existing problems with locking. > If coroutine 1 acquires a lock, the coroutine 2 will deadlock itself. > And someone will spend days figuring that out. And the existing analyzer > tools will not know about the magic coroutine library. Analyzer tools like lock annotations maybe a problem. Locks in DPDK APIs are mostly no-blocking. We can add some restrictions(by reviewer), such as once holding a lock, you can't invoke rte_co_yield() or rte_co_delay() API. In addition, any technology has two sides, the greatest advantage of coroutine I think is removes a large number of callbacks in asychronous programming. And also high-level languages generally provide coroutines (e.g. C++/Python). With the development, the analyzer tools maybe evolved to support detect. And one more, if not acceptable as public library, whether it is allowed intergration of this library in hns3 PMD ? Our internal evaluation solution (use coroutine refactor) is feasible, but the code needs to be upstream, hope to listen to community's comments. > > Bottom line: please no > > . >