Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp365852rwb; Thu, 27 Jul 2023 14:07:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEhTpzlI7AEGH31XXCtZh+jKZ/+I3bwkQ+g1UFuNYsO21fCws36bgfluqsEC9DkJIAkPLvy X-Received: by 2002:a05:6870:32cb:b0:1bb:90c3:bb09 with SMTP id r11-20020a05687032cb00b001bb90c3bb09mr763981oac.9.1690492050898; Thu, 27 Jul 2023 14:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690492050; cv=none; d=google.com; s=arc-20160816; b=sJ4M78W0hfn1fLqPBv8Z6RcByQAu6JG503F/Ssc4onJSUYM0d2VPZHk63hwzEQ3nNj lpeaeVA2OM10T3h7ogluhsLOVXY32rxhsWuVW+n6+3BAetYenv4UGHhRrEZauEd+St7E R/yymxMeoI2Aycvd1tkYKmgNUFB1D9rQRXrGQffIcBB8djElf90drm+X0VfU26ITN/o4 3QW48T1qLwgDFTpzKhY3LUnQbRYdPXK75c0aHimhXp6imM/IfXh+7/tzc5QAybpZiznV QTPxGG6F0+t8yvgL0U0P4NH3Pjbx+GEozukjtKbkn4zIgvKiPqGxmduTa64Aq6mgXZ8i yqBw== 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=FjjzMkACOCZtbhPscQIEM3tXvV94yjwitkJ+tqsf4ps=; fh=f/xCxIsvm9BGpuen8ayDUZXpdusMpfggoCa0JUYoA7o=; b=EXUlO7M+ktVRNdTMK9IyvP8oGzBH1RED5d/9r2eTXpr4f/k4NF6GW8tlAJto+URjrC okyDn7tmdEK+po2RvBh/XFV2yQvefh+M0/6ztF9jeT90Lb5mcxdRgFvjewyHfDtch/P8 aRtPAH6G6oaMt+Nz7igBPUL6xDWlDxyRJ3P7uiZBRsK+JTWNZqRBX/VlZeCZI1G1C9y0 L5LfGBql8sw1bl69ZqXdSmrRlquwrm+LKIxOfYid6TbFWYulWMNFWbnplRqgwaBieVBm fph2X1mACNceHsJlhuys4PapD9j5n+rWR5VjD/5XujDFQLNW/l3EPew90EfJxoazrCq9 Q0MQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a634951000000b0055acc7f8088si1674057pgk.301.2023.07.27.14.07.18; Thu, 27 Jul 2023 14:07:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232723AbjG0UNL convert rfc822-to-8bit (ORCPT + 99 others); Thu, 27 Jul 2023 16:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbjG0UNK (ORCPT ); Thu, 27 Jul 2023 16:13:10 -0400 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADECBE47; Thu, 27 Jul 2023 13:13:08 -0700 (PDT) Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-56475c1b930so176181eaf.0; Thu, 27 Jul 2023 13:13:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690488788; x=1691093588; 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=L5Z31Dq5VWK2apYQ/bvG19BYq0hISSJX9VnwC0J6vTg=; b=BQkYGyaX0c0jsh/oaidhkkGbXEVjca9dtOXnTqqV64piuemI2+z9X6SGLxi50vQ5nv 6cXqgUzr1if6W8dchD/aNQYCkYHbL0ODQoUGNlI9TPuw6PtfClYQRuWYrIbqtS6Q95Fw TvsIwYg2lbpCe0/o28DXhfz5EhTFYXfcHChYh+3gxjUt+/qKN1w+a+OlGGsbL8IHtd2z kXzh1WUfwiVx4xly91PVqpdKp/mRHSqygQyVdPP7mGQVMlnM4OpAIpAwIH9hhUPvOsTr R+ijs6KK5Wmz7RqkZ9ZEdZrTKoj8//fRYjZYVu3C+0KER69QjpQiVA45Nl33rYjl+3Wo GIVA== X-Gm-Message-State: ABy/qLbNXiLOpKZfAE/M52Z24J9tfl/7Oeu+0DN6TsVb7tOy/JNe1W6D PfZW0dgZspKzyfamlXT2WUIUlkFWsFaVBos1E9d3XTkc X-Received: by 2002:a4a:db86:0:b0:560:b01a:653d with SMTP id s6-20020a4adb86000000b00560b01a653dmr565021oou.0.1690488787631; Thu, 27 Jul 2023 13:13:07 -0700 (PDT) MIME-Version: 1.0 References: <4506480.LvFx2qVVIh@kreacher> In-Reply-To: <4506480.LvFx2qVVIh@kreacher> From: "Rafael J. Wysocki" Date: Thu, 27 Jul 2023 22:12:56 +0200 Message-ID: Subject: Re: [PATCH v1] cpuidle: teo: Update idle duration estimate when choosing shallower state To: Linux PM Cc: LKML , Peter Zijlstra , Anna-Maria Behnsen , Frederic Weisbecker , Kajetan Puchalski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 27, 2023 at 10:05 PM Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > The TEO governor takes CPU utilization into account by refining idle state > selection when the utilization is above a certain threshold. The idle state > selection is then refined by choosing an idle state shallower than the > previously selected one. > > However, when this is done, the idle duration estimate needs to be updated > so as to prevent the scheduler tick from being stopped while the candidate > idle state is shallow, which may lead to excessive energy usage if the CPU > is not interrupted quickly enough going forward. Moreover, in case the > scheduler tick has been stopped already and the new idle duration estimate > is too small, the replacement candidate state cannot be used. > > Modify the relevant code to take the above observations into account. > > Fixes: 9ce0f7c4bc64 ("cpuidle: teo: Introduce util-awareness") > Signed-off-by: Rafael J. Wysocki > --- > > @Peter: This doesn't attempt to fix the tick stopping problem, it just makes > the current behavior consistent. > > @Anna-Maria: This is likely to basically prevent the tick from being stopped > at all if the CPU utilization is above a certain threshold. I'm wondering if > your results will be affected by it and in what way. > > --- > drivers/cpuidle/governors/teo.c | 33 ++++++++++++++++++++++++++------- > 1 file changed, 26 insertions(+), 7 deletions(-) > > Index: linux-pm/drivers/cpuidle/governors/teo.c > =================================================================== > --- linux-pm.orig/drivers/cpuidle/governors/teo.c > +++ linux-pm/drivers/cpuidle/governors/teo.c > @@ -397,13 +397,22 @@ static int teo_select(struct cpuidle_dri > * the shallowest non-polling state and exit. > */ > if (drv->state_count < 3 && cpu_data->utilized) { > - for (i = 0; i < drv->state_count; ++i) { > - if (!dev->states_usage[i].disable && > - !(drv->states[i].flags & CPUIDLE_FLAG_POLLING)) { > - idx = i; > + /* > + * If state 0 is enabled and it is not a polling one, select it > + * right away and update the idle duration estimate accordingly, > + * unless the scheduler tick has been stopped. > + */ > + if (!idx && !(drv->states[0].flags & CPUIDLE_FLAG_POLLING)) { > + s64 span_ns = teo_middle_of_bin(0, drv); > + > + if (teo_time_ok(span_ns)) { > + duration_ns = span_ns; > goto end; > } > } > + /* Assume that state 1 is not a polling one and select it. */ Well, I should also check if it is not disabled. Will send a v2 tomorrow. > + idx = 1; > + goto end; > } > > /* > @@ -539,10 +548,20 @@ static int teo_select(struct cpuidle_dri > > /* > * If the CPU is being utilized over the threshold, choose a shallower > - * non-polling state to improve latency > + * non-polling state to improve latency, unless the scheduler tick has > + * been stopped already and the shallower state's target residency is > + * not sufficiently large. > */ > - if (cpu_data->utilized) > - idx = teo_find_shallower_state(drv, dev, idx, duration_ns, true); > + if (cpu_data->utilized) { > + s64 span_ns; > + > + i = teo_find_shallower_state(drv, dev, idx, duration_ns, true); > + span_ns = teo_middle_of_bin(i, drv); > + if (teo_time_ok(span_ns)) { > + idx = i; > + duration_ns = span_ns; > + } > + } > > end: > /* > > >