Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2226401rwl; Fri, 6 Jan 2023 03:43:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXu14zWMkpxGkGclkHmZ+kqNE6uiJp+gRC5VuUMxE2bHjLj7wAzchkJSA5jzZLJK7/dyF/nx X-Received: by 2002:a17:907:d042:b0:7c1:7145:5b3c with SMTP id vb2-20020a170907d04200b007c171455b3cmr42389980ejc.46.1673005411439; Fri, 06 Jan 2023 03:43:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673005411; cv=none; d=google.com; s=arc-20160816; b=HH6w10nm+zPbjqI2PR6iS12cZXOMI9YuXIMgtN4IBhSbe4NR1a3PbxdB9EAq1mS+4a 2x4iNh1/EbyvemuYsBfMKbptKWOIUC8rVTRX4TI7HE/ND5W6ruyCRkKJG0yvMb+Utb1l hnggzfkCzdXprZtv8EgZqywo/w8N+LRtx8mZaD0edF1hwWb7MFrLK4/XJvhucVGviYTb F/zSJ9d/w5xlsu7wAFV6+WmxscjpHU5kz89+yJNDYdHk69dxcZgbZkY/EjSZoGaY070m Xf3JWiXNKbpuSFjGEoIgzUalQNFdnx3arTrZ0LjxG02NzqZOxpdkui7ZJoZBaaofHD+H Yvmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=UbRINRGskfFR02GIjtNPL/ISfheGEe0UyLLhRJPTJOs=; b=R4/WhSvsk43UCYrU6w+Rf/AxocyMtEeHX08qJK/seHWVeIGUtYV9wUPepYgMjhVYoM 2w9oQcE56yPK8g9gZi1FSRqoKfrd2W/4T1cvvgbUNojuiGFKuxP1RgVuGIOK0nrkY4JW E16RXzYuqOdTmJfHyQL6Qr5V1zGMVaQx6n9hmEPLciEk318RWG4GQNa184rmeBAlQc+f K2NVeqHN5BPRkoYNLi7x1M60xWZoB5HJ2RZaenVb0IOHpyOBcfdS44taSE7smPU8/0vK uqdMewoN4hmmqHWjPMEkdodxAaVzCkxIEr3Zg/bYodGJkOIQDznh0YYsGqp3XpcS/tlQ 5k9A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb6-20020a170907160600b008366ae33eb6si1294561ejc.580.2023.01.06.03.43.18; Fri, 06 Jan 2023 03:43:31 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjAFL2f (ORCPT + 54 others); Fri, 6 Jan 2023 06:28:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjAFL2d (ORCPT ); Fri, 6 Jan 2023 06:28:33 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A642126C0 for ; Fri, 6 Jan 2023 03:28:31 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1772A11FB; Fri, 6 Jan 2023 03:29:13 -0800 (PST) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B9FE53F23F; Fri, 6 Jan 2023 03:28:27 -0800 (PST) Message-ID: <1913041e-ee67-1e65-68fa-ef08b97ed9d5@arm.com> Date: Fri, 6 Jan 2023 12:28:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [RFC PATCH v4 1/2] sched/fair: Introduce short duration task check Content-Language: en-US To: Chen Yu Cc: Peter Zijlstra , Vincent Guittot , Tim Chen , Mel Gorman , Juri Lelli , Rik van Riel , Aaron Lu , Abel Wu , K Prateek Nayak , Yicong Yang , "Gautham R . Shenoy" , Ingo Molnar , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Valentin Schneider , Hillf Danton , Honglei Wang , Len Brown , Chen Yu , Tianchen Ding , Joel Fernandes , Josh Don , linux-kernel@vger.kernel.org References: <82689dd6-9db1-dd00-069b-73a637a21126@arm.com> From: Dietmar Eggemann In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 On 06/01/2023 09:34, Chen Yu wrote: > Hi Dietmar, > thanks for reviewing the patch! > On 2023-01-05 at 12:33:16 +0100, Dietmar Eggemann wrote: >> On 16/12/2022 07:11, Chen Yu wrote: >> >> [...] >> >>> @@ -5995,6 +6005,18 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) >>> >>> static void set_next_buddy(struct sched_entity *se); >>> >>> +static inline void dur_avg_update(struct task_struct *p, bool task_sleep) >>> +{ >>> + u64 dur; >>> + >>> + if (!task_sleep) >>> + return; >>> + >>> + dur = p->se.sum_exec_runtime - p->se.prev_sum_exec_runtime_vol; >>> + p->se.prev_sum_exec_runtime_vol = p->se.sum_exec_runtime; >> >> Shouldn't se->prev_sum_exec_runtime_vol be set in enqueue_task_fair() >> and not in dequeue_task_fair()->dur_avg_update()? Otherwise `dur` will >> contain sleep time. >> > After the task p is dequeued, p's sum_exec_runtime will not be increased. True. > Unless task p is switched in again, p's sum_exec_runtime will continue to > increase. So dur should not include the sleep time, because we substract Not sure I get this sentence? p's se->sum_exec_runtime will only increase if p is current, so running? > between the sum_exec_runtime rather than rq->clock_task. Not sure if I understand > this correctly? No, you're right. We're not dealing with time snapshots but rather with sum_exec_runtime snapshots. So the value will not change between dequeue and the next enqueue. e ... enqueue_task_fair() d ... dequeue_task_fair() s ... set_next_entity() p ... put_prev_entity() u ... update_curr_fair()->update_curr() p1: ---|---||--|--|---|--|--||--- d es u p s u pd ^ ^ | | (A) (B) Same se->prev_sum_exec_runtime_vol value in (A) and (B). > My original thought was that, record the average run time of every section: > Only consider that task voluntarily relinquishes the CPU. > For example, suppose on CPU1, task p1 and p2 run alternatively: > > --------------------> time > > | p1 runs 1ms | p2 preempt p1 | p1 switch in, runs 0.5ms and blocks | > ^ ^ ^ > |_____________| |_____________________________________| > ^ > | > p1 dequeued > > p1's duration in one section is (1 + 0.5)ms. Because if p2 does not > preempt p1, p1 can run 1.5ms. This reflects the nature of a task, > how long it wishes to run at most. > >> Like we do for se->prev_sum_exec_runtime in set_next_entity() but for >> one `set_next_entity()-put_prev_entity()` run section. >> >> AFAICS, you want to measure the exec_runtime sum over all run sections >> between enqueue and dequeue. > Yes, we tried to record the 'decayed' average exec_runtime for each section. > Say, task p runs for a ms , then p is dequeued and blocks for b ms, and then > runs for c ms, its average duration is 0.875 * a + 0.125 * c , which is > what update_avg() does. OK.