Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp282142rwd; Wed, 31 May 2023 23:28:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gyM3+SOrGqduV6Nc46UC5SXmYYezyL0e1K6Jx25VV/VMCiuxfoP4+nE2fQ9p+AEmMGZjs X-Received: by 2002:a05:6a20:7350:b0:10f:243c:a6e7 with SMTP id v16-20020a056a20735000b0010f243ca6e7mr10121445pzc.13.1685600922148; Wed, 31 May 2023 23:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685600922; cv=none; d=google.com; s=arc-20160816; b=QFyhueWFNPiAtYBYVwhl70TkllDrriOjJVSI8ITHS7lboOwHL2ijDXJ/Jgvt5x4zQZ DzFgV4B/T/uu+Ueo83Oj8wIeDlIJXzTTu1nUsxq4/kMawfg7qfEygawsN9lrN2WWSmyq ZjRg+zYOP3iLbHn36s46m0hVIUexIMEFey2fMXxOId43RLsoDdyprfsCc5lfdcLhdskm Um/AUMDvNcV/R2T4RGC80FGgH9GuF+YVXcoHr2siG581RGNj9sYwai5W3nqvsoCnEt5A nFCCYLXe7VL24ifLAdjoH5fAKhrEa8kbMNcXG9B03Vs3/yL318MTHh7mnN6jR0rW+MXK 9cNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=sjSiEVFvwgKwRefW1DaGSRLOPMcqZfNZ3si0heaKz+s=; b=g4vhr2Ftx3XmKltUeQ8nvmsHArZjmoK1witqAMURNV2qT1CDB7LdWJhnIMwvyHgFSJ l2VsF/t3F22E9HfuQ4xObPDQvjURwj2WvlBVU6ohws04+30FQAdoxIWiA06nHCkBt26k EgKtqTQzCDZcaJihQ04slxk/lM82wTtUPIYGHfvXYtZJ7zuJysp6nvjdTYnwHkDisPM9 mAhBwNZXtjcbe+oC9bvTs9T6vZhFtv0kyMYw/vMzvahx9nzzGPOwZuVtsEdS8EhWwz+Q 1IeVzHUK5dUPhx/Rk8u+BuMLSyxD8xxrL9PXkpRJ7+hw4jzZWKrQ+2MgKcBo54TKFlis xdgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=b1+z3n6F; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a170902b78300b001a97fd670d5si1116894pls.367.2023.05.31.23.28.29; Wed, 31 May 2023 23:28:42 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=b1+z3n6F; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbjFAGA3 (ORCPT + 99 others); Thu, 1 Jun 2023 02:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbjFAF7q (ORCPT ); Thu, 1 Jun 2023 01:59:46 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F036E4E for ; Wed, 31 May 2023 22:59:16 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-568a8704f6dso6802827b3.1 for ; Wed, 31 May 2023 22:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685599155; x=1688191155; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sjSiEVFvwgKwRefW1DaGSRLOPMcqZfNZ3si0heaKz+s=; b=b1+z3n6FNugQyOLOwnC3N2SWHkOrz7xV94xG8m9n8T+0UtNRNf7tXQzr1gSb+gwSsE oKuKYcSx1oWajoDSZJZYCZ1EYISY9gpjvfSeIsDpBqO73H+ysVsENVAN+wDDw75sgj11 zdnsq3MoAdutrtns1l7bJzmL6oFwp+FLqJ1DYtK5cBt7iQEoYzg8oBHu0fr99Vc5tMgh amfxXyWpjoC3CX5ZtaUQ3ScErPeOQDErr9+Funxhn69wsf6+/LOeU8oCRkIdqYo39cJT SXqZ6Db9Ls1W59tP78/BE4pOtP39ZF+OyFG1LJPMX/k7FbxbN52LaJ14p0CppD1kyKD6 xdyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685599155; x=1688191155; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sjSiEVFvwgKwRefW1DaGSRLOPMcqZfNZ3si0heaKz+s=; b=VWCTB998tITwkqMLxFIz7rdhiaohAYGGMPiCPv2VR+MS4fx1bycD2nOCuME7EujqcY ZDgtRN1ltD5Jtu3oUZnvaawTp27f/LQ4TU54S5Wf5ktr1ZODWXCFEY2BgiY/toNwXjfm jEow4dLhPe5Uhkl9vXXPLvGwwAtOcMuFLltKjKOXA5Wct0FmerZn7xqXGXSHMOy3v2FU 9RgoYYbh0ezfon7YVZYI+dvPTk3cei3a9bWasqtE4jmCeghK+XcN8XpSALmO22b7sbqu /lnmebJ4tza2nDlV8F26bocTSlVh3nSZ8DzXQeskbUEr9ebsqdfqb3OSj3wrv5600QEG EA6w== X-Gm-Message-State: AC+VfDxN+TYbHMOGmWFS4N6xhhkJJ8p77wP7a+PecB1KWgqyxhZd9gRC yyBsxycZW1IMdF+eyuW2TaA0DTN/ox7m5uOmuHLWnYcuxHk2Sc74zhI6YS66kcTgc9B2qRyOQBn ASjQMRpC+GFjBHcg25r0tN6J0APNG00x1M6AlDRkTPdi6eTHT6CtkfX8j5khq2N+y6fvX7q8= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:af4d:0:b0:565:9e73:f92f with SMTP id x13-20020a81af4d000000b005659e73f92fmr4558928ywj.10.1685599155660; Wed, 31 May 2023 22:59:15 -0700 (PDT) Date: Thu, 1 Jun 2023 05:58:14 +0000 In-Reply-To: <20230601055846.2349566-1-jstultz@google.com> Mime-Version: 1.0 References: <20230601055846.2349566-1-jstultz@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230601055846.2349566-12-jstultz@google.com> Subject: [PATCH v4 11/13] sched: Fix runtime accounting w/ proxy-execution From: John Stultz To: LKML Cc: John Stultz , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Youssef Esmat , Mel Gorman , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 The idea here is we want to charge the selected task's vruntime but charge the executed task's sum_exec_runtime. This way cputime accounting goes against the task actually running but vruntime accounting goes against the selected task so we get proper fairness. Cc: Joel Fernandes Cc: Qais Yousef Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Valentin Schneider Cc: Steven Rostedt Cc: Ben Segall Cc: Zimuzo Ezeozue Cc: Youssef Esmat Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E . McKenney" Cc: kernel-team@android.com Signed-off-by: John Stultz --- kernel/sched/fair.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 43efc576d2c6..c2e17bfa6b31 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -891,22 +891,36 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq) } #endif /* CONFIG_SMP */ -static s64 update_curr_se(struct rq *rq, struct sched_entity *curr) +static s64 update_curr_se(struct rq *rq, struct sched_entity *se) { u64 now = rq_clock_task(rq); s64 delta_exec; - delta_exec = now - curr->exec_start; + /* Calculate the delta from selected se */ + delta_exec = now - se->exec_start; if (unlikely(delta_exec <= 0)) return delta_exec; - curr->exec_start = now; - curr->sum_exec_runtime += delta_exec; + /* Update selected se's exec_start */ + se->exec_start = now; + if (entity_is_task(se)) { + struct task_struct *running = rq->curr; + /* + * If se is a task, we account the time + * against the running task, as w/ proxy-exec + * they may not be the same. + */ + running->se.exec_start = now; + running->se.sum_exec_runtime += delta_exec; + } else { + /* If not task, account the time against se */ + se->sum_exec_runtime += delta_exec; + } if (schedstat_enabled()) { struct sched_statistics *stats; - stats = __schedstats_from_se(curr); + stats = __schedstats_from_se(se); __schedstat_set(stats->exec_max, max(delta_exec, stats->exec_max)); } -- 2.41.0.rc0.172.g3f132b7071-goog