From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4052EC54EE9 for ; Tue, 27 Sep 2022 12:51:11 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.96) (envelope-from ) id 1odA33-0004Lj-30; Tue, 27 Sep 2022 08:50:53 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1odA32-0004Lc-1h for kernelnewbies@kernelnewbies.org; Tue, 27 Sep 2022 08:50:52 -0400 Received: by mail-ej1-x629.google.com with SMTP id sd10so20511928ejc.2 for ; Tue, 27 Sep 2022 05:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=h3RgYUhkMXtt8ZAecITUukQh3hSIPgilcNCT6uf3KMo=; b=ezvYU0tsZuYEIRRuoP3S4aIChBK3ViQxvnEqwB4DQZs0jDrt4JUw2D4nohWXj/SkeM 1l9aK1Q01cCEDi/uqXm/tAZnfulZMiMDDi4Io2Fo1wxeq/GuF6uIjUnhxGG0ubQHFKBS HB8OA9chYUrAGIjb+5PVAKiZb/FJ5nstbxpN5mx+IlvMNV/CbBFPV7f+Pc0JXp9cjBLW Ep4LqOei1Pzly2UWt2HJ436bi9vatL+oLqYmDsnvmGADa86/A8NBmlKlLW5PQUBguyzH bggLVRVKQM2L8er3CR4gvctrcuC/KvVhlNNVviyBZU3N9VoCr3efrh0dkygMPxnpuT4V um+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=h3RgYUhkMXtt8ZAecITUukQh3hSIPgilcNCT6uf3KMo=; b=H4/NjB0ugJa7aozTf7WC0RczRYTVvIRifP342eLC9dSu51ddyVqG2SHJA0/i92bBYX R+8kOpNb2/1StbeVfBSUJAycyhf+hF54SLNlMS+8i19p4x5XtEM4X2YQiipvsKC5jr8+ W7+rCYLMFOArJlLStpbErgmHwoX4r1SQyDnbDD4tkJiDvCe000bN4mtWmMSbp99k0B/D IBI9wXtddMzLSzoY8V2ULXtfLzt4FbxNW2B+bqTeAtsdTyg8AxwFaqYc9h0nsfoepboK bBmAZz6teUVU/SJaTc7ZbPrgJnSDl4y7gRFf7eQNQTfH6Q8Gwt57hvIClgfSNWmGYrvC 598A== X-Gm-Message-State: ACrzQf1WQEbLvNUSeFeieIBC7KQAIpRUhWvjNLlRcOMaV/11T4zlDHKj 2u5BlZ6BZEr5SI2iWg0GckMm/UoqwAg= X-Google-Smtp-Source: AMsMyM6p4UICaB97JDrjfkUN9ggce1PzfXDtsd3wHgnrPVmWnQcu5AUGOrF9ofoQXF0w1Xy8FWytwQ== X-Received: by 2002:a17:907:2d09:b0:781:d793:f51e with SMTP id gs9-20020a1709072d0900b00781d793f51emr4618299ejc.628.1664283050143; Tue, 27 Sep 2022 05:50:50 -0700 (PDT) Received: from localhost.localdomain (host-79-34-226-61.business.telecomitalia.it. [79.34.226.61]) by smtp.gmail.com with ESMTPSA id f7-20020a17090631c700b007803083a36asm741330ejf.115.2022.09.27.05.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 05:50:49 -0700 (PDT) From: "Fabio M. De Francesco" To: kernelnewbies@kernelnewbies.org Subject: Re: workqueue - queue + drain Date: Tue, 27 Sep 2022 14:50:48 +0200 Message-ID: <4744153.GXAFRqVoOG@localhost.localdomain> In-Reply-To: <20220811160351.urbqbhquu5u74obe@viti.kaiser.cx> References: <20220811160351.urbqbhquu5u74obe@viti.kaiser.cx> MIME-Version: 1.0 Cc: Martin Kaiser , martin@kaiser.cx X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Thursday, August 11, 2022 6:03:51 PM CEST Martin Kaiser wrote: > Dear all, > > would you mind helping me understand how workers and workqueues act in a > seemingly simple scenario? Hi Martin, After long time away from this list, today I just saw your email. I soon thought that it's a bit odd that nobody has yet responded, since here many experienced developers for sure know how workqueues work :-) (pun intended). However, I had to read your message several times and I must admit that I'm not yet sure about what you are asking for. Perhaps other readers might have had the very same problem that I experienced, so that they decided to skip your question :-) Therefore, I won't provide plain responses. Instead I'm going to ask you a couple of questions while hoping they may help you to rework your question if they cannot help directly with your question... > I'm calling > > queue_work(my_queue, my_worker) > > to add a worker to a queue that was created by calling > create_singlethread_workqueue(). create_singlethread_workqueue() This is deprecated. Please use alloc_ordered_workqueue(name, WQ_MEM_RECLAIM) from the newer Concurrency Managed Workqueues (CMW). > This goes into > > queue_work > queue_work_on > ... > if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) { > __queue_work(cpu, wq, work); > ret = true; > } > ... return false if __queue_work hasn't been called... > > > with > > static void __queue_work(int cpu, struct workqueue_struct *wq, struct work_struct *work) > ... > /* if draining, only works from the same workqueue are allowed */ > if (unlikely(wq->flags & __WQ_DRAINING) && > WARN_ON_ONCE(!is_chained_work(wq))) > return; > > > If drain_workqueue(my_queue) is running while > queue_work(my_queue, my_worker) > is called, my_worker will have WORK_STRUCT_PENDING_BIT set, but it's not > queued and no error is returned. > > With WORK_STRUCT_PENDING_BIT set, all further attempts to > queue_work(my_queue, my_worker) > later, after draining is done, will fail. Correct, this is what I'd expect to see. I'd be very surprised if it wouldn't fail. Are you aware that, while draining is in progress, only "chain queueing" is allowed? "Chain queuing" means that *only* works already in a draining workqueue are allowed to queue further tasks. Furthermore, flush_workqueue() != drain_workqueue(). Can you explain their different semantics? > > This code has been unchanged since at least 4.14. Could anyone shed some > light on this, where am I getting things wrong? > > Thanks and best regards, > > Martin Regards, Fabio > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies@kernelnewbies.org > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies