Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4806297pxb; Thu, 14 Oct 2021 12:19:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHlzrqNQoc6527Qu6RQlWPgh9zvMK2ObmpXEIdhxJWHzhhuazjte/vF6WB2XrEvif4KWwA X-Received: by 2002:a17:90a:4207:: with SMTP id o7mr8083434pjg.192.1634239190534; Thu, 14 Oct 2021 12:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634239190; cv=none; d=google.com; s=arc-20160816; b=hIKFzgpJOkch+uzKoxHDMD0AdQ2T7kn8hKE4BWrxABJkDQF/nrBY3tPKtqpYelSRZf DADTQ3MmksRHAPgdqGd/bwHUgRmazPhZUXQ7cK83js47/8btwFav30Z/Sw9ieKCvQIuo q60Nhr5BPZAIG6604I+XZpQhxzKr6rS0KkTTs/Xdtvz52Ismo62VQ547xPKss4LamkEE tVzg27GG0tI04YEIO6+X/mgRSDqoAjRAa9eSTLpeGrG73qFFA1nQYewr+QDRYV0Tpc/7 fvHESYBrzKZpSoTYKNB0On5avLjCdeTGQyCXsTNCugZhmeAyiD2IEKeOZczdPSU0J3A/ ij7g== 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=jzzZ9zkU/GUllV4qZRlQlXmUhGeFbkVWbMGx4KIDiWM=; b=EP6nEQgu/pDEEjhpW61F+N5LMG/A2FjlmrJFBHyXFKJct6/UUYQ335vOHpW2QEH/qO wTrxoi/2OjYJ5ywCJl2Cg7i14yzhwPO26xByxnWf3PzO48tnLen+FK3gTxZ7Mc4aXEtZ 7WRtxWBZQ09WY5UROsA3RhDFAdeF2gQJVbtaqPRDg/ujZFdmv9/Fi9XIVOPKlcpHtLBX cmPQl/MiswxP8nn0v2Wnsr1kMUI9Ac2s4no3DXS8RTF7BRWg1W5TPqURGzaqrnBxn0yc 8n48RUU8UAo5v7swdoskNBSERwKmpGpTxuzDsMeXP+9FsYPdKVZvbaG7ElzjphbQ08b8 NZFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=inL8IE0B; 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 x3si4677131pgp.147.2021.10.14.12.19.37; Thu, 14 Oct 2021 12:19:50 -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=20210112 header.b=inL8IE0B; 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 S231897AbhJNSAG (ORCPT + 99 others); Thu, 14 Oct 2021 14:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbhJNSAF (ORCPT ); Thu, 14 Oct 2021 14:00:05 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A79DC061570 for ; Thu, 14 Oct 2021 10:58:00 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id w19so27408384edd.2 for ; Thu, 14 Oct 2021 10:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jzzZ9zkU/GUllV4qZRlQlXmUhGeFbkVWbMGx4KIDiWM=; b=inL8IE0B8R5+csw292SRTdl7ZmlAuRjKavBx4sj7PLeCF/ew7YyTPRzex2JQ8TRhAv uI6hWCn0HY1TCWaC6nuc+5JXEjnolA0T/YEc/yDq4ToMjXKWQwAb4Nz5l5/B/QqtlRqq n5Tx5VX8Lb/hWZ1zHGGvzMn7p5Ca8IHFJ5LEeFso8k8mtYl5bjIgIAxhlwksu3Bslnbu sEWvP5bqEAH8qbxc4KNr9/Sj+PMoDgcuCoUY7bI7MBpwwsylOa+if5KDcn9f5Or1DpjN e89WH00hPGPLXrveaIMeNFhirz3GRBtn+TKcbCc/pgF7ndNmAuKime+BEHyfgzjFjHKB ukfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jzzZ9zkU/GUllV4qZRlQlXmUhGeFbkVWbMGx4KIDiWM=; b=OikbmiPwxAyWsc7tAwkVKj5DJ0tfUCdIsT5YCYqbc1Tqfu4Wl5bGKBMBZY5Ri8kXsy PUT5z32Tk4NKaVVkYBDPUsPagFxUns4MtThDEaKKLNdMRZihTfAfXBpy7bSPFEO4fUKN B1TzrhfXfN6TVnhNV17Zkw9q7CU03y4azF3+yn7NTX3A6Es3yvAsJwQSts2Az6njPN4n Cuu4x9PDItHI/CGbHpV8KXfiXpkn+AoWQK86ryge3OZsdNNCRFyyURNuHOGjG9lOWVkY gtOuO0Yso7cFDHjer0jYtyeP8tQSCyUDW0XxTlapCtztbt4TqF0FalllWnlPo91vRSs0 DtTw== X-Gm-Message-State: AOAM530pY8srIitazQLUqBx0y2u5MrmZZwoLQPIKRFUV9tEJPgC4m5Pa ySHi6HdENwRb3fxdSPZ7BoGAxsy86RHFPCthLxj/bA== X-Received: by 2002:a17:906:c252:: with SMTP id bl18mr418348ejb.519.1634234277996; Thu, 14 Oct 2021 10:57:57 -0700 (PDT) MIME-Version: 1.0 References: <20211008000825.1364224-1-joshdon@google.com> In-Reply-To: From: Hao Luo Date: Thu, 14 Oct 2021 10:57:46 -0700 Message-ID: Subject: Re: [PATCH] sched/core: forced idle accounting To: Josh Don Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Joel Fernandes , Vineeth Pillai , linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11, 2021 at 5:31 PM Josh Don wrote: > > On Mon, Oct 11, 2021 at 10:33 AM Hao Luo wrote: > > > > On Thu, Oct 7, 2021 at 5:08 PM Josh Don wrote: > > > -void sched_core_dequeue(struct rq *rq, struct task_struct *p) > > > +void sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags) > > > { > > > rq->core->core_task_seq++; > > > > > > - if (!sched_core_enqueued(p)) > > > - return; > > > + if (sched_core_enqueued(p)) { > > > + rb_erase(&p->core_node, &rq->core_tree); > > > + RB_CLEAR_NODE(&p->core_node); > > > + } > > > > > > - rb_erase(&p->core_node, &rq->core_tree); > > > - RB_CLEAR_NODE(&p->core_node); > > > + /* > > > + * Migrating the last task off the cpu, with the cpu in forced idle > > > + * state. Reschedule to create an accounting edge for forced idle, > > > + * and re-examine whether the core is still in forced idle state. > > > + */ > > > + if (!(flags & DEQUEUE_SAVE) && rq->nr_running == 1 && > > > + rq->core->core_forceidle && rq->curr == rq->idle) > > > + resched_curr(rq); > > > > Resched_curr is probably an unwanted side effect of dequeue. Maybe we > > could extract the check and resched_curr out into a function, and call > > the function outside of sched_core_dequeue(). In that way, the > > interface of dequeue doesn't need to change. > > This resched is an atypical case; normal load balancing won't steal > the last runnable task off a cpu. The main reasons this resched could > trigger are: migration due to affinity change, and migration due to > sched core doing a cookie_steal. Could bubble this up to > deactivate_task(), but seems less brittle to keep this in dequeue() > with the check against DEQUEUE_SAVE (since this creates an important > accounting edge). Thoughts? > I prefer bubbling it up to deactivate_task(). Depending on how many callers of deactivate_task() need this resched, IMHO it is even fine to put it in deactivate_task's caller. Wrapping it in a function may help clarify its purpose. > > > /* > > > @@ -5765,7 +5782,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > > > for_each_cpu_wrap(i, smt_mask, cpu) { > > > rq_i = cpu_rq(i); > > > > > > - if (i != cpu) > > > + if (i != cpu && (rq_i != rq->core || !core_clock_updated)) > > > update_rq_clock(rq_i); > > > > Do you mean (rq_i != rq->core && !core_clock_updated)? I thought > > rq->core has core_clock updated always. > > rq->clock is updated on entry to pick_next_task(). rq->core is only > updated if rq == rq->core, or if we've done the clock update for > rq->core above. I meant 'if (i != cpu && rq_i != rq->core)'. Because at this point, core_clock should already have been updated, is that not the case? Anyway, the tracking of clock updates here is too confusing to me.