Hello,
I am trying to synchronize a PWM output with a PPS signal on the Orin, but calling pwm_config, pwm_disable, or pwm_enable from within an interrupt causes the kernel to crash. Is there an atomic version implemented in L4T 35.1, or is there some other way I can achieve this same goal?
I found the nvidia, no-clk-sleeping-in-ops
device tree flag for the PWM chip, but it still crashes when trying to configure or enable in an interrupt. Curiously I still get BUG: scheduling while atomic
error when trying to enable in an interrupt but if trying to configure one that is already enabled I get the following instead
[ 252.892315] ------------[ cut here ]------------
[ 252.892383] WARNING: CPU: 0 PID: 707 at drivers/firmware/tegra/bpmp.c:363 tegra_bpmp_transfer+0x2e8/0x370
[ 252.902299] Modules linked in: pps_gpio fuse xt_conntrack xt_MASQUERADE nf_conntrack_netlink nfnetlink xt_addrtype iptable_filter iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c br_netfilter lzo_rle lzo_compress zram overlay ramoops reed_solomon bnep loop nvgpu rtk_btusb aes_ce_blk snd_soc_tegra186_asrc crypto_simd snd_soc_tegra210_ope snd_soc_tegra186_dspk snd_soc_tegra210_iqc snd_soc_tegra186_arad cryptd snd_soc_tegra210_mvc snd_soc_tegra210_afc btusb rtl8822ce snd_soc_tegra210_admaif aes_ce_cipher snd_soc_tegra210_adx snd_soc_tegra210_dmic btrtl ghash_ce snd_soc_tegra210_sfc snd_soc_tegra_pcm snd_soc_tegra210_mixer snd_soc_tegra210_amx snd_soc_tegra210_i2s snd_soc_tegra210_adsp ofpart btbcm sha2_ce snd_soc_tegra_machine_driver sha256_arm64 cmdlinepart snd_hda_codec_hdmi ucsi_ccg btintel cfg80211 snd_soc_tegra_utils sha1_ce nvadsp typec_ucsi qspi_mtd snd_hda_tegra snd_soc_simple_card_utils snd_soc_spdif_tx nct1008 pwm_fan typec snd_soc_tegra210_ahub snd_hda_codec
[ 252.902836] mtd tegra_bpmp_thermal tegra210_adma ina3221 userspace_alert snd_hda_core spi_tegra114 binfmt_misc nvmap ip_tables x_tables [last unloaded: pps_gpio]
[ 252.902936] CPU: 0 PID: 707 Comm: sugov:0 Not tainted 5.10.104-tegra #3
[ 252.902942] Hardware name: /, BIOS 1.0-d7fb19b 08/10/2022
[ 252.902953] pstate: 60400089 (nZCv daIf +PAN -UAO -TCO BTYPE=--)
[ 252.902960] pc : tegra_bpmp_transfer+0x2e8/0x370
[ 252.902970] lr : tegra_bpmp_transfer+0x24/0x370
[ 252.902976] sp : ffff800010003a70
[ 252.902982] x29: ffff800010003a70 x28: ffff1c2bc10a1860
[ 252.903000] x27: ffffd99acc6c7000 x26: ffff1c2bd95b8600
[ 252.903019] x25: ffffd99acc6c7000 x24: ffffd99acc9b8998
[ 252.903036] x23: 0000000000fe502b x22: ffff1c32bfb6a880
[ 252.903053] x21: ffff800010003b28 x20: ffff1c2bf9bd4880
[ 252.903069] x19: ffff800010003ba8 x18: 0000000000000000
[ 252.903088] x17: 0000000000000000 x16: ffffd99acb37e1f0
[ 252.903104] x15: ffff1c2bf9bd4df0 x14: ffffffffffffffff
[ 252.903121] x13: ffffd99acccd9de8 x12: ffffd99acccd9a26
[ 252.903139] x11: 0000000000000003 x10: 0101010101010101
[ 252.903156] x9 : ffff800010003d80 x8 : 0000000000000003
[ 252.903176] x7 : 000000000000006d x6 : ffff800010003b28
[ 252.903193] x5 : 000000000000000c x4 : 0000000000000010
[ 252.903209] x3 : ffff800010003b94 x2 : ffffd99acae8e090
[ 252.903228] x1 : 0000000000000080 x0 : 0000000000000080
[ 252.903247] Call trace:
[ 252.903255] tegra_bpmp_transfer+0x2e8/0x370
[ 252.903279] tegra_bpmp_clk_transfer+0x90/0xe0
[ 252.903285] tegra_bpmp_clk_determine_rate+0x94/0xd0
[ 252.903300] clk_core_determine_round_nolock.part.0+0x38/0x80
[ 252.903308] clk_core_round_rate_nolock+0x9c/0xb0
[ 252.903313] clk_core_set_rate_nolock+0x68/0x1c0
[ 252.903320] clk_set_rate+0x44/0x100
[ 252.903340] tegra_pwm_apply+0x210/0x240
[ 252.903345] pwm_apply_state+0x70/0x370
[ 252.903373] pwm_config+0x68/0xa0 [pps_gpio]
[ 252.903380] pps_gpio_irq_handler+0xc8/0x10c [pps_gpio]
[ 252.903402] __handle_irq_event_percpu+0x68/0x2a0
[ 252.903410] handle_irq_event_percpu+0x40/0xa0
[ 252.903418] handle_irq_event+0x50/0xf0
[ 252.903426] handle_edge_irq+0xb8/0x1c0
[ 252.903435] generic_handle_irq+0x40/0x60
[ 252.903445] tegra186_gpio_irq+0x124/0x1f0
[ 252.903454] generic_handle_irq+0x40/0x60
[ 252.903461] __handle_domain_irq+0x70/0xd0
[ 252.903481] gic_handle_irq+0x68/0x134
[ 252.903488] el1_irq+0xd0/0x180
[ 252.903503] smp_call_function_single+0x1b8/0x210
[ 252.903518] tegra234_get_cpu_cluster_id+0x50/0xa0
[ 252.903526] tegra234_set_cpu_ndiv+0x74/0xf0
[ 252.903533] tegra194_cpufreq_set_target+0x6c/0x190
[ 252.903540] __cpufreq_driver_target+0x1b0/0x5c0
[ 252.903554] sugov_work+0x64/0x80
[ 252.903571] kthread_worker_fn+0xa0/0x170
[ 252.903578] kthread+0x148/0x170
[ 252.903585] ret_from_fork+0x10/0x24
[ 252.903594] ---[ end trace f5f0d37064b7c057 ]---
Here is what happens if I do disable, config, and then enable in the same interrupt (note disable and config both work, so no-clk-sleeping-in-ops
is on for those functions:
[ 1092.056413] pps pps0: PPS event at 1670622568.377464972
[ 1092.056435] pps-gpio: echo callback fired!
[ 1092.056447] pps pps0: capture assert seq #1
[ 1092.056453] pps-gpio: PWM PIN CONFIGURED
[ 1092.056455] pps-gpio: DISABLING PWM
[ 1092.056475] pps-gpio: DISABLED PWM PIN
[ 1092.056476] pps-gpio: START UPDATE PWM
[ 1092.056480] pps-gpio: END UPDATE PWM PIN
[ 1092.056482] pps-gpio: ENABLE PWM
[ 1092.056487] BUG: scheduling while atomic: sugov:0/712/0x00010002
[ 1092.062729] Modules linked in: pps_gpio fuse xt_conntrack xt_MASQUERADE nf_conntrack_netlink nfnetlink xt_addrtype iptable_filter iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c br_netfilter lzo_rle lzo_compress zram overlay ramoops reed_solomon bnep loop nvgpu rtl8822ce cfg80211 aes_ce_blk crypto_simd rtk_btusb cryptd snd_soc_tegra186_asrc aes_ce_cipher snd_soc_tegra186_dspk snd_soc_tegra210_ope btusb snd_soc_tegra210_iqc snd_soc_tegra186_arad snd_soc_tegra210_mvc ghash_ce snd_soc_tegra210_admaif btrtl snd_soc_tegra210_afc snd_hda_codec_hdmi snd_soc_tegra210_adsp ucsi_ccg snd_soc_tegra210_dmic ofpart snd_soc_tegra210_adx sha2_ce btbcm snd_soc_tegra_machine_driver snd_soc_tegra210_mixer snd_soc_tegra_pcm snd_soc_tegra210_amx snd_soc_tegra210_i2s sha256_arm64 snd_soc_tegra210_sfc typec_ucsi snd_hda_tegra btintel cmdlinepart snd_soc_tegra_utils sha1_ce nvadsp snd_hda_codec qspi_mtd pwm_fan snd_soc_simple_card_utils snd_soc_spdif_tx typec snd_soc_tegra210_ahub nct1008
[ 1092.062982] mtd snd_hda_core ina3221 tegra210_adma tegra_bpmp_thermal userspace_alert spi_tegra114 binfmt_misc nvmap ip_tables x_tables [last unloaded: pps_gpio]
[ 1092.063032] CPU: 0 PID: 712 Comm: sugov:0 Not tainted 5.10.104-tegra #3
[ 1092.063035] Hardware name: /, BIOS 1.0-d7fb19b 08/10/2022
[ 1092.063045] Call trace:
[ 1092.063104] dump_backtrace+0x0/0x1d0
[ 1092.063113] show_stack+0x30/0x40
[ 1092.063166] dump_stack+0xd8/0x138
[ 1092.063182] __schedule_bug+0x78/0x90
[ 1092.063200] __schedule+0x844/0x910
[ 1092.063204] schedule+0x78/0x110
[ 1092.063209] schedule_preempt_disabled+0x2c/0x50
[ 1092.063214] __mutex_lock.isra.0+0x18c/0x560
[ 1092.063218] __mutex_lock_slowpath+0x28/0x40
[ 1092.063222] mutex_lock+0x60/0x70
[ 1092.063241] clk_prepare_lock+0x4c/0xa0
[ 1092.063249] clk_set_rate+0x30/0x100
[ 1092.063265] tegra_pwm_apply+0x210/0x240
[ 1092.063270] pwm_apply_state+0x70/0x370
[ 1092.063290] pwm_enable+0x58/0x90 [pps_gpio]
[ 1092.063293] pps_gpio_irq_handler+0xf8/0x16c [pps_gpio]
[ 1092.063309] __handle_irq_event_percpu+0x68/0x2a0
[ 1092.063313] handle_irq_event_percpu+0x40/0xa0
[ 1092.063317] handle_irq_event+0x50/0xf0
[ 1092.063319] handle_edge_irq+0xb8/0x1c0
[ 1092.063324] generic_handle_irq+0x40/0x60
[ 1092.063331] tegra186_gpio_irq+0x124/0x1f0
[ 1092.063333] generic_handle_irq+0x40/0x60
[ 1092.063337] __handle_domain_irq+0x70/0xd0
[ 1092.063345] gic_handle_irq+0x68/0x134
[ 1092.063348] el1_irq+0xd0/0x180
[ 1092.063362] smp_call_function_single+0x1b8/0x210
[ 1092.063378] tegra234_get_cpu_cluster_id+0x50/0xa0
[ 1092.063382] tegra234_set_cpu_ndiv+0x74/0xf0
[ 1092.063386] tegra194_cpufreq_set_target+0x6c/0x190
[ 1092.063390] __cpufreq_driver_target+0x1b0/0x5c0
[ 1092.063400] sugov_work+0x64/0x80
[ 1092.063415] kthread_worker_fn+0xa0/0x170
[ 1092.063418] kthread+0x148/0x170
[ 1092.063424] ret_from_fork+0x10/0x24
[ 1092.063604] ------------[ cut here ]------------
hello guotl321,
may I know which PWM pin you’re using, had you also modify pinmux spreadsheets to update pin configuration?
I am outputting on Pin 18 (PWM5) and receiving the interrupt on Pin 13. I used the jetson-io.py tool to update the pin configuration instead of the spreadsheet, and I’m pretty sure that works fine since the PWM output works if I don’t do anything in the interrupt. It’s specifically calling the PWM functions in an interrupt handler that breaks things.
hello guotl321,
you cannot do this… because you cannot call mutex from an interrupt context.
[ 1092.063209] schedule_preempt_disabled+0x2c/0x50
[ 1092.063214] __mutex_lock.isra.0+0x18c/0x560
[ 1092.063218] __mutex_lock_slowpath+0x28/0x40
[ 1092.063222] mutex_lock+0x60/0x70
[ 1092.063241] clk_prepare_lock+0x4c/0xa0
[ 1092.063249] clk_set_rate+0x30/0x100
[ 1092.063265] tegra_pwm_apply+0x210/0x240
[ 1092.063270] pwm_apply_state+0x70/0x370
Yes, I am not purposefully calling a mutex but using the functions pwm_config, pwm_disable, and pwm_enable from pwm-tegra.c
to configure the PWM. Is it possible for me to use these functions in an interrupt context? If not, is there an alternative way to synchronize the PWM?
hello guotl321,
may I know what’s the real use-case to synchronize a PWM output with a PPS signal.
had you now obtain the events that generate on rising edge (or, falling edge) of signal?
I am trying to synchronize some cameras and radars with an IMU that provides a PPS signal. This PPS signal comes in on a GPIO pin and triggers an interrupt in a driver; I am trying to control the PWM from that interrupt to synchronize them.
hello guotl321,
we don’t have similar use-case.
however, according to your comments.
IMU that provides a PPS signal. This PPS signal comes in on a GPIO pin and triggers an interrupt
there’s already interrupt events.
it should be your implementation to have a pin to monitor that interrupt edge, (either rising or falling)
then, you should able to synchronize them.
system
Closed
January 25, 2023, 12:51am
15
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.