From nobody Sat Feb 7 15:10:54 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 627591C1F13 for ; Mon, 25 Nov 2024 19:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564334; cv=none; b=I3U/qC+4L0PC+BTjScP2L5jDdYjkDsedewxO8f5ihb4gDq0TUn1CQ1kRQlYI5NdM5a24YJo1qR8S6vy5ldC1RWQ/pGYQUCkoax5RSDpafy0x5SRoOlZr6jlT3C9uM5RPwQaFQZxVz6z5DKBSWC/5DNbUbC/HHEDeneQAr2G3L3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564334; c=relaxed/simple; bh=JXRMYnd0ucUfDV5Qzz/TxTcy1aNUDBMF3uGjnrjG3tE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Az2+07y5baCkuFhmRs5FK8G2ywUaQmTx9YBuxwVQG8GH30md5e+jPcinYJDxRPfcxAsF9Bv8T4xsA6DR0bUTd+U6fX1eMMoI92mWdep1KrcHdaDxAyDC42W4qxM4awvdGnTBCaKLMI3MpaVkGUXiNlCcXH4kqTO0RFY8DtzCefY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wKe2+NPY; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wKe2+NPY" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-724e565cd84so3018865b3a.3 for ; Mon, 25 Nov 2024 11:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732564331; x=1733169131; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lWiy5IaznfIpEZ7WIDYWdQnPT0DdeHKfKM1+RyqUBX4=; b=wKe2+NPYC5z6UtHAJYhc6BtMB8HXXBrjAEBQImA+jG1Iq+763IMt/GTrZ7z4W7YUcR Q7p5CBRP7pV8ahiNHKv8iJAxYXq0tyCbf60anNKzjIsKD26YQtlDfVdYfoDzZ9FEKCtV WvZdf5p92PYRZYhb9b5DuiP3KV6csPZTir72/EfZSDG0P1T2nWgSSJ6MCr+2up/pv3iH pXnwDaICLIj7X6kY2+Rk5SF17fyxRn8VXwspRPfzKCYw+3wxBU8obOEyUfF92fIsUhxH fQyXaMy2egd1GQPbyXJjSkDB1teA6sxAHfSlSVk58OlEXIK5eSCoGtSlD+ElaAwKE7Vo VDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564331; x=1733169131; 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=lWiy5IaznfIpEZ7WIDYWdQnPT0DdeHKfKM1+RyqUBX4=; b=oEqvupBozmf2d5UvmgLIZazOGToW7oXZ2VzN7TY/7UioENZQITaUplM2rxgFro7pdD oDDqoP6k5ynV6vGEoiLfdRNrp2QBR0c3mHUyXO/f92mTyZBOjJfvHUWgMSya91xdXhQt siXfqKY8vEVcpTiuV0bhJ1M6TRMGiw2YjNrpy4Kmd9UNSlnzuutZ0td48bQFrrVp1oJk RTXrHUUboGyIL7qNmAu+VieN1I5EnhE2UstuqIEep8+Q0dT43qgFqJTRaOqJ6hlSzOMF CmrDdvy3aCcPzBZeVCa09jE5GHc9zt7Vg7cvhOybUIDvpAn7JF7Vbs3F8i/Z9m2kqILi UZzg== X-Gm-Message-State: AOJu0YzUcQ/frOFDWA2Sljw/N9CeoRLPSwR6dYijhFuRfA6GH+N3wagW wX4xFlJSam0NhkcOGfkLAmyVKbhiZz9vf98vMbnPTTrJJfMmnaskL7oXigj7WM7BGh4ue9OPnwV EBWqE1Wt+nJ5z7xJp/PL/infw7i74lGNQmyR2Rp2E0ZlME5ugClrO3u5PhhfIXOhO8h3z/w8JQK SvPu0Xy0jm7+TaUnH2xIUwDr6yC2kht9ssa3TAYEzcKSWK X-Google-Smtp-Source: AGHT+IFHXNDeOJVe69oi2JM6BqGCpzCO91LAcGe7Rb0UVct3JkWQPPkAKq+XzFe/oHCnanpggxnzCwqTROQ6 X-Received: from pfbf2.prod.google.com ([2002:a05:6a00:ad82:b0:724:fa30:554f]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:aa0e:b0:725:14fd:f62c with SMTP id d2e1a72fcca58-72514fdf9cfmr3665231b3a.15.1732564331587; Mon, 25 Nov 2024 11:52:11 -0800 (PST) Date: Mon, 25 Nov 2024 11:51:57 -0800 In-Reply-To: <20241125195204.2374458-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241125195204.2374458-1-jstultz@google.com> X-Mailer: git-send-email 2.47.0.371.ga323438b13-goog Message-ID: <20241125195204.2374458-4-jstultz@google.com> Subject: [RFC][PATCH v14 3/7] sched: Fix runtime accounting w/ split exec & sched contexts 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 , Mel Gorman , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , Daniel Lezcano , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The idea here is we want to charge the scheduler-context task's vruntime but charge the execution-context task's sum_exec_runtime. This way cputime accounting goes against the task actually running but vruntime accounting goes against the rq->donor 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: Mel Gorman Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Cc: Metin Kaya Cc: Xuewen Yan Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: Daniel Lezcano Cc: kernel-team@android.com Signed-off-by: John Stultz --- kernel/sched/fair.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index fbdca89c677f4..ebde314e151f1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1131,22 +1131,33 @@ static void update_tg_load_avg(struct cfs_rq *cfs_r= q) } #endif /* CONFIG_SMP */ =20 -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 =3D rq_clock_task(rq); s64 delta_exec; =20 - delta_exec =3D now - curr->exec_start; + delta_exec =3D now - se->exec_start; if (unlikely(delta_exec <=3D 0)) return delta_exec; =20 - curr->exec_start =3D now; - curr->sum_exec_runtime +=3D delta_exec; + se->exec_start =3D now; + if (entity_is_task(se)) { + struct task_struct *running =3D 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 =3D now; + running->se.sum_exec_runtime +=3D delta_exec; + } else { + /* If not task, account the time against se */ + se->sum_exec_runtime +=3D delta_exec; + } =20 if (schedstat_enabled()) { struct sched_statistics *stats; =20 - stats =3D __schedstats_from_se(curr); + stats =3D __schedstats_from_se(se); __schedstat_set(stats->exec_max, max(delta_exec, stats->exec_max)); } --=20 2.47.0.371.ga323438b13-goog