Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp506349lqo; Thu, 16 May 2024 12:30:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRw94x3uj9tSW5hPGPyEz3UtUcKk3XBVSsXf8SqpBg1EcTc6czM9FbPWEIdFr6gJf9iuHk/X0oproKO+htemMUE2HiQL+99LBfovp7vw== X-Google-Smtp-Source: AGHT+IH1PtqQ5dsUBNuJ+p/8bHuR0uzO2ghr7xa8NndW4cjyf86D2f+owQM4276koYtxa2GQ8EsW X-Received: by 2002:a05:6a00:13a6:b0:6ea:b073:c10c with SMTP id d2e1a72fcca58-6f4e029cbefmr30156197b3a.6.1715887832909; Thu, 16 May 2024 12:30:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715887832; cv=pass; d=google.com; s=arc-20160816; b=D2RLpp7fIwGaAEun9USIEW9w7UWP+6ShkAFFusfVxU/KHiYUz8Ul3FwkqSUt9MVRUf tONt5/LPsVJ1vUFle6206bG4M2s92n3K+onpZYegXLM7w98KU8FgBMp70nhrrP55h/2r KgPWQk0DwgKmGgGQt9pT1DuRRFFcPv9RBBuh1BmWR1A4NqOHtf1vcifFvHWMeeUntOhi 7wuV5GLuiukCDx582l95WOCywB0rfw0Wk6Dw3NP7nOTrfks5pvD1H1XgqSYqdzlHhle9 R8Q+yZQbaZoJvyTqB1FAy1e6ttv4hDXf2R6eoOHZjBf9JytOkzPB7scfBZqplQnYMJGT 16zQ== 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=V/chxMa/Gj7pZdtme6fcFfNNAAL7xcfxQRHCvbZqZis=; fh=xvpLrZ0uwiF/TnwMPVQj7Kf83DcaeKssHeriesNIUb4=; b=G1clSY/TZkpYeYfXtQfD08asyKS2TCVqiQ0EIbJT4coNa9HUnza7XjZDzZIo3WPAlZ r34ZXidzqKB09YlDQuxqZ0WUH3TmZY9bPmHxkSYoKqctX78crRSW+juWe+HsDFN6bjdE XKe0q+9alIjx+wsXHLodedOiCNeTzKh8vwsGz/UyGDWfHWH0OVTao/5YfGF7ZkETdKXM /6xuJuM5+nMMGjknv5xNJL46+RL7N2QhIcIvanpbYEW34C2hf9J9jLOnAUmpQec05jC1 xUiasUAHTY3UH2Ey7BhcCzweh3bkNdaLazfadyucD+mqQ2DCn2TLi95ANlhf3Uxos97E d40A==; 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-181521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181521-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. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4f39aa750si11524972b3a.369.2024.05.16.12.30.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:30:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-181521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181521-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 660ADB25784 for ; Thu, 16 May 2024 19:13:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E30215B13D; Thu, 16 May 2024 19:08:24 +0000 (UTC) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 C1B8915B122; Thu, 16 May 2024 19:08:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886503; cv=none; b=iuGlpkeypLCJJYbsft7SYjYqLJic3dZ5Z2tKib7CXWnlxxcxp87ytsWEtClMdc/io+KSpmrCApbnA6sI722cTL/9pGEQNQfToHke2c3RCjPCiexEx6ZwqTyRS0vTMj+ZZU24fBfk7DucCnsMhC8bilDEK/o9c54nX0Fi8Gu0n+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886503; c=relaxed/simple; bh=BBuLJN0RtiuFgr6SaE8THENmcUL4dkXcdDEVIERoegA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KWfVEGrAx41lbmPaTRfycwnuGunBajeCjx7/n5sUaRC0XX5FCyw7/iI51jskZONUBFeMDNlgMT/rJaYBHW6d6pPjhhTDeZ/O4xZ5OHsBg8WpH0OZ4+30eOtUmty/a4p+ECSVuuhiVrMrzLedNsdVwEgr1ytyYN8ff9qkACyL3T0= 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.46 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-f46.google.com with SMTP id 5b1f17b1804b1-42011507a54so35038485e9.0; Thu, 16 May 2024 12:08:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715886500; x=1716491300; 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=V/chxMa/Gj7pZdtme6fcFfNNAAL7xcfxQRHCvbZqZis=; b=Hma7euspQapO5/MKrO/nD8tImvJPvPwg7UdoEgaLXxVIt6FWqT5QITYGRSJgeG7llL M8OE43C/wErfBFkDaQZ5Ebk6YWVDxtZSuw+z3h7cF/BDVxHjD19I4eK1VLx4otw0SWVB 7+asPNzi3+L9KanaFtKAcOvm4MtIyKDHAjO0gD1qIcL1gyMwxoMTY6HMr13TT38jLyzK FEOIo2UJY9s7HJkLFeyYPfF2fVuUwTuuIzto90EnF9Jr4KkYFg457E4eDvfTkEqZDPLe c5QyGY7BnqDTVB7LDchvsVTTBNFfASO7pvfF9/whkzXSd2yllTajO13gsL1duLTenmfU U2UQ== X-Forwarded-Encrypted: i=1; AJvYcCVluWRIUZNHP6+9EC4dlFDD4Ht14piODvv7epQGsJtB7pvCYawc195BrC7nd6q0ZVcwX/pq9+j4U2uIYeCwzySObnX8/9GnYBGIcY4FEJxrHgl+GgVZs3PBs5ph8kDX7lRSrPUXZw== X-Gm-Message-State: AOJu0YyloG4LM+UkU8VfFw+j3+A8kslDSLzCKm0Ue+xA1iX/r4rC0jI4 Z5ahjlchoXfKK/Nz8HecDsg9SX29QOWhKS3GLN/XBlPs5E2NNAnl X-Received: by 2002:a05:600c:474b:b0:41c:13f6:1ee1 with SMTP id 5b1f17b1804b1-41fea930c73mr192345865e9.4.1715886499933; Thu, 16 May 2024 12:08:19 -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.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:08:19 -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 4/7] sched/isolation: Adjust affinity of managed irqs according to change of housekeeping cpumask Date: Thu, 16 May 2024 22:04:34 +0300 Message-ID: <20240516190437.3545310-5-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 irq_affinity_adjust() is prototyped from irq_affinity_online_cpu() and irq_restore_affinity_of_irq(). Core test snippets without infrastructure: 1. Create managed IRQ on specific cpu with: static int test_set_affinity(struct irq_data *data, const struct cpumask *m, bool f) { irq_data_update_effective_affinity(data, m); return 0; } static int make_test_irq(void) { struct irq_affinity_desc a = { mask: *cpumask_of(test_cpu), is_managed: true }; static struct irq_chip test_chip = { .irq_set_affinity = test_set_affinity }; int test_irq = __irq_alloc_descs(-1, 1, 1, 0, THIS_MODULE, &a); irq_set_chip(test_irq, &test_chip); irq_set_status_flags(test_irq, IRQ_MOVE_PCNTXT); request_irq(test_irq, test_irq_cb, 0, "test_affinity", 0); return test_irq; } 2. Isolate specified CPU. 3. Assure that test_irq doesn't affine with test_cpu: cat /proc/irq/$test_irq/smp_affinity_list Signed-off-by: Costa Shulyupin --- kernel/cgroup/cpuset.c | 3 ++- kernel/sched/isolation.c | 44 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9d01e8e0a3ed9..2e59a2983eb2e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -225,7 +225,8 @@ static struct list_head remote_children; /* * The set of housekeeping flags to be updated for CPU isolation */ -#define HOUSEKEEPING_FLAGS (BIT(HK_TYPE_TIMER) | BIT(HK_TYPE_RCU)) +#define HOUSEKEEPING_FLAGS (BIT(HK_TYPE_TIMER) | BIT(HK_TYPE_RCU) \ + | BIT(HK_TYPE_MANAGED_IRQ)) /* * Partition root states: diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 85a17d39d8bb0..b0503ed362fce 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -135,6 +135,43 @@ static void resettle_all_timers(cpumask_var_t enable_mask, cpumask_var_t disable } } +static int irq_affinity_adjust(cpumask_var_t disable_mask) +{ + unsigned int irq; + cpumask_var_t mask; + + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + return -ENOMEM; + + irq_lock_sparse(); + for_each_active_irq(irq) { + struct irq_desc *desc = irq_to_desc(irq); + + raw_spin_lock_irq(&desc->lock); + struct irq_data *data = irq_desc_get_irq_data(desc); + + if (irqd_affinity_is_managed(data) && cpumask_weight_and(disable_mask, + irq_data_get_affinity_mask(data))) { + + cpumask_and(mask, cpu_online_mask, irq_default_affinity); + cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ)); + irq_set_affinity_locked(data, mask, true); + WARN_ON(cpumask_weight_and(irq_data_get_effective_affinity_mask(data), + disable_mask)); + WARN_ON(!cpumask_subset(irq_data_get_effective_affinity_mask(data), + cpu_online_mask)); + WARN_ON(!cpumask_subset(irq_data_get_effective_affinity_mask(data), + housekeeping_cpumask(HK_TYPE_MANAGED_IRQ))); + } + raw_spin_unlock_irq(&desc->lock); + } + irq_unlock_sparse(); + + free_cpumask_var(mask); + + return 0; +} + /* * housekeeping_update - change housekeeping.cpumasks[type] and propagate the * change. @@ -144,6 +181,8 @@ static void resettle_all_timers(cpumask_var_t enable_mask, cpumask_var_t disable */ static int housekeeping_update(enum hk_type type, cpumask_var_t update) { + int err = 0; + struct { struct cpumask changed; struct cpumask enable; @@ -171,11 +210,14 @@ static int housekeeping_update(enum hk_type type, cpumask_var_t update) lockup_detector_reconfigure(); #endif break; + case HK_TYPE_MANAGED_IRQ: + err = irq_affinity_adjust(&masks->disable); + break; default: } kfree(masks); - return 0; + return err; } static int __init housekeeping_setup(char *str, unsigned long flags) -- 2.45.0