Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4827680pxj; Tue, 22 Jun 2021 08:52:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx19CHlxn7aRnmnDCSrFjsLC9pwt9QdPn88ekmY9S6PmF5a8mYIXHkAMuIPMzlexNs3Cp9w X-Received: by 2002:a17:906:dbee:: with SMTP id yd14mr4835917ejb.49.1624377172387; Tue, 22 Jun 2021 08:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624377172; cv=none; d=google.com; s=arc-20160816; b=BwSLMORfzmg+j4g7ZZRrE4jbj3W5dRsqfrgOAXcX/blHxkgRBtt+bezYMToOwmHXtt JGRN+e/BECkbk7PgqXVGoiW0jua0yqlyooRk5Go9jfFiGV5dPlwqqjiQaBNtyzvymlJr A65OEh+0yk68s9BKCA6MsCgTX2jRy6Ck6/1Bn1XtJZc/pVXBIEeQDrPIj3jIgAU5n7Hp MLG6L1Uau7YFxCjkjbSH7j4/k3tEhw3UqDHbcwYdfWMv8PUgxLJ78ANeBuQ1656fWccx syhx/O5odRXMUp41o/yG/sXYqaNFsXZLKvLuC8dtk6s/nv2NHBv0FyJxmyoC0pZv3D3h FTjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=D08i5WTXo1+ei91JvYVmebG92e88A+VfKzRMQAIzqTM=; b=LKCtVEeJeGL5Sl5uFT8FT9sQT82vAL4c9RdDHpDH5X/R3Q3BIyCmEr24uPVFmTB0zW EjfjQaCNV0Ul9HMvf8rBxvCPVOkLYVuRvgXRXvDeHd64UnfmyLkVgppYvGMTpYYJ09YS pycV4CJkhFXUXVhMXXMLhtg/IcBCN58KBLVrRJifm4h4wp50UbYALUmCa4R31zUPEjw3 g0votpl/3hbb87dE+0MUTrXwvZ06EEbNjclnOHpZDteHeEIWRBuS1khDDK5HmC+cO2J9 XbXOb3xxCcrTWj0vQ8tg+sYfij9+nFw5Qspf1VXQKyDxq4ia3qcKQ5NL8SCn2DZEIyiL JBgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jgidxwU3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si14865835ejf.324.2021.06.22.08.52.28; Tue, 22 Jun 2021 08:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jgidxwU3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbhFVPvW (ORCPT + 99 others); Tue, 22 Jun 2021 11:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231876AbhFVPvV (ORCPT ); Tue, 22 Jun 2021 11:51:21 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADE6C061574 for ; Tue, 22 Jun 2021 08:49:04 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id bl4so4788735qkb.8 for ; Tue, 22 Jun 2021 08:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D08i5WTXo1+ei91JvYVmebG92e88A+VfKzRMQAIzqTM=; b=jgidxwU3rvWrgcqGkIz7gxsf8q34Aei30cqet0yNDoKa6Hm/JCxj6yqJiLESLRrZVA ll899Zhw7iQb7AeReITNvPVIMJ4IFUuR9kw/41EtBa1H0NaYNkvUG59sER6B7M/8D37g YyVOTgTwTFB2xwsVR4l7lukpfDyToapK0CRGmIhcJFHIp0F/AnvtyqJPTOzu7/ae/Tae x06TzLOotgnMYXO25mEI0JSnrFdG9v6SjquOLDWjprM/RezT7h0/pq7eKzpXLL4XgN1I lvf8ANIDlauF1WKmS9U29MZxvstcp1bvqEw/ILDfXRe9l4N0RVyjBJDDwLa4aq2UoIfx K56A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D08i5WTXo1+ei91JvYVmebG92e88A+VfKzRMQAIzqTM=; b=HNr6B9J/RYJ/TjkLp2uoMuXxaSOl1X82pDc8hQoAOc4q3ohuc0pVARnDsz+y7pYQBD y7eIIYqeS86mUFJZVu+uJj3pisWHuAEKax2HuPMJNNY8dWn8iR6pQ1M1mf/+q0AHaQcE pJtYWtJZlgdgc5AtThAYm5UwPK9icgwfdWjCzmBjklC5voIJT/tGUBuKYf2xGSU4Uah0 EB7l2hSe4rFKdcR1ZoPZbdmE+gtvCdIRfdM1I7bmygFPDF3G2+9NgYaJHYR3XgLbeDO/ DF9RmAImgKrRAfF5z9rb4YviPj8IfqOde888V1sNl1QWM8SmxjJgfivLAu6WwRFArsly LdgA== X-Gm-Message-State: AOAM530u65EIgwIbdemO7zTdY3Tb3n7+9SOjvkT4hLldVp4J35Uul31D zd0XJArLMdEz2hI6QcSncebckkEj/nH4GlWBqdzP8w== X-Received: by 2002:a25:d913:: with SMTP id q19mr5873657ybg.397.1624376943574; Tue, 22 Jun 2021 08:49:03 -0700 (PDT) MIME-Version: 1.0 References: <20210617212654.1529125-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 22 Jun 2021 08:48:52 -0700 Message-ID: Subject: Re: [PATCH 1/1] psi: stop relying on timer_pending for poll_work rescheduling To: Johannes Weiner Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , matthias.bgg@gmail.com, Minchan Kim , Tim Murray , YT Chang , =?UTF-8?B?V2VuanUgWHUgKOiuuOaWh+S4vik=?= , =?UTF-8?B?Sm9uYXRoYW4gSk1DaGVuICjpmbPlrrbmmI4p?= , LKML , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 22, 2021 at 8:08 AM Johannes Weiner wrote: > > On Tue, Jun 22, 2021 at 03:56:03PM +0200, Peter Zijlstra wrote: > > On Thu, Jun 17, 2021 at 02:26:54PM -0700, Suren Baghdasaryan wrote: > > > Fixes: 461daba06bdc ("psi: eliminate kthread_worker from psi trigger scheduling mechanism") > > > Reported-by: Kathleen Chang > > > Reported-by: Wenju Xu > > > Reported-by: Jonathan Chen > > > Signed-off-by: Suren Baghdasaryan > > > > Johannes? > > Looks generally good to me, I'd just want to get to the bottom of the > memory ordering before acking... > > > > -/* Schedule polling if it's not already scheduled. */ > > > -static void psi_schedule_poll_work(struct psi_group *group, unsigned long delay) > > > +/* Schedule polling if it's not already scheduled or forced. */ > > > +static void psi_schedule_poll_work(struct psi_group *group, unsigned long delay, > > > + bool force) > > > { > > > struct task_struct *task; > > > > > > - /* > > > - * Do not reschedule if already scheduled. > > > - * Possible race with a timer scheduled after this check but before > > > - * mod_timer below can be tolerated because group->polling_next_update > > > - * will keep updates on schedule. > > > - */ > > > - if (timer_pending(&group->poll_timer)) > > > + /* cmpxchg should be called even when !force to set poll_scheduled */ > > > + if (atomic_cmpxchg(&group->poll_scheduled, 0, 1) != 0 && !force) Will change to Peter's suggested "if (atomic_cmpxchg(&group->poll_scheduled, 0, 1) && !force)" once the ordering question is finalized. > > > > Do you care about memory ordering here? Afaict the whole thing is > > supposed to be ordered by ->trigger_lock, so you don't. > > It's not always held when we get here. > > The worker holds it when it reschedules itself, to serialize against > userspace destroying the trigger itself. But the scheduler doesn't > hold it when it kicks the worker on an actionable task change. > > That said, I think the ordering we care about there is that when the > scheduler side sees the worker still queued, the worker must see the > scheduler's updates to the percpu states and process them correctly. > But that should be ensured already by the ordering implied by the > seqcount sections around both the writer and the reader side. Thanks Johannes! I have nothing to add here really. > > Is there another possible race that I'm missing?