Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp543183rwe; Wed, 19 Apr 2023 02:22:20 -0700 (PDT) X-Google-Smtp-Source: AKy350bn9FfN4x9niddGGYujL4UH8+C+qicuqAVBsHf1ZdwNYDsIhxv6QWlMigi0WBqFL5DHO9Ph X-Received: by 2002:a05:6808:171a:b0:38d:1597:71f1 with SMTP id bc26-20020a056808171a00b0038d159771f1mr3027183oib.31.1681896140706; Wed, 19 Apr 2023 02:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681896140; cv=none; d=google.com; s=arc-20160816; b=lmr5ZG9Y9u5t/LCd0Tvca/k+H8DuqXkxjW9bh0fWRi7qFN8S9j18Na4xht+CMQdKCv 78wUIDuojc+gGy3MBZKda3970RKq2aLCtrI2feNAW0HeJFNuJXRQsxM8ojlYZ9QfM/mz Tv3B7b/H9Prixu6MiCZ8TRBs61MzRXYZhyGsKltOzHeU8gqSNUS6xp6aBhtEceVKSRhY Mcz6AbJCuAaffy7ARkOy+9mNRfweC2dEvNXOUgKqyx4UEwyItkQEjiY8RhM2D+/ktyXs BHU0v22bJX2d97npU3w9w0z2Sblzlq1sltVSom8fOF1WfJbekLEtQd5pp7oc8XGzLF0W T20Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TBL2mrpGpNtV0AqOUQCeITGJj0Z1eKXNOORfERV1fuk=; b=WY1tRa2FE/q7LVoSdHKb5Rdmpw9sofGinlrvLNQSVcTP3x/R+yrSODEHpFZMNMZfm5 eln5f+lXfP2rOzKrEyF+xKCIn+nrCA5xSjMFC3uTNvTABOVvr7VWHEpP9uTkZWvMcuYv J2AApWLUReaaEV+gh6L/7AUcT0Qxb9xdrM9rbRpz6HLgcQaVOV1WTRPlcHJ5nv67AMPU TyZwJWHPiH0+Ou43rwzIdWxA5oWB9ZLlz+L2oD8SKveeeIkHlDYgGTRiBuU/0tpBfaCg NCQdxPVo7NqoKykDHZ/1kKufoWEwCEqg+YHKYx7KmVz5/n2Achw6qrTtLqyrLy9IrUEG i/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QcNT5UtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv22-20020a0568201b1600b0053c3b0372easi12423957oob.93.2023.04.19.02.22.05; Wed, 19 Apr 2023 02:22:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QcNT5UtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232408AbjDSJMf (ORCPT + 99 others); Wed, 19 Apr 2023 05:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230289AbjDSJMe (ORCPT ); Wed, 19 Apr 2023 05:12:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEA0B107; Wed, 19 Apr 2023 02:12:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6D010616F2; Wed, 19 Apr 2023 09:12:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80449C433EF; Wed, 19 Apr 2023 09:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681895551; bh=6YUk6AAUM3ORtZrVrup0K5gL81Envy2abVP09sfpCtM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QcNT5UtHpG5io2IFoZ/G9pv2UUsfH2QQ/hC3mndggqwowNMEe+Gpb9i6hJO6ZQ9At z3plzTA9Lme0bPCMpxtKRU7uAAFLVx4fuy1ptVuYrCdFHzN8jLA16+TZQyuab7I6/u /aeFTe52sGK6zM7lQJZrfRAQOuJhxFlbw3ciP6ncyT+XW9XsuLZioZXA7CBcxcYveD 3w996/ZwzUPCH+VHOaPAe6ZjG0261i5jT/wBFMYXMBrLDzs44mia4hUuW0dpCWR7OB k2Zm4L1Vo1xIJkgHgOo6JbZKlPuQbc03OTcyvntPC1MNofXLCRMdafYR7zRKOWiglN nr/TJXLxohPQA== Date: Wed, 19 Apr 2023 11:12:25 +0200 From: Christian Brauner To: Jens Axboe Cc: Wen Yang , Alexander Viro , Christoph Hellwig , Dylan Yudaken , David Woodhouse , Paolo Bonzini , Fu Wei , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] eventfd: support delayed wakeup for non-semaphore eventfd to reduce cpu utilization Message-ID: <20230419-blinzeln-sortieren-343826ee30ce@brauner> References: <817984a2-570c-cb23-4121-0d75005ebd4d@kernel.dk> <7dded5a8-32c1-e994-52a0-ce32011d5e6b@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7dded5a8-32c1-e994-52a0-ce32011d5e6b@kernel.dk> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 18, 2023 at 08:15:03PM -0600, Jens Axboe wrote: > On 4/17/23 10:32?AM, Wen Yang wrote: > > > > ? 2023/4/17 22:38, Jens Axboe ??: > >> On 4/16/23 5:31?AM, wenyang.linux@foxmail.com wrote: > >>> From: Wen Yang > >>> > >>> For the NON SEMAPHORE eventfd, if it's counter has a nonzero value, > >>> then a read(2) returns 8 bytes containing that value, and the counter's > >>> value is reset to zero. Therefore, in the NON SEMAPHORE scenario, > >>> N event_writes vs ONE event_read is possible. > >>> > >>> However, the current implementation wakes up the read thread immediately > >>> in eventfd_write so that the cpu utilization increases unnecessarily. > >>> > >>> By adding a configurable delay after eventfd_write, these unnecessary > >>> wakeup operations are avoided, thereby reducing cpu utilization. > >> What's the real world use case of this, and what would the expected > >> delay be there? With using a delayed work item for this, there's > >> certainly a pretty wide grey zone in terms of delay where this would > >> perform considerably worse than not doing any delayed wakeups at all. > > > > > > Thanks for your comments. > > > > We have found that the CPU usage of the message middleware is high in > > our environment, because sensor messages from MCU are very frequent > > and constantly reported, possibly several hundred thousand times per > > second. As a result, the message receiving thread is frequently > > awakened to process short messages. > > > > The following is the simplified test code: > > https://github.com/w-simon/tests/blob/master/src/test.c > > > > And the test code in this patch is further simplified. > > > > Finally, only a configuration item has been added here, allowing users > > to make more choices. > > I think you'd have a higher chance of getting this in if the delay > setting was per eventfd context, rather than a global thing. That patch seems really weird. Is that an established paradigm to address problems like this through a configured wakeup delay? Because naively this looks like a pretty brutal hack.