From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58E98EE14D0 for ; Wed, 6 Sep 2023 21:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244891AbjIFVyH (ORCPT ); Wed, 6 Sep 2023 17:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbjIFVyF (ORCPT ); Wed, 6 Sep 2023 17:54:05 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7DDCFD for ; Wed, 6 Sep 2023 14:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1694037238; bh=G5b1ZiEouWXtelHmJRdYj6k9w+4imdkEkkLJLYw/1Jg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=UBwp6g/9YK7qIUFTyKTIq/7a4FH8XaA4f4RVpkGk7KcKGPrLjQl2g5XWEcyTdYcHw 2RsTovdzQ5Qs84PpJp5mb+28CfqU9BvhrEwp1GfFSzAdAU1WnnnZnl6U2qic+E5kzO E0td9MWBqSv4v9jKt+urho/y1wQM1R+bj9mnYLYPfK64rz5QzxLJdltAYM9HxpsGHE UgX90hx2Af+8B8MqvCx84MACJ9hMtb4InnCatw1IXT2GoJwu66dYYFJX8ZjnezeL2I puUqS1h0wPSIp215LmhMla3imJi0GIP6DU+zqNeKd/cabOdn8K4b/toBJ6ERrcP4MK +vlCP/qwVQqrA== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Rgx396lCkz1Nr1; Wed, 6 Sep 2023 17:53:57 -0400 (EDT) Message-ID: <245448a2-6d2c-4c4c-51b3-c610e7e7a68d@efficios.com> Date: Wed, 6 Sep 2023 17:55:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [RFC PATCH 1/2] sched: Rate limit migrations to 1 per 2ms per task Content-Language: en-US To: Tim Chen , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Valentin Schneider , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Vincent Guittot , Juri Lelli , Swapnil Sapkal , Aaron Lu , Julien Desfossez , x86@kernel.org References: <20230905171105.1005672-1-mathieu.desnoyers@efficios.com> <20230905171105.1005672-2-mathieu.desnoyers@efficios.com> <866f23cc-6725-fc74-099f-450939fc0dc4@efficios.com> <20230906094744.GE38741@noisy.programming.kicks-ass.net> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/6/23 16:51, Tim Chen wrote: > On Wed, 2023-09-06 at 11:47 +0200, Peter Zijlstra wrote: >> On Tue, Sep 05, 2023 at 03:44:57PM -0700, Tim Chen wrote: >> >>> Reading up on sched_clock() documentation and seems like it should >>> indeed be monotonic. >> >> It tries very hard to be monotonic but cannot guarantee. The moment TSC >> is found unstable it's too late to fix up everything. >> > > Yes, if TSC becomes unstable and could cause sched_clock to reset and go way backward. > Perhaps we can add the following check in Mathieu's original > patch to fix things up: > > +static bool should_migrate_task(struct task_struct *p, int prev_cpu) >> +{ > /* sched_clock reset causing next migration time to be too far ahead */ > if (p->se.next_migration_time > sched_clock_cpu(prev_cpu) + SCHED_MIGRATION_RATELIMIT_WINDOW) > p->se.next_migration_time = sched_clock_cpu(prev_cpu) + SCHED_MIGRATION_RATELIMIT_WINDOW; > >> + /* Rate limit task migration. */ >> + if (sched_clock_cpu(prev_cpu) < p->se.next_migration_time) >> + return false; >> + return true; >> +} >> + > Along those lines I think something like this should work: static bool should_migrate_task(struct task_struct *p, int prev_cpu) { u64 now = sched_clock_cpu(prev_cpu); /* sched_clock reset causing next migration time to be too far ahead. */ if (now + SCHED_MIGRATION_RATELIMIT_WINDOW < p->se.next_migration_time) return true; /* Rate limit task migration. */ if (now >= p->se.next_migration_time) return true; return false; } It will let migrate_task_rq_fair() update se->next_migration_time. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com