From patchwork Fri Feb 16 07:59:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 201986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp367665dyb; Fri, 16 Feb 2024 00:12:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbyQu4BvXfPAEafe+JPNddNbnaLQTWSkxNQ/eEa7EH8L7Xa/ZSvjtE3Y7pvbDUCnseMe5PHOKextwGyOZU5gxAnovMLQ== X-Google-Smtp-Source: AGHT+IETwGxNBmtz2u0lcURDVIj4XgfflWOFvkAcdB3zmEetpguu7SlRJLD8mbYj+/bxFLBMuxWl X-Received: by 2002:a05:6a00:3a81:b0:6e0:392b:c236 with SMTP id fk1-20020a056a003a8100b006e0392bc236mr3969497pfb.11.1708071152881; Fri, 16 Feb 2024 00:12:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708071152; cv=pass; d=google.com; s=arc-20160816; b=q5fp5J2v9Nb00od5URM5XVsy9nT3cHfMZIr8sTfdgPt7q8SuksbG+l3oIPA41fWyUp /bW9Jnct91orMUnLCVjtHtdPZxEpnCWVlEV2zgHFz/1hmrgxp3g0gSpFJHKveUh4sayG lCkJQmC8b/JPx9iUBKrfGSHbcdjdnUbftjjIbEV1amSbz7tNGwMeH24cTzoGP9HrBBBn MRRG/xUcdzmGq+zLhVkzFQiXbOOQEP95mhB/4yAnTSFmAGBNBYWdbYuDgFYoHLWJBqEM ACQl2+APuwNPb99BCvJ6+MgkmDfKVgYCSmm4xdO8HPZJdeFccpi4j+TV4dkRTt6AsG8G t86A== 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:cc:to:from:dkim-signature; bh=LC1bKFmWstjcuRp0NCZgXGUr7lDByzyZO+jUi4bsRIg=; fh=k34Nnq/Kwq/SZsiVv5WWtSAM8XrsxgnVMy19Vz8zceU=; b=iLVRydp/5OT5l/8uFWhm16lVdhZjKL2o4MYt2EcBfnBcpxp2QB+6i4F2XIrPZOhkMH JC9vCdysPLNbtWyu98RqPQQLSsdPKkKV89gOyyjoLpRP7pe2tcuWqnsnX4RaLwVx3fGt I/+mJy8Fsh6rHoT9ybN+5Jw/hyTuAFsXdYE7ccbR0d8539a6SLZP0cgcUpNb8llbYCCc TRn9sDaMBahNlkSPZcm1R5r+eWu/gW+k4X+/cHD6SWKEbvkb4y7B2DbdVYjjAUF4wmpf hjrOQlq2CWhkxvkl34HZdLduIaixXXv+6we2TqYgISdBLJcvgxli9ZPMG7viD5ynAyQM 08ww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DBE+Xc9t; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68205-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68205-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s186-20020a635ec3000000b005ced6c45233si2543785pgb.712.2024.02.16.00.12.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:12:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68205-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DBE+Xc9t; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68205-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68205-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9076C281F27 for ; Fri, 16 Feb 2024 08:12:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 527DB1BC3F; Fri, 16 Feb 2024 08:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DBE+Xc9t" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 C19A21B966 for ; Fri, 16 Feb 2024 08:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070428; cv=none; b=CdX0945px40GpcT6BGfG2GIeY7si7WZwEBNeNnYNm+eKFfMM9cPCWFXOC35io+c5wWMR7YwSrBHs51PuGhSnUhx0x4/uA56YjXbN+fILYR7EyBaiaxqmxSnoKwVOiG5/13SSh3aPWdD/f9Uhty29z/jZoAW0xEP5milxOGjgOQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070428; c=relaxed/simple; bh=I7YQyvteIahvp42EiZA+1wJMmZSJKR2ugc165xDp9JA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dnw6qHnGze9x/vuyHwwZQr8s+BE5O8gAofGLcp8S6MNleGj/W9+QegQ7C2JXn31RE2Y9ji1D3UIQ2MS31Z5/qbTMqMNrhn2jtDW56UJ/UKyM7l0hTwze4TnXs8Ua+l+1QrCLFaTVciqaMDbFRwlT1pn/jrG1+OTYg9KSHrlx+Xw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DBE+Xc9t; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708070424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LC1bKFmWstjcuRp0NCZgXGUr7lDByzyZO+jUi4bsRIg=; b=DBE+Xc9tJl/0LeLAU81fPIj28BzWM1ii/y6wBbv4DwWcoXtvCZGEDhVTvP7eYtrQPZvXcm 6cTQXWriR/KdfVQrGY27/kxWmtGuoDZD8kP/QxrSZy50NCf7DiKeeTCeiu3ret5WUlQJdl Q3ob2rSwXumZjTCEyfMqLrEksd10hrc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-245-FaZWLHlCNle43F5nURfdvg-1; Fri, 16 Feb 2024 03:00:21 -0500 X-MC-Unique: FaZWLHlCNle43F5nURfdvg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-781d8e14fd8so229610385a.3 for ; Fri, 16 Feb 2024 00:00:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708070420; x=1708675220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LC1bKFmWstjcuRp0NCZgXGUr7lDByzyZO+jUi4bsRIg=; b=Q9kj+fyAmwB+fzbr9FRKaCLXWN/lockWZvS6V35OdWQ2CJQV/jf+wZtIzGwpflYloI BMciXkj0iqoRW28F8gX8pIUfr0nFBgGOToh87t4KrxUmV8gPFfEbxtaHxDAwNmSSTYY2 jq/SWWlw72xmJjNBRDYnzKEzuJI7pav29rlnm1tAYr9kO2narBS2XVaCmhPuJx0xhqUb cuYsRKnaMVkjc7wc0fwKjHLkbmnUbR/iQJDD9K5HFwtWoDs+B4xDSC4QT4rrma5845Nl DS6nKKanvwTNjQjyJ+XhvlR+iPBVZjmB2mlvwkwbyspVMyA5V0vn4H+1uyHlPurhkUTn 0jrQ== X-Gm-Message-State: AOJu0YzhgiZslAMbBauRh6OtYpeLJO9X7/RomN9zIcV6nCKscRb+9eWV kVd2/xeCS9AnvNEqJiS1VrRBisCwMFlFdhFKOgcD1WYpUyZjDHG3l+JQk1iyAgxunMH1EZm2dcj BrlpFk1u6aSs/+BQZUvnN4XgWF8r/ZYsqvDXlbsC/VCndZEGz01M+oLEITh1g2Q== X-Received: by 2002:a05:620a:810:b0:787:28cb:5ab8 with SMTP id s16-20020a05620a081000b0078728cb5ab8mr4048020qks.41.1708070420521; Fri, 16 Feb 2024 00:00:20 -0800 (PST) X-Received: by 2002:a05:620a:810:b0:787:28cb:5ab8 with SMTP id s16-20020a05620a081000b0078728cb5ab8mr4047996qks.41.1708070420262; Fri, 16 Feb 2024 00:00:20 -0800 (PST) Received: from LeoBras.redhat.com ([2804:1b3:a800:4770:9d0:4bac:1782:4637]) by smtp.gmail.com with ESMTPSA id br37-20020a05620a462500b00787346f1edasm1300756qkb.54.2024.02.16.00.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:00:19 -0800 (PST) From: Leonardo Bras To: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Tony Lindgren , Andy Shevchenko , John Ogness , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , =?utf-8?q?U?= =?utf-8?q?we_Kleine-K=C3=B6nig?= , Leonardo Bras , Florian Fainelli , Shanker Donthineni Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH v2 1/4] irq: Move spurious_deferred bit from BIT(31) to BIT(0) Date: Fri, 16 Feb 2024 04:59:43 -0300 Message-ID: <20240216075948.131372-3-leobras@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216075948.131372-2-leobras@redhat.com> References: <20240216075948.131372-2-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791042417158091522 X-GMAIL-MSGID: 1791042417158091522 Makes sure the threads_handled reserve a bit for that. This will be useful in the next patch in this series. Signed-off-by: Leonardo Bras --- include/linux/irqdesc.h | 9 +++++++++ kernel/irq/manage.c | 4 ++-- kernel/irq/spurious.c | 6 ++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index d9451d456a733..62aff209315fe 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -251,4 +251,13 @@ irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class, __irq_set_lockdep_class(irq, lock_class, request_class); } +#define SPURIOUS_DEFERRED (0x1) +#define SPURIOUS_DEFERRED_SHIFT (1) + +static inline void irq_add_handled(struct irq_desc *desc, int i) +{ + i <<= SPURIOUS_DEFERRED_SHIFT; + atomic_add(i, &desc->threads_handled); +} + #endif diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 1782f90cd8c6c..5bc609c7b728c 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1191,7 +1191,7 @@ irq_forced_thread_fn(struct irq_desc *desc, struct irqaction *action) local_irq_disable(); ret = action->thread_fn(action->irq, action->dev_id); if (ret == IRQ_HANDLED) - atomic_inc(&desc->threads_handled); + irq_add_handled(desc, 1); irq_finalize_oneshot(desc, action); if (!IS_ENABLED(CONFIG_PREEMPT_RT)) @@ -1212,7 +1212,7 @@ static irqreturn_t irq_thread_fn(struct irq_desc *desc, ret = action->thread_fn(action->irq, action->dev_id); if (ret == IRQ_HANDLED) - atomic_inc(&desc->threads_handled); + irq_add_handled(desc, 1); irq_finalize_oneshot(desc, action); return ret; diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c index 02b2daf074414..d92f33b2e31ee 100644 --- a/kernel/irq/spurious.c +++ b/kernel/irq/spurious.c @@ -267,8 +267,6 @@ try_misrouted_irq(unsigned int irq, struct irq_desc *desc, return action && (action->flags & IRQF_IRQPOLL); } -#define SPURIOUS_DEFERRED 0x80000000 - void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) { unsigned int irq; @@ -312,7 +310,7 @@ void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) if (action_ret == IRQ_WAKE_THREAD) { int handled; /* - * We use bit 31 of thread_handled_last to + * We use bit 0 of thread_handled_last to * denote the deferred spurious detection * active. No locking necessary as * thread_handled_last is only accessed here @@ -328,7 +326,7 @@ void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) * returned IRQ_HANDLED since the last * interrupt happened. * - * For simplicity we just set bit 31, as it is + * For simplicity we just set bit 0, as it is * set in threads_handled_last as well. So we * avoid extra masking. And we really do not * care about the high bits of the handled From patchwork Fri Feb 16 07:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 201987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp368548dyb; Fri, 16 Feb 2024 00:14:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUufC4IFCoCgkcY9o5tFXaMcWxILNjUKi8K5KTOr1PT22dzRS+rxH/QrsgbU40AlVrD7uAOX7uEUCw/YlTKZfv3JJOYsg== X-Google-Smtp-Source: AGHT+IE/m8yIiQSaKilpoY83JB4VNgdGgXOQT4b2wJIUog+EwTqv0e6m8FFIhOsd5TOOqyWXWytt X-Received: by 2002:a05:6402:646:b0:560:1652:e7cb with SMTP id u6-20020a056402064600b005601652e7cbmr3140792edx.16.1708071291993; Fri, 16 Feb 2024 00:14:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708071291; cv=pass; d=google.com; s=arc-20160816; b=NOq7RfF1UxZsHUbxac4Ea/j/AAxcrncWDhV9h/Lv++LLxZshl/nP0AuCYg6O1xl46F BlrlTbYQ6g/OjcUABpX0riAsV2mq7opNlAtNBTH3cGSHvNCjnhRy/my91EG4i+kl0mCR BWwcPHYc9pSkl1YsZ3Yep1DPJjc12VqPYumOMc1+lN0oqa84QALEgxmMeO+73b1c909l EZ19HOr/hU4mMpbdkWvDBZ3Mt+7fpF5r1x4zdabWnm+UPyCFror5HMtKPnYa7UX+1PmI FlJFyk0C7MzcGEw5Kc+5qTLILqFCh+jxKKI+yDefDgGx3hK0yH5W0EX6+pLhuds37JI8 x2fQ== 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:cc:to:from:dkim-signature; bh=d3/GSmZNXXq4OmuXU9kp4Oh7aTznSf//j0PB7MhvXcY=; fh=k34Nnq/Kwq/SZsiVv5WWtSAM8XrsxgnVMy19Vz8zceU=; b=YZqZdns80MooFkt+gJvRXgXTbXYQfykT852XAf4LLPJdWDupx8D7bOSYynYh9dhtCs 5hNddYwlSYpjvbiiwAgvjnP/vg2mp86Vt+L3wrjXe0QKBwZPFDSTjuGR6Uudl9EqziJ6 8X8mXqtDGLApy7bDx0pv1ACesLNhLCRMRTqcaYDzmdx8BPPLEwp/e4SsPJjIJK3gPn3a yAOQ1ec/vq8iylR03DxydkQjPYqN/E97yOe7+VfjhgXUMck3xr1JU8BIn0bsDSjqkVKL DHzJUuWXSstjfl9QlUnPI5ERADK5pZboMT1lzPLwPY5yeeJhV0N5iVR+lciBf9/IWJeG gSvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M7qmMtQ9; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68206-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68206-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cy28-20020a0564021c9c00b0056117e168basi1365285edb.621.2024.02.16.00.14.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68206-ouuuleilei=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=@redhat.com header.s=mimecast20190719 header.b=M7qmMtQ9; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68206-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68206-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5925F1F21ABC for ; Fri, 16 Feb 2024 08:14:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47FAA1C288; Fri, 16 Feb 2024 08:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M7qmMtQ9" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 658A01BC30 for ; Fri, 16 Feb 2024 08:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070432; cv=none; b=fUdEcf5SMGeorYDshgt/DqdpNp6liXDD7u+XH1O3RZ9uu0QMIIYh7AXQyli42uGfMwYcVzvJreERZCTX3U6gP2zJ1ieBFbAd9UR2c+kakG0xOQvjLNUlH7DoXcToVYMFSF+VFV2VDucOgBceoF8Ywb0XmmcbZLVPDNgvTQZ74TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070432; c=relaxed/simple; bh=aEHy6hiozJg0zLqSV3cEv145/oODe8VbFXoxgPA/6rM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i69shDsMgbPU5mP6qxbVX95p+e/68U5unxT717HxMtOGwYzseZ4xvgBzh+sBq8o9CYEK2sNiwS0U9K2P0KMI1hhnbarRLi0xsfv+Jr6GFq3OY87Q6epXx2VbLBPBLoLrCfPfPuLGxGUBWELuCqaUmo9hp2Nz0yCKLw5oEEIB9BM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M7qmMtQ9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708070429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d3/GSmZNXXq4OmuXU9kp4Oh7aTznSf//j0PB7MhvXcY=; b=M7qmMtQ9h/tVlim7Iu/AT12Rb4aU5Qv6Bv07d7JSYxEHOjQWImk1KdyemsAM3Uf34KZnDC H5EykllLMOWs0M1Z2AtoclS86MPd6AvWx/pfMh6SNh2ztNGGqEW1tr0ohxU+PxmDwr1nE8 ahuwyU16NmHIUFIfmyRVEJRECfyCTrw= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-_PLKMkuAOouGUMwm9pvHKg-1; Fri, 16 Feb 2024 03:00:23 -0500 X-MC-Unique: _PLKMkuAOouGUMwm9pvHKg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-78732274d13so43725385a.1 for ; Fri, 16 Feb 2024 00:00:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708070423; x=1708675223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d3/GSmZNXXq4OmuXU9kp4Oh7aTznSf//j0PB7MhvXcY=; b=Z2AQOAFAWTLkU/J5FLObcmmNsHRPbEfdnQwA24TlFEoHu3lco/Yw4VUYC/ujzpEisj +fcWTJjwszoS/7UatD5+E2MDNEMDEFcYQk7NmRiN3oN5a/SH++GNHxyiib0BdC8EPUp9 tRLfLiklZdtJR17z5/J1RxXoM0WT8/uRKOcpZBE+y1ZDMIrOx+xrtKgamfkwb9bF/Bfg lyRMRFU1c5FGOEigk5yBPoxq9vYJEc+kxgh6aepk4A0Ou40FvjyoO4mzjBchzKnQz2JS AEDOsjFjk57qMY4DaBNaSJzflOK0FbNmGh8mUN379hshS0BDwkarbbY/brjbw106OvEL Q+0A== X-Gm-Message-State: AOJu0YzAQLV2XlbKKeCx2ybHf90vZXTJuDE8h5+9gmFLuLNrmQrpdnSZ XWO5HQjTJDVShvMHLGfvK3Hv2w/OD06yGXoMlDRBO2cqOV9juXRI4qLb7HN+A7y0RY0lMfBkc4W R+/nn7bKDyOib4/5KM0oFuzHT1isGFPBNn/gASOjrXMaTXRIUC9kv2OEpm9W3EQ== X-Received: by 2002:a05:620a:20dc:b0:785:bd25:e5f7 with SMTP id f28-20020a05620a20dc00b00785bd25e5f7mr4327146qka.40.1708070423378; Fri, 16 Feb 2024 00:00:23 -0800 (PST) X-Received: by 2002:a05:620a:20dc:b0:785:bd25:e5f7 with SMTP id f28-20020a05620a20dc00b00785bd25e5f7mr4327129qka.40.1708070423128; Fri, 16 Feb 2024 00:00:23 -0800 (PST) Received: from LeoBras.redhat.com ([2804:1b3:a800:4770:9d0:4bac:1782:4637]) by smtp.gmail.com with ESMTPSA id br37-20020a05620a462500b00787346f1edasm1300756qkb.54.2024.02.16.00.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:00:22 -0800 (PST) From: Leonardo Bras To: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Tony Lindgren , Andy Shevchenko , John Ogness , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , =?utf-8?q?U?= =?utf-8?q?we_Kleine-K=C3=B6nig?= , Leonardo Bras , Florian Fainelli , Shanker Donthineni Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH v2 2/4] irq/spurious: Account for multiple handles in note_interrupt Date: Fri, 16 Feb 2024 04:59:44 -0300 Message-ID: <20240216075948.131372-4-leobras@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216075948.131372-2-leobras@redhat.com> References: <20240216075948.131372-2-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791042563363051382 X-GMAIL-MSGID: 1791042563363051382 Currently note_interrupt() will check threads_handled for changes and use it to mark an IRQ as handled, in order to avoid having a threaded interrupt to falsely trigger unhandled IRQ detection. This detection can still be falsely triggered if we have many IRQ handled accounted between each check of threads_handled, as those will be counted as a single one in the unhandled IRQ detection. In order to fix this, subtract from irqs_unhandled the number of IRQs handled since the last check (threads_handled_last - threads_handled). Signed-off-by: Leonardo Bras --- include/linux/irqdesc.h | 2 +- kernel/irq/spurious.c | 53 ++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index 62aff209315fe..957ac02e9ec2b 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -67,7 +67,7 @@ struct irq_desc { unsigned long last_unhandled; /* Aging timer for unhandled count */ unsigned int irqs_unhandled; atomic_t threads_handled; - int threads_handled_last; + unsigned int threads_handled_last; raw_spinlock_t lock; struct cpumask *percpu_enabled; const struct cpumask *percpu_affinity; diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c index d92f33b2e31ee..4e8e2727b8beb 100644 --- a/kernel/irq/spurious.c +++ b/kernel/irq/spurious.c @@ -267,6 +267,28 @@ try_misrouted_irq(unsigned int irq, struct irq_desc *desc, return action && (action->flags & IRQF_IRQPOLL); } +static inline int get_handled_diff(struct irq_desc *desc) +{ + unsigned int handled; + int diff; + + handled = (unsigned int)atomic_read(&desc->threads_handled); + handled |= SPURIOUS_DEFERRED; + + diff = handled - desc->threads_handled_last; + diff >>= SPURIOUS_DEFERRED_SHIFT; + + /* + * Note: We keep the SPURIOUS_DEFERRED bit set. We are handling the + * previous invocation right now. Keep it for the current one, so the + * next hardware interrupt will account for it. + */ + if (diff != 0) + desc->threads_handled_last = handled; + + return diff; +} + void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) { unsigned int irq; @@ -308,7 +330,7 @@ void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) * interrupt. */ if (action_ret == IRQ_WAKE_THREAD) { - int handled; + int diff; /* * We use bit 0 of thread_handled_last to * denote the deferred spurious detection @@ -325,27 +347,20 @@ void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret) * Check whether one of the threaded handlers * returned IRQ_HANDLED since the last * interrupt happened. - * - * For simplicity we just set bit 0, as it is - * set in threads_handled_last as well. So we - * avoid extra masking. And we really do not - * care about the high bits of the handled - * count. We just care about the count being - * different than the one we saw before. */ - handled = atomic_read(&desc->threads_handled); - handled |= SPURIOUS_DEFERRED; - if (handled != desc->threads_handled_last) { - action_ret = IRQ_HANDLED; + diff = get_handled_diff(desc); + if (diff > 0) { /* - * Note: We keep the SPURIOUS_DEFERRED - * bit set. We are handling the - * previous invocation right now. - * Keep it for the current one, so the - * next hardware interrupt will - * account for it. + * Subtract from irqs_unhandled the number of + * IRQs handled since the last change in + * threads_handled. */ - desc->threads_handled_last = handled; + if (diff < desc->irqs_unhandled) + desc->irqs_unhandled -= diff; + else + desc->irqs_unhandled = 0; + + action_ret = IRQ_HANDLED; } else { /* * None of the threaded handlers felt From patchwork Fri Feb 16 07:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 201988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp368808dyb; Fri, 16 Feb 2024 00:15:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXvz+pxLYE1ztEtpWEoMj1nkcUbkN4SGdVUVEmyXO8NzWFXS1GpoYbkgn81/IEhnxhRMG4JKmsFAkrIu9JzQfnv/Z40qw== X-Google-Smtp-Source: AGHT+IH2qF5iw7hqN/CCGBkm5luGJNIA5M1tuoQI3t6zfJq0/myhEBYeVy2AsafDWkitVVbGoPjv X-Received: by 2002:a17:902:6f01:b0:1d7:5c60:f4f5 with SMTP id w1-20020a1709026f0100b001d75c60f4f5mr4026129plk.16.1708071331194; Fri, 16 Feb 2024 00:15:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708071331; cv=pass; d=google.com; s=arc-20160816; b=eKFPxXquHZdkb8wKYgLD7wFAUl/JA4XaMJZw6dUrw4BWiNPoD+FH4q1LQpAMBQiO5q f8LB9Q5pKWhZTQnrSrvBIg/dE8nwaX+YwglW0DQ/4NzWyX8RUN5RtRALNJIbDWdkn7nP cCZaLJNbaIUjPvagjQtJjiAmZ7GXZXg8TSgrz4lcXhWtzlrcYhUk/zGmqFppRR0i+fh7 L/w4VqMrOz+3Qgea18Pe/byhGiQxh4CScWgAb0AGswfZYP0iwhMaxbQcKqfLC+WrvbUT 1uEeRaF9hKIdty18Tsy4+q0nf3K7J/lLg3D8vGZ98aidOiSjIIASzW4zi1oyQixTAJYT sJ2A== 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:cc:to:from:dkim-signature; bh=lf9jFY+y8CayXQz2V+yS9ViGyyGoBfGEuY3heLM9Fu0=; fh=k34Nnq/Kwq/SZsiVv5WWtSAM8XrsxgnVMy19Vz8zceU=; b=YRuIvcTv00fUQ7j6uQDFWd+bNqQwBbG5t+dgNppp8V7aTAnrfY2yIyHJYqcWNkpZNS uGQR6bxG2kOdVFEK4u+Tbe4d5ho1GWWXus5EErS7TxfzhOX3LCIMbOOZidgrT4OFJ1jk 4xqWw2GfW8ZWvtxmcu7b8QPtOMk2KyHW/LhoG8jwp6VVGO/CSXP22nRgqk8O0up0gxYe q30/W3gp0KMqhUevqSRoYjTdfiEHt+lwzJb+tE+ZmpjGonkCrE+8D8Qv7envxP/7N9Qk 27pP3mzSqW+ymRGA2wba9pCjBiuw8j+fPP+A63XQyMzZUynEiwJ+RlGlh5uNYW31GFcy zrpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gMUWd2iW; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68207-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68207-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q5-20020a170902dac500b001d95a6b0b54si2664701plx.252.2024.02.16.00.15.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:15:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68207-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gMUWd2iW; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68207-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68207-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5CB1828462D for ; Fri, 16 Feb 2024 08:15:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAEFC1C29E; Fri, 16 Feb 2024 08:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gMUWd2iW" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 EBA431BC39 for ; Fri, 16 Feb 2024 08:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070432; cv=none; b=kY/26h06JAeNLEsmcLpo1cbUiuzgbLNTkKiD16xl4S4+O0XXsxZTqSN/U66UwlbMWfivdNGX72hi3ZTfxA2R+HlIoB1dIgH4EI3I5iq1IvC1hOy4f4tURF2pizlWFc8P34StkcpTjC3ID6OSFbhwApRSCNp0EVyHTQB/0g+3UUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070432; c=relaxed/simple; bh=Ap0hhSVhCcUi+ugheKg7fHGNULFldbyGXWaIBynCIwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TYe9reLImW9Dyd0evJe3lDqq70fssn0Wa9B4456An2AQZfrWW6RI/YUdHL9u+UfI6aB19t9uAZTCO8Zy19emQynV2tX29Lk4v+MOz5kVM1BkYMwuAIqJ3DRiBd+TOWciYUDxDSQ/4wmLs9dMzgxLfC8vy6Yx7BLyUejyJg54nUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gMUWd2iW; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708070429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lf9jFY+y8CayXQz2V+yS9ViGyyGoBfGEuY3heLM9Fu0=; b=gMUWd2iW71WYeAHeazHEo7DdiWwwCQwa7tMLQ0z7UsDbFzkaR+RbjO1nsoazHkZo7TmMZm uSdTCF4irKKjtMU/P8weT4ZZ4RJFKtDLgBFjbb8p1mL8BVWtmpgWewfwow2hllMmcAbFBZ M4AVfG830dPYPTRH+FX/4k2QMi7Ift0= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-3isx2fRgMLm3cMqidJZdYA-1; Fri, 16 Feb 2024 03:00:26 -0500 X-MC-Unique: 3isx2fRgMLm3cMqidJZdYA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7873fd60a11so97553185a.1 for ; Fri, 16 Feb 2024 00:00:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708070426; x=1708675226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lf9jFY+y8CayXQz2V+yS9ViGyyGoBfGEuY3heLM9Fu0=; b=kwFSI7I035ox5ACIUsneSZ/WrvCFWtHlhQvaj8ZXou08lgJEwvZZ7eiwgMll59iXzY v7pZwi1YolbRRMXN/n+/lz2zf4joguqPqCghixHqYMpqPt3LDZJZpJEnaZmChZgLUaFb w1y5tx/QOJTdAsgNK9SHDUtjhDBQcOnRsfvgIR3JXUMrDz22yhxPLuJG9AYzNdafo7pj l7eEtSyz2P2Yxgl8/NO/+CoyQq8NGkIMyMzAEaNnRk8qIe1A8EWdd1EbzAYfpAH1GVN5 nhB8gMy1T9ZvofugwRg71zZrLY3Dk1P9UaG/Qxw0p2pE6pye1w78z0lZfZRdbdde6fk7 5PCg== X-Gm-Message-State: AOJu0YzpT1rfTM8Yju1eFPX1E6uwK/c+ozQjzcNRBB7PSlmUfc/HM+uO /9e5hOk7Ze7TMouviptmNr3NEpPjL/677IVK2VvFfvwR/aTmsmaFGEmHnWJBRt0Pg+7Y49dyWN2 LeVowWA/A6zAi2XRtG49QKWxzQbwhxgVLnIvH2uOrfE5U1UI21JLLY962MPZ7iQ== X-Received: by 2002:a05:620a:372a:b0:787:2d4a:e91 with SMTP id de42-20020a05620a372a00b007872d4a0e91mr12380860qkb.12.1708070426070; Fri, 16 Feb 2024 00:00:26 -0800 (PST) X-Received: by 2002:a05:620a:372a:b0:787:2d4a:e91 with SMTP id de42-20020a05620a372a00b007872d4a0e91mr12380824qkb.12.1708070425766; Fri, 16 Feb 2024 00:00:25 -0800 (PST) Received: from LeoBras.redhat.com ([2804:1b3:a800:4770:9d0:4bac:1782:4637]) by smtp.gmail.com with ESMTPSA id br37-20020a05620a462500b00787346f1edasm1300756qkb.54.2024.02.16.00.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:00:25 -0800 (PST) From: Leonardo Bras To: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Tony Lindgren , Andy Shevchenko , John Ogness , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , =?utf-8?q?U?= =?utf-8?q?we_Kleine-K=C3=B6nig?= , Leonardo Bras , Florian Fainelli , Shanker Donthineni Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH v2 3/4] irq: Introduce IRQ_HANDLED_MANY Date: Fri, 16 Feb 2024 04:59:45 -0300 Message-ID: <20240216075948.131372-5-leobras@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216075948.131372-2-leobras@redhat.com> References: <20240216075948.131372-2-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791042603929754354 X-GMAIL-MSGID: 1791042603929754354 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. Signed-off-by: Leonardo Bras --- include/linux/irqreturn.h | 23 ++++++++++++++++++++++- kernel/irq/chip.c | 10 ++++++++-- kernel/irq/handle.c | 3 +++ kernel/irq/manage.c | 4 ++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/linux/irqreturn.h b/include/linux/irqreturn.h index d426c7ad92bfd..204030696676c 100644 --- a/include/linux/irqreturn.h +++ b/include/linux/irqreturn.h @@ -7,14 +7,35 @@ * @IRQ_NONE: interrupt was not from this device or was not handled * @IRQ_HANDLED: interrupt was handled by this device * @IRQ_WAKE_THREAD: handler requests to wake the handler thread + * @IRQ_HANDLED_MANY: interrupt was handled by this device multiple times + * should be the only bit set in the first 3 bits, and + * carry a count > 1 in the next bits. */ enum irqreturn { IRQ_NONE = (0 << 0), IRQ_HANDLED = (1 << 0), IRQ_WAKE_THREAD = (1 << 1), + IRQ_HANDLED_MANY = (1 << 2), + IRQ_RETMASK = IRQ_HANDLED | IRQ_WAKE_THREAD | IRQ_HANDLED_MANY, }; -typedef enum irqreturn irqreturn_t; +#define IRQ_HANDLED_MANY_SHIFT (3) + +typedef int irqreturn_t; #define IRQ_RETVAL(x) ((x) ? IRQ_HANDLED : IRQ_NONE) +#define IRQ_RETVAL_MANY(x) \ +({ \ + __typeof__(x) __x = (x); \ + irqreturn_t __ret; \ + if (__x == 0) \ + __ret = IRQ_NONE; \ + else if (__x == 1) \ + __ret = IRQ_HANDLED; \ + else \ + __ret = IRQ_HANDLED_MANY | (__x << IRQ_HANDLED_MANY_SHIFT); \ + __ret; \ +}) + +#define IRQ_HANDLED_MANY_GET(x) ((x) >> IRQ_HANDLED_MANY_SHIFT) #endif diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index dc94e0bf2c940..233cf22a5b771 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -482,8 +482,14 @@ void handle_nested_irq(unsigned int irq) raw_spin_unlock_irq(&desc->lock); action_ret = IRQ_NONE; - for_each_action_of_desc(desc, action) - action_ret |= action->thread_fn(action->irq, action->dev_id); + for_each_action_of_desc(desc, action) { + irqreturn_t ret = action->thread_fn(action->irq, action->dev_id); + + if ((ret & IRQ_RETMASK) == IRQ_HANDLED_MANY) + ret = IRQ_HANDLED; + + action_ret |= ret; + } if (!irq_settings_no_debug(desc)) note_interrupt(desc, action_ret); diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c index 9489f93b3db34..bfc6e3e43045a 100644 --- a/kernel/irq/handle.c +++ b/kernel/irq/handle.c @@ -162,6 +162,9 @@ irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc) irq, action->handler)) local_irq_disable(); + if ((res & IRQ_RETMASK) == IRQ_HANDLED_MANY) + res = IRQ_HANDLED; + switch (res) { case IRQ_WAKE_THREAD: /* diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 5bc609c7b728c..e684c7107ff90 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1192,6 +1192,8 @@ irq_forced_thread_fn(struct irq_desc *desc, struct irqaction *action) ret = action->thread_fn(action->irq, action->dev_id); if (ret == IRQ_HANDLED) irq_add_handled(desc, 1); + else if ((ret & IRQ_RETMASK) == IRQ_HANDLED_MANY) + irq_add_handled(desc, IRQ_HANDLED_MANY_GET(ret)); irq_finalize_oneshot(desc, action); if (!IS_ENABLED(CONFIG_PREEMPT_RT)) @@ -1213,6 +1215,8 @@ static irqreturn_t irq_thread_fn(struct irq_desc *desc, ret = action->thread_fn(action->irq, action->dev_id); if (ret == IRQ_HANDLED) irq_add_handled(desc, 1); + else if ((ret & IRQ_RETMASK) == IRQ_HANDLED_MANY) + irq_add_handled(desc, IRQ_HANDLED_MANY_GET(ret)); irq_finalize_oneshot(desc, action); return ret; From patchwork Fri Feb 16 07:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 201989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp368933dyb; Fri, 16 Feb 2024 00:15:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU+fzeGJRqXSdEivYZf+bRbLVJe/WUDeIJLa7OKqJnA1PuyVXhCEQ0hzMtsTvIVU1wb7r0idsNmYDddMWEDSW69tcbnSQ== X-Google-Smtp-Source: AGHT+IFa/ZM3c9uwDTXbjfaNGod1UT1Q+/PBZhUlQXtp//7GUFedW4xhmwZE9v0sYGZv9J18ID5f X-Received: by 2002:a37:c243:0:b0:783:d709:54e3 with SMTP id j3-20020a37c243000000b00783d70954e3mr4292691qkm.25.1708071349406; Fri, 16 Feb 2024 00:15:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708071349; cv=pass; d=google.com; s=arc-20160816; b=DOMFwMLABTUwB8wXzbT3RuyR/X+dbMM2LvEia5AVrKnctKgT2VtckzsCCdTxLrVDrT 0+pvalWedoozmWVzlVTBCZB2ffwf2+7uvsHkBcQeEuq787HLl2xcCcWIkkrWbDYcln3y sebOGxawAd+ao61jh5UnVAI+rjXcp0Ew+0dzGKeMG7dHXdm/L4VkKBa6ZF0Ee/X9+JVW d5uMG21rVm/3O3VX5Qfp8ykfWWPIAdd9VVz135B/UOFLaeL6hik1gKErhQ7dwI+YitzN plagJAN817Zrndj2rT2H4lFR+vf7bLtx0rHVfRRDua5YANRR1ib4bdcMLOFPFCgL2v8u lu3Q== 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:cc:to:from:dkim-signature; bh=bho+yn8M4kGUaS4UAXQ+fSY/db1hBVlHnbWifBhcoOQ=; fh=k34Nnq/Kwq/SZsiVv5WWtSAM8XrsxgnVMy19Vz8zceU=; b=fvfzAQS5gg/+GMccjXcrHf6AiK0luHmkQIqVkJ0NW8t53lJO10ty+3sZlxDX04p+V4 I8VMZAp/QVgw4aVxWLvxpIdcSr0RRm3f/ju6Aqi/kEDUYc1g3Q/CyQtuE69mkuSZ2BNd XgnpHw+n+FhyhFg3mcozqpu85kNarOHVsZAphzi5IR7QN74IwxbnRgsUbxhDT3EaWfTo egzmzQWHDVMZ5Qvb9qEQ1ipUS+BcbGasf0N1MTkj+ywxTnAliUhadc4ni1bW3vw4ujEa kgsr+kLS9vdn1rRiDjpNqNaVtuNVirlebQlo1P9+QBXfU1e8gDNPzkV0Mgr8anzWvgKA vLew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RraAo3q5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68208-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68208-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j9-20020a05620a000900b007873f7f2841si1431455qki.30.2024.02.16.00.15.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:15:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68208-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RraAo3q5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-68208-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68208-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AD2731C2279F for ; Fri, 16 Feb 2024 08:15:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A48E1C694; Fri, 16 Feb 2024 08:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RraAo3q5" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 40E921BC5E for ; Fri, 16 Feb 2024 08:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070433; cv=none; b=I81MSrAJE2MzD9KPVR3uoa1xHLk+/5xhRMR5GZH0IfZH4Az20jM/ZzJAxwHuXEJ6Rc+KUEse7eKUlsuWAvgIgseJlQEWf5d4L5cfvFFUVdh6yw0S85lOJ0BgB1XXz69g/iaQ3WCx1CMYnXDkOcoJ1bv0+oS9tpZjQw/gT/qwU1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708070433; c=relaxed/simple; bh=DpW7fdG3PEtBSw4uHybL/y6wUJ0RIFhtQZUvi+EiDQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iJusRGlNsDF7ZsAHjdEu2/nUO8ydR22ARxe8drFe2d/J7uMktudVhiK+lkzXQfFcFuDZ6qCHTzk5CpBytGpFueeNdXYPmZLmQtmMdAF4+3nDdURZ+xMOjCpqLhobFaxEqvHfResKBHVMH0Ju9OKDS61m6vrZ4zyHb9K/AiWNOVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RraAo3q5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708070431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bho+yn8M4kGUaS4UAXQ+fSY/db1hBVlHnbWifBhcoOQ=; b=RraAo3q5dyTB7UDfIRn+NPY26twP/+NfzQNQoOL7jVuF6W3eR7ZZr896GbEahfwks+nXH/ VeL2hjBoV1zNBturjEXnfZz2s6eTb2UUDLxLkiTFITz0IeYXsvA08yz1VVedQeyXK9XUVV iFU0iOj52V5hsoqQgfJ1mQhocwY2X/M= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-noXIOcegN7GhhCaugE67Mw-1; Fri, 16 Feb 2024 03:00:29 -0500 X-MC-Unique: noXIOcegN7GhhCaugE67Mw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-785d3e4f98aso189429485a.1 for ; Fri, 16 Feb 2024 00:00:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708070429; x=1708675229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bho+yn8M4kGUaS4UAXQ+fSY/db1hBVlHnbWifBhcoOQ=; b=nq5oWPgHEEdEdQPK6L19RAPXJsonPr9N8VnOxgYktr1h3+jz+GtuZUVa3/A+ijsOyy ZZckuQ0FjwTYIQETx46AAMCo7yTjib0FDAfwfLklrdjIu0uQ48ZTEMOA2NTiQmEb5EdJ Vc5MklfCyTYpWgaG+tG4Dex9UsI7X9Ju25t7j0ISslvSd9P5WZkioVe0rav5OG2mYW+T Jpzetf6PTRkLB4xanwo2xoR79r3v9Wy3EHEqJbBdV+IJ45zYq9raz1uMj+7qy6JcncI+ ab2UvZLpsWwvXI6eGfhYDG6OE2fL5SSAHQnkTC1tsycXlFmw/jZC1OMApS3ZbohxBbjv pUig== X-Gm-Message-State: AOJu0YzB5q7wsh0z6wx4Okn7hcwGC/R6salun8wX/SS/QgMZLN3nIe2D FMjqXy4kDxtTqa5AopTZs9ZePGsqLbVbKZ3wtam2tfZ9A1zCuONPuz8kaEehJeUpM/GO91XAFFZ 7ae12ld3YL5cBIfocPtQeXMkZ6vb1WP+AaSwBOqWVNSzkshfRdUY84gbUA3pcbw== X-Received: by 2002:a05:620a:564a:b0:785:ec1f:6aee with SMTP id vw10-20020a05620a564a00b00785ec1f6aeemr3631452qkn.27.1708070428744; Fri, 16 Feb 2024 00:00:28 -0800 (PST) X-Received: by 2002:a05:620a:564a:b0:785:ec1f:6aee with SMTP id vw10-20020a05620a564a00b00785ec1f6aeemr3631427qkn.27.1708070428387; Fri, 16 Feb 2024 00:00:28 -0800 (PST) Received: from LeoBras.redhat.com ([2804:1b3:a800:4770:9d0:4bac:1782:4637]) by smtp.gmail.com with ESMTPSA id br37-20020a05620a462500b00787346f1edasm1300756qkb.54.2024.02.16.00.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:00:28 -0800 (PST) From: Leonardo Bras To: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Tony Lindgren , Andy Shevchenko , John Ogness , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , =?utf-8?q?U?= =?utf-8?q?we_Kleine-K=C3=B6nig?= , Leonardo Bras , Florian Fainelli , Shanker Donthineni Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH v2 4/4] tty/serial8250: Make use of IRQ_HANDLED_MANY interface Date: Fri, 16 Feb 2024 04:59:46 -0300 Message-ID: <20240216075948.131372-6-leobras@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216075948.131372-2-leobras@redhat.com> References: <20240216075948.131372-2-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791042623468346390 X-GMAIL-MSGID: 1791042623468346390 For every TX byte an IRQ is requested. On threaded IRQs, the handler calls serial8250_tx_chars can send multiple bytes, limited to it's queue size (tx_loadsz). When this happens, the handler return IRQ_HANDLED with reduces the unhandled IRQ counter only by 1, even though many requests have been handled at once. This causes the unhandled IRQ counter to go up until it reaches the maximum and causes the registered IRQ to be disabled, thus breaking the serial console. Make use of the newly introduced IRQ_HANDLED_MANY interface to return the number of requests handled, so the unhandled IRQ counter can get decreased accordingly. Signed-off-by: Leonardo Bras --- include/linux/serial_8250.h | 2 +- drivers/tty/serial/8250/8250_core.c | 13 ++++++++----- drivers/tty/serial/8250/8250_port.c | 16 ++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index ec46e3b49ee99..c9d4271b71d70 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -200,7 +200,7 @@ int fsl8250_handle_irq(struct uart_port *port); int serial8250_handle_irq(struct uart_port *port, unsigned int iir); u16 serial8250_rx_chars(struct uart_8250_port *up, u16 lsr); void serial8250_read_char(struct uart_8250_port *up, u16 lsr); -void serial8250_tx_chars(struct uart_8250_port *up); +int serial8250_tx_chars(struct uart_8250_port *up); unsigned int serial8250_modem_status(struct uart_8250_port *up); void serial8250_init_port(struct uart_8250_port *up); void serial8250_set_defaults(struct uart_8250_port *up); diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index ae637155fe7cd..2fab9102eec45 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -110,7 +110,7 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id) { struct irq_info *i = dev_id; struct list_head *l, *end = NULL; - int pass_counter = 0, handled = 0; + int pass_counter = 0, handled_total = 0; pr_debug("%s(%d): start\n", __func__, irq); @@ -120,15 +120,18 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id) do { struct uart_8250_port *up; struct uart_port *port; + int handled; up = list_entry(l, struct uart_8250_port, list); port = &up->port; - if (port->handle_irq(port)) { - handled = 1; + handled = port->handle_irq(port); + if (handled) { + handled_total += handled; end = NULL; - } else if (end == NULL) + } else if (end == NULL) { end = l; + } l = l->next; @@ -140,7 +143,7 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id) pr_debug("%s(%d): end\n", __func__, irq); - return IRQ_RETVAL(handled); + return IRQ_RETVAL_MANY(handled_total); } /* diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index f799c34f1603c..74d53507a73d4 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1802,7 +1802,7 @@ u16 serial8250_rx_chars(struct uart_8250_port *up, u16 lsr) } EXPORT_SYMBOL_GPL(serial8250_rx_chars); -void serial8250_tx_chars(struct uart_8250_port *up) +int serial8250_tx_chars(struct uart_8250_port *up) { struct uart_port *port = &up->port; struct circ_buf *xmit = &port->state->xmit; @@ -1810,15 +1810,15 @@ void serial8250_tx_chars(struct uart_8250_port *up) if (port->x_char) { uart_xchar_out(port, UART_TX); - return; + return 0; } if (uart_tx_stopped(port)) { serial8250_stop_tx(port); - return; + return 0; } if (uart_circ_empty(xmit)) { __stop_tx(up); - return; + return 0; } count = up->tx_loadsz; @@ -1858,6 +1858,9 @@ void serial8250_tx_chars(struct uart_8250_port *up) */ if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM)) __stop_tx(up); + + /* Return number of chars sent */ + return up->tx_loadsz - count; } EXPORT_SYMBOL_GPL(serial8250_tx_chars); @@ -1923,6 +1926,7 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) bool skip_rx = false; unsigned long flags; u16 status; + int handled = 0; if (iir & UART_IIR_NO_INT) return 0; @@ -1956,14 +1960,14 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) serial8250_modem_status(up); if ((status & UART_LSR_THRE) && (up->ier & UART_IER_THRI)) { if (!up->dma || up->dma->tx_err) - serial8250_tx_chars(up); + handled = serial8250_tx_chars(up); else if (!up->dma->tx_running) __stop_tx(up); } uart_unlock_and_check_sysrq_irqrestore(port, flags); - return 1; + return handled ? : 1; } EXPORT_SYMBOL_GPL(serial8250_handle_irq);