Skip to content

drivers/devfreq: add missing governor_data field and ondemand declaration - #19788

Merged
acassis merged 1 commit into
apache:masterfrom
zzby0:devfreq-ondemand-fix
Aug 11, 2026
Merged

drivers/devfreq: add missing governor_data field and ondemand declaration#19788
acassis merged 1 commit into
apache:masterfrom
zzby0:devfreq-ondemand-fix

Conversation

@zzby0

@zzby0 zzby0 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

The ondemand governor (drivers/devfreq/devfreq_ondemand.c) stores its
private state in dev->governor_data and defines devfreq_ondemand(),
but neither the governor_data field in struct devfreq_s nor the
devfreq_ondemand() declaration were present in
include/nuttx/devfreq.h. As a result, building with
CONFIG_DEVFREQ_GOV_ONDEMAND=y failed to compile.

This gap was introduced during upstreaming of the devfreq framework: the
two definitions originally lived in a downstream commit whose main topic
was a cpufreq refactor, and that commit was not part of the devfreq
upstreaming series. The performance and powersave governors do not use
governor_data, so the problem only surfaces when the ondemand governor
is enabled (which additionally requires !CONFIG_SCHED_CPULOAD_NONE and
is off by default), which is why it was not caught earlier.

This PR:

  • adds the governor_data field to struct devfreq_s
  • declares devfreq_ondemand() alongside devfreq_performance() and
    devfreq_powersave()

Reported-by: @raiden00pl

Impact

  • Fixes a build failure for CONFIG_DEVFREQ_GOV_ONDEMAND=y.
  • No impact on existing configurations: governor_data is a new field in
    struct devfreq_s and the declaration is additive; the default build
    (ondemand off) is unchanged.
  • No API breakage; no behavioral change to the performance/powersave
    governors.

Testing

Host

  • OS: Linux x86_64 (Ubuntu)
  • Toolchain: host gcc (sim)
  • Base: apache/master

Before this PR — building sim with the ondemand governor enabled
fails to compile devfreq_ondemand.c because struct devfreq_s has no
governor_data member and devfreq_ondemand() is undeclared.

After this PR — clean build:

./tools/configure.sh -l sim:nsh
kconfig-tweak --file .config -e CONFIG_DEVFREQ
kconfig-tweak --file .config -e CONFIG_DEVFREQ_PROCFS
kconfig-tweak --file .config -e CONFIG_DEVFREQ_PROCFS_QOS
kconfig-tweak --file .config -d CONFIG_SCHED_CPULOAD_NONE
kconfig-tweak --file .config -e CONFIG_SCHED_CPULOAD_SYSCLK
kconfig-tweak --file .config -e CONFIG_DEVFREQ_GOV_ONDEMAND
make olddefconfig
make -j

Result:

CC:  devfreq/devfreq_ondemand.c
...
LD:  nuttx

devfreq_ondemand.o is produced and linking succeeds with no errors or warnings.

tools/checkpatch.sh -g apache/master..HEAD passes.

…tion

The ondemand governor (devfreq_ondemand.c) references dev->governor_data
to store its private state, and defines devfreq_ondemand(), but neither
the field in struct devfreq_s nor the function declaration were present
in include/nuttx/devfreq.h.  As a result, building with
CONFIG_DEVFREQ_GOV_ONDEMAND=y failed to compile.

These two definitions were originally introduced by a downstream commit
that was not part of the devfreq upstreaming series, so the gap only
surfaced when the ondemand governor is enabled (which additionally
requires !CONFIG_SCHED_CPULOAD_NONE and is off by default).

Add the governor_data field to struct devfreq_s and declare
devfreq_ondemand() alongside the other governors.

Signed-off-by: guanyi <guanyi@xiaomi.com>
@zzby0

zzby0 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216
Does devfreq really need "ondemand" governor?

  1. Ondemand requires enabling CPU load as a prerequisite.
  2. Ondemand is designed specifically for CPUs, not general-purpose devices.
  3. Ondemand has not been extensively validated on our products.

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Aug 11, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 Does devfreq really need "ondemand" governor?

  1. Ondemand requires enabling CPU load as a prerequisite.
  2. Ondemand is designed specifically for CPUs, not general-purpose devices.

user can enable it only for cpu freq scaling.

  1. Ondemand has not been extensively validated on our products.

@acassis
acassis merged commit 83e4b60 into apache:master Aug 11, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants