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 46C3B42A02; Wed, 26 Apr 2023 13:28:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 33A11410FA; Wed, 26 Apr 2023 13:28:52 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) by mails.dpdk.org (Postfix) with ESMTP id C392F40DDA for ; Wed, 26 Apr 2023 13:28:50 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NvnCFu9SHHaHpQ4YZBRTfhR+LjrmnqsIC00YQ69Lw18xEXEV7ybsuFlgoTSP+MVM9CF2f3NWYMLmEb7wU195HWOAsfVUBpUc9JQCDnW70kTHn5kKeYO7RDXmUy/t61Tn3nbS/oef+CkMrJRwo9jxs7iyi5xZRH1ivRayAnpWmlNH8YGvUSMWmKCOHchB71NMwMJ4G7psXaIC7qi4K8L+8Z5wxkQIZljaIsJTCxZhNx3wMAOiPPc0HXVJmTWBNwIeIE6yHKmv0Z615r9N9eRnt+jOUTEJD1ukF16bJNpZf+dCDGsQwMOu35euQNTBytq3LCMfELSh+fJ9m2kuxWkBwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jMWJHgv2ghOKGbjBxISW8gQUyJ6XNd/YPBbzzPMZGZc=; b=lYA5coZ+1KgOU9JXjlgRo5HaV836/EKwuTTrKAnD8SKjpNRG2fkD3hYjInPeR/JQnLOzQsoGUcDGOClNBCfv9BzyA46R/qhS36UxEUMeK1ubt0tNj2MYHT5wJgeeGGIqQtGYH4GHaC9SHSRxaBR65+u9naNZfeZMUFn+Pr8IZ+f8DWrJiFjgAxyeH9Wx91AlBNRRMHWjWJvn8/e71qP9GnsxewJnWFwrZiKfvXFAjLKPeoa8ElDkVTSTv89c2zoDQKgPKeeF1Ke5tLeAv3/sg+QfJdV8v7p99XGyxz3TiAVi1T+4fe31/7bV2on+FpeX243sybKAJgJRQNMnvjpawQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jMWJHgv2ghOKGbjBxISW8gQUyJ6XNd/YPBbzzPMZGZc=; b=vEzbaOutcyx6Zxr20wO/0aLjc1BWUf3DV5Y7sTiJxu+JKfiwTSa0rjCWsj3IFvvE1ZncUMUFGwDvzVZn/yCxCnih2fzGArHmEPXEi/9/TYMU2IIB9wJgjq72w5b1sx0fJKtNv6U2Amx97qApQsL4dBpmluCik1VTaB3iFqp6JmI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from MN2PR12MB4301.namprd12.prod.outlook.com (2603:10b6:208:1d4::22) by PH0PR12MB7469.namprd12.prod.outlook.com (2603:10b6:510:1e9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21; Wed, 26 Apr 2023 11:28:48 +0000 Received: from MN2PR12MB4301.namprd12.prod.outlook.com ([fe80::6f2d:9990:c8b5:714a]) by MN2PR12MB4301.namprd12.prod.outlook.com ([fe80::6f2d:9990:c8b5:714a%6]) with mapi id 15.20.6340.021; Wed, 26 Apr 2023 11:28:48 +0000 Message-ID: <332f8d59-1c45-4cc8-dd61-a9495cce6d93@amd.com> Date: Wed, 26 Apr 2023 12:28:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Content-Language: en-US To: Chengwen Feng Cc: dev@dpdk.org, thomas@monjalon.net References: <20230424130208.9517-1-fengchengwen@huawei.com> <20230424130208.9517-2-fengchengwen@huawei.com> From: Ferruh Yigit Subject: Re: [RFC 1/3] lib/coroutine: add coroutine library In-Reply-To: <20230424130208.9517-2-fengchengwen@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:276::22) To MN2PR12MB4301.namprd12.prod.outlook.com (2603:10b6:208:1d4::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4301:EE_|PH0PR12MB7469:EE_ X-MS-Office365-Filtering-Correlation-Id: 339085db-6c87-4622-af05-08db4649677f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pJN69hbfi9Ukz1VjZceNQGlL7uMKsxFEyCSXJkqgjOh1x+fN9xQxHvrzDXFwp/idUtSix6t1/WX9hq5UeXez/3x8evGKi65q8KSPDt6wgNX/MEQeB6xxAyPHegN+0BzIyUh0knnRrEeNTp0inhsn6/JQqkD0cZiH97tGF+Vk1jUfYrGiHf+OiRxZDws2kNmXVEF/aVfN+5dKO4KC6dsdORSVNIKLT6ONLmv4B4ggbIpgy5ydo/eUSHN+2AoZuWsMlhn5MD3Yn0a4Ln1cliaCA2KER80tBdLZby/E/iZyzBfxQjMFJGRn9jGQ+/sXCnpBT8F+USlN/8ujc5aekK6xh7HuivEifRciCRo/q1JdyME8jnXFjx1X2AW+ND3SVhBVEOqtMw7tU244AugKmo9pT2j3qtlzUuqH4WiDOgn2ZRgqcKT7SOlBgrK96so/T07UKalbuprEz/+cMJj36iYEYRGfk2d7SZe7VNpTIW02Jq+U/kKWWre2YBrfd+/mMmAom5QTTOP1O0p6U639wlfwD7GouVpXRy+1AaSNbtsyrISFu/Mwmm0NniGQ5HBR4p9/pU07uWAi2cAof8U8m1qNBGFS6FdV9LT7scDEZCJGgp+XylngdNwNVclHzpxJvA7FH4P+PSBS8zp6thTuN8e45A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR12MB4301.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(136003)(39860400002)(396003)(376002)(366004)(451199021)(53546011)(6506007)(31696002)(316002)(44832011)(86362001)(6916009)(66476007)(66946007)(66556008)(2906002)(8676002)(38100700002)(8936002)(41300700001)(5660300002)(186003)(6512007)(26005)(83380400001)(4326008)(36756003)(2616005)(31686004)(6666004)(6486002)(478600001)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Qk1mL2s2VHBJendCSmp5eVZvWm1yRGN1NDBuQWkxemVLTUM3WFJ5Wm9GVGQv?= =?utf-8?B?VjZvelBTblJLSHRaVXJ0a0IrUFQvSm4xMkpsbU9HeWVYSkY5OWMxVFZFRnRR?= =?utf-8?B?U0Rma2NzemtKTWoxSHVRRTI4TWVyaW80bU5rR0dFVkFBQXgxU0Z0ZkUrb2o3?= =?utf-8?B?dEhnUDdIYm1oU010djU2NDFSUzlhV2RzM1l3YXVyemhiMnd2UXhkbUZKR0NJ?= =?utf-8?B?cFlVQUtiQjhLZGhKM1hpaUtzS3R1Y2dCMHNxRzRhT042ME85MUg0L1NsR1Q0?= =?utf-8?B?Y1pCTlhIeUZTOU9mdVEwdWF5TkpoeTVacEp1bEd5alRraEFnNE1hTkZwSkxY?= =?utf-8?B?cjl5R3ZNdnNzclY3aEd5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enant-Network-Message-Id: 339085db-6c87-4622-af05-08db4649677f X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4301.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2023 11:28:48.7927 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gtkXWVzBO376+qLR9ne5m42oMndjEuTE1gjHQThZpcf4N3wZ+yCUdudkmItTI3Oy X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7469 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 4/24/2023 2:02 PM, Chengwen Feng wrote: > This patch adds coroutine library. The main elements are: > 1. scheduler: container of coroutines, which is responsible for > scheduling coroutine. > 2. coroutine: Minimum scheduling unit, it should associated to one > scheduler. > > In the coroutine callback, application could invoke rte_co_yield() to > give up the CPU, and invoke rte_co_delay() to delay the specified > microsecond. > > Signed-off-by: Chengwen Feng <...> > +++ b/lib/coroutine/rte_coroutine.c > @@ -0,0 +1,190 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 HiSilicon Limited > + */ > + > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include "rte_coroutine.h" > +#include "rte_coroutine_imp.h" > + > +#define FATAL(fmt, args...) printf("[FATAL] %s() %d: " fmt "\n", __func__, __LINE__, ##args) > + No 'printf' for logging please. <...> > +int > +rte_schedule_run(struct rte_schedule *s) > +{ > + struct rte_cocontext *co = NULL; > + uintptr_t ptr; > + > + /* Set local thread variable as input argument. */ > + co_schedule = s; > + > + while (!rte_ring_empty(s->ring)) { > + rte_ring_dequeue(s->ring, (void **)&co); > + if (co->state == COROUTINE_READY) { > + getcontext(&co->ctx); > + co->ctx.uc_stack.ss_sp = co->stack; > + co->ctx.uc_stack.ss_size = co->stack_sz; > + co->ctx.uc_link = &s->main; > + co->state = COROUTINE_RUNNING; > + s->running = co; > + ptr = (uintptr_t)co; > + makecontext(&co->ctx, (void (*)(void))co_run_func, 2, > + (uint32_t)ptr, (uint32_t)(ptr >> 32)); Why passing 'co' address as two 32bit values? Why not just pass address of it? Also can it be possible to set context to 'co->cb()' here and do the cleanup after context returned to 's->main' (below)? > + swapcontext(&s->main, &co->ctx); > + } else if (co->state == COROUTINE_SUSPEND) { > + co->state = COROUTINE_RUNNING; > + s->running = co; > + swapcontext(&s->main, &co->ctx); > + } else { > + FATAL("invalid state!"); > + } > + } > + > + while (s->yield_head != NULL) { > + co = s->yield_head; > + s->yield_head = co->yield_next; > + if (co->state == COROUTINE_YIELD) { > + co->state = COROUTINE_RUNNING; > + s->running = co; > + swapcontext(&s->main, &co->ctx); > + } else { > + FATAL("invalid yield state!"); > + } > + } > + As coroutines in 'ready' state stored in a ring, same can be done for the coroutines in 'yield' state, instead of using a linked list, to simplify the flow. Just a question, both works fine. > + return 0; > +} > + > +int > +rte_co_create(struct rte_schedule *s, coroutine_callback_t cb, void *arg, uint32_t stack_sz) > +{ > + struct rte_cocontext *co = calloc(1, sizeof(struct rte_cocontext)); > + int ret; > + if (co == NULL) > + return -ENOMEM; > + I guess somewhere here should check the 's->max_coroutines';