From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755353AbcFTO6S (ORCPT ); Mon, 20 Jun 2016 10:58:18 -0400 Received: from foss.arm.com ([217.140.101.70]:33519 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752897AbcFTO6K (ORCPT ); Mon, 20 Jun 2016 10:58:10 -0400 Subject: Re: [PATCH 4/4] sched,fair: Fix PELT integrity for new tasks To: Vincent Guittot References: <20160617120136.064100812@infradead.org> <20160617120454.150630859@infradead.org> <20160617142814.GT30154@twins.programming.kicks-ass.net> <20160617160239.GL30927@twins.programming.kicks-ass.net> <20160617161831.GM30927@twins.programming.kicks-ass.net> <5767D51F.3080600@arm.com> Cc: Peter Zijlstra , Yuyang Du , Ingo Molnar , linux-kernel , Mike Galbraith , Benjamin Segall , Paul Turner , Morten Rasmussen , Matt Fleming From: Dietmar Eggemann Message-ID: <5768027E.1090408@arm.com> Date: Mon, 20 Jun 2016 15:49:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/06/16 13:35, Vincent Guittot wrote: > On 20 June 2016 at 13:35, Dietmar Eggemann wrote: >> >> >> On 17/06/16 17:18, Peter Zijlstra wrote: >>> On Fri, Jun 17, 2016 at 06:02:39PM +0200, Peter Zijlstra wrote: >>>> So yes, ho-humm, how to go about doing that bestest. Lemme have a play. >>> >>> This is what I came up with, not entirely pretty, but I suppose it'll >>> have to do. >>> >>> --- >>> --- a/kernel/sched/fair.c >>> +++ b/kernel/sched/fair.c >>> @@ -724,6 +724,7 @@ void post_init_entity_util_avg(struct sc >>> 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; >>> + u64 now = cfs_rq_clock_task(cfs_rq); >>> >>> if (cap > 0) { >>> if (cfs_rq->avg.util_avg != 0) { >>> @@ -738,7 +739,20 @@ void post_init_entity_util_avg(struct sc >>> sa->util_sum = sa->util_avg * LOAD_AVG_MAX; >>> } >>> >>> - update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, false); >>> + if (entity_is_task(se)) { >>> + struct task_struct *p = task_of(se); >>> + if (p->sched_class != &fair_sched_class) { >>> + /* >>> + * For !fair tasks do attach_entity_load_avg() >>> + * followed by detach_entity_load_avg() as per >>> + * switched_from_fair(). >>> + */ >>> + se->avg.last_update_time = now; >>> + return; >>> + } >>> + } >>> + >>> + update_cfs_rq_load_avg(now, cfs_rq, false); >>> attach_entity_load_avg(cfs_rq, se); >>> } >>> >>> >> >> Doesn't a sleeping !fair_sched_class task which switches to fair uses >> try_to_wake_up() rather than wake_up_new_task() so it won't go through >> post_init_entity_util_avg()? > > It will go through wake_up_new_task and post_init_entity_util_avg > during its fork which is enough to set last_update_time. Then, it will > use the switched_to_fair if the task becomes a fair one Oh I see. We want to make sure that every task (even when forked as !fair) has a last_update_time value != 0, when becoming fair one day.