From mboxrd@z Thu Jan 1 00:00:00 1970 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 606A9C25B75 for ; Mon, 3 Jun 2024 07:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XdX62VDV+TT5nJkkGdPIHaZyogTCZK+hjO/JS1KdBAo=; b=Ow/BXf7h0yFYqE Jpj7VoWZ0EqoHS1E64PuHr7iEC60CUyzBFK4u2TefrUmP1ZF+kZs1rty6nYvwybREpJCYYlwxaYfC RAtu22Uo2jg7RdLhskVYIGLSeEMGj8Ajh9pkUKJ/tVqGFPYpV38bcRHWW03xMYnEgoKlQoAJKvjEX Ghwz3ATex/oQ+CNgRRzPtcAB0pVm8MIXzFwhXVw0S/U7TkFNMDBuFk3GAQ4izWSjFkvD+0Rqs4zgV 9kerWN7rc6amFeNeyQ7wa144YYJKsV1ix5saBoqgLdsnGJfJMcAmFKxChuDP30jMWyd2DfsQ7e/hY d9AlC9ad+aXL2C7DbVTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE2M4-0000000FwPz-25bR; Mon, 03 Jun 2024 07:43:44 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE2M2-0000000FwPS-0XXW for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 07:43:43 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-356c4e926a3so3231300f8f.1 for ; Mon, 03 Jun 2024 00:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717400619; x=1718005419; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9+3KpBVqTTJeo965A1KR/YlsEUxQQiOfIdsh4+kRbIs=; b=HC4Q9E9sN5m4TYo0CvHquTUoLxVfL8fKNlAnrnNJx4qSMCY5oIVSmmKbhHxyqZZgqe 3Wb1PCMmGu1Mh+1NRlcLwNSzh4Mja+c4k1DmwmHfwRM1pPGcRiFkHdh3/dDbAIB0nNRy 4jdR3ap4uRJE9B4P1YuNYdQTpYY3CWh/SmiS9s31zjVqh8j7xm0sPIhjlz7k9+2IU06D 7UmP2LGZ8kPUkib7T3RvWp8aPMiXLD7xeEfqtDYbxO9nT7v0AmTxqa4JD/DSJl0Z7H3V YHeVU7ZXTOmme6bdZo+ie/02p+lmmn2uM+6FzFJcshCcFs6tvac/Uy5G/yyTtnKpeLJt zj8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717400619; x=1718005419; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9+3KpBVqTTJeo965A1KR/YlsEUxQQiOfIdsh4+kRbIs=; b=hEWASobL3pxhqHq8U2LamFpCtXix4k2tqZG17mr8iD0YCWzIM5fMb7q4iZvSRkRO3f /f7/EAf31baHNZlwDcRTAZ1IijKRLLwrRwj4VmG2Yp0U6Hg5qHJ+cqWz63iy8Q1OSh/K 47WaV/3JRGQqaBSPHrpL96bEDDRROHkf+s2ieNYgBZLB0sbM7HjiR1SCyEY8jJeGB1hy 4NIMQ91l3YdmFzQMzUQQyIj71BZRa+t6F6uJaF3tBe+UX54TD+0C4RiHb/lvKcR9xURL GJOYwQOi6Rop9dYNbOZdNBYtU10KY6E6WMuOfom548noTyEf8LSmYQjSR+1fzNUIDtYK 4Whw== X-Forwarded-Encrypted: i=1; AJvYcCXbxpIb2aChAaFk6Ymf+mY2d+CrTn5azhFWALunvOJMPx4rEVsRZ1wEIkUVC0ofy/qgWl5e8ElZcrQIzxCgmwWFBY2LuLxVItpqJ2nL2ooZ5hU2+Zc= X-Gm-Message-State: AOJu0YwezhOiFgYgScpMP4P4jRvnq2yqMhP4LZ1P+39TLt/TbDY44TJI 8VQWY3Ev/38nJmSJBwAfF5Wy97HkmBm9w7mQU+Eiy0/YI6Jz3o7c X-Google-Smtp-Source: AGHT+IEanqGnQyE0VRVI9jQex6bQ4+XQs3Oue5+MhhMZ/CjI0wOwj0rSpqUdBr/gjbzmQgzPke+uJA== X-Received: by 2002:a05:6000:1944:b0:34c:cca6:3d18 with SMTP id ffacd0b85a97d-35e0f333b6emr5523593f8f.68.1717400619152; Mon, 03 Jun 2024 00:43:39 -0700 (PDT) Received: from eichest-laptop ([2a02:168:af72:0:2b03:375:843f:be9d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd062ea66sm7981749f8f.78.2024.06.03.00.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 00:43:37 -0700 (PDT) Date: Mon, 3 Jun 2024 09:43:35 +0200 From: Stefan Eichenberger To: Andy Shevchenko Cc: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, jic23@kernel.org, lars@metafoo.de, nuno.sa@analog.com, u.kleine-koenig@pengutronix.de, marcelo.schmitt@analog.com, gnstark@salutedevices.com, francesco.dolcini@toradex.com, linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Stefan Eichenberger Subject: Re: [RFC PATCH] i2c: imx: avoid rescheduling when waiting for bus not busy Message-ID: References: <20240531142437.74831-1-eichest@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_004342_197389_E698AB26 X-CRM114-Status: GOOD ( 31.33 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, May 31, 2024 at 05:45:10PM +0300, Andy Shevchenko wrote: > On Fri, May 31, 2024 at 04:24:37PM +0200, Stefan Eichenberger wrote: > > From: Stefan Eichenberger > > > > On our i.MX8M Mini based module we have an ADS1015 I2C ADC connected to > > the I2C bus. The ADS1015 I2C ADC will timeout after 25ms when the I2C > > bus is idle. The imx i2c driver will call schedule when waiting for the > > bus to become idle after switching to master mode. When the i2c > > controller switches to master mode it pulls SCL and SDA low, if the > > ADS1015 I2C ADC sees this for more than 25 ms without seeing SCL > > clocking, it will timeout and ignore all signals until the next start > > condition occurs (SCL and SDA low). This can occur when the system load > > is high and schedule returns after more than 25 ms. > > > > This rfc tries to solve the problem by using a udelay for the first 10 > > ms before calling schedule. This reduces the chance that we will > > reschedule. However, it is still theoretically possible for the problem > > to occur. To properly solve the problem, we would also need to disable > > interrupts during the transfer. > > > > After some internal discussion, we see three possible solutions: > > 1. Use udelay as shown in this rfc and also disable the interrupts > > during the transfer. This would solve the problem but disable the > > interrupts. Also, we would have to re-enable the interrupts if the > > timeout is longer than 1ms (TBD). > > 2. We use a retry mechanism in the ti-ads1015 driver. When we see a > > timeout, we try again. > > 3. We use the suggested solution and accept that there is an edge case > > where the timeout can happen. > > > > There may be a better way to do this, which is why this is an RFC. > > ... > > > + /* > > + * Avoid rescheduling in the first 10 ms to avoid > > + * timeouts for SMBus like devices > > + */ > > + if (time_before(jiffies, orig_jiffies + msecs_to_jiffies(10))) > > + udelay(10); > > + else > > + schedule(); > > Isn't there cond_resched() or so for such things? > More info here: 494e46d08d35 ("airo: Replace in_atomic() usage.") The problem would be that I have to disable preemption during the transfer, then cond_resched would do nothing if I understand it correctly. However, an I2C transfer @100kHz for 3 bytes takes at least 240us + overhead (e.g. waiting for the bus idle) which might end in a close to ms ranage. This is what concerns me. Regards, Stefan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel