From patchwork Tue Oct 17 12:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 154231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4091527vqb; Tue, 17 Oct 2023 05:18:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmVpx6VmQbg9OYWsBlkOVULp1pX9vbFnc+ML4DqukGTsgO5Fi2L4MXKN1yqQYJKLaHgmoC X-Received: by 2002:a17:90b:4f88:b0:274:99ed:a80c with SMTP id qe8-20020a17090b4f8800b0027499eda80cmr2115793pjb.3.1697545125441; Tue, 17 Oct 2023 05:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697545125; cv=none; d=google.com; s=arc-20160816; b=f3vnDury9SkFjn4LtrPgH5Sb8zreWKmDtKYSaQkLrE5hROjCwRT4NWAz8P7Nl3na2O 3igE63WNagfJFvoslOFFzCiJs70x0q55Xs94ghdDeTk68xrDuG4VdzmlFkxCOWBXZZr5 liq0fY4l3+iBKII3mnCk6h5/cOiVAanDEPZjEgmjuBOMNOc17efJNRgv7MqxkzvlJkip MJ1Rwb0SlQimMfTVDsNDDh1SF3PSK4vdYx7AUaHmhRISrTV0uwzEnRrLAmclGOehzMxg mULJJxO8CbyLqLq+y2hvpzcT1R7R5UefPkO6oI11qepzbD9fVEolvPqodeJm23qTsd2m aczw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=QbYP9dGfEQSVZtPNiC/4mXl13vm8ozRDwm7/4xMAAVM=; fh=xlieDj8o+jXNpmF12Ogr15ctNOIP4IDTbgVIdoNwRD8=; b=KVclt3rC+/2XZBNsB6nqQE0aJ6f8RlVgmz6PMoh+qwxGvW07L7lV5dEsqT0K7KExYM TVnlwW4RnURgE9nA/bCji7QSjfaIJzzjrD70ZKj2ndTFck3MkXFL/RfOqDpQBzCrZfBG Bz535405fHd4CFNClTlDyQ09FTPhX8LlJF5r4BhjJHC7BYJvGd13uwORdP8idBEMyV03 jp3hsV9t0Ck7SruTLk8sq5r/tcZJWzLmuwXPahWTH80r18nQr+eZGczOyBJdLC8sZnL+ P4P98Zr4tcNN/3drbY9lir3wiXnZ5IC1eJbZh7PXGjlnwBBi3DZ7Kg1NYb+s/PmHNWhf Mo5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4PbyoR0a; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q125-20020a632a83000000b005ac86e7df6esi1633038pgq.363.2023.10.17.05.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:18:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4PbyoR0a; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 92E5C801C7C4; Tue, 17 Oct 2023 05:18:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234341AbjJQMSh (ORCPT + 19 others); Tue, 17 Oct 2023 08:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234794AbjJQMSG (ORCPT ); Tue, 17 Oct 2023 08:18:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF14B95; Tue, 17 Oct 2023 05:18:04 -0700 (PDT) Date: Tue, 17 Oct 2023 12:18:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697545083; h=from:from:sender:sender:reply-to: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; bh=QbYP9dGfEQSVZtPNiC/4mXl13vm8ozRDwm7/4xMAAVM=; b=4PbyoR0a6tmvfBHMGrGf0Q3tO0nQUjRxHfYlXPblr6dMdF4fCyvph4YoIjbRAWQ3dqFtuv CWI35peKYMR7qeyosrB8udg0NiOqP2O2XwET2ysrUal3Fj+EQyKhdZu4euAEqTIFHesFDG wp0o+mWbh93QMsFdFSCM68fmljzxpZPFsaD5m6tQ5MOOLE5xk1WVSYMDad9OhSWDYn1DUv BUslMZqX9lVe1DDMBt9GPJ/ir/3nOZ/2uZC91+UCJy+IfZ03pzk8IY8m1UAtO5IrzNUr7y CTOA7l6lWGmAAQL9Plz75SOurXdQAD4AGnf+vMIEDNqXuDFeNP3fs8AlHPzmTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697545083; h=from:from:sender:sender:reply-to: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; bh=QbYP9dGfEQSVZtPNiC/4mXl13vm8ozRDwm7/4xMAAVM=; b=3ESPB+KFr4j+1Ce9nJz8K1BO9fRHYtPmUyDHw0Yh/ki0dJctdjWsg/n5xdaW9aDJtelVPa yX3Xm+gE6D3rmQAA== From: "tip-bot2 for Babu Moger" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Add multiple tasks to the resctrl group at once Cc: Babu Moger , "Borislav Petkov (AMD)" , Peter Newman , Tan Shaopeng , Fenghua Yu , Reinette Chatre , ilpo.jarvinen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231017002308.134480-2-babu.moger@amd.com> References: <20231017002308.134480-2-babu.moger@amd.com> MIME-Version: 1.0 Message-ID: <169754508299.3135.1526802957654004468.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 05:18:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779960097432161371 X-GMAIL-MSGID: 1780005077419586939 The following commit has been merged into the x86/cache branch of tip: Commit-ID: fe2a20ea0b0953189e57740debc7dcc789d1ea55 Gitweb: https://git.kernel.org/tip/fe2a20ea0b0953189e57740debc7dcc789d1ea55 Author: Babu Moger AuthorDate: Mon, 16 Oct 2023 19:23:00 -05:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 17 Oct 2023 11:27:50 +02:00 x86/resctrl: Add multiple tasks to the resctrl group at once The resctrl task assignment for monitor or control group needs to be done one at a time. For example: $mount -t resctrl resctrl /sys/fs/resctrl/ $mkdir /sys/fs/resctrl/ctrl_grp1 $echo 123 > /sys/fs/resctrl/ctrl_grp1/tasks $echo 456 > /sys/fs/resctrl/ctrl_grp1/tasks $echo 789 > /sys/fs/resctrl/ctrl_grp1/tasks This is not user-friendly when dealing with hundreds of tasks. Support multiple task assignment in one command with tasks ids separated by commas. For example: $echo 123,456,789 > /sys/fs/resctrl/ctrl_grp1/tasks Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Peter Newman Reviewed-by: Tan Shaopeng Reviewed-by: Fenghua Yu Reviewed-by: Reinette Chatre Reviewed-by: Ilpo Järvinen Tested-by: Peter Newman Tested-by: Tan Shaopeng Link: https://lore.kernel.org/r/20231017002308.134480-2-babu.moger@amd.com --- Documentation/arch/x86/resctrl.rst | 9 ++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 25 ++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst index 4c6421e..178ab1d 100644 --- a/Documentation/arch/x86/resctrl.rst +++ b/Documentation/arch/x86/resctrl.rst @@ -306,7 +306,14 @@ 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 + group. Multiple tasks can be added by separating the task ids + with commas. Tasks will be assigned sequentially. Multiple + failures are not supported. A single failure encountered while + attempting to assign a task will cause the operation to abort and + already added tasks before the failure will remain in the group. + Failures will be logged to /sys/fs/resctrl/info/last_cmd_status. + + 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 diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 09848ff..fe23969 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -696,11 +696,10 @@ 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) - return -EINVAL; rdtgrp = rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { rdtgroup_kn_unlock(of->kn); @@ -715,7 +714,27 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of, goto unlock; } - ret = rdtgroup_move_task(pid, rdtgrp, of); + while (buf && buf[0] != '\0' && buf[0] != '\n') { + pid_str = strim(strsep(&buf, ",")); + + if (kstrtoint(pid_str, 0, &pid)) { + rdt_last_cmd_printf("Task list parsing error pid %s\n", pid_str); + ret = -EINVAL; + break; + } + + if (pid < 0) { + rdt_last_cmd_printf("Invalid pid %d\n", pid); + ret = -EINVAL; + break; + } + + ret = rdtgroup_move_task(pid, rdtgrp, of); + if (ret) { + rdt_last_cmd_printf("Error while processing task %d\n", pid); + break; + } + } unlock: rdtgroup_kn_unlock(of->kn);