Remove ir-rx51 driver
Subsystems (8)
Sean Young
maintainerv5 cover Remove ir-rx51 driver
The ir-rx51 driver is no longer necessary, pwm-ir-tx does the same job and is more generic.
changes:
v5:
- Fix cc/to lists
v4:
- Fixed issues with pwm-ir-tx.yaml and did some more testing
v3:
- Fixed issues with pwm-ir-tx.yaml
v2:
- Made pwm-ir-tx compatible with nokia,n900-ir rather than changing the n900 devicetree
Sean Young (2):
dt-bindings: media: remove nokia,n900-ir as pwm-ir-tx is compatible
media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
.../bindings/leds/irled/pwm-ir-tx.yaml | 5 +- .../devicetree/bindings/media/nokia,n900-ir | 20 -- arch/arm/configs/omap2plus_defconfig | 1 - drivers/media/rc/Kconfig | 10 - drivers/media/rc/Makefile | 1 - drivers/media/rc/ir-rx51.c | 285 ------------------ drivers/media/rc/pwm-ir-tx.c | 1 + 7 files changed, 5 insertions(+), 318 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-ir delete mode 100644 drivers/media/rc/ir-rx51.c
Signature · 1 line
2.42.0
Sean Young
maintainerPATCH v5 1/2 dt-bindings: media: remove nokia,n900-ir as pwm-ir-tx is compatible
The generic pwm-ir-tx driver works for the Nokia n900, so nokia,n900-ir can be removed.
--- .../bindings/leds/irled/pwm-ir-tx.yaml | 5 ++++- .../devicetree/bindings/media/nokia,n900-ir | 20 ------------------- 2 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-ir
Documentation/devicetree/bindings/leds/irled/pwm-ir-tx.yaml +4 -1
@@ -15,7 +15,10 @@ description: properties: compatible: - const: pwm-ir-tx + oneOf: + - const: pwm-ir-tx + - const: nokia,n900-ir + deprecated: true pwms: maxItems: 1
Documentation/devicetree/bindings/media/nokia,n900-ir deleted +0 -20
@@ -1,20 +0,0 @@ -Device-Tree bindings for LIRC TX driver for Nokia N900(RX51) - -Required properties: - - compatible: should be "nokia,n900-ir". - - pwms: specifies PWM used for IR signal transmission. - -Example node: - - pwm9: dmtimer-pwm@9 { - compatible = "ti,omap-dmtimer-pwm"; - ti,timers = <&timer9>; - ti,clock-source = <0x00>; /* timer_sys_ck */ - #pwm-cells = <3>; - }; - - ir: n900-ir { - compatible = "nokia,n900-ir"; - - pwms = <&pwm9 0 26316 0>; /* 38000 Hz */ - };
Signature · 1 line
2.42.0
Re: [PATCH v5 1/2] dt-bindings: media: remove nokia,n900-ir as pwm-ir-tx is compatible
Quoted 4 lines · Sean Young
The generic pwm-ir-tx driver works for the Nokia n900, so nokia,n900-ir can be removed.
Signed-off-by Sean Young <[email protected]>
Thanks,
Conor.
Quoted 51 lines
--- .../bindings/leds/irled/pwm-ir-tx.yaml | 5 ++++- .../devicetree/bindings/media/nokia,n900-ir | 20 ------------------- 2 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-irDocumentation/devicetree/bindings/leds/irled/pwm-ir-tx.yaml +4
-1@@ -15,7 +15,10 @@ description: properties: compatible: - const: pwm-ir-tx + oneOf: + - const: pwm-ir-tx + - const: nokia,n900-ir + deprecated: true pwms: maxItems: 1Documentation/devicetree/bindings/media/nokia,n900-ir deleted +0
-20@@ -1,20 +0,0 @@ -Device-Tree bindings for LIRC TX driver for Nokia N900(RX51) - -Required properties: - - compatible: should be "nokia,n900-ir". - - pwms: specifies PWM used for IR signal transmission. - -Example node: - - pwm9: dmtimer-pwm@9 { - compatible = "ti,omap-dmtimer-pwm"; - ti,timers = <&timer9>; - ti,clock-source = <0x00>; /* timer_sys_ck */ - #pwm-cells = <3>; - }; - - ir: n900-ir { - compatible = "nokia,n900-ir"; - - pwms = <&pwm9 0 26316 0>; /* 38000 Hz */ - };Signature · 1 line
2.42.0
Re: [PATCH v5 1/2] dt-bindings: media: remove nokia,n900-ir as pwm-ir-tx is compatible
Quoted 10 lines · Conor Dooley
Quoted 4 lines · Sean Young
The generic pwm-ir-tx driver works for the Nokia n900, so nokia,n900-ir can be removed.
Signed-off-by Sean Young <[email protected]>Acked-by Conor Dooley <[email protected]>Quoted 2 lines
--- .../bindings/leds/irled/pwm-ir-tx.yaml | 5 ++++-
Quoted 49 lines
Quoted 49 lines
.../devicetree/bindings/media/nokia,n900-ir | 20 ------------------- 2 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-irDocumentation/devicetree/bindings/leds/irled/pwm-ir-tx.yaml +4
-1@@ -15,7 +15,10 @@ description: properties: compatible: - const: pwm-ir-tx + oneOf: + - const: pwm-ir-tx + - const: nokia,n900-ir + deprecated: true pwms: maxItems: 1Documentation/devicetree/bindings/media/nokia,n900-ir deleted +0
-20@@ -1,20 +0,0 @@ -Device-Tree bindings for LIRC TX driver for Nokia N900(RX51) - -Required properties: - - compatible: should be "nokia,n900-ir". - - pwms: specifies PWM used for IR signal transmission. - -Example node: - - pwm9: dmtimer-pwm@9 { - compatible = "ti,omap-dmtimer-pwm"; - ti,timers = <&timer9>; - ti,clock-source = <0x00>; /* timer_sys_ck */ - #pwm-cells = <3>; - }; - - ir: n900-ir { - compatible = "nokia,n900-ir"; - - pwms = <&pwm9 0 26316 0>; /* 38000 Hz */ - };Signature · 1 line
2.42.0
Signature · 1 line
Lee Jones [李琼斯]
Sean Young
maintainerPATCH v5 2/2 media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
In reply to Sean YoungThe 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.
Note that the suspend code in the ir-rx51 driver is unnecessary, since during transmit, the process is not in interruptable sleep. The process is not put to sleep until the transmit completes.
--- arch/arm/configs/omap2plus_defconfig | 1 - drivers/media/rc/Kconfig | 10 - drivers/media/rc/Makefile | 1 - drivers/media/rc/ir-rx51.c | 285 --------------------------- drivers/media/rc/pwm-ir-tx.c | 1 + 5 files changed, 1 insertion(+), 297 deletions(-) delete mode 100644 drivers/media/rc/ir-rx51.c
arch/arm/configs/omap2plus_defconfig +0 -1
@@ -484,7 +484,6 @@ CONFIG_LIRC=y CONFIG_RC_DEVICES=y CONFIG_IR_GPIO_TX=m CONFIG_IR_PWM_TX=m -CONFIG_IR_RX51=m CONFIG_IR_SPI=m CONFIG_MEDIA_SUPPORT=m CONFIG_V4L_PLATFORM_DRIVERS=y
drivers/media/rc/Kconfig +0 -10
@@ -337,16 +337,6 @@ config IR_REDRAT3 To compile this driver as a module, choose M here: the module will be called redrat3. -config IR_RX51 - tristate "Nokia N900 IR transmitter diode" - depends on (OMAP_DM_TIMER && PWM_OMAP_DMTIMER && ARCH_OMAP2PLUS || COMPILE_TEST) && RC_CORE - help - Say Y or M here if you want to enable support for the IR - transmitter diode built in the Nokia N900 (RX51) device. - - The driver uses omap DM timers for generating the carrier - wave and pulses. - config IR_SERIAL tristate "Homebrew Serial Port Receiver" depends on HAS_IOPORT
drivers/media/rc/Makefile +0 -1
@@ -43,7 +43,6 @@ obj-$(CONFIG_IR_MTK) += mtk-cir.o obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o obj-$(CONFIG_IR_PWM_TX) += pwm-ir-tx.o obj-$(CONFIG_IR_REDRAT3) += redrat3.o -obj-$(CONFIG_IR_RX51) += ir-rx51.o obj-$(CONFIG_IR_SERIAL) += serial_ir.o obj-$(CONFIG_IR_SPI) += ir-spi.o obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
drivers/media/rc/ir-rx51.c deleted +0 -285
285 lines not on this page · raw message
drivers/media/rc/pwm-ir-tx.c +1 -0
@@ -23,6 +23,7 @@ struct pwm_ir {static const struct of_device_id pwm_ir_of_match[] = { { .compatible ="pwm-ir-tx" , }, + { .compatible ="nokia,n900-ir" }, { }, };MODULE_DEVICE_TABLE (of, pwm_ir_of_match);
Signature · 1 line
2.42.0
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Hello,
Quoted 8 lines · Sean Young
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.
Note that the suspend code in the ir-rx51 driver is unnecessary, since during transmit, the process is not in interruptable sleep. The process is not put to sleep until the transmit completes.
Quoted 5 lines
Cc Timo Kokkonen <[email protected]>Cc Pali Rohár <[email protected]>Cc Ivaylo Dimitrov <[email protected]>Tested-by Sicelo A. Mhlongo <[email protected]>Signed-off-by Sean Young <[email protected]>
I just commented on v3 of this patch. It was an
which I forward hereby to this v5. As with the previous revisions I'll mark this as handled-elsewhere in the pwm patchwork in the assumption that the pwm tree isn't involved to get this into the mainline.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
In reply to Sean YoungQuoted 4 lines · Sean Young
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...
In either case help is appreciated to dig further trying to find the reason for such a big delay.
Regards,
Ivo
Sean Young
maintainerRe: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Quoted 13 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_latency_qos_add_request()in pwm-ir-tx, but it made no difference.
Quoted 4 lines
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.
Quoted 2 lines
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.
I don't have a n900 to test on, unfortunately.
Thanks
Sean
Tony Lindgren
maintainerRe: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Quoted 22 lines · Sean Young
Quoted 13 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_latency_qos_add_request()in pwm-ir-tx, but it made no difference.Quoted 4 lines
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.
Quoted 6 lines
Quoted 2 lines
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 thatusleep_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.
Maybe using fsleep() fixes this issue? See commit c6af13d33475 ("timer: add fsleep for flexible sleeping"), and Documentation/timers/timers-howto.rst.
The long wake-up time for an idle state could explain the values. I think Ivaylo already tested with most cpuidle states disabled via sysfs though.
Quoted 1 line
I don't have a n900 to test on, unfortunately.
If you want one for development, the maemo folks cc:ed here likely have some available devices.
Regards,
Tony
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Quoted 26 lines · Tony Lindgren
Quoted 25 lines · Sean Young
Quoted 13 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_latency_qos_add_request()in pwm-ir-tx, but it made no difference.Quoted 4 lines
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.
Quoted 2 lines
In either case help is appreciated to dig further trying to find the reason for such a big delay.
Quoted 7 lines
Quoted 3 lines
pwm-ir-tx uses
usleep_range()and ir-rx51 uses hrtimers. I thought thatusleep_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.Maybe using
fsleep()fixes this issue? See commitc6af13d33475("timer: add fsleep for flexible sleeping"), andDocumentation/timers/timers-howto.rst.
I doubt, time intervals we are talking about are > 500 us, which means fsleep will always use usleep_range() (or even worse, msleep()), see https://elixir.bootlin.com/linux/v6.6-rc3/source/include/linux/delay.h#L82
Quoted 3 lines
The long wake-up time for an idle state could explain the values. I think Ivaylo already tested with most cpuidle states disabled via sysfs though.
Yes, I disabled all idle states on both n900 and droid4 (when doing cyclictest experiments), with no difference. I also locked frequency on n900 to 500MHz, which improved the things a bit, by some 20-50 us (IIRC), which makes sense, but also makes me think frequency scaling is not the one to blame either.
Quoted 5 lines
Quoted 1 line
I don't have a n900 to test on, unfortunately.
If you want one for development, the maemo folks cc:ed here likely have some available devices.
I think we can arrange one, yes, but my gut feeling tells me the issue is not n900 specific, it is just a bit worse there as the device is relatively slow already. I have no sane explanation why one would see similar latencies on droid4, given that it is times faster than n900.
Regards,
Ivo
Quoted 4 lines
Regards,
Tony
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
In reply to Sean YoungQuoted 14 lines · Sean Young
Quoted 13 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_latency_qos_add_request()in pwm-ir-tx, but it made no difference.
Quoted 8 lines
Quoted 4 lines
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?
ir-rx51 does not suffer from the same problem (albeit it has its own one, see bellow)
Quoted 7 lines
Quoted 2 lines
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 thatusleep_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.
Quoted 2 lines
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()
Thanks,
Ivo
Quoted 3 lines
Thanks
Sean
Sean Young
maintainerRe: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Quoted 20 lines · Ivaylo Dimitrov
Quoted 19 lines · Sean Young
Quoted 17 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_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...
Quoted 6 lines
Quoted 3 lines
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.
Quoted 18 lines
ir-rx51 does not suffer from the same problem (albeit it has its own one, see bellow)
Quoted 7 lines
Quoted 2 lines
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 thatusleep_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, whileusleep_range()puts the task inTASK_UNINTERRUPTIBLEstate and then callsschedule_hrtimeout_range(). For some reason it takes at least 200-400 us (on average) even on OMAP4 to switch back toTASK_RUNNINGstate.
Quoted 8 lines
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#L502I 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.
Quoted 6 lines
Quoted 2 lines
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
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Hi,
Quoted 41 lines · Sean Young
Quoted 20 lines · Ivaylo Dimitrov
Quoted 19 lines · Sean Young
Quoted 17 lines · Ivaylo Dimitrov
Quoted 4 lines · Sean Young
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 triedcpu_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...
Quoted 6 lines
Quoted 3 lines
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.
Quoted 7 lines
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.
The issue with hrtimers is that we cannot use them directly, as pwm_apply_state() may sleep, but hrtimer function is called in atomic context.
Quoted 23 lines
Quoted 23 lines
ir-rx51 does not suffer from the same problem (albeit it has its own one, see bellow)
Quoted 7 lines
Quoted 2 lines
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 thatusleep_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, whileusleep_range()puts the task inTASK_UNINTERRUPTIBLEstate and then callsschedule_hrtimeout_range(). For some reason it takes at least 200-400 us (on average) even on OMAP4 to switch back toTASK_RUNNINGstate.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
Quoted 6 lines
Quoted 3 lines
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.
I made some POC here, but unfortunately it failed more or less. The idea of POC is: setup hrtimer, start it in pwm_ir_tx() and do wait_for_completion() in a loop while calling complete() for the timer function. While it improves things a bit, I wouldn't say it makes the driver working ok on n900 - my TV registers one of let's say 5-10 pulse packages.
We have couple of issues:
- scheduler seems to use 32kHz timer, which means that we can never have precise pulse width, with error up to ~30 us, no matter what we do, IIUC.
- wait_for_completion() suffers from the same latency issue that usleep_range() has - it exits after 300-400 us after complete() has been called in the timer function.
- turning pwm off needs ~300us, because of either omap_dm_timer_stop() calling clk_get_rate() or __omap_dm_timer_stop() waiting for fclk period * 3.5 (see https://elixir.bootlin.com/linux/v6.6-rc3/source/drivers/clocksource/timer-ti-dm.c#L269)
- in order to achieve some sane latency distribution, I have to set_user_nice(current, MIN_NICE); in pwm_ir_tx()
Quoted 3 lines
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.
ir-rx51 has conceptual problem of calling function that might sleep from atomic context, however, we can fix omap_dm_timer_stop() to not call clk_get_rate() and that would make it working. So yeah, if we can't fix pwm-ir-tx then patches removal along with fixing dmtimer and fixing a couple of code issues ir-rx51 has, seems the only option to have working IRTX on n900. Maybe we can rename it to pwm-ir-tx-hrtimer as there is nothing n900 specific in it.
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
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.
The only thing I didn't try yet is to start another thread and to set that thread to use FIFO scheduler. I will report once I have tried that.
Regards,
Ivo
Quoted 3 lines
Thanks,
Sean
Sean Young
maintainerRe: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Hello Uwe,
Just wanted to run an idea by you.
Quoted 7 lines · Ivaylo Dimitrov
Quoted 2 lines · Sean Young
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.
The issue with hrtimers is that we cannot use them directly, as
pwm_apply_state()may sleep, but hrtimer function is called in atomic context.
I've also been looking at this problem and came to same conclusion: the fact that pwm_apply_state() sleeps is a huge problem.
1) The vast majority of pwm drivers don't sleep, or could even be converted to spinlocks (e.g pwm-sifive.c could use spinlocks, as far as I can see).
2) Sure, some pwm devices are on i2c busses, so the driver needs to sleep. Those devices aren't great for what we're trying to do here, since the sleeping may cause delays and affect the generated signal.
What would be ideal here is to have pwm-ir-tx work in atomic context if a non-sleeping pwm device is used, and another (non-optimal) code path for sleeping pwm drivers. We could even just refuse to run on sleeping pwm drivers.
Uwe what do you think of this idea? The pwm api could have a
bool pwm_may_sleep(struct pwm *pwm) function, and pwm_apply_state() does not contain might_sleep() - only the driver-specific apply calls might_sleep().
It would be nice if this could all be done at compile time through e.g. a device tree attribute.
Thanks,
Sean
Re: [PATCH v5 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
Hello Sean,
Quoted 19 lines · Sean Young
Quoted 7 lines · Ivaylo Dimitrov
Quoted 2 lines · Sean Young
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.
The issue with hrtimers is that we cannot use them directly, as
pwm_apply_state()may sleep, but hrtimer function is called in atomic context.I've also been looking at this problem and came to same conclusion: the fact that
pwm_apply_state()sleeps is a huge problem.1) The vast majority of pwm drivers don't sleep, or could even be converted to spinlocks (e.g
pwm-sifive.ccould use spinlocks, as far as I can see).2) Sure, some pwm devices are on i2c busses, so the driver needs to sleep. Those devices aren't great for what we're trying to do here, since the sleeping may cause delays and affect the generated signal.
Quoted 7 lines
What would be ideal here is to have pwm-ir-tx work in atomic context if a non-sleeping pwm device is used, and another (non-optimal) code path for sleeping pwm drivers. We could even just refuse to run on sleeping pwm drivers.
Uwe what do you think of this idea? The pwm api could have a bool
pwm_may_sleep(struct pwm *pwm)function,
It's certainly possible. The idea of introducing the might_sleep() was to catch atomic users and if some appear to be able to evaluate if something needs to be done. See commit 4ad91a227817 ("pwm: Make it explicit that pwm_apply_state() might sleep").
It complicates things concerning my last bigger pwm series, see
https://lore.kernel.org/linux-pwm/[email protected]/
which introduces a mutex_lock() in pwm_apply_state(). Hmm.
Quoted 2 lines
and
pwm_apply_state()does
not containmight_sleep()- only the driver-specific apply callsmight_sleep().
I'd replace the might_sleep() by something like might_sleep_if(pwm_may_sleep(pwm)); but that's an implementation detail.
Quoted 2 lines
It would be nice if this could all be done at compile time through e.g. a device tree attribute.
I wouldn't have something like "linux,slow-pwm" or similar in the device tree, and I'd expect the dt maintainers to shoot down something like that, too. What is the problem with a pwm_can_sleep() function only?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |