Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp857676pxv; Thu, 1 Jul 2021 10:49:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5a+/Ayd25CaCSYMrPu/Nt20hTII6yVqLp7Oxgq20xWrAYM/jR6aC6yUMZ/WFXfHR6dund X-Received: by 2002:a02:cdc7:: with SMTP id m7mr890313jap.127.1625161780352; Thu, 01 Jul 2021 10:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625161780; cv=none; d=google.com; s=arc-20160816; b=hdMpRlfIUpcJOvAw9FRCt0uC/5h1DIRQll6bMbJ1Tps9zchZ4U82o7otnz6Qhl4ovI bAXqu5SBCdZgP3LbiMoKycOoy4k8DOFe4KkeLzF5Th1gSHzWTAdqSjWWBIu8SF3NSi5U tAFdwXeVmoKopUe+3MANMTwb4NeGNr3V5BHZglvCu35at7cuAL6ZZqMR6ZGRCofNf3PQ r35eN0V87cdUxT9hVZrhd5GYfwaZ+ckAIOx6IBuzZ5PKmYsIavFlTaVklVA8ezmvlfPx CBkd1SAwHmU41vNINhSO0uOAK7ne6nEHFU9OT3khQf15dJJZBeK06ElRd/V9CYpCi03y Ey6A== 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=YuEQ/0+GfUXuD93+sD0b18biDb2M6pGGHSqSSO1+UuE=; b=VX+4k+Hq76il6ddd5YZP55zqBSYlguVrTAzpeoYca/5c8RViKiKo5NjaVsiTbu4F0n 6vVuYF8KCkByyZ3SqM8mMd77VX7Bpepxbo6Am2S0/9yd6WAmY13v5tQHTfOO+3VOtl3g NnqFUhM0qHUxXmNO78+m2sq+eL+wRNFO5/spn3h/oK0T4xrUwThsjaCLnQjHJKLLVLqB ZcVKIwhiw3oBbwIk3jP7Zar0L65IsxTG5+M1AlpYTovP2ywbly7R5p84neVrBZwZRaoR ec+EYIuK1R4EE853uipNaN6F7G63aKvITFhrLcA17w/16zvFX2JkzrKo+vPpBKoyBGRS V24Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LwRldiJ6; 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 m22si632246jat.35.2021.07.01.10.49.27; Thu, 01 Jul 2021 10:49:40 -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=LwRldiJ6; 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 S229958AbhGARso (ORCPT + 99 others); Thu, 1 Jul 2021 13:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbhGARsn (ORCPT ); Thu, 1 Jul 2021 13:48:43 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13637C061762 for ; Thu, 1 Jul 2021 10:46:13 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id m9so12146714ybo.5 for ; Thu, 01 Jul 2021 10:46:13 -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=YuEQ/0+GfUXuD93+sD0b18biDb2M6pGGHSqSSO1+UuE=; b=LwRldiJ6x3BDPyzWXCUQCVT7w7Nq6ItegVRwz4Hvnijj6RznRtT6uC+9iCLJJYi02f zzHxxy8uov62zs7l+LUOTT2P2/0A3RTfmmDwkwSbdU8OeTFmo3+g/0x6stmjWlYW8iP0 E267aJc0D98iMrWtKF0OqHOsfJuyoO2P4Tnr00mVS7NKlj/jCCwAUYv/76rc9PbWfZb+ TB92w5TUe9RTMCLYfVSADk2JJ6kpREuyEEXk1uvYzjxbJLOvu/aV47llCbzQX5nsBYk9 6yxuTDS8ZD5FvhhC9z+ggI6rYAUJqE4pMLgTU7zHXqRc8gm8ltSTr2yK/aIOmZ0b9hCa 4R1A== 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=YuEQ/0+GfUXuD93+sD0b18biDb2M6pGGHSqSSO1+UuE=; b=eI+gPVMJz8xm0MLgM2kVxscAoVyotQfIaMJTThOl0KVtckk4ii1pituw2oaqBYmjSu Hf+7Wh5MxAKYeveYESJheCMcChxIsUqpKVRXMBPD/nVbLzsKogDklgorKChqvGLK/mBm 3kgPKl52YFaTQBb5fqdC2Ggnj1P3gwZOYET28rbRLBTUkegEjURcVd0SPJHd1LQUaKMS kvAnyt3dBBxCbqwceKCIw7Yi2GAetmzhN83mjydrfoulWk8DfATSopn8xufaPTtJO11y bngZI2o3ZVkdIm2/xJFt2dw8JIERlelgP4TrvOJWbCoExHjwIY4nKUOZxn+CwWf0syOB 6Giw== X-Gm-Message-State: AOAM531KKhociCW+aqAAAWPVXqySmAevLQZGqScZZMYT5RgD8c/lGp+b iAqT/X46jzsosUsQII7zZbOGjq9P3v6+Z2b0MMJ9Eg== X-Received: by 2002:a25:2e49:: with SMTP id b9mr1337732ybn.250.1625161571802; Thu, 01 Jul 2021 10:46:11 -0700 (PDT) MIME-Version: 1.0 References: <20210630205151.137001-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 1 Jul 2021 10:46:00 -0700 Message-ID: Subject: Re: [PATCH v2 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 , SH Chen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 1, 2021 at 9:39 AM Johannes Weiner wrote: > > On Thu, Jul 01, 2021 at 10:58:24AM +0200, Peter Zijlstra wrote: > > On Wed, Jun 30, 2021 at 01:51:51PM -0700, Suren Baghdasaryan wrote: > > > + /* cmpxchg should be called even when !force to set poll_scheduled */ > > > + if (atomic_cmpxchg(&group->poll_scheduled, 0, 1) && !force) > > > return; > > > > Why is that a cmpxchg() ? > > I now realize you had already pointed that out, but I dismissed it in > the context of poll_lock not being always taken after all. > > But you're right, cmpxchg indeed seems inappropriate. xchg will do > just fine for this binary toggle. > > When it comes to ordering, looking at it again, I think we actually > need ordering here that the seqcount doesn't provide. We have: > > timer: > scheduled = 0 > smp_rmb() > x = state > > scheduler: > state = y > smp_wmb() > if xchg(scheduled, 1) == 0 > mod_timer() > > Again, the requirement is that when the scheduler sees the timer as > already or still pending, the timer must observe its state updates - > otherwise we miss poll events. > > The seqcount provides the wmb and rmb, but the scheduler-side read of > @scheduled mustn't be reordered before the write to @state. Likewise, > the timer-side read of @state also mustn't occur before the write to > @scheduled. > > AFAICS this is broken, not just in the patch, but also in the current > code when timer_pending() on the scheduler side gets reordered. (Not > sure if timer reading state can be reordered before the detach_timer() > of its own expiration, but I don't see full ordering between them.) > > So it seems to me we need the ordered atomic_xchg() on the scheduler > side, and on the timer side an smp_mb() after we set scheduled to 0. Thanks for the analysis Johannes. Let me dwell on it a bit.