From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 B5ACB215F71 for ; Thu, 9 Jan 2025 10:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736417550; cv=none; b=tasUe+jVQUR8adxTt28cyK9K2MQPVBG7wls+IbwO00BNQWDYMB134NQuLMAzKcr/Ta7dWIA28bsSOl3N8G7rWPH/huYBAnn1gaDgvPKnN8FzzQX9XxLc5UeExYm7muFP2uKzKk/DBSMTIMhUUS5MnMArV+500tfDx1igeAZ/gKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736417550; c=relaxed/simple; bh=BJh550snbk3NTEamb1uwGi0GONUnmtIfEKF/Ekz6970=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HYPCsWxTq8J98TLIDwSXs05i6Jyz4lGIYf6nKQ1cHudyD19GxPhiUhJ+A6/g9UdFDDgjKBtqb0UdTFg39zYJLBpHsl5VRP5gyJYfogXxhwgZkpdNH/UlF+FRIOFlyyENY3ilbEw5+9HGoS+LtIShmQ5SEw6nFdRxVOMKhumiO1c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ONbH+Ahe; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ONbH+Ahe" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21661be2c2dso9994695ad.1 for ; Thu, 09 Jan 2025 02:12:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736417548; x=1737022348; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ng2S3j7UK5RBH6sAGUEyfs0sr7alPlb0CvaT11xV2Uk=; b=ONbH+AheN4VcUVDfDrS0tye6BQ2prilkLPo11LpvTge3TziisSjCoeU9rIrtC8Kx10 AMKMAAoKa2Px/Rt4axcs7+ZU3hHpDY4bVDb+WrZZ1oil5xrMIO09Kf6TPjVK8eNfaVN7 QYCxfZX1EsW/dGzW6wFLgLqj254b9aI1/9Wv5hIMWlgHkPx5Nv+AnmhiitQJOaN+Ph4R k330JORIxTX2R02pWKQ2J4FTNxIE52Qi6OZqn/cRxq0JQNvekwaH9kYXQrGkW5QCovyb RWgfL+urYv9/pSa44fCJEQfp5Fjy1WLBFcK6N8EmkcbDMebzK1+3Vqi10YROOyaL8m07 nfLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736417548; x=1737022348; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ng2S3j7UK5RBH6sAGUEyfs0sr7alPlb0CvaT11xV2Uk=; b=sjlhhHTNd+glE+aaieTlBVOjxYTO/ze25/XMWL1ShieMjuCU+Sw+On/zylD/JfCDq0 IY24P/2llleULk5uY1MDxG3v7r4Kk4D78msv2BIY5Q+1E9e3SXzPv5RG+jzYk4tDuBXR kC4p7v6FGnT6lQn801HvuLKEP9JAuguSFpgsjYHl3GPCghgcYZsy+vyFueAz1wJGqpyE ogfK++xfA43L3sKX1zqHoV9tsHk6jQBKDx6WuGZNIKOStcs3BmxqC4aqNS5YtJb7J+WS hI8FOqjYFdI6LvoZHMSuGluSPL6qI1akKqW8ShLqgKVBbXL65RQdLFKRGAmTmkNnSHpI 6W7A== X-Forwarded-Encrypted: i=1; AJvYcCUE0fq68BFKQhymrZjFlSgXFHwAErbcBJhRPMD04gnS/xHoLDYCl8sHaQJ8C88MEHWq7hP5kW2tjGjaFh8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz14eCYGoL5O196Zo4E+3HUteb8RHlijlE2VX4POtYmA8N/b9m4 sc/LLwKQQO4AxSWT8pUoPDAmiEkgBayAMQ9XLlW+IClyISd+QMF8 X-Gm-Gg: ASbGncvFobvBlXwPrkyaJxWDhydiLjS1RCwWu4pBPcmnkTBs4hvae/9af2KKpPBDCuZ MhRUMcN6iGSjQ9Wzun9wbxF0w5keJ2LX3Q3f/diBR+aSNF2dnnqBdRhDarsEvSBbcsX6VwrRSK2 qVdiMmUbq8EB3uQWWHbC/drCWidNtd+aE6ircLTEeVzRHZo1lCkWx5iuH4HptVVCiDJylfUxQ7g Mj4AKbkSIH5sM6eH+dqOz61z8dI0wG7vGzlHnQ1YU7ILSgB9gHYVBV8aFGMFuoDZMq6SGK6FQ== X-Google-Smtp-Source: AGHT+IE7IW3advFZbW1lLxREP65yBKojeSdLgYGHLPaFRk48387vUT0Ab8s0NWfjP7wRAlnEDkjKXg== X-Received: by 2002:a17:902:cec3:b0:216:7ee9:220b with SMTP id d9443c01a7336-21a83f4f43amr98767595ad.22.1736417547899; Thu, 09 Jan 2025 02:12:27 -0800 (PST) Received: from vaxr-BM6660-BM6360 ([2001:288:7001:2703:e2de:c21d:6dd5:9d2a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9176619esm9188105ad.54.2025.01.09.02.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 02:12:27 -0800 (PST) Date: Thu, 9 Jan 2025 18:12:22 +0800 From: I Hsin Cheng To: Peter Zijlstra Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] sched/fair: Refactor can_migrate_task() to elimate looping Message-ID: References: <20250108172948.452158-1-richard120310@gmail.com> <20250109094627.GP20870@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250109094627.GP20870@noisy.programming.kicks-ass.net> On Thu, Jan 09, 2025 at 10:46:27AM +0100, Peter Zijlstra wrote: > On Thu, Jan 09, 2025 at 01:29:47AM +0800, I Hsin Cheng wrote: > > kernel/sched/fair.c | 16 ++++++++++------ > > 1 file changed, 10 insertions(+), 6 deletions(-) > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 2d16c8545..ce46f61da 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -9404,12 +9404,16 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env) > > return 0; > > > > /* Prevent to re-select dst_cpu via env's CPUs: */ > > - for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) { > > - if (cpumask_test_cpu(cpu, p->cpus_ptr)) { > > - env->flags |= LBF_DST_PINNED; > > - env->new_dst_cpu = cpu; > > - break; > > - } > > + struct cpumask dst_mask; > > Except you cannot put cpumask on-stack... > > > + > > + cpumask_and(&dst_mask, env->dst_grpmask, env->cpus); > > + cpumask_and(&dst_mask, &dst_mask, p->cpus_ptr); > > + > > + cpu = cpumask_first(&dst_mask); > > + > > + if (cpu < nr_cpu_ids) { > > + env->flags |= LBF_DST_PINNED; > > + env->new_dst_cpu = cpu; > > } > > > > return 0; > > -- > > 2.43.0 > > > > Except you cannot put cpumask on-stack... Oh I'm sorry, may I ask the reason? is it because cpumask tends to be very large? I assume we're not supposed to change the value of "env->dst_grpmask" or "env->cpus" here, so in order to achieve something like this we need another cpumask, explicitly allocate a cpumask on heap for this section would be an overkill I think ? Or maybe we can have kernel maintain a global cpumask so anyone wishing to perform some operations will get to do it without maintain allocate a cpumask themselves?