From patchwork Mon Oct 14 13:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13835097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA930D16273 for ; Mon, 14 Oct 2024 14:06:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=qiu63abS+lcmc+QEZqAra0R6AmKde2YbO88Y6AxKGhw=; b=WdOuU8lcYds3/3e4PXkkbVOwJ9 uLC8MtbUOfimGN5IpIj9T6QXcPnXOLZB/8OeOq3uTKXn3F5m5Uxvqx4ESKPLsTSKqdTKspbrMG2Pe Sm5GwmCRfglvVdb5Le3QVvI0Ze6BtcF9287wDgZlrkJy7AH4pCbzSr7gpymAzcuySSi9O2s5LVd0B nwDXPCQ5JbUzP4zEf7SfsmEuNy38HQ04JwVDjovo689mwOrpGBVirvGWrwmAKk0nQmhHo8XkAfCgX M5A/TKBS/x6xD9cP+HPFidoXXmDKFkvBBm9YABUGMNnnt3IQxzH+GCs8I2Pr+mScPncHz3Ydnu7FN +4pVd3Kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0LiX-00000005Plw-1Ccx; Mon, 14 Oct 2024 14:06:37 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0KwF-00000005EI0-2GbC for linux-arm-kernel@bombadil.infradead.org; Mon, 14 Oct 2024 13:16:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=qiu63abS+lcmc+QEZqAra0R6AmKde2YbO88Y6AxKGhw=; b=X4M92jWp8ls9dfykEYOYcewby3 jVY2NAbacjn646NGpdkfyXO6n7NVWTch6AO26WyKySbkO4HOROn25gXBmTHK0iqPWyWj/OskqUNc0 XhZLWi324F7Vuflgj2vPP+VTsR5J0jaeii2GR5bUhg/3VniOfPQnwJEu1U8LD63kGlauk5AoLm/YL 6CU92ZbKwrLxImr3lb5Megz47ufxiY5DG79kXCfE7WpdcMRrldkYybHN8XYbenY37PTctdO+Aj+DE mI6SDbEpL0MEHbHPfVIapeGM940t43jrDQeYHX2OG3dD1TPwRQgUH+Kyy83xut86yJEdjCG/IbEXC hM3Nx4Gw==; Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0KwC-00000006LTv-0a4O for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 13:16:42 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42f6bec84b5so41597535e9.1 for ; Mon, 14 Oct 2024 06:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728911797; x=1729516597; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qiu63abS+lcmc+QEZqAra0R6AmKde2YbO88Y6AxKGhw=; b=I4WedwWn16a4UZ4uCDq/NJMoK1hzDJO1KtG1eUL36Xe3t1kBnXe1NVQE1C6n/wVAju 1Qv1d2FRJrFMZF9dy1POjxgWCcUfiofl5QvyuwUNsUSQvAis981umHTqKc/CKInN1Yrz mB4c9DbfePybcFr0MjaZxz7rDiyAZo3/N145Jmz9/DIwLOqUuh0u8rsOEVvw6F0jZkYi YKQ8gUIpX2JX3fgjVC8GThRbbEXtgsPiah2Tq30ydo30lRut+CvMe1zoaJBG8WxtBQDx 1zBuUZJYQMvzLN6VI1Riho3WbSPxrlvIW5j20Xs2+xrJnEcCDkfhvX9iivBA1d3eZu60 LRUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728911797; x=1729516597; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qiu63abS+lcmc+QEZqAra0R6AmKde2YbO88Y6AxKGhw=; b=HvKDRJsjAGwRFQYGBlrfYh6+PlANgNWaCfcGa1aoWbBJ/uDkFT7nV2tKktS41X6/tf Fm5oDFAjzVtngskb36xsXFNS2eFbhYIzo+2wi3oJ12Bu5G5TMU1LGOyJMxgmJqDzXvQi /0iuxdab5E6AXpq3I4JhlA9QCe0zy35k/Ot6ufU4WJqcWI6CCzX2F7vAZqJaBphex4au IH37h/2rFVc9AZsuDTaVKGtowvU3N1pDXDVzGZiWF1YFz3mI2DTudDWWe1nnrWkNCLR+ E2pQrI6WokQumIUKd51r0slOQUIHUFiucLjjaffu+UG8+f1Fqmnkt7RlQN4mlNf3bJ6c 6Eug== X-Forwarded-Encrypted: i=1; AJvYcCVm56YkukfgR2/iOjPA0h60CnQwbRutp9sWcy4l+Z9JjDi9g+CZbumcL1zzVcpH2AtuczlU2sYND7+9fnQkUuOR@lists.infradead.org X-Gm-Message-State: AOJu0YwSKadhyH7GhYgz5R6NzdCQSu8Ui6UZXOvtiz1/KpYtrIXJAOLu ADCBKR110eLm9xKWuIPewMwKSm9ODl20g2pX5usm6RlaRwlvYvMkxivkMDZo X-Google-Smtp-Source: AGHT+IFcCp01a+hQ3E59skIEwWoYCKjNqEuIfGS+TTlAmsmQTY97kQB30zIN0dZ9uu9D+NYoMH5lpg== X-Received: by 2002:a05:600c:1d0e:b0:42c:c080:7954 with SMTP id 5b1f17b1804b1-4311df55bc4mr96397855e9.30.1728911796745; Mon, 14 Oct 2024 06:16:36 -0700 (PDT) Received: from eichest-laptop.lan ([2a02:168:af72:0:d130:f8ef:c6c1:55ee]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d748d42fsm153420425e9.43.2024.10.14.06.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 06:16:36 -0700 (PDT) From: Stefan Eichenberger To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com, l.stach@pengutronix.de, arnd@arndb.de, Frank.Li@nxp.com Cc: linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 0/3] i2c: imx: prevent rescheduling in non-dma mode Date: Mon, 14 Oct 2024 15:15:11 +0200 Message-ID: <20241014131635.205489-1-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_141640_434679_E627D7B5 X-CRM114-Status: GOOD ( 19.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org While running tests on an i.MX8M Mini connected to a TI ADS1015 ADC, we found that the ADC would stop responding to i2c requests because it would timeout after the bus was idle for 25ms. This timeout could be traced back to the rescheduling events in the i2c-imx driver. The problem is that if the system is under heavy load, the schedule call and the wait_event_timeout may be rescheduled too late to reach the 25ms timeout. The same problem may occur with other SMBus devices. Therefore, this patchset removes the scheduling calls for non-DMA mode by handling the interrupt events directly in the ISR instead of scheduling a task to handle the events. This patch will introduce some bigger changes because the logic for handling events in the ISR had to be rewritten. Therefore we have tested the following combinations: - i.MX8M Mini with dma - i.MX8M Mini without dma - i.MX8M Plus with dma - i.MX8M Plus without dma - i.MX7D with dma - i.MX7D without dma - i.MX7D atomic mode Because we do not have any devices that use the SMBus block transfer mode, we were not able to test it. The ideas are based on the RFC: https://lore.kernel.org/all/20240531142437.74831-1-eichest@gmail.com/ However, the handling of events in the ISR is new, because further testing showed that it was not enough to simply remove the schedule call. Changes since v4: - Drop patch 3 use relaxed readb and writeb (Arnd) - Make multi master default again and use simple-master as property (Lucas) - Print a debug message instead of an error if read and write fails. An error message would spam the kernel log when using i2cdetect -r -y 0. - Fix error message in read (read instead of write) Changes since v3: - Fixed style issues with checkpatch.pl --strict (Andi) - Add comments to explain the code (Andi) Changes since v2: - Add Acked-by tags from Oleksij - Renamed i2c_imx_start_read to i2c_imx_prepare_read - I did not add a Fixes tag because the issues from Flavio have a different root cause and are not fixed by this patchset Changes since v1: - Add Reviewed-by tags from Frank - Add new patch to use readb_relaxed and writeb_relaxed (Frank) - Update commit message for patch 1 with some clarifications (Frank) Stefan Eichenberger (3): i2c: imx: do not poll for bus busy in single master mode i2c: imx: separate atomic, dma and non-dma use case i2c: imx: prevent rescheduling in non dma mode drivers/i2c/busses/i2c-imx.c | 370 ++++++++++++++++++++++++++++++----- 1 file changed, 320 insertions(+), 50 deletions(-)