From patchwork Wed Feb 8 07:35:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 13132537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB180C05027 for ; Wed, 8 Feb 2023 07:36:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B07B6B0075; Wed, 8 Feb 2023 02:36:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 65F596B0078; Wed, 8 Feb 2023 02:36:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 501226B007B; Wed, 8 Feb 2023 02:36:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3E7BE6B0075 for ; Wed, 8 Feb 2023 02:36:49 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05731C03F8 for ; Wed, 8 Feb 2023 07:36:48 +0000 (UTC) X-FDA: 80443317738.22.F231E95 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) by imf20.hostedemail.com (Postfix) with ESMTP id 15D901C000A for ; Wed, 8 Feb 2023 07:36:45 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=vIoOqa4m; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf20.hostedemail.com: domain of bharata@amd.com designates 40.107.94.60 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675841806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MdjzojHcuBT96abEwzKozCOPIPJAXDc3x8XJ/bPfy5Q=; b=AIkHfyLIxLxWDAT4DsFjERauaB0ohjAqzHxwB3TYhPcaOA/y3nuBoPeDqv9p/lHTToYq+t +TJkvSJ3lNDrsNmChtwkOQoHabtf/ydniOV9KDnZfoFRZS62ijVC/g0+UIzVIUkpSL2Jxa UfAw8GdupAWCLJ6ec7OQuWjrFw5s3qg= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=vIoOqa4m; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf20.hostedemail.com: domain of bharata@amd.com designates 40.107.94.60 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1675841806; a=rsa-sha256; cv=pass; b=hCJLEwid7n+yZMXMoZuUo/uIa8kDN2hat7dnRz4JYpWgDs1SjscqDWIfeFRZO9zmnE8TBE Ba2UYP12PmrVyQ19i5WIdOn7Pp1cyaT3mynnrJ4spWUNaVRIFsQGjTMSmvlosKk1wgw6MD uGQNqOfsH3B7eeS95LfHMvKdQet03CA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W/1oo5aZfjIYzZIXXNpj5NSRuFEmAeI7wA+mrspqDZCNK2nKW5q3AGr9nkPP1+LMJ9EvALNCgZ/wFbhSEGgMemDgPJVoMviWfkVfWeCIl998x1DvxTXcu/g4htXJwZu3NVQUndHvd3nWnFDywR/KWfHrWDXKOXt8eBFhYKJpT4yuEeaWf/jFl035iBar0FMgp4UEv5gRL8VEV1HF269OoB/GjVPUrelzoMER7QpglH6jNYTTDagKdCkX+YkiWtIGTmnZZwmOmIk4MeOKKTVjYBPw+6WAIXyas0adSySCBaVk1FhmnhfuDFa94mCBYuQxQbAHzWIp1UpCyMYzJuRyMw== 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=MdjzojHcuBT96abEwzKozCOPIPJAXDc3x8XJ/bPfy5Q=; b=k7DA+t6UglK+1Q+c9VK3ZnFgRi6g7w0ty0OGJOcFatc9inttjcWmIP8c16761gjP93kgRRf3OEGvguYZ0gUw0LlMEpG8gZVNfFtum8DvbCvn/CKK/YRxXTADD/JsAAM/Jo+hH/VWvqMmNkS7Gyvym3ZjB1kO/3G/3pcRKsf2ffkmb41oN2HceuVm5qFNokahQDyVcKLdZPXuplM4kKsV7ODjqGvXCF+FKSMR5zpffpAkyvvKn06mjYzy3b9j85AYl0eVQV1O2KnZf+FYOZymI5BwEQa3Fpaoctw2LV+KwmsDYWoHyL+dK0PwqBk5/aXS+9Vwvy1dnOleEOzi/kSEHQ== 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 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=MdjzojHcuBT96abEwzKozCOPIPJAXDc3x8XJ/bPfy5Q=; b=vIoOqa4mvMhnwt7c9P4c9z1Ys0wh9nq+NxBSf7EVsPkeOVlBRxplLZ4WHsOSOjdAikzJi8jqzdKY/dfVAkJhrE49wJ/MXuEDejTbMQWr7ltffgt1Tup+wfYnDJwN+z6Xpze7x6m+ir2+uT3xsKhN02toNYeIkfEDR9zeJsOJGHs= Received: from BN1PR10CA0021.namprd10.prod.outlook.com (2603:10b6:408:e0::26) by DS7PR12MB5766.namprd12.prod.outlook.com (2603:10b6:8:75::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Wed, 8 Feb 2023 07:36:42 +0000 Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e0:cafe::b5) by BN1PR10CA0021.outlook.office365.com (2603:10b6:408:e0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.17 via Frontend Transport; Wed, 8 Feb 2023 07:36:42 +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 BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6086.17 via Frontend Transport; Wed, 8 Feb 2023 07:36:42 +0000 Received: from BLR-5CG1133937.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.2375.34; Wed, 8 Feb 2023 01:36:37 -0600 From: Bharata B Rao To: , CC: , , , , , , , , , , , Bharata B Rao Subject: [RFC PATCH 3/5] x86/ibs: Enable per-process IBS from sched switch path Date: Wed, 8 Feb 2023 13:05:31 +0530 Message-ID: <20230208073533.715-4-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230208073533.715-1-bharata@amd.com> References: <20230208073533.715-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT031:EE_|DS7PR12MB5766:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a363116-817e-43b1-5c51-08db09a738df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IdTCdkx5UyzbNDKrYc1PoxsP1Y2dCzUNsXnJggY4dBOSLyvfsHBaLBlXfiqGlVWtz3H0vdl+1OfrMRVCiJ3dZSrgKDKNWeCVnXy2Mlp1Dter99h1KbDBCYOSiQiJXIOcArvAMyaac1JOOc5iFWbxArQt60cxmdYOvbTSxez1UYu7RrtYs3PO88dxIX61z3xOYTkZVs6kNuwa+eXd4VvbC5RR5EVS9jDZL6eZnxNENQT+7dmZZ+jl79GL1hdKnVG9kMETXnvmoKJjmNS8tQ6iIZF5aisd/aVvvYvfUA0E7ohhsC6LgdF6lecxQbyy+ppTRagg9EK9qUK0dtFBSRDjB5azQavyyQR11nc1K9kxst10pNZgufjRdTt+gWOgUVjJ4qEhFuZQKlXA7ZajfwVJU7eS5ouheYXXaBrX3wBKjEuwRVaR0DJkxlLIglWoFg4MMIb01NUeQQpzCWvR/CcA4PVKD468yAketZqRFR+p00TMnWqzItIqq9eZt/WURbzT1rbjK0fY28AogW9j12EzD0ot84BABkdAzwTzLMi0G1RVTgnQuTiM/IYGPpimzxGc4ocz6+sL0Am8TaOZ9X46+o3Anz6NHkkTnLqnOrnAnMyxZnAH3O762kFyetNnNILxLnAqLIPiD0xLlknC2lVSOSFqcWBP3EbTi4kb3aRZI4cIBAVEYi7ia1H5CxzNTTBNi7afe2O/N0ASS4B6nwJiRTgRRPqLce2FJ09uxH0LXC6qgpAJ6sN/wh0p0kfp5Wu+ 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:(13230025)(4636009)(346002)(136003)(376002)(396003)(39860400002)(451199018)(36840700001)(40470700004)(46966006)(81166007)(426003)(83380400001)(47076005)(36756003)(5660300002)(2906002)(7416002)(1076003)(186003)(16526019)(82310400005)(26005)(8936002)(6666004)(41300700001)(478600001)(40460700003)(7696005)(86362001)(82740400003)(2616005)(40480700001)(336012)(356005)(110136005)(54906003)(4326008)(70206006)(70586007)(316002)(8676002)(36860700001)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2023 07:36:42.1095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a363116-817e-43b1-5c51-08db09a738df 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: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5766 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mjbqhwin1pw84jpubshe4jju4x7mnpie X-Rspamd-Queue-Id: 15D901C000A X-HE-Tag: 1675841805-912634 X-HE-Meta: U2FsdGVkX18ZiXm/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LKlkjMJhI8h/qlf4xVC96hM+Ew8lyG/WVmDMbcDoF5r0WpNYJtoO7f1AHZW8FCjyLxPOZ1V56ED4iKNP8e4Etk+L14gSwP4OLuxGE7xCzqQzqTEPjMU0K/54xZgADjQlNoOhO1WKy5SWnSvwq5j4Pg3JN8pJwRZZPrfu0Ek6XDoU7x3lJAa06al5n9jJIKhHXLHn1mQNSMDlWJ1G5FC9s9xkT8L4nI9UsdR8hITuleLJuyo/bon2BYfFMkOkm2hEXM/CBq3mud2mCBtqQzBh3FXifEZ9Jhs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Program IBS for access profiling for threads from the task sched switch path. IBS is programmed with a period that corresponds to the incoming thread. Kernel threads are excluded from this. The sample period is currently kept at a fixed value of 10000. Signed-off-by: Bharata B Rao --- arch/x86/mm/ibs.c | 27 +++++++++++++++++++++++++++ include/linux/sched.h | 1 + kernel/sched/core.c | 1 + kernel/sched/fair.c | 1 + kernel/sched/sched.h | 5 +++++ 5 files changed, 35 insertions(+) diff --git a/arch/x86/mm/ibs.c b/arch/x86/mm/ibs.c index adbc587b1767..a479029e9262 100644 --- a/arch/x86/mm/ibs.c +++ b/arch/x86/mm/ibs.c @@ -8,6 +8,7 @@ #include /* TODO: Move defns like IBS_OP_ENABLE into non-perf header */ #include +#define IBS_SAMPLE_PERIOD 10000 static u64 ibs_config __read_mostly; struct ibs_access_work { @@ -15,6 +16,31 @@ struct ibs_access_work { u64 laddr, paddr; }; +void hw_access_sched_in(struct task_struct *prev, struct task_struct *curr) +{ + u64 config = 0; + unsigned int period; + + if (!static_branch_unlikely(&hw_access_hints)) + return; + + /* Disable IBS for kernel thread */ + if (!curr->mm) + goto out; + + if (curr->numa_sample_period) + period = curr->numa_sample_period; + else + period = IBS_SAMPLE_PERIOD; + + + config = (period >> 4) & IBS_OP_MAX_CNT; + config |= (period & IBS_OP_MAX_CNT_EXT_MASK); + config |= ibs_config; +out: + wrmsrl(MSR_AMD64_IBSOPCTL, config); +} + void task_ibs_access_work(struct callback_head *work) { struct ibs_access_work *iwork = container_of(work, struct ibs_access_work, work); @@ -198,6 +224,7 @@ int __init ibs_access_profiling_init(void) x86_amd_ibs_access_profile_startup, x86_amd_ibs_access_profile_teardown); + static_branch_enable(&hw_access_hints); pr_info("IBS access profiling setup for NUMA Balancing\n"); return 0; } diff --git a/include/linux/sched.h b/include/linux/sched.h index 19dd4ee07436..66c532418d38 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1254,6 +1254,7 @@ struct task_struct { int numa_scan_seq; unsigned int numa_scan_period; unsigned int numa_scan_period_max; + unsigned int numa_sample_period; int numa_preferred_nid; unsigned long numa_migrate_retry; /* Migration stamp: */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e838feb6adc5..1c13fed8bebc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5165,6 +5165,7 @@ static struct rq *finish_task_switch(struct task_struct *prev) prev_state = READ_ONCE(prev->__state); vtime_task_switch(prev); perf_event_task_sched_in(prev, current); + hw_access_sched_in(prev, current); finish_task(prev); tick_nohz_task_switch(); finish_lock_switch(rq); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c9b9e62da779..3f617c799821 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3094,6 +3094,7 @@ void init_numa_balancing(unsigned long clone_flags, struct task_struct *p) p->node_stamp = 0; p->numa_scan_seq = mm ? mm->numa_scan_seq : 0; p->numa_scan_period = sysctl_numa_balancing_scan_delay; + p->numa_sample_period = 0; p->numa_migrate_retry = 0; /* Protect against double add, see task_tick_numa and task_numa_work */ p->numa_work.next = &p->numa_work; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 771f8ddb7053..953d16c802d6 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1723,11 +1723,16 @@ extern int migrate_task_to(struct task_struct *p, int cpu); extern int migrate_swap(struct task_struct *p, struct task_struct *t, int cpu, int scpu); extern void init_numa_balancing(unsigned long clone_flags, struct task_struct *p); +void hw_access_sched_in(struct task_struct *prev, struct task_struct *curr); #else static inline void init_numa_balancing(unsigned long clone_flags, struct task_struct *p) { } +static inline void hw_access_sched_in(struct task_struct *prev, + struct task_struct *curr) +{ +} #endif /* CONFIG_NUMA_BALANCING */ #ifdef CONFIG_SMP