Skip to content

Setting LED trigger to 'cpu' doesn't work with 64-bit kernel #4425

Open

Description

@ZakKemble

Describe the bug
Setting cpu or cpuX as the LED trigger in /sys/class/leds/ledX/trigger doesn't work with 64-bit kernel (using arm_64bit=1 in config.txt), but does work with 32-bit kernel. cat /sys/class/leds/ledX/trigger shows cpu and cpuX as available options.

To reproduce
echo cpu | sudo tee /sys/class/leds/led0/trigger

Expected behaviour
LED should flicker with CPU usage

Actual behaviour
LED stays off and no errors

System
Pi Model:
Raspberry Pi 4 and CM4

cat /etc/rpi-issue
Raspberry Pi reference 2021-05-07
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, dcfd74d7d1fa293065ac6d565711e9ff891fe2b8, stage2

vcgencmd version
May 27 2021 14:02:31
Copyright (c) 2012 Broadcom
version 7d9a298cda813f747b51fe17e1e417e7bf5ca94d (clean) (release) (start_cd)

uname -a
Linux router.localnet 5.10.17-v8+ #1421 SMP PREEMPT Thu May 27 14:01:37 BST 2021 aarch64 GNU/Linux

Activity

  1. pelwell commented on Jul 1, 2021

    @pelwell
    Contributor

    The cpu trigger exports the ledtrig_cpu API, calls to which mark the times the CPU is busy and idle. A quick search through the kernel source show that it is only called from one place - arch/arm/kernel/process.c, in functions arch_cpu_idle_enter and arch_cpu_idle_exit.

    Adding support on the arm64/aarch64 platform is trivial:

    diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
    index ed919f633ed8..a8fab468bbf0 100644
    --- a/arch/arm64/kernel/process.c
    +++ b/arch/arm64/kernel/process.c
    @@ -44,6 +44,7 @@
     #include <linux/percpu.h>
     #include <linux/thread_info.h>
     #include <linux/prctl.h>
    +#include <linux/leds.h>
     
     #include <asm/alternative.h>
     #include <asm/arch_gicv3.h>
    @@ -136,6 +137,16 @@ void arch_cpu_idle_dead(void)
     }
     #endif
     
    +void arch_cpu_idle_enter(void)
    +{
    +       ledtrig_cpu(CPU_LED_IDLE_START);
    +}
    +
    +void arch_cpu_idle_exit(void)
    +{
    +       ledtrig_cpu(CPU_LED_IDLE_END);
    +}
    +
     /*
      * Called by kexec, immediately prior to machine_kexec().
      *

    However, it will have a small overhead every time each CPU enters and leaves the idle state - some very simple logic, an atomic counter update, and walking a (likely empty) list under a spinlock. If there is an LED with a cpu trigger then the list won't be empty.

    We're always wary of enabling configuration options that ending up costing all users memory, cpu or disk storage for the benefit of a few. This has the added disincentive of being a downstream patch (unless you decided to take it to the upstream maintainers of arm64), so I'm even less tempted.

    I'll leave this here to see if there are any other opinions, but I'll need some persuasion (e.g. some performance measurements) before considering applying the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions