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 07EAA429E4; Tue, 25 Apr 2023 04:16:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9A6A140A7E; Tue, 25 Apr 2023 04:16:25 +0200 (CEST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 80925400D7 for ; Tue, 25 Apr 2023 04:16:24 +0200 (CEST) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-63b60365f53so6605425b3a.0 for ; Mon, 24 Apr 2023 19:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1682388983; x=1684980983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=PaBSCJKIHD9zh+nwSwvV3S97b9xMaDgIHc/+VS6/AA4=; b=3bmio1Ti0N9zA/CZStKXd/JLaFnQLLLhL0CmXlBcslMA8TBLMWtGHBSE9wwKUFAInX /Oth5JJeQCbTYCq8BUxN/coFGNgciJJKRvAibcxu2dv0JMoRO4G4wbTU3kD01cQW0bT3 Gqq0oIGN2YIeCPapcaA06pNB95xr7mA4yyKFqJTWISm3IT+hBM6qFmQtyCIg5+0Jxlc0 u5xpwnK2yFm9crU2dClDcfnT5CCrukQSkk9f6SbQ5M8mGeifsEjfHFTVOFiDFmS3MCd+ gG7zM1a9xLMInQCDeuVSuRXfXkRQhWCd8TCaebID0X6s8btFevc14SbPJmdcenhEGNGb RH9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682388983; x=1684980983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PaBSCJKIHD9zh+nwSwvV3S97b9xMaDgIHc/+VS6/AA4=; b=BMZAq6cQ5bsBUBV3e7rPUT1gg1F0aqJESSecZRn4Gn4sYlGx7FzEPVyA/0sQgudyr0 jsePUPhQtj5Oeexzq7BFbvRSY2wgX/bVZ6P5WdrWFl0QlgH6CCcVdZRbWhuWrx/70gT2 LNpPU7KJ6/yeiSkbiPPF2fonzUOGSZH4//T5GmKtMcu8gZ/BaFnJVkpOzNdOy/9WIjTZ jlj2PXO/C9eqRy7ivziDG9lTlNP4cAJe8D5ZyrJq5EpOJFnJEzUnNWuUoKwnEf0ka3IP 3ZSSC1qe+W1ShQXSu7hWI2GJ0BuOshdNUJ2GJQotNLB5JhpDMLNzpfw+AXubwuUxuhf9 /ZSA== X-Gm-Message-State: AAQBX9eDaZQ44j5CC4KLqfdy2dOxvLwgzL7FX8p1CZshV0dPftUjBdA+ y+5Msh6ZbLlFrvNwOAbn+ttpgLs6XLtMeJS7bYj7vg== X-Google-Smtp-Source: AKy350aXYlVNPkMbAeXDZ20qwucNzz6IbYoVKivgwBE8Cgo7BcuovDYlrUiJ9lNehnGY3YrWIXzKGw== X-Received: by 2002:a05:6a20:a690:b0:f0:f96a:bf36 with SMTP id ba16-20020a056a20a69000b000f0f96abf36mr17752819pzb.43.1682388983414; Mon, 24 Apr 2023 19:16:23 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id s9-20020a63e809000000b00476d1385265sm6991129pgh.25.2023.04.24.19.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 19:16:23 -0700 (PDT) Date: Mon, 24 Apr 2023 19:16:21 -0700 From: Stephen Hemminger To: fengchengwen Cc: , , Subject: Re: [RFC 0/3] introduce coroutine library Message-ID: <20230424191621.2075bf31@hermes.local> In-Reply-To: References: <20230424130208.9517-1-fengchengwen@huawei.com> <20230424090836.0550e14b@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Tue, 25 Apr 2023 10:11:43 +0800 fengchengwen wrote: > 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. The standard DPDK architecture is to have dedicated threads. Unless you convert the user application to some other model, there really is no other useful work that can be done while waiting for your driver. There was a previous DPDK library for lightweight threading, but it never got any usage and was abandoned and dropped. Why is this better?