Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3781630imm; Mon, 4 Jun 2018 09:08:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIlZb6dqSIdL3PLfn69KD/BcrrtzrS1vJECv+lzUlzkENY7VnsLsISquG5ai75NvbbkDCmK X-Received: by 2002:a65:5006:: with SMTP id f6-v6mr3645340pgo.116.1528128492490; Mon, 04 Jun 2018 09:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528128492; cv=none; d=google.com; s=arc-20160816; b=jSTuvykEDfWEe2Vmnpu1m1D+Vfeh1APFICOSuk99N6C4GDFQx/kHOUOxWxDEM4ZjxL sYIwo6WXZy/aa5JrrkWg68mguwTj3AHETWVakij6VeDTALrkgjja3S5ZpJ5Vcpqd1mRq S74EjnLuThUaF1aIIWJAlS0A53S3RV7fducLhkewZEv0ZMUrj9LSW7qmA/L1DwRmu3vw 2KhHZ2wC062nIJHt32QE1WkTrvZ8ih/yOJSCUC9OKt1JFJLVP8j7OESfeGH5CJkpMdyT X9ddU7cp0WaDFAr8jl2XoCI3gEhg0LO3vh5ErzBQ1I/nUJbsORK4hUI+PqhMqOItQxZ2 /fZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kDSQ6yXaq7zIHwvf0CJ8J8UEr9H/rohO4/xVeZHWcAo=; b=f/WpUXWqf6PhqGH2eibujihsBqfQ+3MfWO7H8AsSmPhAwmiqZ7recRt/xX69SWvRkp woxli0KAwIZBY/l29/ERH7m0hQhxwwMWNoJJ7F79psIiGXS3OrqrkiElyLMVRw/vi+pU Syte4rL/3ltLS0DdtmIebf5luDrhrrP3H99DkmXP0FvJc/uPFmoFFtePi1732ap52GWb UfrVo3kyWhZ46DFKlvsGrC1V3S9LGxuZk9fbMy5B220BauJfHDOiInyoLjD7cRHJuU5V XaxbNaw00CLm6PEScPzb8LsKha//r7/aAi0DrBPi6Bwrf2OxqgX3ddDH6ozfDKe5bM9B Xq9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c125-v6si5825046pga.413.2018.06.04.09.07.57; Mon, 04 Jun 2018 09:08:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751441AbeFDQGT (ORCPT + 99 others); Mon, 4 Jun 2018 12:06:19 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751058AbeFDQGP (ORCPT ); Mon, 4 Jun 2018 12:06:15 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA7B315AD; Mon, 4 Jun 2018 09:06:14 -0700 (PDT) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.210.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 53E193F557; Mon, 4 Jun 2018 09:06:12 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Joel Fernandes , Steve Muckle , Todd Kjos Subject: [PATCH 1/2] sched/fair: pelt: use u32 for util_avg Date: Mon, 4 Jun 2018 17:05:59 +0100 Message-Id: <20180604160600.22052-2-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180604160600.22052-1-patrick.bellasi@arm.com> References: <20180604160600.22052-1-patrick.bellasi@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The util_avg signal is used to track the utilization (i.e. RUNNING time) of SEs and RQs. Its values are computed according to the PELT algorithm and thus, for SE, they are bounded to an (internal) representation which uses 20bits. For RQ instead they are technically un-bounded, since when tasks are migrated across RQs we sum their utilization to the destination RQ. We currently use an unsigned long to track util_avg which maps into a 64bits storage on 64bits systems. However, 32bits should be good enough for all practical usages. Indeed, even for RQs, the remaining 12bits allows to track up to 4K 100% tasks concurrently RUNNABLE on a single CPU. Since the sched_avg data structure already completely fits a 64B cache line, let's get back 4B by using u32 to track util_avg. The recovered space could be conveniently used to fit other load tracking related metrics into the same cache line. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Vincent Guittot Cc: Juri Lelli Cc: Todd Kjos Cc: Joel Fernandes Cc: Steve Muckle Cc: Dietmar Eggemann Cc: Morten Rasmussen Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- include/linux/sched.h | 2 +- kernel/sched/debug.c | 2 +- kernel/sched/fair.c | 17 ++++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 28ff3ca9f752..9d8732dab264 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -402,7 +402,7 @@ struct sched_avg { u32 period_contrib; unsigned long load_avg; unsigned long runnable_load_avg; - unsigned long util_avg; + u32 util_avg; struct util_est util_est; } ____cacheline_aligned; diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 15b10e210a6b..a985789eeb9c 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -541,7 +541,7 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) cfs_rq->avg.load_avg); SEQ_printf(m, " .%-30s: %lu\n", "runnable_load_avg", cfs_rq->avg.runnable_load_avg); - SEQ_printf(m, " .%-30s: %lu\n", "util_avg", + SEQ_printf(m, " .%-30s: %u\n", "util_avg", cfs_rq->avg.util_avg); SEQ_printf(m, " .%-30s: %u\n", "util_est_enqueued", cfs_rq->avg.util_est.enqueued); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e497c05aab7f..f74441be3f44 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -750,19 +750,22 @@ static void attach_entity_cfs_rq(struct sched_entity *se); void post_init_entity_util_avg(struct sched_entity *se) { struct cfs_rq *cfs_rq = cfs_rq_of(se); - struct sched_avg *sa = &se->avg; long cap = (long)(SCHED_CAPACITY_SCALE - cfs_rq->avg.util_avg) / 2; if (cap > 0) { - if (cfs_rq->avg.util_avg != 0) { - sa->util_avg = cfs_rq->avg.util_avg * se->load.weight; - sa->util_avg /= (cfs_rq->avg.load_avg + 1); + struct sched_avg *sa = &se->avg; + u64 util_avg = READ_ONCE(sa->util_avg); - if (sa->util_avg > cap) - sa->util_avg = cap; + if (cfs_rq->avg.util_avg != 0) { + util_avg = cfs_rq->avg.util_avg * se->load.weight; + util_avg /= (cfs_rq->avg.load_avg + 1); + if (util_avg > cap) + util_avg = cap; } else { - sa->util_avg = cap; + util_avg = cap; } + + WRITE_ONCE(sa->util_avg, util_avg); } if (entity_is_task(se)) { -- 2.15.1