
This also support for multicolor leds which wasn't supported by brightnessctl. And it provides a significant performance improvement. The sxmo_led.sh script takes quite a bit of cpu power to run, which isn't great because it runs about every 2 seconds when the system is idle. This rewrites most of it in c which should solve help speed it up. Before the led blink process would consume somewhere around 20% cpu usage (0.7 seconds / 3 seconds total for a blink). After this patch it should come down closer 10% cpu usage. This is significantly better, but still not very good. I think most of the remaining time is being spent in sxmo_wakelock.sh, reimplementing that and/or finding a way to not need it will probably be necessary to get this to execute in a reasonable amount of time. Before: $ sudo perf stat -r 8 ./scripts/core/sxmo_led.sh blink red blue Performance counter stats for './scripts/core/sxmo_led.sh blink red blue' (8 runs): 796.76 msec task-clock # 0.715 CPUs utilized ( +- 1.64% ) 316 context-switches # 396.604 /sec ( +- 3.77% ) 35 cpu-migrations # 43.928 /sec ( +- 7.87% ) 12,505 page-faults # 15.695 K/sec ( +- 0.04% ) 883,688,799 cycles # 1.109 GHz ( +- 2.16% ) 310,020,051 instructions # 0.35 insn per cycle ( +- 0.09% ) 33,193,824 branches # 41.661 M/sec ( +- 0.09% ) 5,169,519 branch-misses # 15.57% of all branches ( +- 0.19% ) 1.1151 +- 0.0274 seconds time elapsed ( +- 2.46% ) $ hyperfine 'sxmo_led.sh blink red blue' Benchmark 1: sxmo_led.sh blink red blue Time (mean ± σ): 1.059 s ± 0.042 s [User: 0.284 s, System: 0.458 s] Range (min … max): 1.013 s … 1.163 s 10 runs After: $ sudo perf stat -r 8 sxmo_led.sh blink red blue Performance counter stats for 'sxmo_led.sh blink red blue' (8 runs): 347.50 msec task-clock # 0.337 CPUs utilized ( +- 2.25% ) 176 context-switches # 506.474 /sec ( +- 8.81% ) 13 cpu-migrations # 37.410 /sec ( +- 19.22% ) 3,243 page-faults # 9.332 K/sec ( +- 0.05% ) 383,056,720 cycles # 1.102 GHz ( +- 2.84% ) 143,365,214 instructions # 0.37 insn per cycle ( +- 0.14% ) 15,816,749 branches # 45.516 M/sec ( +- 0.15% ) 2,520,323 branch-misses # 15.93% of all branches ( +- 0.46% ) 1.0326 +- 0.0359 seconds time elapsed ( +- 3.48% ) $ hyperfine 'sxmo_led.sh blink red blue' Benchmark 1: sxmo_led.sh blink red blue Time (mean ± σ): 1.006 s ± 0.027 s [User: 0.128 s, System: 0.186 s] Range (min … max): 0.963 s … 1.051 s 10 runs Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
37 lines
608 B
Bash
Executable File
37 lines
608 B
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2022 Sxmo Contributors
|
|
|
|
# shellcheck source=scripts/core/sxmo_common.sh
|
|
. sxmo_common.sh
|
|
|
|
set -e
|
|
|
|
finish_blinking() {
|
|
sxmo_wakelock.sh unlock sxmo_playing_with_leds
|
|
trap - INT TERM EXIT
|
|
}
|
|
|
|
blink_leds() {
|
|
sxmo_wakelock.sh lock sxmo_playing_with_leds 2s
|
|
trap 'finish_blinking' TERM INT EXIT
|
|
sxmo_status_led blink "$@"
|
|
}
|
|
|
|
[ -z "$SXMO_DISABLE_LEDS" ] || exit 1
|
|
|
|
exec 3<> "${XDG_RUNTIME_DIR:-$HOME}/sxmo.led.lock"
|
|
|
|
cmd="$1"
|
|
shift
|
|
case "$cmd" in
|
|
set)
|
|
flock -x 3
|
|
sxmo_status_led set "$@"
|
|
;;
|
|
blink)
|
|
flock -x 3
|
|
blink_leds "$@"
|
|
;;
|
|
esac
|