driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* drivers/devfreq/devfreq_qos.c
|
|
|
|
|
*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/devfreq/devfreq_qos.h>
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
|
#include <errno.h>
|
2025-05-16 16:07:54 +08:00
|
|
|
#include <execinfo.h>
|
driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: qos_constraints_init
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Initialize a qos_constraints_s struct.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* qos - The qos constraints struct to initialize.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* None
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void qos_constraints_init(FAR struct qos_constraints_s *constraints)
|
|
|
|
|
{
|
|
|
|
|
plist_head_init(&constraints->min_requests);
|
|
|
|
|
plist_head_init(&constraints->max_requests);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: qos_add_request
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Add a qos request to qos constraints.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* qos - The qos constraints to add the request to.
|
|
|
|
|
* min - The minimum priority/value of the request.
|
|
|
|
|
* max - The maximum priority/value of the request.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* A pointer to the new qos_request_s.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FAR struct qos_request_s *qos_add_request(
|
|
|
|
|
FAR struct qos_constraints_s *constraints,
|
|
|
|
|
uint32_t min, uint32_t max)
|
|
|
|
|
{
|
|
|
|
|
FAR struct qos_request_s *req;
|
|
|
|
|
|
|
|
|
|
if (!constraints)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req = kmm_zalloc(sizeof(struct qos_request_s));
|
|
|
|
|
if (!req)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plist_node_init(&req->min_req, min);
|
|
|
|
|
plist_node_init(&req->max_req, max);
|
|
|
|
|
|
|
|
|
|
plist_add(&req->min_req, &constraints->min_requests);
|
|
|
|
|
plist_add(&req->max_req, &constraints->max_requests);
|
|
|
|
|
|
2025-05-16 16:07:54 +08:00
|
|
|
#ifdef CONFIG_DEVFREQ_PROCFS_QOS
|
|
|
|
|
req->backtrace = backtrace_record(0);
|
|
|
|
|
#endif
|
|
|
|
|
|
driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: qos_remove_request
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Remove qos request from qos constraints.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* qos - The qos_constraints_s to remove the request from.
|
|
|
|
|
* req - The qos_request_s to remove.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero on success; a negated errno on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int qos_remove_request(FAR struct qos_constraints_s *constraints,
|
|
|
|
|
FAR struct qos_request_s *req)
|
|
|
|
|
{
|
|
|
|
|
if (!req || !constraints)
|
|
|
|
|
{
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plist_del(&req->min_req, &constraints->min_requests);
|
|
|
|
|
plist_del(&req->max_req, &constraints->max_requests);
|
|
|
|
|
|
2025-05-16 16:07:54 +08:00
|
|
|
#ifdef CONFIG_DEVFREQ_PROCFS_QOS
|
|
|
|
|
backtrace_remove(req->backtrace);
|
|
|
|
|
#endif
|
|
|
|
|
|
driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
kmm_free(req);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: qos_update_request
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Update qos request.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* qos - The qos constraints.
|
|
|
|
|
* req - The qos request to update.
|
|
|
|
|
* min - The new minimum priority/value of the request.
|
|
|
|
|
* max - The new maximum priority/value of the request.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero on success; a negated errno on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int qos_update_request(FAR struct qos_constraints_s *constraints,
|
|
|
|
|
FAR struct qos_request_s *req,
|
|
|
|
|
uint32_t min, uint32_t max)
|
|
|
|
|
{
|
|
|
|
|
if (!req || !constraints)
|
|
|
|
|
{
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req->min_req.prio = min;
|
|
|
|
|
req->max_req.prio = max;
|
|
|
|
|
|
|
|
|
|
plist_del(&req->min_req, &constraints->min_requests);
|
|
|
|
|
plist_del(&req->max_req, &constraints->max_requests);
|
|
|
|
|
plist_add(&req->min_req, &constraints->min_requests);
|
|
|
|
|
plist_add(&req->max_req, &constraints->max_requests);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: qos_get_value
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Get min or max value of qos constraints.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* qos - The qos constraints.
|
|
|
|
|
* type - The type of request to get the value of.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* The value of the qos request.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint32_t qos_get_value(FAR struct qos_constraints_s *constraints,
|
|
|
|
|
enum qos_req_type_e type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case QOS_REQ_MIN:
|
|
|
|
|
{
|
2026-03-06 16:26:00 +08:00
|
|
|
return plist_last(&constraints->min_requests)->prio;
|
driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case QOS_REQ_MAX:
|
|
|
|
|
{
|
2026-03-06 16:26:00 +08:00
|
|
|
return plist_first(&constraints->max_requests)->prio;
|
driver/devfreq: DVFS framework for devices
This commit introduces a devfreq framework to manage device frequency
scaling. The framework includes the following features:
1.devfreq governor
- provide governor ops, including init, start, stop, exit
- default governor, performance & powersave
- customized governor, device can provide governor when register
2.runtime register and unregister
- device can runtime register & unregister, search by name
3.suspend and resume
- suspend and resume frequency scaling
4.notify
- register & unregister notifier callback, notify frequency changes
5.qos support
- simplified QoS, manage multiple freq range request
- including init, add/remove/update request, get value
Signed-off-by: guanyi <guanyi@xiaomi.com>
2025-04-02 14:19:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|