From patchwork Tue Jan 3 22:06:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 38664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4837785wrt; Tue, 3 Jan 2023 14:08:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXu9Xw9zLWZpPyvUUQ3JGOXtN5VCqWqUxHVKS9qlgIDxYd5BQl/DA9Uv64zz1+iDTHgmGTMt X-Received: by 2002:a17:90a:5e0f:b0:225:cf39:425a with SMTP id w15-20020a17090a5e0f00b00225cf39425amr39868443pjf.20.1672783718958; Tue, 03 Jan 2023 14:08:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1672783718; cv=pass; d=google.com; s=arc-20160816; b=Ak8xHhDg1Hgk/ArbWERHKpFlyNbS/3SbTGbs21cDlDKM0BohPDAaZW3eyq7fah5LYP 8/j9H7d5Bq6AyP5tZQcpduMJzWbDvbS3l2MfoLjoYwqSCEEx2mIGzx+R6ZgcKqJcQ0Ix j8QtUybeWr/8Hi1UwqvPOWOq6/AsH0kJ2xcfsH7yVxp9u4h3Kd8BQwcAJ6ZPYse+cjpi NnkHU5OG26oPKWpdWFZx7qjUAe4Z7LuzXh0c0VSGe2MRNzjmi477o5g8pMuVOkkV50Ms WLpgUcJkhSIrizOUh4H4bac3FJZOSObUCiw2u+V0S7Ktrqtt4LKntk9NyWcNNlHvmjfg VGPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=XGoGdo5+YBuE6uAlKVq9zY0tvuT7OvAW/M2XeRWX/o4=; b=H/1NtVEs83cwy/oGzP8e0DyhEpUjd9pBzf09LZWuAIU9lqmlCUz3f1ZBmYzNZw4YDl /scAzZDuLImZvYOW7ewkBq+GYk8SimZ9suU5HotYfTQHKDFI1th/EU2mT1ReA/w/YlP2 5XKEMwSWXD31tveknoCdiXTG/OdOPMa+sBsARXf5+LZMuMH1nHYObpmqeW7LxejHrunA F+QIHoQ9hx2veUaM0e5u57khDQ3Sc9mY2lWurCzzXvfjxVIglDYhV6nep+XX7R/w6Ody e5BLVJECHDF/SAQcJpYQ7LDRFXrbWK9t5hFYXZfn28Wjrhy3d08BQHbamwS8XlsUdIHz 0VPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="C/Ql8vcB"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj15-20020a17090b088f00b002188ec41c94si30228690pjb.98.2023.01.03.14.08.26; Tue, 03 Jan 2023 14:08:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="C/Ql8vcB"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238350AbjACWHj (ORCPT + 99 others); Tue, 3 Jan 2023 17:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238343AbjACWHF (ORCPT ); Tue, 3 Jan 2023 17:07:05 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2056.outbound.protection.outlook.com [40.107.92.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB22F008; Tue, 3 Jan 2023 14:06:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aMMmVzKWFg5GMBI2k9cfPAJcUTWFOYSjuFIgWhCY3tI7iBx+aWzEz4sG/jVwA3+Zr994tOp/3eg0wEzAzsK4M46I0nXr2Kq+wbv6VY3F9vBpEp4axD4h7ity36GfMvhCSz7zDf2Wcgq4f4lIqR5KM80sA3zRHei2B557p9qrSUwI7eFAKIrjKHwPakBJMDWYnFMG0coBoU3IpAZizyacWjXqeRK7AmBg9O1cNoW4txFNzjj9ssT07WqKj5ppGAS0B+I66ZHBkrD8or+Txv0+DIhI50zl0nCzT9ypYGLqCFedsNNiLgzk4gv9MD1LHEAlCI/CY6/FqPVyxMGSXQXUxg== 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=XGoGdo5+YBuE6uAlKVq9zY0tvuT7OvAW/M2XeRWX/o4=; b=lXeja4ARC1lKpvjELpKgSRHm+OvkOWTQaP/VhpR9Rsq8gKG+PfXOW5AEyquB0T0QeAvrUP+fipgrDxeuAXGnxCV884MYf1TDvlLvfHv+YdJBSOCsIl7A93tzlObKhf6mPZTm2KpeyCLh0hT+66XB4F/+6OT7NxQw0/0gvR+fqincH3CuOloXt/Ea28vvU7zqD7V0hiC8xbEpmRoKe1HJbnbDMdn5KTZUzLuufDYDBHdVsIE+C2JJZAjiBvmwxNL3KyZasKeLx/6ySPTgR6GSuKp0nTO6KsAX8zgvXYayyA+xP3backtOlszgtiwhWxCOnZ7CsgS1EskV+c3ga0seDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de 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=XGoGdo5+YBuE6uAlKVq9zY0tvuT7OvAW/M2XeRWX/o4=; b=C/Ql8vcBnZRD8McJbNqOBK7B06Ruf7mfOUSgv6Kcx3T/voqP4+vtJbHxL0borjGhnDnjrx86qwyUWwfBgv2RbgGSF1sTvplnYxlY6e3cQrDxpqMJ+JpfAwwLVo/3hyuhcoaA4Clqb7DgmtkBJjD17+QgSis0QXzTMPqdb9t/6Lw= Received: from DM5PR07CA0110.namprd07.prod.outlook.com (2603:10b6:4:ae::39) by CY8PR12MB8066.namprd12.prod.outlook.com (2603:10b6:930:70::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Tue, 3 Jan 2023 22:06:37 +0000 Received: from DS1PEPF0000E645.namprd02.prod.outlook.com (2603:10b6:4:ae:cafe::33) by DM5PR07CA0110.outlook.office365.com (2603:10b6:4:ae::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5966.19 via Frontend Transport; Tue, 3 Jan 2023 22:06:37 +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 DS1PEPF0000E645.mail.protection.outlook.com (10.167.17.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5944.8 via Frontend Transport; Tue, 3 Jan 2023 22:06:37 +0000 Received: from [127.0.1.1] (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; Tue, 3 Jan 2023 16:06:35 -0600 Subject: [RFC PATCH 1/3] x86/resctrl: Add multiple tasks to the resctrl group at once From: Babu Moger To: , CC: , , , , , , , , , , Date: Tue, 3 Jan 2023 16:06:35 -0600 Message-ID: <167278359522.34228.17439739885350817510.stgit@bmoger-ubuntu> In-Reply-To: <167278351577.34228.12803395505584557101.stgit@bmoger-ubuntu> References: <167278351577.34228.12803395505584557101.stgit@bmoger-ubuntu> User-Agent: StGit/1.1.dev103+g5369f4c 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: DS1PEPF0000E645:EE_|CY8PR12MB8066:EE_ X-MS-Office365-Filtering-Correlation-Id: 41f26d17-a2b6-4a1a-74d1-08daedd6c8c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uZEsVfrM5HH8l6khSVSPNVOEpBNxdThYo4HMJ0ox01fJy0G5sfvpc0PhW0izXucLFZeWKt0/OL4cGMpx3zsH18rWJpSaWyIMATRGqoulafIQQOfc7vzfRTVKuyhWNHMHGu4rer03VFRHAtFmN+tTJk/I3J8jlbvoTuGpMTey1qRNs0YApOpQ3Di/uZt2/gJjdWU9PktsuVRYFzVQOM7YYK8ansQjbn+H6nvHNvpC4Eg0LTDWONONuorjkkJp6LlAXhumikjQisnZIdeml66bGXCVMGd7c+LZkDwTh+apv8/S9XVA8uGhzYu0JVsLGU1bWD9rMAoUQqvc5mRPNcVn7o+eNPK1SkY7ggZjV3K79wcXlVkiHWieMcdFnXTfDfMLjGTiCbJsrWEvWutC0bo31lniO3O0jM9iiUDWw/fOfMJKETvsdHMsI1pOALuQ6uD+v9ahhRQ9krXzGXYfx3ErxRBHzfn5/EHHjutuu7n2gyW48hJlI8Ksa6nGJBY2FKSpsWtNIgRb4OENnAkqCqA9BmnOMc9fV7sY6fWgex7Cokfr8XfF1/YVgoZqDrmJDWoHQNUqc+0QQmqcSd0puszxb/N0OzH4JUWPy0dUWWJyPpP4H4iE4Otn+XbcYadUCJH36n88D0wKU7Wl8CwRDCDgAgjH/UvnDyHH6T/bp8rR4KH0wSAa72PCCGPzPyyaS+4PcjsVqh8MszY1nICftthypubZz6Gr0Z2vDtjWWxatUjpA92NVxJIB0hNeQ96achT6qwjbv3H0OZSMhLDgY513WWtyZKT6WEjdULF4TKj4Y/8= 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:(13230022)(4636009)(7916004)(396003)(376002)(136003)(346002)(39860400002)(451199015)(40470700004)(46966006)(36840700001)(5660300002)(2906002)(7416002)(44832011)(8936002)(8676002)(41300700001)(4326008)(66899015)(16576012)(316002)(70206006)(70586007)(54906003)(110136005)(478600001)(9686003)(33716001)(82310400005)(336012)(26005)(16526019)(40480700001)(186003)(426003)(83380400001)(47076005)(103116003)(82740400003)(356005)(81166007)(86362001)(40460700003)(36860700001)(22166009)(71626007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2023 22:06:37.2798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41f26d17-a2b6-4a1a-74d1-08daedd6c8c6 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: DS1PEPF0000E645.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8066 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754040860883298711?= X-GMAIL-MSGID: =?utf-8?q?1754040860883298711?= Right now, the resctrl task assignment for the MONITOR or CONTROL group needs to be one at a time. For example: $mount -t resctrl resctrl /sys/fs/resctrl/ $mkdir /sys/fs/resctrl/clos1 $echo 123 > /sys/fs/resctrl/clos1/tasks $echo 456 > /sys/fs/resctrl/clos1/tasks $echo 789 > /sys/fs/resctrl/clos1/tasks This is not user-friendly when dealing with hundreds of tasks. Improve the user experience by supporting the multiple task assignment in one command with tasks separated by commas. For example: $echo 123,456,789 > /sys/fs/resctrl/clos1/tasks Signed-off-by: Babu Moger --- Documentation/x86/resctrl.rst | 13 ++++++------ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 ++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst index 71a531061e4e..f26e16412bcb 100644 --- a/Documentation/x86/resctrl.rst +++ b/Documentation/x86/resctrl.rst @@ -208,12 +208,13 @@ All groups contain the following files: "tasks": Reading this file shows the list of all tasks that belong to this group. Writing a task id to the file will add a task to the - group. If the group is a CTRL_MON group the task is removed from - whichever previous CTRL_MON group owned the task and also from - any MON group that owned the task. If the group is a MON group, - then the task must already belong to the CTRL_MON parent of this - group. The task is removed from any previous MON group. - + group. Multiple tasks can be assigned at once with each task + separated by commas. If the group is a CTRL_MON group the task + is removed from whichever previous CTRL_MON group owned the task + and also from any MON group that owned the task. If the group is + a MON group, then the task must already belong to the CTRL_MON + parent of this group. The task is removed from any previous MON + group. "cpus": Reading this file shows a bitmask of the logical CPUs owned by diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index e5a48f05e787..344607853f4c 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -686,28 +686,49 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct rdtgroup *rdtgrp; + char *pid_str; int ret = 0; pid_t pid; - if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0) + /* Valid input requires a trailing newline */ + if (nbytes == 0 || buf[nbytes - 1] != '\n') return -EINVAL; + + buf[nbytes - 1] = '\0'; + + cpus_read_lock(); rdtgrp = rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { - rdtgroup_kn_unlock(of->kn); - return -ENOENT; + ret = -ENOENT; + goto exit; + } + +next: + if (!buf || buf[0] == '\0') + goto exit; + + pid_str = strim(strsep(&buf, ",")); + + if (kstrtoint(pid_str, 0, &pid) || pid < 0) { + ret = -EINVAL; + goto exit; } + rdt_last_cmd_clear(); if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED || - rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { - ret = -EINVAL; + rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { rdt_last_cmd_puts("Pseudo-locking in progress\n"); - goto unlock; + ret = -EINVAL; + goto exit; } ret = rdtgroup_move_task(pid, rdtgrp, of); -unlock: + goto next; + +exit: + cpus_read_unlock(); rdtgroup_kn_unlock(of->kn); return ret ?: nbytes;