Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4636154rdb; Tue, 12 Dec 2023 05:28:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGHIYirU+Ae0PVfNiJEradgBDttZzbQ13URQJyhBH3MXW5VULj6Y38vF5AnWP581GS5Paj X-Received: by 2002:a05:6a20:6d9e:b0:190:b98:9bf0 with SMTP id gl30-20020a056a206d9e00b001900b989bf0mr3151117pzb.102.1702387698758; Tue, 12 Dec 2023 05:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702387698; cv=none; d=google.com; s=arc-20160816; b=J36eSnYBRg8kv+lQR/L2vRJ18/VhXGMt8XXB9nvIHhq6sh0GCmQ884+C/D5r/j7QoF nScJpG19RxBF0OlrAZ4jH6vafGU7xVCOzJoWOx/PeIUIwVzEvCuz5Ivv+KQW2D9K7oyP dCyQ93Kw1ijbX9iPw1vECWOxM10edemyAocU2JsOa286HwBMUoKpe12N6iLrmA0glntz 2NsEgr5nTz+4ZmgEatF1JGqwDp51ulF9GNJO2jLeTG7yG8pnsCStm4fq4XQVOuTpYv1C ipXNwZtO55He0XPuS6OeJFDHb9kWIRrIJdlR35qM6FkkQv4IVTmQuiOGqCFwJL6DqODF zB5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=fCmPksvKj2CJbCX1cBpYt1YL0N91utphQKoc/Terokk=; fh=Ex/TP0FQL8Qmw7yMR9dWou3JcsYXvXXH7E8ivuoqhvc=; b=qkyTJdOTU0iH71CaUtg+rlVx4nXrUpBqm5vXiVPNCWFxRUl55itpyQXvcdnqVi8CDQ /wP4YCwoNphuvkyqWu8qhMWykmUJ/TzQIA8J7BYIPRyGjfPa+Am6aAU36KWuFxrAzyrU Gr7V8iKWTaazWDSS2c0c2Hfv07eV9etZ2/kffit4JksMnfkPUlH+By2Ed7nbqVoutISs DbV+KXuXUuBxt902V1sMAa2KR6SqOJ8lfnIpX8/LdmIZh79P4YWuLKIqakN+bH+8knAY 0NaqfKdpXjC78yzdX+pwQvgi79bz+BCnFjNaRT5/Ke5lZLcHRyIbMH1Fmif4rkoDtEnC Ac8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bx21-20020a17090af49500b00286c0eb88f3si9181609pjb.34.2023.12.12.05.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:28:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3D579809A761; Tue, 12 Dec 2023 05:28:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346427AbjLLN2A convert rfc822-to-8bit (ORCPT + 99 others); Tue, 12 Dec 2023 08:28:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346522AbjLLN1r (ORCPT ); Tue, 12 Dec 2023 08:27:47 -0500 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63525D65; Tue, 12 Dec 2023 05:27:50 -0800 (PST) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-590a21e977aso137318eaf.1; Tue, 12 Dec 2023 05:27:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702387669; x=1702992469; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tt6fdI/cbCPQ7iqiyCD0Kz5AK/2nJCArCn0TPONSklY=; b=Qo0NkIUFlrMGBjz0Qdi+mPsasQyRuM9MaAkIbAPXqqUj1CLNxXQVsUNcEoNoue/Vsx Dp1PJ6f6I5lztb1IP7pX6tS5ZBx3gBrBh36SyGzP1r0smdZrVoVwpJbpr7mHeQ1b9WAL Rv1tEzIfiEA9pjuAshYgoksRu5RcQzWOmYt9yMmuTRid/jVqBfBaIewDTAc9XTDWyFRg 7z2cOVGXIZ5OeGmI/7I38uuKTjPOWD48ACKzdlU+XVPgYNyuraIcDLZyZo5Kp7S67FGc WLSEOaqxEBUYmTPXHYoUS5o4+A/+UsCQdzWIPXZQbhiqgr8eZuZsdp2pCz+Zy4SMwgl0 6H1A== X-Gm-Message-State: AOJu0YzV4elXXxb/QhItI4Dqmdtg0s4SeZkm+N++cobYqpBDfJ231dtl KLzepdfDJHb10/VY6F4VckJbJgXYA1j/QqHBrrw= X-Received: by 2002:a4a:c487:0:b0:58d:ddcb:db1a with SMTP id f7-20020a4ac487000000b0058dddcbdb1amr10131153ooq.1.1702387669582; Tue, 12 Dec 2023 05:27:49 -0800 (PST) MIME-Version: 1.0 References: <20231124223226.24249-1-frederic@kernel.org> <20231124223226.24249-8-frederic@kernel.org> In-Reply-To: <20231124223226.24249-8-frederic@kernel.org> From: "Rafael J. Wysocki" Date: Tue, 12 Dec 2023 14:27:38 +0100 Message-ID: Subject: Re: [PATCH 7/7] cpuidle: Handle TIF_NR_POLLING on behalf of software polling idle states To: Frederic Weisbecker Cc: LKML , "Rafael J . Wysocki" , Daniel Lezcano , linux-pm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:28:16 -0800 (PST) On Fri, Nov 24, 2023 at 11:33 PM Frederic Weisbecker wrote: > > Software polling idle states set again TIF_NR_POLLING and clear it upon > exit. This involves error prone duplicated code and wasted cycles > performing atomic operations, sometimes RmW fully ordered. > > To avoid this, benefit instead from the same generic TIF_NR_POLLING > handling that is currently in use for hardware polling states. > > Signed-off-by: Frederic Weisbecker > --- > drivers/cpuidle/cpuidle-powernv.c | 10 ---------- > drivers/cpuidle/cpuidle-pseries.c | 11 ----------- > drivers/cpuidle/cpuidle.c | 4 ++-- > drivers/cpuidle/poll_state.c | 30 ++++++++++++------------------ > 4 files changed, 14 insertions(+), 41 deletions(-) > > diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c > index 675b8eb81ebd..b88bbf7ead41 100644 > --- a/drivers/cpuidle/cpuidle-powernv.c > +++ b/drivers/cpuidle/cpuidle-powernv.c > @@ -71,8 +71,6 @@ static int snooze_loop(struct cpuidle_device *dev, > { > u64 snooze_exit_time; > > - set_thread_flag(TIF_POLLING_NRFLAG); > - > local_irq_enable(); > > snooze_exit_time = get_tb() + get_snooze_timeout(dev, drv, index); > @@ -81,21 +79,13 @@ static int snooze_loop(struct cpuidle_device *dev, > HMT_very_low(); > while (!need_resched()) { > if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time) { > - /* > - * Task has not woken up but we are exiting the polling > - * loop anyway. Require a barrier after polling is > - * cleared to order subsequent test of need_resched(). > - */ > - clear_thread_flag(TIF_POLLING_NRFLAG); > dev->poll_time_limit = true; > - smp_mb(); > break; > } > } > > HMT_medium(); > ppc64_runlatch_on(); > - clear_thread_flag(TIF_POLLING_NRFLAG); > > local_irq_disable(); > > diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c > index 4e08c9a39172..0ae76512b740 100644 > --- a/drivers/cpuidle/cpuidle-pseries.c > +++ b/drivers/cpuidle/cpuidle-pseries.c > @@ -39,8 +39,6 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv, > { > u64 snooze_exit_time; > > - set_thread_flag(TIF_POLLING_NRFLAG); > - > pseries_idle_prolog(); > raw_local_irq_enable(); > snooze_exit_time = get_tb() + snooze_timeout; > @@ -50,21 +48,12 @@ int snooze_loop(struct cpuidle_device *dev, struct cpuidle_driver *drv, > HMT_low(); > HMT_very_low(); > if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time) { > - /* > - * Task has not woken up but we are exiting the polling > - * loop anyway. Require a barrier after polling is > - * cleared to order subsequent test of need_resched(). > - */ > dev->poll_time_limit = true; > - clear_thread_flag(TIF_POLLING_NRFLAG); > - smp_mb(); > break; > } > } > > HMT_medium(); > - clear_thread_flag(TIF_POLLING_NRFLAG); > - > raw_local_irq_disable(); > > pseries_idle_epilog(); > diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c > index 49078cc83f4a..9eb811b5d8b6 100644 > --- a/drivers/cpuidle/cpuidle.c > +++ b/drivers/cpuidle/cpuidle.c > @@ -236,8 +236,8 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev, > broadcast = false; > } > > - polling = target_state->flags & CPUIDLE_FLAG_POLLING_HARD; > - > + polling = (target_state->flags & (CPUIDLE_FLAG_POLLING_SOFT | > + CPUIDLE_FLAG_POLLING_HARD)); The outer parens are not needed on the right-hand side, or apply !! to it. > /* > * If the target state doesn't poll on need_resched(), this is > * the last check after which further TIF_NEED_RESCHED remote setting > diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c > index a2fe173de117..3bfa251b344a 100644 > --- a/drivers/cpuidle/poll_state.c > +++ b/drivers/cpuidle/poll_state.c > @@ -13,35 +13,29 @@ > static int __cpuidle poll_idle(struct cpuidle_device *dev, > struct cpuidle_driver *drv, int index) > { > - u64 time_start; > - > - time_start = local_clock_noinstr(); > + u64 time_start = local_clock_noinstr(); > + unsigned int loop_count = 0; > + u64 limit; > > dev->poll_time_limit = false; > > raw_local_irq_enable(); > - if (!current_set_polling_and_test()) { > - unsigned int loop_count = 0; > - u64 limit; > > - limit = cpuidle_poll_time(drv, dev); > + limit = cpuidle_poll_time(drv, dev); > > - while (!need_resched()) { > - cpu_relax(); > - if (loop_count++ < POLL_IDLE_RELAX_COUNT) > - continue; > + while (!need_resched()) { > + cpu_relax(); > + if (loop_count++ < POLL_IDLE_RELAX_COUNT) > + continue; > > - loop_count = 0; > - if (local_clock_noinstr() - time_start > limit) { > - dev->poll_time_limit = true; > - break; > - } > + loop_count = 0; > + if (local_clock_noinstr() - time_start > limit) { > + dev->poll_time_limit = true; > + break; > } > } > raw_local_irq_disable(); > > - current_clr_polling(); > - > return index; > } > > --