From patchwork Thu Jun 13 18:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: K Prateek Nayak X-Patchwork-Id: 13697256 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2073.outbound.protection.outlook.com [40.107.223.73]) (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 8A9E34C6B; Thu, 13 Jun 2024 18:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718302659; cv=fail; b=o/O6+cWaKkhhqLRCg/6N9LIEEfXao7R2QNokBQ7HZLTJ0C6HAz+Va8YawNhMd38fkwSJEpRKUqsxdGyY6wk3G8EshHjw4xiV1FkvR3wlwRI4Z/bc0hPPUXG7a/gbeCwEQRdQPuMFnv0fmKacMzfy1TLmHwhGEMz6TCWcshmXD9k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718302659; c=relaxed/simple; bh=2H8EhQ1NnvWapO/5VC3C5pjfSaOa7xdHEoj1B80D+S4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O3+NCXxdUTqZIJ3uaFWR79fi8CgoJQd/GkVj/fs9iMelqiSPm2kbx1ULCZMWcwpaJI033mzi89inOftnNYt7x0ViW1d2C7mxh/CTIS6ZcuPvNkLVRAtGAEpwRmoxB9TgOKRKV2lsVPxJHIuP0mnQArYcg2uh30K/wowvc3JvfvI= 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=sX8+K4ry; arc=fail smtp.client-ip=40.107.223.73 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="sX8+K4ry" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h4vnLIHNqf6EMaus+lVKV5QnYMXB1uDfXGYo/TPGsT1sRrc10nj9Ma8Xfowm8Ety9SoGywT7fVWvtQkSbRHvMy6rzb3fs9iwWmmZ/OBEBQPST7BX3+oMHWK4a4R/HE+ohygGxlU13T+GfzdgcJ+YREv8G9qPKF888WS3CSQYdBNT5su2aK1miHvnhpLpfGcwLCLQ+sfCFedaJ8+MgFB8reOGoh31Lj3yQzu8vR+wuh+p+EpBZHQrpWZ6fLRZTCU3E5zT9AYMfBfWbcs8QOV1tJTQpmiWqvnFLFp8XtoCOPjck6/QnP1ZdesMOb6SfjSob7kddqpVV7o3Nv5lFHXocQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=NBDm/3LMK0oErkDvBoPiWdU5abmUSz18MIXn67uiZ4Q=; b=ZojCpX3Czq6YaKtbZm7hKkH9y5OG9QBj2MEuUykqB+fTD/mVPoy1pNusEMsSLEa29nkYecPaeS02lBJbz7EXY0gxAh5ewVzgNvTRg4uJfWa/5USSOp6xIVX4iVd7medU7sua2WQopFQeV7LH+CxkbdyCsUJnMLb/jr1XxX972JH/jrGEuyq6W+rFAwFgpgFkA/B51s2y5VOhsmJCApoiC2x738iPdWpwC+I304aYR0dnJQShkxar3Q1nCMzkHUUDdBYotu+Tppsfq0AAfsmcO2TgTCFDMxR7PoK2riWP+PKHeA3kxS6g7fPX72uDePKV+BynfCIUOKumI3wop23V6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=NBDm/3LMK0oErkDvBoPiWdU5abmUSz18MIXn67uiZ4Q=; b=sX8+K4ryqOG1Ochl8dUeXR94hVUTyMv8zjvOLiS2mSka8XpVuOMAxtWaWdpHG9iPsl3YHnfC2QUmBhcQBdNCQOlCGDBDA1zyt6d86myl/RU/iwz4oAPnkz2Dcv5BeCXIZDTm95iqL+SAKblQPQM+db8wdKR8Z9qbTZBu1gY7WO0= Received: from BN0PR04CA0087.namprd04.prod.outlook.com (2603:10b6:408:ea::32) by MW3PR12MB4364.namprd12.prod.outlook.com (2603:10b6:303:5c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.25; Thu, 13 Jun 2024 18:17:33 +0000 Received: from BL6PEPF00022573.namprd02.prod.outlook.com (2603:10b6:408:ea:cafe::59) by BN0PR04CA0087.outlook.office365.com (2603:10b6:408:ea::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.24 via Frontend Transport; Thu, 13 Jun 2024 18:17:32 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF00022573.mail.protection.outlook.com (10.167.249.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 13 Jun 2024 18:17:32 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 13 Jun 2024 13:17:12 -0500 From: K Prateek Nayak To: CC: "Gautham R. Shenoy" , K Prateek Nayak , Richard Henderson , Ivan Kokshaysky , Matt Turner , Russell King , Guo Ren , "Michal Simek" , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Yoshinori Sato , Rich Felker , "John Paul Adrian Glaubitz" , "David S. Miller" , Andreas Larsson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Rafael J. Wysocki" , Daniel Lezcano , Peter Zijlstra , "Juri Lelli" , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , "Valentin Schneider" , Andrew Donnellan , Benjamin Gray , Frederic Weisbecker , Xin Li , Kees Cook , Rick Edgecombe , "Tony Battersby" , Bjorn Helgaas , "Brian Gerst" , Leonardo Bras , Imran Khan , "Paul E. McKenney" , "Rik van Riel" , Tim Chen , David Vernet , Julia Lawall , , , , , , , , , , Subject: [PATCH v2 01/14] thread_info: Add helpers to test and clear TIF_NOTIFY_IPI Date: Thu, 13 Jun 2024 18:16:00 +0000 Message-ID: <20240613181613.4329-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240613181613.4329-1-kprateek.nayak@amd.com> References: <20240613181613.4329-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00022573:EE_|MW3PR12MB4364:EE_ X-MS-Office365-Filtering-Correlation-Id: a2fff5df-6d2e-479b-b436-08dc8bd5180e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230035|376009|7416009|1800799019|36860700008|82310400021; X-Microsoft-Antispam-Message-Info: eKPfG6UdmTVhoqRYP2D7Uk4xzVOFM6kU7mCeOZqhjLz14QCOFiwSRifwdQpdvPTnOmqeiWxhdYTj5ec4SB6LJssA2Ms2GSmRXUA88G8QjAgN6BR14fsOub/DHpwvdRz+8VSNLVfWD2YgvX/WUWNRbn8+p2VtKwTAGcI/VZgP0h0KW5qHGvddMdc1KedchdnzbjUFc3WVYOpP90+11yDQ9vIJv/wN6h2CJ/Gs+4Wb5C/YyS7Wu9cshuYyNN6jQFoEcrfGyWqhj6GOlAUhQZOWsX5NWGmeK/9iYgo036g0tOX2lSACDtTrTz+iSO6cmIcIkg+Ep6WLUMfUxrlFCN1M805eMVmNy9mm1g56RS+0YVjUKshyMqE/mPsQVkpH8GlTfcaCGtLz0XXtDmqH6hXzAJAziwwkHD0rftPnBYgI3UeY/qHIo4dnHu0r6qwW5XW2eKjLE3cH3pO1uDoNXycdqGSTntnuDhUyIcBWHTvV9ETrYIivowe5B4ntiYzphmr01UHfuUXLzKWMsAsJuGE5EVIAC4XiLaOUuuj7l17Ry0bjYvN5D+UGLoXMjmK7s6uhYMeJlmcVxo+eepxfpko7q4Dop1z33lEdOHT6uBDobzHxrTDOgTzqDAYy5fovvd/Xro3opHeb3ne1vUxmLaws/3bMmPULfbwxCLdzLJqwYmOf5hJ/EXcEy9+3zfTgLcgGFVTRkrWIlH7ZKrok2Mzix4J7A/SF37luja2PsM6VQyQS5fPGE5lq6PKA8lfBRDVjgAI+FM0h7/Z81dgQYX9vf+1LMKk51ZdSsoL/eGfED8iBdO1yRkPnhYNR0ahiiHqgbTNDwRp133OpCr1epjhMrIiYgUr/2RTLxDk2NrBAkH/GhKAiEYD/kV4nOjjpPQZ0EyJXcghE/FoGiLoVY2ATb41/1/ZodOXzUde3Tmuolh8Hxe9yEc7XtgaO4vDZ2w4xAJy+XI5BnMkCPje8ohHDpIyahVx4Ptm8LzlIyp+2saAfVBHi/JidmHQOs0YtY3GgfszFmW0WfJpGwM38wNyMgsrbtkCHBuOiSc3amf/7aBsZSS8GuJtFhByCFx2aBhTSy0eIzD8yXQrCy3enj3vSK1lZlruFOrBtPZkVEQlVn4cOkQX0bIN5Wx8vf+oxV+AqX3ZYtqrAPhiKhs0fzXygITlzQw14XPjT3gsPFMPIaBQs5dCDX2kCM9yVQfyWIFulSf6DuCrDDRk76cP3LuvuRvbpz1c7/OMhR/qsnqVkcbVcnCFaybzzLkt7ZZunQiYID2c2brqL1mVpK4aqxRzsburSK9LPl/CaGJ9UexftXCVJCRAsJpzN0zg7/jxLPUJbK/ssAXN69xdsDwHQRbrkZh7yJxmUEBvZNpS1xEj9+w7vqJetJyU+cR5jpu+g19C3e8L9pkfMSSUX1hbaP3E3jQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230035)(376009)(7416009)(1800799019)(36860700008)(82310400021);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2024 18:17:32.5335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2fff5df-6d2e-479b-b436-08dc8bd5180e 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00022573.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4364 From: "Gautham R. Shenoy" Introduce the notion of TIF_NOTIFY_IPI flag. When a processor in TIF_POLLING mode needs to process an IPI, the sender sets NEED_RESCHED bit in idle task's thread_info to pull the target out of idle and avoids sending an interrupt to the idle CPU. When NEED_RESCHED is set, the scheduler assumes that a new task has been queued on the idle CPU and calls schedule_idle(), however, it is not necessary that an IPI on an idle CPU will necessarily end up waking a task on the said CPU. To avoid spurious calls to schedule_idle() assuming an IPI on an idle CPU will always wake a task on the said CPU, TIF_NOTIFY_IPI will be used to pull a TIF_POLLING CPU out of idle. Since the IPI handlers are processed before the call to schedule_idle(), schedule_idle() will be called only if one of the handlers have woken up a new task on the CPU and has set NEED_RESCHED. Add tif_notify_ipi() and current_clr_notify_ipi() helpers to test if TIF_NOTIFY_IPI is set in the current task's thread_info, and to clear it respectively. These interfaces will be used in subsequent patches as TIF_NOTIFY_IPI notion is integrated in the scheduler and in the idle path. [ prateek: Split the changes into a separate patch, add commit log ] Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Russell King Cc: Guo Ren Cc: Michal Simek Cc: Dinh Nguyen Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: "Naveen N. Rao" Cc: Yoshinori Sato Cc: Rich Felker Cc: John Paul Adrian Glaubitz Cc: "David S. Miller" Cc: Andreas Larsson Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: "Rafael J. Wysocki" Cc: Daniel Lezcano Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Andrew Donnellan Cc: Benjamin Gray Cc: Frederic Weisbecker Cc: Xin Li Cc: Kees Cook Cc: Rick Edgecombe Cc: Tony Battersby Cc: Bjorn Helgaas Cc: Brian Gerst Cc: Leonardo Bras Cc: Imran Khan Cc: "Paul E. McKenney" Cc: Rik van Riel Cc: Tim Chen Cc: David Vernet Cc: Julia Lawall Cc: linux-alpha@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-csky@vger.kernel.org Cc: linux-openrisc@vger.kernel.org Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-sh@vger.kernel.org Cc: sparclinux@vger.kernel.org Cc: linux-pm@vger.kernel.org Cc: x86@kernel.org Signed-off-by: Gautham R. Shenoy Co-developed-by: K Prateek Nayak Signed-off-by: K Prateek Nayak --- v1..v2: o No changes. --- include/linux/thread_info.h | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 9ea0b28068f4..1e10dd8c0227 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -195,6 +195,49 @@ static __always_inline bool tif_need_resched(void) #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */ +#ifdef TIF_NOTIFY_IPI + +#ifdef _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H + +static __always_inline bool tif_notify_ipi(void) +{ + return arch_test_bit(TIF_NOTIFY_IPI, + (unsigned long *)(¤t_thread_info()->flags)); +} + +static __always_inline void current_clr_notify_ipi(void) +{ + arch_clear_bit(TIF_NOTIFY_IPI, + (unsigned long *)(¤t_thread_info()->flags)); +} + +#else + +static __always_inline bool tif_notify_ipi(void) +{ + return test_bit(TIF_NOTIFY_IPI, + (unsigned long *)(¤t_thread_info()->flags)); +} + +static __always_inline void current_clr_notify_ipi(void) +{ + clear_bit(TIF_NOTIFY_IPI, + (unsigned long *)(¤t_thread_info()->flags)); +} + +#endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */ + +#else /* !TIF_NOTIFY_IPI */ + +static __always_inline bool tif_notify_ipi(void) +{ + return false; +} + +static __always_inline void current_clr_notify_ipi(void) { } + +#endif /* TIF_NOTIFY_IPI */ + #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES static inline int arch_within_stack_frames(const void * const stack, const void * const stackend,