Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1065730pxj; Fri, 21 May 2021 05:48:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzozHI/WCu0Btmb5EY+f7KIQeWMvMSer8KrYy0MB3wNpRzCeUtctI5FQVzwcvQZBAeD8ze+ X-Received: by 2002:a92:d9d2:: with SMTP id n18mr12993959ilq.10.1621601313270; Fri, 21 May 2021 05:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621601313; cv=none; d=google.com; s=arc-20160816; b=b3FTjCYDmAFTJOaVNYxQ3S2NhlmyW5rjY+yk33g6YerVh0xHzgKreclUtllp5ueUJX nJ92kAqlZkKRIiMt4gWwiyDVofH/jrgwndtUGq5wE16JAiuB7SMrNmke3nEThoZAcL4c /9Z79vIofx14OcvPmaL8boY1J7l51BoYIoLfXWveifIpNtpd6bENJ1AsYdMKNw+RAUch nHXPz3RHmvQOfnXmPwAhJiwAGYDcBR4x989CUqXLHRtm9gxYKBekebvyHF45hHOAL+z3 TvwLwQRbY698m6Hbwv1v766HOrhFpkIiRnrDSIDIkR7Hl2zUrkacAQCSsrWg0PJfSjKl wKYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=73BhFEnE00P9EM7W8eDaV9ldNZ5X2YG6+sa8CRY7WwM=; b=pZ3Is9R8sFRO8HPNiNlWGNUbZsp7KBfpkAOFaVOpueYO5wVAjda01ujw3fpBpERSFs PgR8ykXUr5ykerUc/NNcHtG6ButDdecj2xh0fAJNk7B7JRn6CgY4ozDsjulTSE2ZGkSV 4+zK1iQ16QCP6EHqWULp/KoIlJtpiL6TGwPMBSr3zjdTDptu0rVJUCDOx+8536G+hqT4 txk3SyMsGWebrXIp5eq4ff7QpcIOAviB36hacJfXrxHbgtEZIg+JCyxLB6nkPRGhkTmk ZHEwCmnwhQ6n1Ty27RxhpI0yaFpom8U1ezc8Y/mJETNI2tdCQAQDcDDW0BEB6F1uJps0 rBbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=L25M5Zy6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si5163468iow.103.2021.05.21.05.48.18; Fri, 21 May 2021 05:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=L25M5Zy6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234083AbhEUMEc (ORCPT + 99 others); Fri, 21 May 2021 08:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbhEUMEb (ORCPT ); Fri, 21 May 2021 08:04:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B7C0C061574; Fri, 21 May 2021 05:03:08 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1621598586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=73BhFEnE00P9EM7W8eDaV9ldNZ5X2YG6+sa8CRY7WwM=; b=L25M5Zy6NkFNkFQBlo/MBFeB3Te3ulISHeXqR86FRlFCq8g6/qWe3XZ9/pwYYjkJ12704U q9oPzIRd0iGCg1nN3gY3diTI02L0JBvQSKYWgiTFFoH/ZRePhtv2PYf5UsVDswqr7r+DwQ 5zJSxlP4BkqdpHUn2cv5x/8f/hXJK1toxKuforc+pQ193/UextIlqjeeGgMSPvANL+vr+p iIg82cUse/0NSDAEaaV0af9Jig2TmfUADkV5cd6/QqMDOfDCFqcqJJG1rZUTNJ//Gl1gZp 6xZSGTHaCw0eAQW50oGNbgCMYvaZatY6jV+UxSdVx1J3k1tD1GaaYLHk1Vh6Qw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1621598586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=73BhFEnE00P9EM7W8eDaV9ldNZ5X2YG6+sa8CRY7WwM=; b=HEmmL6baryu7dXT+7IwyJWArNzSXr5UDH3j4xtBPCKgdAYRJHTQFzFPDgdTW9qDXx7Dk2G 3SF1UU9zwPJyrCBA== To: Nitesh Lal , Jesse Brandeburg , Robin Murphy , Marcelo Tosatti Cc: Ingo Molnar , linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, jbrandeb@kernel.org, "frederic\@kernel.org" , "juri.lelli\@redhat.com" , Alex Belits , "linux-api\@vger.kernel.org" , "bhelgaas\@google.com" , "linux-pci\@vger.kernel.org" , "rostedt\@goodmis.org" , "peterz\@infradead.org" , "davem\@davemloft.net" , "akpm\@linux-foundation.org" , "sfr\@canb.auug.org.au" , "stephen\@networkplumber.org" , "rppt\@linux.vnet.ibm.com" , "jinyuqi\@huawei.com" , "zhangshaokun\@hisilicon.com" , netdev@vger.kernel.org, chris.friesen@windriver.com, Marc Zyngier , Neil Horman , pjwaskiewicz@gmail.com Subject: [PATCH] genirq: Provide new interfaces for affinity hints In-Reply-To: <87zgwo9u79.ffs@nanos.tec.linutronix.de> References: <20210504092340.00006c61@intel.com> <87pmxpdr32.ffs@nanos.tec.linutronix.de> <87im3gewlu.ffs@nanos.tec.linutronix.de> <87zgwo9u79.ffs@nanos.tec.linutronix.de> Date: Fri, 21 May 2021 14:03:06 +0200 Message-ID: <87wnrs9tvp.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The discussion about removing the side effect of irq_set_affinity_hint() of actually applying the cpumask (if not NULL) as affinity to the interrupt, unearthed a few unpleasantries: 1) The modular perf drivers rely on the current behaviour for the very wrong reasons. 2) While none of the other drivers prevents user space from changing the affinity, a cursorily inspection shows that there are at least expectations in some drivers. #1 needs to be cleaned up anyway, so that's not a problem #2 might result in subtle regressions especially when irqbalanced (which nowadays ignores the affinity hint) is disabled. Provide new interfaces: irq_update_affinity_hint() - Only sets the affinity hint pointer irq_apply_affinity_hint() - Set the pointer and apply the affinity to the interrupt Make irq_set_affinity_hint() a wrapper around irq_apply_affinity_hint() and document it to be phased out. Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20210501021832.743094-1-jesse.brandeburg@intel.com --- Applies on: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core --- include/linux/interrupt.h | 41 ++++++++++++++++++++++++++++++++++++++++- kernel/irq/manage.c | 8 ++++---- 2 files changed, 44 insertions(+), 5 deletions(-) --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -328,7 +328,46 @@ extern int irq_force_affinity(unsigned i extern int irq_can_set_affinity(unsigned int irq); extern int irq_select_affinity(unsigned int irq); -extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); +extern int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, + bool setaffinity); + +/** + * irq_update_affinity_hint - Update the affinity hint + * @irq: Interrupt to update + * @cpumask: cpumask pointer (NULL to clear the hint) + * + * Updates the affinity hint, but does not change the affinity of the interrupt. + */ +static inline int +irq_update_affinity_hint(unsigned int irq, const struct cpumask *m) +{ + return __irq_apply_affinity_hint(irq, m, true); +} + +/** + * irq_apply_affinity_hint - Update the affinity hint and apply the provided + * cpumask to the interrupt + * @irq: Interrupt to update + * @cpumask: cpumask pointer (NULL to clear the hint) + * + * Updates the affinity hint and if @cpumask is not NULL it applies it as + * the affinity of that interrupt. + */ +static inline int +irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m) +{ + return __irq_apply_affinity_hint(irq, m, true); +} + +/* + * Deprecated. Use irq_update_affinity_hint() or irq_apply_affinity_hint() + * instead. + */ +static inline int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m) +{ + return irq_apply_affinity_hint(irq, cpumask); +} + extern int irq_update_affinity_desc(unsigned int irq, struct irq_affinity_desc *affinity); --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -487,7 +487,8 @@ int irq_force_affinity(unsigned int irq, } EXPORT_SYMBOL_GPL(irq_force_affinity); -int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m) +int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, + bool setaffinity) { unsigned long flags; struct irq_desc *desc = irq_get_desc_lock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL); @@ -496,12 +497,11 @@ int irq_set_affinity_hint(unsigned int i return -EINVAL; desc->affinity_hint = m; irq_put_desc_unlock(desc, flags); - /* set the initial affinity to prevent every interrupt being on CPU0 */ - if (m) + if (m && setaffinity) __irq_set_affinity(irq, m, false); return 0; } -EXPORT_SYMBOL_GPL(irq_set_affinity_hint); +EXPORT_SYMBOL_GPL(__irq_apply_affinity_hint); static void irq_affinity_notify(struct work_struct *work) {