Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp505524lqo; Thu, 16 May 2024 12:28:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbvfLxx5zwxfHypX4UBsIIIMZSgs3IwjnNcBh4ze5GtFlSOUgJtJbX7BwBx0oLroMF6wQ9ZzPTXyPgYpIh3nPYhc2GE5dro+z0xmWw+w== X-Google-Smtp-Source: AGHT+IGVF+6pxvpLwzUb1duyICsqac9fPQJhtrjFSwFxZnbc+fFPRsdKAZ+GG55GxGerdbb39reF X-Received: by 2002:a05:6a20:a124:b0:1a7:4f8b:6439 with SMTP id adf61e73a8af0-1afde0ecb90mr32613945637.34.1715887734186; Thu, 16 May 2024 12:28:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715887734; cv=pass; d=google.com; s=arc-20160816; b=y3E+qZcmgxtDuVaZotv8zEHJCapJY0SDrAjvw64DRdPPpV868+XbZKKBQCzYfpYgIH Rh+TIephfprr7mIbkXpk0owKJqj+1v7uk6hl3x8JmbJts42QU0c7Aid6jpAqNmWs6Btl T5Oj1JR4Cpd0bbWAnop5kDkIWL981LVne2+4ArcZHpXDG6epBtAOogvqpoU10d9cT8HA YJ7qMyZ64CrmWkMJ67eSX37sirUCbcwUtcMV1LuZsOrqVCKFTKW1xy4NYhP8upTKvq8A xPkjqmB0JKEp17QAQ0VBinDyRRRc+pC7WlGiKl7SUdIEtwo5G7VvifVV1TDGUtj75BNZ LHTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from; bh=61LwWLE7vVj50HZOr0xZhY/e3UrTUHc9jD8In45+Uew=; fh=FfqHtK8EjqCQStJOOZ/kMx8XET1qElbVUlfe5L7w+GU=; b=v4mYh022+My3z0BSXJV/IZRrnqA3OaDjFOX/AWJLJMyS4LtHCVnXPe64fV/LC5ZDZA rZLbu3iaAEh3QEbcdHFwflo31SI95ACI6GjjA0bQUebHvBnWg1flam8xJD/h6VqTdgl4 HC6Drql1Hst8+zkMxgHR1ELdcy6VySA0hQydWhgneQrT55iQyiMiOOFopnhzDwW67vIv Z5iQJAgQQAb/kVoBDUuGn6YnBbtslP94nvMoyOzjV4XKHlAKpOv25VPvmVXkFDMESPcl 6+D5+C9jfYb1N5n8jW1XQZiIOpEeIu19Dw0nSrMcNSFSgHmGvoVdt9FDYKK4BT/3AzoL 23XQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-181518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181518-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-65d71b55f44si626027a12.160.2024.05.16.12.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:28:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-181518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181518-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 85A8EB25262 for ; Thu, 16 May 2024 19:12:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B26CB158DD0; Thu, 16 May 2024 19:07:47 +0000 (UTC) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60412158D72; Thu, 16 May 2024 19:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886467; cv=none; b=iyp6aSSdE6tqupwZD7mfE+MSUXMBwkt9DXvPeTID44CqXU6iKFklc+J26d9JuKT0XNgyVWYw+2rvM41qQwRI+KFF03A+vbbBDOrVF4xkPPeQdhDORiJG4DkM4KOn51p7gDEGvhFG+VuM1eyezzzFGembhZzvRRDbjnFEfSJD0ww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886467; c=relaxed/simple; bh=EmFSx8/Ii7PDX25whTQOapn04D9/HEs4Zzlo9FTr/5A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PnLvNplX5VozThf9gUVsy8UYK4Y8Gogo90Ytg1ExkR2w1k6Bi1ClpkIForkFtb/Rmi7FDlpsTReWrQIMI2P+AKwFA4tVFNWvcryQNjYVqLIlOxqcuV99nCKDTcJGo9snzjUF1/u1pOYYuRfce+HlcvESMELKQQwTcosSLEor6tU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42016c8daa7so33208275e9.2; Thu, 16 May 2024 12:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715886464; x=1716491264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=61LwWLE7vVj50HZOr0xZhY/e3UrTUHc9jD8In45+Uew=; b=SCYCtO24VQHRUl/Z1D2vfoR3Xd+qjz7bCNLlux16gb++RFvygVgpMI/dSHhYRj+FJD dRUAzao1z4cTAtubeZq2GWVjk/gaNenSU5HYu4K1odYoJ+qOHSF1HTT9Ilpyr7NKJUvD R0Nm5VP5IneWoNr9j9J8hJRAm7tV081KPbKPgzek4XOLoIdM8tBGxGfH6uceulyQ214X 4KgSVuC405rUXDnt9INU6/1fPKqEH93hRrwloLM4ysOc9oCZ3xcqhlWCriFna7/HSvNy tsY8yATMcVz5U0LV4J7rB91ekb3dmo8WGOW2YqDJ5j3TvPn79jaLZs5yqnXdAoifJ7OY llGA== X-Forwarded-Encrypted: i=1; AJvYcCXSRlJM1mcBtnR15flDV1dr550aDIXdjJJht8t1jWr4WQydxnPl8ghzLmAJzvhzyF26HFeNXzOmpSF4a6yp7NKVInKIUfOAHsy3Zt3nId9oHPLL88vRBXFNzauxTisZMQ03EsUwFw== X-Gm-Message-State: AOJu0YyHryGzBM2baZXx6Bm1PPADyLJlx9pl2pQPM02sZlOTAf12M3zh QaEza/Sxq2bFLWCHxrKGcFnxcQfEr1fAP8Nkrv9SG3pRHEL3MV+d X-Received: by 2002:a05:600c:5487:b0:41b:851a:af43 with SMTP id 5b1f17b1804b1-41feaa38f9dmr133889165e9.11.1715886463488; Thu, 16 May 2024 12:07:43 -0700 (PDT) Received: from costa-tp.redhat.com ([2a00:a040:1a3:c059:8b18:f13e:da9b:5a8e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9335sm275834155e9.29.2024.05.16.12.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:07:43 -0700 (PDT) From: Costa Shulyupin To: longman@redhat.com, pauld@redhat.com, juri.lelli@redhat.com, prarit@redhat.com, vschneid@redhat.com, Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Zefan Li , Tejun Heo , Johannes Weiner , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Petr Mladek , Andrew Morton , Masahiro Yamada , Randy Dunlap , Yoann Congal , "Gustavo A. R. Silva" , Nhat Pham , Costa Shulyupin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: [PATCH v1 1/7] sched/isolation: Add infrastructure to adjust affinity for dynamic CPU isolation Date: Thu, 16 May 2024 22:04:31 +0300 Message-ID: <20240516190437.3545310-2-costa.shul@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240516190437.3545310-1-costa.shul@redhat.com> References: <20240516190437.3545310-1-costa.shul@redhat.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 Introduce infrastructure function housekeeping_update() to change housekeeping_cpumask during runtime and adjust affinities of depended subsystems. Affinity adjustments of subsystems follow in subsequent patches. Parent patch: "sched/isolation: Exclude dynamically isolated CPUs from housekeeping masks" https://lore.kernel.org/lkml/20240229021414.508972-2-longman@redhat.com/ Test example for cgroup2: cd /sys/fs/cgroup/ echo +cpuset > cgroup.subtree_control mkdir test echo isolated > test/cpuset.cpus.partition echo $isolate > test/cpuset.cpus Signed-off-by: Costa Shulyupin --- kernel/sched/isolation.c | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 948b9ee0dc2cc..036e48f0e7d1b 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -116,6 +116,39 @@ static void __init housekeeping_setup_type(enum hk_type type, housekeeping_staging); } +/* + * housekeeping_update - change housekeeping.cpumasks[type] and propagate the + * change. + * + * Assuming cpuset_mutex is held in sched_partition_write or + * cpuset_write_resmask. + */ +static int housekeeping_update(enum hk_type type, cpumask_var_t update) +{ + struct { + struct cpumask changed; + struct cpumask enable; + struct cpumask disable; + } *masks; + + masks = kmalloc(sizeof(*masks), GFP_KERNEL); + if (!masks) + return -ENOMEM; + + lockdep_assert_cpus_held(); + cpumask_xor(&masks->changed, housekeeping_cpumask(type), update); + cpumask_and(&masks->enable, &masks->changed, update); + cpumask_andnot(&masks->disable, &masks->changed, update); + cpumask_copy(housekeeping.cpumasks[type], update); + housekeeping.flags |= BIT(type); + if (!static_branch_unlikely(&housekeeping_overridden)) + static_key_enable_cpuslocked(&housekeeping_overridden.key); + + kfree(masks); + + return 0; +} + static int __init housekeeping_setup(char *str, unsigned long flags) { cpumask_var_t non_housekeeping_mask, housekeeping_staging; @@ -314,9 +347,12 @@ int housekeeping_exlude_isolcpus(const struct cpumask *isolcpus, unsigned long f /* * Reset housekeeping to bootup default */ - for_each_set_bit(type, &housekeeping_boot.flags, HK_TYPE_MAX) - cpumask_copy(housekeeping.cpumasks[type], - housekeeping_boot.cpumasks[type]); + for_each_set_bit(type, &housekeeping_boot.flags, HK_TYPE_MAX) { + int err = housekeeping_update(type, housekeeping_boot.cpumasks[type]); + + if (err) + return err; + } WRITE_ONCE(housekeeping.flags, housekeeping_boot.flags); if (!housekeeping_boot.flags && @@ -344,9 +380,11 @@ int housekeeping_exlude_isolcpus(const struct cpumask *isolcpus, unsigned long f cpumask_andnot(tmp_mask, src_mask, isolcpus); if (!cpumask_intersects(tmp_mask, cpu_online_mask)) return -EINVAL; /* Invalid isolated CPUs */ - cpumask_copy(housekeeping.cpumasks[type], tmp_mask); + int err = housekeeping_update(type, tmp_mask); + + if (err) + return err; } - WRITE_ONCE(housekeeping.flags, housekeeping_boot.flags | flags); excluded = true; if (!static_branch_unlikely(&housekeeping_overridden)) static_key_enable_cpuslocked(&housekeeping_overridden.key); -- 2.45.0