Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1870247rdb; Tue, 20 Feb 2024 09:16:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfuv2nZ4VB17ciz8JUI+0vDbU0dOaps3wTA7e67FcdySaNxgKUFRovXWWmqtONM7+kU9WDzKmcHW/BMnjJ6pXvBF8bDeuyZfnM5Bud2g== X-Google-Smtp-Source: AGHT+IGeEuze5F4AXfmc3ulKmgHZk5awpsmeCHjLGidB7oAUnduExnV/dxfXnSE7aH08QXDOqLZa X-Received: by 2002:a17:902:70c4:b0:1db:7052:2f45 with SMTP id l4-20020a17090270c400b001db70522f45mr13438682plt.61.1708449402899; Tue, 20 Feb 2024 09:16:42 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2-20020a170902cec200b001db2ac74e8fsi6446850plg.381.2024.02.20.09.16.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:16:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73414-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="nua/yKas"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-73414-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73414-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 43A43286889 for ; Tue, 20 Feb 2024 17:16:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E72CE76909; Tue, 20 Feb 2024 17:16:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nua/yKas" Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2087.outbound.protection.outlook.com [40.107.102.87]) (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 56802626C6; Tue, 20 Feb 2024 17:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.87 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708449383; cv=fail; b=VcfO6I0jibjT6RITnmt0mGaKnp7VeLIreezjMqvayj2kz82ElDbhRG5PGibzFZzQad6xeIyvytMhFMxolaNIuwKNYbw0jddp6el4UA8Kdhwg0p46DvN0lPAhPrn0I0d2/Aa47K0IcgaEnt6Itn2ox/rShjvzUo/HciDNfJfcgVk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708449383; c=relaxed/simple; bh=+83drqfYC8Xe4UqCzmUPm3kVQ1QS2mWTb9Xdtc63oQY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nxs2IuOrWwv3CAys6rYqkBZNazyLU/ubdjSmkiJHs2aEtzfp2YZ2eYPM2yXGHHyS2ffJlVSJvQm4l0k8yH2NCx6XTZGpmJmfbv50odt7keyx0baP23g1iWDGAaLFF6W4Hr+aRREN7rLO8SWYEZzRVwzM1wJEVlPIeuR6qNWUDWM= 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=nua/yKas; arc=fail smtp.client-ip=40.107.102.87 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AKm0qV1ViYO6k6xFAms8GJXCIGavzaCUXjmiV9tWZ7KJBIyHo80lSsMv3Oj/JDPsKsIuTWb15z9PalzkR9qi0bdbz6dFitDX8H/s0pndj9GsLT007qc1YhJRjBjN97jLu7sAAlCAfUsUzNXAKXq9ZR2+AeCWhwszQ2EjVVXFlaAkJKLWoVcRjxrbx6zJbPW9jiiDrapHKjT2LNBwUifos4WXpOSIRX7TMusLU5X2g2xN6EjpsbM0tKzrZes9qLUfIsSWX0gyl6nywe1LTmKprqXfngXQMgCidG2OKDDH+2C8TCmXXsYskuipA74TlV+kZjWb++/LYVi9TcxC/kswvw== 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=quZsNkcGT9Wh6N0HLP1+7TfKAtPtAmacaj9LCgxfhHo=; b=TtrPS13UocYReYInoQ7ETK56+ROfF2KmZgJQGP8V+njL2FZzY1s+mkXP4PnGnLU2M1jnLQLRvQD5MCTBoNYKluu9z9sJOr6L+G/n+bKaGjkNsujH6N8qTyEfJbMEKsC9g1nko9LNXOu+fBX0+SFiVcyNpX0esdcMAX5jxSng0N0SgZlwF2jwX+O0U0AxSQGvmH6xqvWacXY77GU8ceb3UJhYinYiMZ23Ksibl33qjo1BM6UJAJdsoQh80HhilZREAXz0PmyL1lUaCZO0sEE2C4D4rS2KlksXVfjRP7Gfjnp1t6qBueRJ4mGA6nLNz413WMfXcnj+FLo/a7ollb9zGA== 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=quZsNkcGT9Wh6N0HLP1+7TfKAtPtAmacaj9LCgxfhHo=; b=nua/yKasOTvHORFHiCb8vPsLqQkRZbyQAw6eOv3VPG4Ixw1lLRCx/Et9aMU8Z4CVKRl4SKEdXULH0bArx9Z8OzLi2KLYRGj09tA0MruO8pUHTQSjKQbohhEHM8f8sF0ZXCl+iC5fi5R3ez/ECs0BiEljAvjseUapeek90khZ7jc= Received: from DS7PR03CA0081.namprd03.prod.outlook.com (2603:10b6:5:3bb::26) by DM6PR12MB4203.namprd12.prod.outlook.com (2603:10b6:5:21f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.20; Tue, 20 Feb 2024 17:16:17 +0000 Received: from DS1PEPF00017095.namprd03.prod.outlook.com (2603:10b6:5:3bb:cafe::f6) by DS7PR03CA0081.outlook.office365.com (2603:10b6:5:3bb::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.40 via Frontend Transport; Tue, 20 Feb 2024 17:16:17 +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 DS1PEPF00017095.mail.protection.outlook.com (10.167.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Tue, 20 Feb 2024 17:16:17 +0000 Received: from BLR5CG134614W.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.35; Tue, 20 Feb 2024 11:15:57 -0600 From: K Prateek Nayak To: CC: "Gautham R. Shenoy" , 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 , "Aneesh Kumar K.V" , "Naveen N. Rao" , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , 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 , Al Viro , Linus Walleij , Ard Biesheuvel , Andrew Donnellan , Nicholas Miehlbradt , Andrew Morton , "Arnd Bergmann" , Josh Poimboeuf , "Kirill A. Shutemov" , Rick Edgecombe , Tony Battersby , "Brian Gerst" , Tim Chen , "David Vernet" , , , , , , , , , , , K Prateek Nayak Subject: [RFC PATCH 01/14] thread_info: Add helpers to test and clear TIF_NOTIFY_IPI Date: Tue, 20 Feb 2024 22:44:44 +0530 Message-ID: <20240220171457.703-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220171457.703-1-kprateek.nayak@amd.com> References: <20240220171457.703-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: DS1PEPF00017095:EE_|DM6PR12MB4203:EE_ X-MS-Office365-Filtering-Correlation-Id: 4eb4d987-a812-4cdb-a2a9-08dc3237a66d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1PHn4rdjZx5dckahSzNyAtyE18pz/wuCdYswBnjZz1uMl4IiK+vmnleg7VvbcXv77L1F4csYu0PQ0Ilp2/XNyu/5Kf9Uq6vqq4nd/XMhPb4Gltv1tPxeCyS5VEwgfFotO/sqM3JuGIAVKPCLNnc8ZPzMueNUBPiX+owSc3i5fHS7y/mXLURcHsJgwwwrVdKWV6j6gZq3msDpBnSHiYhtEFpLN3/7gWXGME9KM55UmFz8q8cfnk8GfBOLdpelGurI1edhTrFCsnmWszgG51CaDbP+EMr3ZsfMOkJQ7xof4OijH8Rs3hQtEx0ruIXGx/nNORVnZdLIZEtwEAVN49v1ofSeMJ7opno+P+edqOFIcAZ5IJ5yn0hBuOl7K906C4iTFUMD1MdYCwveMuEzGTuyDcm0hHFHAYeJaEmDe1ANpnVqb3okggp8N2Je61UIT8SMfVMdOgYlyjJAYbeTbORjirKp4tSjwwAmUEquVGJGLiH4EJCT3N7v7Ldv8919lxsjPOKFEGpshHDhJfU/Rnh1HpHGPEfObiTtPJSzoa8XWjk9uwIdztWGe+tM78VbYLENjm7ysS6PSjp+SfSbfehlLJGv/LQRJ2Ds6Y9WvKLtsKg1MT34YAAWacAALNbZb25mESyfKuZpcpNMCDZyQuWMpETkG2WFMbJmbTVIFZ0Ldk4= 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:(13230031)(36860700004)(40470700004)(46966006);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 17:16:17.5310 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4eb4d987-a812-4cdb-a2a9-08dc3237a66d 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: DS1PEPF00017095.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4203 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: "Aneesh Kumar K.V" Cc: "Naveen N. Rao" Cc: Yoshinori Sato Cc: Rich Felker Cc: John Paul Adrian Glaubitz Cc: "David S. Miller" 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: Al Viro Cc: Linus Walleij Cc: Ard Biesheuvel Cc: Andrew Donnellan Cc: Nicholas Miehlbradt Cc: Andrew Morton Cc: Arnd Bergmann Cc: Josh Poimboeuf Cc: "Kirill A. Shutemov" Cc: Rick Edgecombe Cc: Tony Battersby Cc: Brian Gerst Cc: Tim Chen Cc: David Vernet Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-alpha@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 Signed-off-by: Gautham R. Shenoy Co-developed-by: K Prateek Nayak Signed-off-by: K Prateek Nayak --- 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, -- 2.34.1