From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C12B9188713 for ; Tue, 9 Dec 2025 23:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765322266; cv=none; b=puSODJwO3WsklHTnCwYciHGbutRje5+SKEhzCIWBCehZVvWXAVR6+fBotEwhC5c1fTzzYGiJfp/bjjvu6CURjtomKYtWRxiIsoWfymrjaAigeV7aTHLjnN6jU+pvTzkxVb3wNnG9I3RtcZUjMrUv1UT+XV+oPyxXIzy0UJVDx10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765322266; c=relaxed/simple; bh=BO/FLkEPE9aVe70DxtVXXsgAEL5aT+6LHEop10HLFJ4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=nSnkgPNwgARnIvahLBWHaJ1P1eqMqzrpkuqCWJfgqlvzCQSXBqQJhCNKgnmcLAxORQdj1cfBu5nEZjPdpgJS13UzB6aKwX0JGk9RbhZzy1jK5Q6o6XtdGov5ic3Jn4LWqbjIpKL9pM3dw+6mr/RaJHtWxpS66QbvVFZmWSYqoDk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PYAr5Ac6; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PYAr5Ac6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765322264; x=1796858264; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=BO/FLkEPE9aVe70DxtVXXsgAEL5aT+6LHEop10HLFJ4=; b=PYAr5Ac6VgzpfiNfnUCYdP8uyPHR3cRxTCnHdTgaWGocGwM6Scu3mY6i P4mpH7+CtQnnZJPOxvZQROjSUvk7pEEs4OoE42Iu5oFtINlShCEhdkoMn wr8RJeZwvwc5rHrD/EO778i/uCqWArm/fUMqvbw/qd7Ha9MiNwt8bHiQk BGvpABl0i7MrzSM2pCQoVGsVfkGslFHsprZPLjeJ++CbGhCsmHrRNxDpo opbTpHGb/noWaVFDmgDVXOFwnJkbP2f9efeFSK1p0IzR3UR5hOEwcdHZ2 3RhaN/DMJ2rwZc9nQfCWAEjWPsqDWthEALdF8tmBUQEdujo8eDjgYfaYO Q==; X-CSE-ConnectionGUID: iTk/5Z8GT3amQCxEwuDxCw== X-CSE-MsgGUID: YCImyHbLSACX5Mj/DfBDVw== X-IronPort-AV: E=McAfee;i="6800,10657,11637"; a="70910681" X-IronPort-AV: E=Sophos;i="6.20,262,1758610800"; d="scan'208";a="70910681" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2025 15:17:43 -0800 X-CSE-ConnectionGUID: YmcHWsR8QMy9GOe2ztw/hQ== X-CSE-MsgGUID: nqkVwBEyQ/618xvpegtoXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,262,1758610800"; d="scan'208";a="219696561" Received: from unknown (HELO [10.241.243.18]) ([10.241.243.18]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2025 15:17:42 -0800 Message-ID: <82a6c5269b048a05cba10cda4d7b3e7952108914.camel@linux.intel.com> Subject: Re: [PATCH v2 07/23] sched/cache: Introduce per runqueue task LLC preference counter From: Tim Chen To: Peter Zijlstra Cc: Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , linux-kernel@vger.kernel.org Date: Tue, 09 Dec 2025 15:17:41 -0800 In-Reply-To: <20251209130629.GO3707891@noisy.programming.kicks-ass.net> References: <63091f7ca7bb473fbc176af86a87d27a07a6e149.1764801860.git.tim.c.chen@linux.intel.com> <20251209130629.GO3707891@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.1 (3.58.1-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2025-12-09 at 14:06 +0100, Peter Zijlstra wrote: > On Wed, Dec 03, 2025 at 03:07:26PM -0800, Tim Chen wrote: >=20 > > +#ifdef CONFIG_SCHED_CACHE > > + > > +static unsigned int *alloc_new_pref_llcs(unsigned int *old, unsigned i= nt **gc) > > +{ > > + unsigned int *new =3D NULL; > > + > > + new =3D kcalloc(new_max_llcs, sizeof(unsigned int), > > + GFP_KERNEL | __GFP_NOWARN); > > + > > + if (!new) { > > + *gc =3D NULL; > > + } else { > > + /* > > + * Place old entry in garbage collector > > + * for later disposal. > > + */ > > + *gc =3D old; > > + } > > + return new; > > +} > > + > > +static void populate_new_pref_llcs(unsigned int *old, unsigned int *ne= w) > > +{ > > + int i; > > + > > + if (!old) > > + return; > > + > > + for (i =3D 0; i < max_llcs; i++) > > + new[i] =3D old[i]; > > +} > > + > > +static int resize_llc_pref(void) > > +{ > > + unsigned int *__percpu *tmp_llc_pref; > > + int i, ret =3D 0; > > + > > + if (new_max_llcs <=3D max_llcs) > > + return 0; > > + > > + /* > > + * Allocate temp percpu pointer for old llc_pref, > > + * which will be released after switching to the > > + * new buffer. > > + */ > > + tmp_llc_pref =3D alloc_percpu_noprof(unsigned int *); > > + if (!tmp_llc_pref) > > + return -ENOMEM; > > + > > + for_each_present_cpu(i) > > + *per_cpu_ptr(tmp_llc_pref, i) =3D NULL; > > + > > + /* > > + * Resize the per rq nr_pref_llc buffer and > > + * switch to this new buffer. > > + */ > > + for_each_present_cpu(i) { > > + struct rq_flags rf; > > + unsigned int *new; > > + struct rq *rq; > > + > > + rq =3D cpu_rq(i); > > + new =3D alloc_new_pref_llcs(rq->nr_pref_llc, per_cpu_ptr(tmp_llc_pre= f, i)); > > + if (!new) { > > + ret =3D -ENOMEM; > > + > > + goto release_old; > > + } > > + > > + /* > > + * Locking rq ensures that rq->nr_pref_llc values > > + * don't change with new task enqueue/dequeue > > + * when we repopulate the newly enlarged array. > > + */ >=20 > guard(rq_lock_irq)(rq); >=20 > Notably, this cannot be with IRQs disabled, as you're doing allocations. Okay. >=20 > > + rq_lock_irqsave(rq, &rf); > > + populate_new_pref_llcs(rq->nr_pref_llc, new); > > + rq->nr_pref_llc =3D new; > > + rq_unlock_irqrestore(rq, &rf); > > + } > > + > > +release_old: > > + /* > > + * Load balance is done under rcu_lock. > > + * Wait for load balance before and during resizing to > > + * be done. They may refer to old nr_pref_llc[] > > + * that hasn't been resized. > > + */ > > + synchronize_rcu(); > > + for_each_present_cpu(i) > > + kfree(*per_cpu_ptr(tmp_llc_pref, i)); > > + > > + free_percpu(tmp_llc_pref); > > + > > + /* succeed and update */ > > + if (!ret) > > + max_llcs =3D new_max_llcs; > > + > > + return ret; > > +} >=20 > I think you need at least cpus_read_lock(), because present_cpu is > dynamic -- but I'm not quite sure what lock is used to serialize it. Let me check on what is the right lock for making sure present_cpu is not chenged. Thanks. Tim