Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp87063imu; Tue, 22 Jan 2019 14:23:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN7ImaHC+L+yiWeZURe4UrYKdeYQOCk2Jl4VGT7yAgHa4FAQkdKqkZ2W25c1gag/0ySNQr3S X-Received: by 2002:a17:902:9a8b:: with SMTP id w11mr35316133plp.121.1548195787706; Tue, 22 Jan 2019 14:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548195787; cv=none; d=google.com; s=arc-20160816; b=KOkAH07b8EIyApR06d3fH2bysAqwLOnfiiU/gpzUNmUlFBWknyuqwIEuOzCWYrB42l 8IBmsyycTXOAlVcnGdQCXK7edCCU0TaxQBjGk2linvaKmC79S9mK9oEJ3X712OTfzSXV npyi2+jm7PfNlrLTj445KjWEcup74koffOREf7NWFrVcrVh/b/KE5IdiYhNSyzGv6dOp C5HLvyBEmxgyYjbLz/3BuUCpVNHFmNGVUoT+IwhN1855HBFYxe4z6sKnlMmcrl5Zr8KH gQlquear60kboV4eOKv3IBJuyUgfPz7DJQtAU0OhOGneJs7q3NIUX+JB/9Sg1yLQYq/Z JQNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EQIsUq/WjPCU+7D5spFv+4jiuFGwbuG24v7sxTqsz88=; b=lJObQafXzihiw8gk7QlWlAoxeShde8FspKVkYW3k5BOCRAXNY2mu8xzEskOexqXnct Xo4vcGgHloZcAMX+Vor1PTDb2wt6pVdnVrk17jpIMb7TmOH1BHjgjHTGaNU6aPeBVgsZ w6wzcOQJ5L4x10PZtogts8UWjSfauGqz/75hFeMdxDyB75kYTuNC2JEjbAkqIbXoe0lz BhsPzutbIbDernX87l/GKg66qotZDIBkbIiMEQ4rW1CkrdcxvujAvWCOHcuPYY3fxTRB nh0rN8/VfYJ8/ZIXSWrg1RIzLYhxAFyBG7LdiPtuScJqWNfOov2Z3DeJ75FYgzHAxdKj nlhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=u6lhP5JV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7si17091845plb.234.2019.01.22.14.22.44; Tue, 22 Jan 2019 14:23:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=u6lhP5JV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726816AbfAVWU7 (ORCPT + 99 others); Tue, 22 Jan 2019 17:20:59 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:38325 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbfAVWU7 (ORCPT ); Tue, 22 Jan 2019 17:20:59 -0500 Received: by mail-qt1-f195.google.com with SMTP id p17so197637qtl.5 for ; Tue, 22 Jan 2019 14:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EQIsUq/WjPCU+7D5spFv+4jiuFGwbuG24v7sxTqsz88=; b=u6lhP5JV/uBirGyZBgegn7Rt3UCx2O69Tr3a0M/UUyZBHHI4/YHC34l3qaFb5pJsVg PfUZRUfH7vQr9Wsxde0p8IocqFvtdhnSDpbBno+Hjqbu+ivBZiDrP8u+Y5zJWX2a0GNj 80R1rKderCoWTGBBzDJ6OWOHidtEOJXt2WnJA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EQIsUq/WjPCU+7D5spFv+4jiuFGwbuG24v7sxTqsz88=; b=O7JDSlZ1K8hGzYaeQRPcZlZw8A89F5C4kkbLXNTOM7HeIXAunPCM0a+e9UKcazQO2D PVJX4QWXYU9EeWvllVFZF3SH/mtnT8Yr2J25cP9pO6Fv+2WUzSEdvuzI7WdWLVo1ZBz5 +Ca072FGjqK7Yl+jTsLjKzwSHG91RR6myX5GN7CUbiUan2qsUu/eLL09CWGaE01pkux/ T2QDiMpDV2krw+FHfCwtuwds2IsfCzHZw3lMxnfBfF/a6k3uedg0arZM2/Qs4K8ACgBV RohVmsq/UHt4CvK2YuwI4rdJG5sW5n5YBXrtjpAN5yFmAX7kBi6wmVMY8VCjxFDpDbDV VfSw== X-Gm-Message-State: AJcUukcelVG0cKA1a3INmbu800mCz7C70hfwUysrweMs63bDQairqIUw A3RRKc2RZX8HGJ43eWntiS4yhQ== X-Received: by 2002:a0c:ad48:: with SMTP id v8mr31077250qvc.83.1548195657730; Tue, 22 Jan 2019 14:20:57 -0800 (PST) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id a185sm58262440qkb.1.2019.01.22.14.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Jan 2019 14:20:55 -0800 (PST) Date: Tue, 22 Jan 2019 17:20:54 -0500 From: Joel Fernandes To: Hugo Lefeuvre Cc: Greg Kroah-Hartman , Greg Hartman , Alistair Strachan , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Christian Brauner , Ingo Molnar , Peter Zijlstra , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched/wait: introduce wait_event_freezable_hrtimeout Message-ID: <20190122222054.GA37126@google.com> References: <20190117224135.GC8100@hle-laptop.local> <20190118151941.GB187589@google.com> <20190118170801.GA4537@hle-laptop.local> <20190119015355.GA115342@google.com> <20190119102912.GA2647@hle-laptop.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190119102912.GA2647@hle-laptop.local> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 19, 2019 at 11:29:12AM +0100, Hugo Lefeuvre wrote: > > > as far as I understand this code, freezable_schedule() avoids blocking the > > > freezer during the schedule() call, but in the end try_to_freeze() is still > > > called so the result is the same, right? > > > I wonder why wait_event_freezable is not calling freezable_schedule(). > > > > It could be something subtle in my view. freezable_schedule() actually makes > > the freezer code not send a wake up to the sleeping task if a freeze happens, > > because the PF_FREEZER_SKIP flag is set, as you pointed. > > > > Whereas wait_event_freezable() which uses try_to_freeze() does not seem to have > > this behavior and the task will enter the freezer. So I'm a bit skeptical if > > your API will behave as expected (or at least consistently with other wait > > APIs). > > oh right, now it is clear to me: > > - schedule(); try_to_freeze() > > schedule() is called and the task enters sleep. Since PF_FREEZER_SKIP is > not set, the task wakes up as soon as try_to_freeze_tasks() is called. > Right after waking up the task calls try_to_freeze() which freezes it. > > - freezable_schedule() > > schedule() is called and the task enters sleep. Since PF_FREEZER_SKIP is > set, the task does not wake up when try_to_freeze_tasks() is called. This > is not a problem, the task can't "do anything which isn't allowed for a > frozen task" while sleeping[0]. > > When the task wakes up (timeout, or whatever other reason) it calls > try_to_freeze() which freezes it if the freeze is still underway. > > So if a freeze is triggered while the task is sleeping, a task executing > freezable_schedule() might or might not notice the freeze depending on how > long it sleeps. A task executing schedule(); try_to_freeze() will always > notice it. > > I might be wrong on that, but freezable_schedule() just seems like a > performance improvement to me. > > Now I fully agree with you that there should be a uniform definition of > "freezable" between wait_event_freezable and wait_event_freezable_hrtimeout. > This leaves me to the question: should I modify my definition of > wait_event_freezable_hrtimeout, or prepare a patch for wait_event_freezable ? > > If I am right with the performance thing, the latter might be worth > considering? > > Either way, this will be fixed in the v2. I agree, it is probably better to use freezable_schedule() for all freeze related wait APIs, and keep it consistent. Your analysis is convincing. Peter, what do you think? > > > That being said, I am not sure that the try_to_freeze() call does anything > > > in the vsoc case because there is no call to set_freezable() so the thread > > > still has PF_NOFREEZE... > > > > I traced this, and PF_NOFREEZE is not set by default for tasks. > > Well, I did not check this in practice and might be confused somewhere but > the documentation[1] says "kernel threads are not freezable by default. > However, a kernel thread may clear PF_NOFREEZE for itself by calling > set_freezable()". > > Looking at the kthreadd() definition it seems like new tasks have > PF_NOFREEZE set by default[2]. > > I'll take some time to check this in practice in the next days. > > Anyways, thanks for your time ! Yeah, no problem. thanks, - Joel