Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2440434rdh; Wed, 27 Sep 2023 02:44:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDNcwpGK5NYALxIk9aXDLBqI0bC+iyHtWojxbNM3Wv7r0VYXEOSpp72hzQninFLoDsHq94 X-Received: by 2002:a05:6a00:3998:b0:68a:49bc:e0af with SMTP id fi24-20020a056a00399800b0068a49bce0afmr1674972pfb.1.1695807867190; Wed, 27 Sep 2023 02:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807867; cv=none; d=google.com; s=arc-20160816; b=Bc72xOj7PWsiVGiuX5tLVeleEOpWNvtX3o4foggFVSO4TUNbDSA2eGQFmaLSbXQy4W EuWFijyx/8wcFoRLQLCtPmvwuR6uCeZSxubN3PLBpwoG5JziQkTIe2iKihlu06T8QVNC ZgYzfsM0qT8DNSicQuevCSM7yPyvU8yy+Jre5TQO9eThOy2AuAKD7FUnjwb82myImaGP pks1BZnGsRT05HRxC+z02lV1TENSpLwZHSsgwj/3Z1qZXY2yceaZBt5ISdILLIFJ3mRo EA3NyIC1aOVh8ebN3wZmrRjav569uV/ioZ+j201sxQa3PZXzIHcQOkE050K4lVpxaVQb Whfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WCtPJxPxfngcZtPLStMkiQfylOeT1S31p76pkGY+PoM=; fh=FO4s9sn4NKBgioBuAzrElziRM7Jle8gjnEduNVW4O9s=; b=QFcOtjqCRJS/m+KGVEvC6B8gSAqhi0dOfb0mazZsgCDZbWv/zsvG9oKAG12RhUiZKC RaUj4vcENxVXpF+6Ihrj0qJGbpc2dE0SrPeVq0f/qSZ83bvMoc+KlmdVe0EO4fM0RPn8 6UzS07QxQhXTxlw1ATeCPM3fhsBq8L7CcXHERdgbq637TJYXoCUZotuWQUs8b4Sk/nJl e0wArFsMjRHDvvf7uIc2uXtmh8FP++H9ut7dfjVVoB87s6YGXf/mp23AdXXfcCjhlXtr yuwXySs99qdlY0KLLUcHikst/BB2lqfXP34V27WpvDWo8r4K/czJz/XNHuPc2EOwkN6+ MV1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mess.org header.s=2020 header.b=ZPjwXYcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mess.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ef7-20020a056a002c8700b00690bdd08026si14862330pfb.251.2023.09.27.02.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@mess.org header.s=2020 header.b=ZPjwXYcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mess.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 00E5680307B5; Tue, 26 Sep 2023 13:18:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233232AbjIZUSb (ORCPT + 99 others); Tue, 26 Sep 2023 16:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235810AbjIZUS3 (ORCPT ); Tue, 26 Sep 2023 16:18:29 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5698120 for ; Tue, 26 Sep 2023 13:18:22 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id E979E1000B2; Tue, 26 Sep 2023 21:18:16 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mess.org; s=2020; t=1695759496; bh=T2t6tUV8F3RVHU1NTNGqT5xpfoZaTbVdG1BjZ0eXs5U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZPjwXYcjtXvLSniQ86lo5+xTlypyv4zAqmj+uztkYev+AEyI6GDQFsBV4FpN+6E9h dYIJ33tUeCJWG/DXqk1vajUIKdUTys4INNIVAMcykCeiHPxsGoNBTd1DEDjpfeImKh 1LWROf7Sk2j4Bdh0rGx/9jg3KZrLqEZCbSlrRZ6MUW4vcsOtC95Ktwlqg5qfCwis/H Ve2d/qmWEd3JXm0YmYkd/vyn7t2Dy5wvGeIlw0ed1daTMe19aBbCJNNwYgKWQASKog J7ytGkPbUAuDR1XLprXZ1wzig+zhfz2EoEq/qWwvqviy4zYAV2qxfBTtxfaX4s96Ja Tzk/e6bII+G5w== Date: Tue, 26 Sep 2023 21:18:16 +0100 From: Sean Young To: Ivaylo Dimitrov Cc: linux-media@vger.kernel.org, Tony Lindgren , Russell King , Mauro Carvalho Chehab , Thierry Reding , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Timo Kokkonen , Pali =?iso-8859-1?Q?Roh=E1r?= , "Sicelo A . Mhlongo" , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org Subject: Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx Message-ID: References: <99f0042f-538c-bcaf-96fd-bac24a87f88e@gmail.com> <1715e2bf-5d02-4f20-1476-29a1fdf350b1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1715e2bf-5d02-4f20-1476-29a1fdf350b1@gmail.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 26 Sep 2023 13:18:35 -0700 (PDT) On Tue, Sep 26, 2023 at 03:43:18PM +0300, Ivaylo Dimitrov wrote: > On 26.09.23 г. 10:16 ч., Sean Young wrote: > > On Mon, Sep 25, 2023 at 07:06:44PM +0300, Ivaylo Dimitrov wrote: > > > On 1.09.23 г. 17:18 ч., Sean Young wrote: > > > > The ir-rx51 is a pwm-based TX driver specific to the N900. This can be > > > > handled entirely by the generic pwm-ir-tx driver, and in fact the > > > > pwm-ir-tx driver has been compatible with ir-rx51 from the start. > > > > > > > > > > Unfortunately, pwm-ir-tx does not work on n900. My investigation shows that > > > for some reason usleep_range() sleeps for at least 300-400 us more than what > > > interval it is requested to sleep. I played with cyclictest from rt-tests > > > package and it gives similar results - increasing the priority helps, but I > > > was not able to make it sleep for less that 300 us in average. I tried > > > cpu_latency_qos_add_request() in pwm-ir-tx, but it made no difference. > > > > > > I get similar results on motorola droid4 (OMAP4), albeit there average sleep > > > is in 200-300 us range, which makes me believe that either OMAPs have issues > > > with hrtimers or the config we use has some issue which leads to scheduler > > > latency. Or, something else... > > > > The pwm-ir-tx driver does suffer from this problem, but I was under the > > impression that the ir-rx51 has the same problem. > > > > Could you elaborate on the "pwm-ir-tx driver does suffer from this problem"? > Where do you see that? So on a raspberry pi (model 3b), if I use the pwm-ir-tx driver, I get random delays of up to 100us. It's a bit random and certainly depends on the load. I'm measuring using a logic analyzer. There have been reports by others on different machines with random delays and/or transmit failures (as in the receiver occassionally fails to decode the IR). I usually suggest they use the gpio-ir-tx driver, which does work as far as I know (the signal looks perfect with a logic analyzer). So far I've taken the view that the driver works ok for most situations, since IR is usually fine with upto 100us missing here or there. The gpio-ir-tx driver works much better because it does the entire send under spinlock - obviously that has its own problems, because an IR transmit can be 10s or even 100s of milliseconds. I've never known of a solution to the pwm-ir-tx driver. If using hrtimers directly improves the situation even a bit, then that would be great. > ir-rx51 does not suffer from the same problem (albeit it has its own one, > see bellow) > > > > In either case help is appreciated to dig further trying to find the reason > > > for such a big delay. > > > > pwm-ir-tx uses usleep_range() and ir-rx51 uses hrtimers. I thought that > > usleep_range() uses hrtimers; however if you're not seeing the same delay > > on ir-rx51 then maybe it's time to switch pwm-ir-tx to hrtimers. > > > > usleep_range() is backed by hrtimers already, however the difference comes > from how hrtimer is used in ir-rx51: it uses timer callback function that > gets called in softirq context, while usleep_range() puts the task in > TASK_UNINTERRUPTIBLE state and then calls schedule_hrtimeout_range(). For > some reason it takes at least 200-400 us (on average) even on OMAP4 to > switch back to TASK_RUNNING state. > > The issue with ir-rx51 and the way it uses hrtimers is that it calls > pwm_apply_state() from hrtimer function, which is not ok, per the comment > here > https://elixir.bootlin.com/linux/v6.6-rc3/source/drivers/pwm/core.c#L502 > > I can make pwm-ir-tx switch to hrtimers, that's not an issue, but I am > afraid that there is some general scheduler or timers (or something else) > issue that manifests itself with usleep_range() misbehaving. If we can switch pwm-ir-tx to hrtimers, that would be great. The ir-rx51 removal patches have already been queued to media_staging; we may have to remove them from there if we can't solve this problem. > > I don't have a n900 to test on, unfortunately. > > > > I have and once I have an idea what's going on will port pwm-ir-tx to > hrtimers, if needed. Don't want to do it now as I am afraid the completion I > will have to use will have the same latency problems as usleep_range() That would be fantastic. Please do keep us up to date with how you are getting on. Like I said, it would be nice to this resolved before the next merge window. Thanks, Sean