From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011005.outbound.protection.outlook.com [40.93.194.5]) (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 EEF60477984 for ; Tue, 30 Jun 2026 16:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.5 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782836183; cv=fail; b=VXkG0O4tVc/45nkpBLrHxlFXbO3GAjEGgevXEK6dkQTk489asBT72fctDgtT8zfc+YvT46JrMVK/ar9U4yGNEivlv4pOkpDUSn2nblCNdWqYR/XPfi9K5+eHgjZ+zbEL06k108K5pZ4AoHo53+XFV/yOG97GioyFpu8L+OFOoi0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782836183; c=relaxed/simple; bh=ExxFh6Cv9qgZsif7jRqNV1X0LcE/lV3bUd4kzbM2ut8=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=VBVynsRupgqx9eFDXLWSGW5JOkmap10QHevTADwZA/Ayk/d001p/OmfpnB3dkxShVQMFjbD1Csbo6Z/5PhssGeuiDOu0NMhWnUvo2UM1yCJUU6z3XRQSbBDYhSP+4puKTPcOe1OMq6rEjtmdbUqI/8mCHtQimB6QAQ0U7hkSKsM= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=xdwEDysM; arc=fail smtp.client-ip=40.93.194.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xdwEDysM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lnzYHTyaNqDElFVmwREvfH2DdXdKbsM6jfi0F/ybB9qF+I6BcZ2ghYyvaP5LODESbvNOM3CQpIxHWTjOL23PRbCcKUn1AXUPOM2HKTmch1V8mc7EhIzEH6vcjC8V2AaAwTzrWc6d9/k5HEObKUdRtUX7KsMPYstdv0EXUtnYcZA+BUbyk2HC4oVV62ebc/12iCg8xFUgAKgskoseebPG/VP2ATb8wR9WEtn5wDYYLTUPEOv63A3R3uwhc6ZxzhF9/JCLbCvmymu3kHR1DXY/MPEzxrMImT9Z7S6Ym/E15VtOxeBGdQFXybmEsYSFnZYeP813xCLKRR5aF1oV0XQJqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fx/oRJgLcxocNU1kG/zeSTeEWorzMblu7jlHeaI1F/k=; b=ZTI9y+q8MJoqQR48Sj21sUQ0oxiklLg0mYAQkvCd1VlvsgVj3iD3/wCIsdNTdGkFpcGpQ/tMSlulCszgJS7VVQAYAFAj26ZKPV3FjwNBuiUnWit5GsRf5k18NPWY6ZnXIVgWgi8W+VcWNYokyXxYJSOVP0EYjcGWFTKR1VjSeZIH3SFDuZGndIXc9NRW3PK4eboUhkiSict76rXrwzGpc3v2VXsGQl3kVPW3Ba6scN2vfg4+c2nGRtwf0RcakUCit1FA6cD2Y3MrwFRNb6oVyyk0qATXP9j6h5zRB2iuVxyaIpZ2dNPMukd/XVHkjpC9iiGy/o64AsWw0c3Y7BE2Zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fx/oRJgLcxocNU1kG/zeSTeEWorzMblu7jlHeaI1F/k=; b=xdwEDysMJ142Wczfq8AZnuPgrLVvPBH7fS0mBiW7ac/Y0nHvj/S/zap2Y+skAkeYYeElwb15uiiOSfYFGnjsYn4Z5Z4ynf/unapvl/VTN/gZ+X3E3PzkB95Zfk21z47BjRW/NkK3+fgGWnzagGn0UruyLZ2jB3YNuvfUWodGf54= Received: from SA1P222CA0082.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:35e::29) by CH3PR12MB9731.namprd12.prod.outlook.com (2603:10b6:610:253::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.8; Tue, 30 Jun 2026 16:16:17 +0000 Received: from SA2PEPF00003AE8.namprd02.prod.outlook.com (2603:10b6:806:35e:cafe::95) by SA1P222CA0082.outlook.office365.com (2603:10b6:806:35e::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.8 via Frontend Transport; Tue, 30 Jun 2026 16:16:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003AE8.mail.protection.outlook.com (10.167.248.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 16:16:16 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Tue, 30 Jun 2026 11:16:15 -0500 Received: from [172.31.184.125] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Tue, 30 Jun 2026 11:16:11 -0500 Message-ID: Date: Tue, 30 Jun 2026 21:46:11 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched() To: Gabriele Monaco , Sechang Lim , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , References: <20260627081657.499781-1-rhkrqnwk98@gmail.com> <6cbcc3ea742b92b6a34b5994f5498c7611beac7e.camel@redhat.com> <5f47566b-88f4-458d-87a4-7794e6ba8203@amd.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003AE8:EE_|CH3PR12MB9731:EE_ X-MS-Office365-Filtering-Correlation-Id: 2424806a-d2a9-44e7-d25a-08ded6c2e9ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|7416014|1800799024|82310400026|36860700016|18002099003|22082099003|11063799006|4143699003|56012099006; X-Microsoft-Antispam-Message-Info: DQ0IyvCwZJp8DUv4OiVjuch96EIyFujnAFAmBJA24IIDnl87iwfW4akG6fCeOvaQYB4zO6msLzpCN0Wk2b3YG8sKBaWdTmwvXKdT61Ilra8/bxYpUkVEMcDHO2Qmx+dCno5fN3MVzZP1fTfiV2NfdsLUUpmBbtpAwRPBL3jLzvWD/pbWD37fFsx727l2gwzqh3SaNd3LUTcGUq58Zi7uLjtWiDPyEKfh/0QKA/XMoIlw+u4aOmjy7LI+g67HI6Y6+nHGGntjwPkwKyxCBJCPde6fUUCXcOt03vlco3YdSGK2EuUAHPEc/vg2Qt721fyoRubnG0MJJTNoFpe8JtbgtnLADEeaYBu6Y+bLcD2SeNftQywBT8wwKNiEYbPp2WVt+M1hilZgg0o50aa/HwlJEx4R1hrivigf63rB+xDXe/ilKSfF/6xy8rVknVsepHMWit3xXgplnTD/EwlvqhJB25Byd4is9sBbc48MxEtoepZn+S2b+jBeQtn7QC0+CQm2FT0zzrwSYjo3J4qOZ32dm5HyGanJR3Ovau6EfkTNzFS5Rl8wCC1TMx2f/YcZWSc/QE8LmWud8ST6f4oqjVa2Q+M5HoTySX3dhMh9YOYc+FD9OyIzH/rs1J238l++QErApPKRkaDkigCgWbxz15MH/EzG7eBUsyvYo6ZdlC46bq1m4UEKS54MPJkA/tw+CiN1d4baA3SrURwM7182Wvsnxg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(23010399003)(7416014)(1800799024)(82310400026)(36860700016)(18002099003)(22082099003)(11063799006)(4143699003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cif0a3VyOVoyBMbccie7MNQMNON470J2KxLsZe2DQ6FapQ6vN+W6lj5dHKrmz/nQNr7YPBULGCORiT91K7Yn1RL3Ld/A7jwH5QZpfQkttszSISDk09QGZFJRt7pSfg5FTp8Gh2IWs0MxK1Nn016m5WJK/vGqABHZRylZXHxl55sV24M+k9TyxonnW9KvY2Gt4uwpv1R9HzPO6vSovrJpUlGMHWwMJ2gryPbF8/EK6yHnXhiczrRInX/Qg9CcoDluoxGmrwrbhmhf001i38yCDeKlYpzElv9tiOkOTK0F1KVmech4VOND00IGVe3KWsODVHuxx/GyRPTJscO0RCDgo+nOCsAJz2NBeCcCyyLWxalwJUYWpU8xyR03EJsKfn1p/At8WZnqjntMdxsDBVtDzINr8huC3sT78e7z/sGNIsjW7YvpAZIF9pphfZ3dWcys X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 16:16:16.4885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2424806a-d2a9-44e7-d25a-08ded6c2e9ab X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003AE8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9731 Hello Gabriele, On 6/30/2026 2:28 PM, Gabriele Monaco wrote: > On Mon, 2026-06-29 at 23:05 +0530, K Prateek Nayak wrote: >>> That said, we should indeed add the tracepoint to that path and probably >>> adapt the monitor if that's making it fail indirectly. >> >> For the npr use-case, I think the current scheme is fine since >> only SM_PREEMPt counts as a "schedule_entry_preempt" transition >> and only that can transition the state machine out of the >> "any_thread_running" state. > > Right, the monitor can live without it, but I wonder if we need to put that > tracepoint for correctness sake. After all, however unlikely, that's a > need_resched too. > > (then if the monitor really saw a need_resched after it's sched_entry, it would > stay erroneously in rescheduling). > > Anyway this all isn't related to the patch. Ack! Would something like this work for completeness: (Lightly tested; Based on current tip:sched/core) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 96226707c2f6..934f540d0d3f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1049,9 +1049,16 @@ static inline void hrtick_schedule_exit(struct rq *rq) { } * this avoids any races wrt polling state changes and thereby avoids * spurious IPIs. */ -static inline bool set_nr_and_not_polling(struct thread_info *ti, int tif) +static inline bool set_nr_and_not_polling(struct rq *rq, int tif) { - return !(fetch_or(&ti->flags, 1 << tif) & _TIF_POLLING_NRFLAG); + struct task_struct *curr = rq->curr; + struct thread_info *ti = task_thread_info(curr); + unsigned long old_flags = fetch_or(&ti->flags, 1 << tif); + + if (trace_sched_set_need_resched_tp_enabled() && !(old_flags & (1 << tif))) + trace_call__sched_set_need_resched_tp(curr, cpu_of(rq), tif); + + return !(old_flags & _TIF_POLLING_NRFLAG); } /* @@ -1076,8 +1083,11 @@ static bool set_nr_if_polling(struct task_struct *p) } #else -static inline bool set_nr_and_not_polling(struct thread_info *ti, int tif) +static inline bool set_nr_and_not_polling(struct rq *rq, int tif) { + struct task_struct *curr = rq->curr; + struct thread_info *ti = task_thread_info(curr); + set_ti_thread_flag(ti, tif); return true; } @@ -1202,15 +1212,17 @@ static void __resched_curr(struct rq *rq, int tif) cpu = cpu_of(rq); - trace_sched_set_need_resched_tp(curr, cpu, tif); if (cpu == smp_processor_id()) { - set_ti_thread_flag(cti, tif); + int set = test_and_set_ti_thread_flag(cti, tif); + + if (trace_sched_set_need_resched_tp_enabled() && !set) + trace_call__sched_set_need_resched_tp(curr, cpu, tif); if (tif == TIF_NEED_RESCHED) set_preempt_need_resched(); return; } - if (set_nr_and_not_polling(cti, tif)) { + if (set_nr_and_not_polling(rq, tif)) { if (tif == TIF_NEED_RESCHED) smp_send_reschedule(cpu); } else { @@ -1350,7 +1362,7 @@ static void wake_up_idle_cpu(int cpu) * and testing of the above solutions didn't appear to report * much benefits. */ - if (set_nr_and_not_polling(task_thread_info(rq->idle), TIF_NEED_RESCHED)) + if (set_nr_and_not_polling(rq, TIF_NEED_RESCHED)) smp_send_reschedule(cpu); else trace_sched_wake_idle_without_ipi(cpu); --- > > Thanks, > Gabriele > -- Thanks and Regards, Prateek