Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp260826rdb; Tue, 19 Dec 2023 16:21:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8qZJZanBPJ6KkdtF4YoPvb7CA3p73ooyfwexoQRghvJGyE18ZCJCNfc36jH4UEVbg23zT X-Received: by 2002:a05:6e02:1a44:b0:35d:59a2:332b with SMTP id u4-20020a056e021a4400b0035d59a2332bmr27030473ilv.47.1703031690753; Tue, 19 Dec 2023 16:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703031690; cv=none; d=google.com; s=arc-20160816; b=nR0wL5yUmvlYUAgve6OzYfnWkGj1rtusxGllsFhhijQsCcarwA1NKUMeYxLrFUbKNV NL5IRIg7InPbjrVFV6Idd7zQLWYq747RlnRa8ZUFtGMjxErgxA7oW5OsLQJ3l3c4ab0D XovvUFfd2KezHrBEe9BXF7G6fmMz6y2w8U5ACn2QGUEUF9mNAAKeQkeG8woTpyWOumZ4 rv4H9wJial7+DacvuoWAtWYZEp9fEipkLO+1PERK8zcitxD+KUe0rj5QsygHruWqQnWN xI+PiH7wO+8//kXbBWAVwe6Oyr6jS8VDDypKJTeIC60zv5+nuX4r+KVvg++sO0u2a6IX kqvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=cuXcWz7no4J7hYPFBrTfbHGW+LQBOb7rSCL/XXuOMcE=; fh=lq1k4m46TqOToIb7rHC/F2KmHTJTjmaV9sS3Am9W7nA=; b=eqOQfSyLDaz9ieslW9vvNPPQz+7lZ2tJXJHkGrScxNGAlsenTNVsFmpRzMHkE2CH4H bjNm2h4WGKb3dcFuo0udndwUhO4p/t8YYtAaBMikjRPTrnxzYsxJduPUzW+h2S0ixaAr Vgy7Rhx4VWIWXYATjZXT6BwcPFcQWPOhnKevUwKeMJ96fgTs69LCJekpUs/4XhmW70Xz 36Q0M09gDz9gZstpsBZcviToJD1H8Ci6QXKP46IcVJPJhQlNVA9zYe5gtl3aR6TZNSm7 Ix5aZ23djej0hyaq3ZbarRptu0eSBO6rA4l9GA6353kkhgmq1JCzOLow7GBfc4BThV+1 z79g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hdc7kpd0; spf=pass (google.com: domain of linux-kernel+bounces-6144-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f15-20020a65628f000000b005c66e4949a8si20491536pgv.246.2023.12.19.16.21.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 16:21:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6144-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hdc7kpd0; spf=pass (google.com: domain of linux-kernel+bounces-6144-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5FEF1288007 for ; Wed, 20 Dec 2023 00:21:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0280E14AA0; Wed, 20 Dec 2023 00:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hdc7kpd0" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 9D473FBF9 for ; Wed, 20 Dec 2023 00:19:19 +0000 (UTC) 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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5e744f7ca3bso28795007b3.2 for ; Tue, 19 Dec 2023 16:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703031558; x=1703636358; 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=cuXcWz7no4J7hYPFBrTfbHGW+LQBOb7rSCL/XXuOMcE=; b=Hdc7kpd0JSlaT6HaqU305GT9p2q+6sERQ+Tawqr7rtKFHHnhymgsIXAPPxiGdO0uEQ wrWzuDOQvYyE8HJkwjxRJBGs/KBtvF5EHixfSqxgxg5v89+/VZCf3pVlZDLIoPLEYdyn xREssLNiBELIXorXgCF58uuECIqIBEuftfN1RndRJ3bBw06XoJadHxmzhA6cAVoonx7f yJib8bO1AKl8nykmM2DUWOIdhnOeLdknNbkyIkryeikF0o8w+1/6tbel3HCbeEVYGY85 GSx4Sp4pmsIBjblBsZqqOnJnZ7UxpwbNjuyEHEzdCfmn0D4kms5xZ/OjksFdsJwl77Bt MD6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703031558; x=1703636358; 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=cuXcWz7no4J7hYPFBrTfbHGW+LQBOb7rSCL/XXuOMcE=; b=I6ei6OQyHjjxoMH/m/jOJdvEtWqmRiAil5bPJbwkGqdOTA8kExAsloFQEqmoNX+CB8 A6XedcFbveylXpKLMCbqm1rG/ZfqLrTiO1CCQeEI67E7P/XXUwX8WfVxmdTDkNxyG5Mq HW3BmCiNOQFwR3c/u6MJ9d8hKLqDk8LEA5rNsj/bFcG3rooPH0QoKNf4qvspwN8J5S8u JFd1Oi7u74fJVrsAp0XEbg33yydlrXUFbPLq6vJoG9ksJeSzmimc2xKv3paMTX68ssBL h84mjjNCZ8ZyfG7pWJDiKZLiWgk2Qd+Qv5hj/65RnRAAw8ZPL/sPJ6nWUfV4iZhDdb0d PXRQ== X-Gm-Message-State: AOJu0YxJ+pzu4uY0QYWZ83Jiuw3TAI76oYpwVeUlp7hZiliycrRDGz6h XBd0zgbE+GWZ5KorFiz4Ena90SlerPSW/ndbsfwPvohCf1Ir3bb/eEGaZtKgJH2TIxWLHKT3yVD fNThN5cWWAZPFOfyucWvgLNgJXu8mR+Oyr7kZsCJL/jHa4CmEr70YjE34hdYTPz4fsWBOGjQ= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:690c:f09:b0:5e6:27ee:67fb with SMTP id dc9-20020a05690c0f0900b005e627ee67fbmr1972577ywb.4.1703031558554; Tue, 19 Dec 2023 16:19:18 -0800 (PST) Date: Tue, 19 Dec 2023 16:18:20 -0800 In-Reply-To: <20231220001856.3710363-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: <20231220001856.3710363-1-jstultz@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231220001856.3710363-10-jstultz@google.com> Subject: [PATCH v7 09/23] 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 , Youssef Esmat , Mel Gorman , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , kernel-team@android.com 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 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: Metin Kaya Cc: Xuewen Yan Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: kernel-team@android.com Signed-off-by: John Stultz --- kernel/sched/fair.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 07216ea3ed53..085941db5bf1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1129,22 +1129,35 @@ 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.43.0.472.g3155946c3a-goog