This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7a1c62911d35bc7cf9b0ecbecac9cc7589dc955c Author: guanyi3 <[email protected]> AuthorDate: Tue Mar 17 21:31:03 2026 +0800 devfreq/procfs: add write support for frequency QoS constraints Add the ability to set frequency constraints via procfs write. Supported formats: echo <min>,<max> > /proc/devfreq/<name> - set frequency range echo 0,0 > /proc/devfreq/<name> - remove constraint The QoS request is bound to the devfreq device lifetime so that shell commands like echo (which open, write, close immediately) work correctly. Leading whitespace in the write buffer is skipped to handle extra writes from nsh echo (e.g. trailing newline). Also add write permissions in devfreq_stat() and a procfs_qos field in devfreq_s guarded by CONFIG_DEVFREQ_PROCFS. Signed-off-by: guanyi3 <[email protected]> (cherry picked from commit 70ae195c84f35a4d0b85fcc14187989b60fc0280) --- drivers/devfreq/devfreq_procfs.c | 76 +++++++++++++++++++++++++++++++++++++++- include/nuttx/devfreq.h | 4 +++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/devfreq_procfs.c b/drivers/devfreq/devfreq_procfs.c index 700e1a960aa..bf1fe7b09be 100644 --- a/drivers/devfreq/devfreq_procfs.c +++ b/drivers/devfreq/devfreq_procfs.c @@ -239,11 +239,84 @@ static ssize_t devfreq_read(FAR struct file *filep, /**************************************************************************** * Name: devfreq_write + * + * Description: + * Handle write to devfreq procfs entry. + * Format: "<min_freq> <max_freq>" in kHz. + * This creates or updates a QoS request to constrain the frequency. + * Write "0 0" to remove the QoS constraint. + * ****************************************************************************/ static ssize_t devfreq_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { + FAR struct devfreq_procfs_s *devfreq_procfs = filep->f_priv; + FAR struct devfreq_s *devfreq = devfreq_procfs->devfreq; + uint32_t min_freq; + uint32_t max_freq; + FAR char *endptr; + char tmp[32]; + int ret; + + if (buflen == 0 || buflen >= sizeof(tmp)) + { + return -EINVAL; + } + + memcpy(tmp, buffer, buflen); + tmp[buflen] = '\0'; + + min_freq = strtoul(tmp, &endptr, 10); + if (endptr == tmp) + { + return buflen; + } + + if (*endptr == ',' || *endptr == ' ') + { + endptr++; + } + + max_freq = strtoul(endptr, &endptr, 10); + + /* Write "0 0" to remove the QoS constraint */ + + if (min_freq == 0 && max_freq == 0) + { + if (devfreq->procfs_qos) + { + devfreq_qos_remove_request(devfreq, devfreq->procfs_qos); + devfreq->procfs_qos = NULL; + } + + return buflen; + } + + if (min_freq > max_freq) + { + return -EINVAL; + } + + if (devfreq->procfs_qos) + { + ret = devfreq_qos_update_request(devfreq, devfreq->procfs_qos, + min_freq, max_freq); + if (ret < 0) + { + return ret; + } + } + else + { + devfreq->procfs_qos = devfreq_qos_add_request(devfreq, + min_freq, max_freq); + if (!devfreq->procfs_qos) + { + return -ENOMEM; + } + } + return buflen; } @@ -376,7 +449,8 @@ static int devfreq_stat(FAR const char *relpath, FAR struct stat *buf) return -ENOENT; } - buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR | + S_IWOTH | S_IWGRP | S_IWUSR; } return 0; diff --git a/include/nuttx/devfreq.h b/include/nuttx/devfreq.h index 79fd6ca441e..5189e6e1895 100644 --- a/include/nuttx/devfreq.h +++ b/include/nuttx/devfreq.h @@ -72,6 +72,10 @@ struct devfreq_s mutex_t lock; FAR void *priv; + +#ifdef CONFIG_DEVFREQ_PROCFS + FAR struct qos_request_s *procfs_qos; +#endif }; struct devfreq_governor_s
