Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1059980rdb; Mon, 19 Feb 2024 03:03:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/su8oh63i5ru+o/YPA2PaZeVK4eb7zcGRsNJQYDpt1jAVqY5latsdD577CFkzK4h34hhjiPhjilSrwYAgPobuBIgrFh8zW89BZ/cP0g== X-Google-Smtp-Source: AGHT+IGBRJ+ZNuYq/XvN1k+RbUgENNNm0VebcnqBIyN3u3HyM31tIPRLjvIYjnpCLAqW+buSn8FQ X-Received: by 2002:a17:906:649:b0:a3e:b869:11b3 with SMTP id t9-20020a170906064900b00a3eb86911b3mr915281ejb.55.1708340599250; Mon, 19 Feb 2024 03:03:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708340599; cv=pass; d=google.com; s=arc-20160816; b=brnjQJlEJ0fiWU2aFT7NZ1VsUqiTjf065dFJFiMy3CT2NM1UF1hRi5rrtysZFPjxbC d6ndU4iQUbz8LR7uPu80gToutSRx3mVJXaU5qTbLpxdqt3tDapqAabRPHadTxqTTpI2+ jNljHKWTD0AgrxaN3fSKN3MDqEaImCf/3PTs2xfSrIWCy2T/RAIEQwTTQhtEZJjfBggN PxeAHicAO/Ce1K8gFXbE/S2Vy07kq+dSZIoUh6Fm5u2/2cJf1KejXXHsxnCWc5aW0krg v4fWtw414PhiMz2fMagah1IlYmkXDIP5NCt4xRP6+M1tqVs/TNfLOoYwuUIozP3Bc27w Kojw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=zKDld/uBnZjKtA3ymC1kDB57x1PvjJD6+IsbauqnIRc=; fh=WSXPwQPYnnWCb9RV2+NbxK+Xyy/eY4aCAqhOpzNNfrw=; b=xRBqNRLur/S1KQWyRKrE1lZtmjQRIMxZBS3Ouh898r/nexV9kjH0vC5d/MpZQUAs16 XaSOu4j59GzL/cYTTFHZtjNgql19OH11/htkVpO4GG/guR21qCfrQNPfyywTqyhe5fS1 qGJ4Md5YJUjTl85p3lvb38qInR+l3MybbT8R/O5BYYbqhoIc9oU3WYsIwb5CszMGD4LT wY6oXWx10L8/PPqJhRE9+XTIbe7p3YGSJOxVMq46WeD+jsN5/OcUh9u3z+u6bCA91Ku+ zXpPCkD4V5EZvVJAUijXtILAg67fNMwhPzu2WtMY5T90tLDjZiGIb4TSGfHHtIY/x1qS bJgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="km/R2N0W"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71171-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a18-20020a1709064a5200b00a3deba43856si2271197ejv.706.2024.02.19.03.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:03:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71171-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="km/R2N0W"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71171-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 am.mirrors.kernel.org (Postfix) with ESMTPS id EC87D1F24468 for ; Mon, 19 Feb 2024 11:03:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBBF12C182; Mon, 19 Feb 2024 11:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="km/R2N0W"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="W4XwrQWP" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7892EE572; Mon, 19 Feb 2024 11:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708340592; cv=none; b=X4yIi37FIG9li3KMlQtidXt+fKxfkQsdxo1TzSZ2KPGb1oKlcd80lb1AlP7awnvy5H28pLDFcwIZiH1E6xRJZCPxs8j/Yp3mBfi3Uv+fbfTTDzMqHz5gOxEN2ogHeLdFQPCh+/4H+ZeNtGNnBdc32YIUrGbOxUDS2sexbV4Yes8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708340592; c=relaxed/simple; bh=FmJQEyGJLQVLQYwch0n2HMhFM8e+cKsyEMeHqRiQ8SM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=ddeTZWuWB+VX4txXf93QEcS2036swhX7Sfa/cK0lRrnkVuje5qhN582pEmz6ARUxxiBVUhzcSWlvpDbG25yu4n/jdejmGXnlrbu8gYcpbFGOo3kDRguy+6MR/20Jm8x0LkW+o84mpmZXpANw3/9r6aVAnuvN+UJGmXp55dMckn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=km/R2N0W; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=W4XwrQWP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708340587; 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=zKDld/uBnZjKtA3ymC1kDB57x1PvjJD6+IsbauqnIRc=; b=km/R2N0WeQl1h7yz5GnViOyv7tHLEwvzYLLabsfcjt2IUYyU2sVbYVViII9pL9a+1hoS6k sHJeBmxpSQEMjJ31AWpD7773/d94TU2p76eVW+0GdnqNLRhSqVoEBJJJIphQSGeouP3Nly Xl4WHudNOWljN1nOdgU1njWe8N7aEw1Daul6PfIhRVGSrIDAdc/KckanTTE/eYIpI1tRjR x/bhGxyNLcrwMnsZGDs/BZKvfIOUwMB6m+/XvPKDxceXwPwlpYrbHDWiRU/PLAkZ3xywjn 4YrhVBf2SUNgEYaRzHKGg+BqugSuJkdz0PfPHU0mZ5MVuWYOQ20Ic4NojGByGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708340587; 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=zKDld/uBnZjKtA3ymC1kDB57x1PvjJD6+IsbauqnIRc=; b=W4XwrQWPdPbbcWQ5uhHpV6oF0yPIWmY7na5LfqG+OiWCsL3D4e2qkqsujOrvpTnPSkMEKv HZdEgHYk2Jrf0AAA== To: Leonardo Bras , Greg Kroah-Hartman , Jiri Slaby , Tony Lindgren , Andy Shevchenko , John Ogness , Ilpo =?utf-8?Q?J=C3=A4rvinen?= , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Leonardo Bras , Florian Fainelli , Shanker Donthineni Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [RFC PATCH v2 3/4] irq: Introduce IRQ_HANDLED_MANY In-Reply-To: <87zfvwai62.ffs@tglx> References: <20240216075948.131372-2-leobras@redhat.com> <20240216075948.131372-5-leobras@redhat.com> <87zfvwai62.ffs@tglx> Date: Mon, 19 Feb 2024 12:03:07 +0100 Message-ID: <87v86kaf84.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Mon, Feb 19 2024 at 10:59, Thomas Gleixner wrote: > On Fri, Feb 16 2024 at 04:59, Leonardo Bras wrote: > >> In threaded IRQs, some irq handlers are able to handle many requests at a >> single run, but this is only accounted as a single IRQ_HANDLED when >> increasing threads_handled. >> >> In order to fix this, introduce IRQ_HANDLED_MANY, so the returned value of >> those IRQ handlers are able to signal that many IRQs got handled at that >> run. >> >> Is scenarios where there is no need to keep track of IRQ handled, convert >> it back to IRQ_HANDLED. > > That's not really workable as you'd have to update tons of drivers just > to deal with that corner case. That's error prone and just extra > complexity all over the place. > > This really needs to be solved in the core code. Something like the uncompiled below should do the trick. Thanks, tglx --- --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -38,7 +38,8 @@ struct pt_regs; * @affinity_notify: context for notification of affinity changes * @pending_mask: pending rebalanced interrupts * @threads_oneshot: bitfield to handle shared oneshot threads - * @threads_active: number of irqaction threads currently running + * @threads_active: number of irqaction threads currently activated + * @threads_running: number of irqaction threads currently running * @wait_for_threads: wait queue for sync_irq to wait for threaded handlers * @nr_actions: number of installed actions on this descriptor * @no_suspend_depth: number of irqactions on a irq descriptor with @@ -80,6 +81,7 @@ struct irq_desc { #endif unsigned long threads_oneshot; atomic_t threads_active; + atomic_t threads_running; wait_queue_head_t wait_for_threads; #ifdef CONFIG_PM_SLEEP unsigned int nr_actions; --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1194,9 +1194,11 @@ irq_forced_thread_fn(struct irq_desc *de local_bh_disable(); if (!IS_ENABLED(CONFIG_PREEMPT_RT)) local_irq_disable(); + atomic_inc(&desc->threads_running); ret = action->thread_fn(action->irq, action->dev_id); if (ret == IRQ_HANDLED) atomic_inc(&desc->threads_handled); + atomic_dec(&desc->threads_running); irq_finalize_oneshot(desc, action); if (!IS_ENABLED(CONFIG_PREEMPT_RT)) --- a/kernel/irq/spurious.c +++ b/kernel/irq/spurious.c @@ -350,6 +350,12 @@ void note_interrupt(struct irq_desc *des desc->threads_handled_last = handled; } else { /* + * Avoid false positives when there is + * actually a thread running. + */ + if (atomic_read(&desc->threads_running)) + return; + /* * None of the threaded handlers felt * responsible for the last interrupt *