Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,12 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
#ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6768/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/dramc/$(MTK_PLATFORM)/
ccflags-y += -I$(srctree)/drivers/devfreq
ccflags-y += -I$(srctree)/drivers/misc/mediatek/qos/
obj-y += qos_pfm.o
obj-y += obpfm_qos_bound.o
@@ -0,0 +1,364 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_qos: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
#include <linux/ktime.h>
#include <linux/hrtimer.h>
#include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/rbtree.h>
#include <linux/preempt.h>
#include <linux/proc_fs.h>
#include <linux/trace_events.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <trace/events/pob.h>
#include "helio-dvfsrc.h"
//#include "mtk_qos_sram.h"
#ifdef CONFIG_MTK_DRAMC
#include <mtk_dramc.h>
#else
__weak int dram_steps_freq(unsigned int step) { return 0; }
#endif
#include "pob_int.h"
#include "obpfm_qos_bound.h"
#define QOS_TOTAL_BW_BUF(idx) (idx * 4)
#define QOS_TOTAL_BW_BUF_SIZE 8
#define QOS_TOTAL_BW_BUF_LAST 0x4C
static BLOCKING_NOTIFIER_HEAD(qos_bound_chain_head);
static DECLARE_WAIT_QUEUE_HEAD(qos_waitqueue);
unsigned short bound_seqnum;
unsigned short bound_idx;
//#define _MTK_OBPFMQOS_DO_CHECK_ 1
//#define _MTK_OBPFMQOS_DEBUG_ 1
static u64 checked_timestamp;
static u64 ms_interval = 2 * NSEC_PER_MSEC;
static DEFINE_SPINLOCK(check_lock);
static struct qos_bound bound;
static int sspm_lastidx = -1;
static int inited;
static HLIST_HEAD(bwq_list);
struct bwq {
struct hlist_node hlist;
struct work_struct sWork;
};
static struct workqueue_struct *_gpBWQNtfWQ;
#ifdef _MTK_OBPFMQOS_DEBUG_
static inline void _trace_pob_log(char *log)
{
preempt_disable();
trace_pob_log(log);
preempt_enable();
}
#define TRACELOG_SIZE 512
void pob_wall_tracelog(u64 wallclock, s64 diff)
{
char log[TRACELOG_SIZE];
int tmplen;
tmplen = snprintf(log, TRACELOG_SIZE, "%s %llu %llu",
"wallclock",
(unsigned long long) wallclock,
(unsigned long long) diff);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
_trace_pob_log(log);
}
void pob_src_tracelog(char *file, int line, void *ptr)
{
char log[TRACELOG_SIZE];
int tmplen;
tmplen = snprintf(log, TRACELOG_SIZE, "%s %d %p",
file, line, ptr);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
_trace_pob_log(log);
}
#endif
static inline s64 do_check(u64 wallclock)
{
s64 do_check = 0;
#ifdef _MTK_OBPFMQOS_DO_CHECK_
unsigned long flags;
#endif
/* check interval */
#ifdef _MTK_OBPFMQOS_DO_CHECK_
spin_lock_irqsave(&check_lock, flags);
#endif
do_check = (s64)(wallclock - checked_timestamp);
if (do_check >= (s64)ms_interval)
checked_timestamp = wallclock;
else
do_check = 0;
#ifdef _MTK_OBPFMQOS_DO_CHECK_
spin_unlock_irqrestore(&check_lock, flags);
#endif
return do_check;
}
static int _get_qos_bound_bw_threshold(int state, int val)
{
if (state == QOS_BOUND_BW_FULL)
return val * QOS_BOUND_BW_FULL_PCT / 100;
else if (state == QOS_BOUND_BW_CONGESTIVE)
return val * QOS_BOUND_BW_CONGESTIVE_PCT / 100;
return 0;
}
static int _pob_qos_tracker_set_event(struct qos_bound_stat *stat)
{
int isfull = 0;
int val = dram_steps_freq(0) * 4;
if (stat->emibw_mon[QOS_EMIBM_TOTAL] >=
_get_qos_bound_bw_threshold(QOS_BOUND_BW_FULL, val)) {
stat->event = QOS_BOUND_BW_FULL;
isfull = 1;
} else if (stat->emibw_mon[QOS_EMIBM_TOTAL] >=
_get_qos_bound_bw_threshold(QOS_BOUND_BW_CONGESTIVE, val))
stat->event = QOS_BOUND_BW_CONGESTIVE;
else
stat->event = QOS_BOUND_BW_FREE;
return isfull;
}
static int _pob_qos_tracker_set_stat(struct qos_bound_stat *stat,
int sramidx,
u64 wallclock)
{
int isfull = 0;
int bw_total;
bw_total = qos_sram_read(QOS_TOTAL_BW_BUF(sramidx));
stat->emibw_mon[QOS_EMIBM_TOTAL] = 0x0000FFFF & bw_total;
stat->num = (0xFF000000 & bw_total) >> 24;
stat->wallclock = wallclock;
if (_pob_qos_tracker_set_event(stat))
isfull = 1;
return isfull;
}
static void mtk_qb_wq_cb(struct work_struct *psWork)
{
unsigned long flags;
struct bwq *vbwq;
vbwq = POB_CONTAINER_OF(psWork, struct bwq, sWork);
spin_lock_irqsave(&check_lock, flags);
hlist_add_head(&(vbwq->hlist), &bwq_list);
spin_unlock_irqrestore(&check_lock, flags);
qos_notifier_call_chain(bound.state, &bound);
}
static void _pob_qos_tracker(u64 wallclock, s64 diff)
{
int i;
int isfull = 0;
int vIdx;
int vLastIdx;
u64 vDiff;
int bi;
vLastIdx = sspm_lastidx;
if (vLastIdx == -1) {
vLastIdx = qos_sram_read(QOS_TOTAL_BW_BUF_LAST);
if (vLastIdx >= QOS_TOTAL_BW_BUF_SIZE || vLastIdx < 0)
goto final;
sspm_lastidx = vLastIdx;
}
vDiff = div_u64(((u64) diff), NSEC_PER_MSEC);
if (vDiff > QOS_TOTAL_BW_BUF_SIZE - 2)
vDiff = QOS_TOTAL_BW_BUF_SIZE - 2;
vIdx = qos_sram_read(QOS_TOTAL_BW_BUF_LAST);
if (vIdx >= QOS_TOTAL_BW_BUF_SIZE || vIdx < 0)
goto final;
if (vDiff == QOS_TOTAL_BW_BUF_SIZE - 2)
vLastIdx = (vIdx + 3) % QOS_TOTAL_BW_BUF_SIZE;
else
vLastIdx = (vLastIdx + 1) % QOS_TOTAL_BW_BUF_SIZE;
if (vLastIdx > vIdx) {
for (i = 0; vLastIdx + i < QOS_TOTAL_BW_BUF_SIZE; i++) {
bi = bound_idx % QOS_BOUND_BUF_SIZE;
if (_pob_qos_tracker_set_stat(&(bound.stats[bi]),
vLastIdx + i, wallclock))
isfull = 1;
bound.idx = bi;
bound_idx++;
}
vLastIdx = 0;
}
for (i = 0; vLastIdx + i <= vIdx; i++) {
bi = bound_idx % QOS_BOUND_BUF_SIZE;
if (_pob_qos_tracker_set_stat(&(bound.stats[bi]),
vLastIdx + i, wallclock))
isfull = 1;
bound.idx = bi;
bound_idx++;
}
sspm_lastidx = vIdx;
if (isfull) {
unsigned long flags;
struct bwq *vbwq = NULL;
struct bwq *iter;
struct hlist_node *tmp;
bound.state = QOS_BOUND_BW_FULL;
spin_lock_irqsave(&check_lock, flags);
hlist_for_each_entry_safe(iter, tmp, &bwq_list, hlist) {
hlist_del(&iter->hlist);
vbwq = iter;
}
spin_unlock_irqrestore(&check_lock, flags);
if (vbwq) {
INIT_WORK(&vbwq->sWork, mtk_qb_wq_cb);
queue_work(_gpBWQNtfWQ, &vbwq->sWork);
}
}
final:
return;
}
void pob_qos_tracker(u64 wallclock)
{
s64 diff;
diff = do_check(wallclock);
#ifdef _MTK_OBPFMQOS_DEBUG_
pob_wall_tracelog(wallclock, diff);
#endif
if (!inited || !diff)
return;
_pob_qos_tracker(wallclock, diff);
}
struct qos_bound *get_qos_bound(void)
{
return &bound;
}
unsigned short get_qos_bound_idx(void)
{
return bound.idx;
}
int get_qos_bound_bw_threshold(int state)
{
int val = dram_steps_freq(0) * 4;
if (state == QOS_BOUND_BW_FULL)
return val * QOS_BOUND_BW_FULL_PCT / 100;
else if (state == QOS_BOUND_BW_CONGESTIVE)
return val * QOS_BOUND_BW_CONGESTIVE_PCT / 100;
return 0;
}
int register_qos_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&qos_bound_chain_head, nb);
}
int unregister_qos_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&qos_bound_chain_head, nb);
}
int qos_notifier_call_chain(unsigned long val, void *v)
{
int ret = NOTIFY_DONE;
ret = blocking_notifier_call_chain(&qos_bound_chain_head, val, v);
return notifier_to_errno(ret);
}
void qos_bound_init(void)
{
struct bwq *vbwq[3];
int i;
unsigned long flags;
_gpBWQNtfWQ = create_singlethread_workqueue("bwq_ntf_wq");
if (_gpBWQNtfWQ == NULL)
return;
for (i = 0; i < 3; i++)
vbwq[i] = pob_alloc_atomic(sizeof(struct bwq));
spin_lock_irqsave(&check_lock, flags);
for (i = 0; i < 3; i++)
hlist_add_head(&(vbwq[i]->hlist), &bwq_list);
spin_unlock_irqrestore(&check_lock, flags);
inited = 1;
}
@@ -0,0 +1,83 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MTK_QOS_BOUND_H__
#define __MTK_QOS_BOUND_H__
#define QOS_BOUND_BUF_SIZE 64
#define QOS_BOUND_BW_FREE 0x1
#define QOS_BOUND_BW_CONGESTIVE 0x2
#define QOS_BOUND_BW_FULL 0x4
#define QOS_BOUND_BW_CONGESTIVE_PCT 70
#define QOS_BOUND_BW_FULL_PCT 95
enum qos_emibm_type {
QOS_EMIBM_TOTAL,
QOS_EMIBM_CPU,
QOS_EMIBM_GPU,
QOS_EMIBM_MM,
QOS_EMIBM_MD,
NR_QOS_EMIBM_TYPE
};
enum qos_smibm_type {
QOS_SMIBM_VENC,
QOS_SMIBM_CAM,
QOS_SMIBM_IMG,
QOS_SMIBM_MDP,
QOS_SMIBM_GPU,
QOS_SMIBM_APU,
QOS_SMIBM_VPU0,
QOS_SMIBM_VPU1,
QOS_SMIBM_MDLA,
NR_QOS_SMIBM_TYPE
};
enum qos_lat_type {
QOS_LAT_CPU,
QOS_LAT_VPU0,
QOS_LAT_VPU1,
QOS_LAT_MDLA,
NR_QOS_LAT_TYPE
};
struct qos_bound_stat {
unsigned short num;
unsigned short event;
u64 wallclock;
unsigned short emibw_mon[NR_QOS_EMIBM_TYPE];
unsigned short emibw_req[NR_QOS_EMIBM_TYPE];
unsigned short smibw_mon[NR_QOS_SMIBM_TYPE];
unsigned short smibw_req[NR_QOS_SMIBM_TYPE];
unsigned short lat_mon[NR_QOS_LAT_TYPE];
};
struct qos_bound {
unsigned short idx;
unsigned short state;
struct qos_bound_stat stats[QOS_BOUND_BUF_SIZE];
};
extern void qos_bound_init(void);
extern struct qos_bound *get_qos_bound(void);
extern int get_qos_bound_bw_threshold(int state);
extern unsigned short get_qos_bound_idx(void);
extern int register_qos_notifier(struct notifier_block *nb);
extern int unregister_qos_notifier(struct notifier_block *nb);
extern int qos_notifier_call_chain(unsigned long val, void *v);
extern int is_qos_bound_enabled(void);
extern void qos_bound_enable(int enable);
extern int is_qos_bound_stress_enabled(void);
extern void qos_bound_stress_enable(int enable);
extern int is_qos_bound_log_enabled(void);
extern void qos_bound_log_enable(int enable);
extern unsigned int get_qos_bound_count(void);
extern unsigned int *get_qos_bound_buf(void);
#endif
@@ -0,0 +1,565 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_qos: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
#include <linux/ktime.h>
#include <linux/hrtimer.h>
#include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/rbtree.h>
#include <linux/preempt.h>
#include <linux/proc_fs.h>
#include <linux/trace_events.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#include "obpfm_qos_bound.h"
#define MS_TO_NS 1000000
#define ADJUST_INTERVAL_MS 32
enum POBQOS_NTF_PUSH_TYPE {
POBQOS_NTF_TIMER = 0x00,
};
struct POBQOS_NTF_PUSH_TAG {
enum POBQOS_NTF_PUSH_TYPE ePushType;
int value;
struct work_struct sWork;
};
static void pob_enable_timer(void);
static void pob_disable_timer(void);
static atomic64_t last_time_ms;
static atomic_t last_idx;
static int pob_pfm_qos_cb(struct notifier_block *nb,
unsigned long val, void *data);
static struct notifier_block pob_pfm_qos_notifier = {
.notifier_call = pob_pfm_qos_cb,
};
static void pob_qos_set_last_time_ms(int setinvalid)
{
int vIdx;
ktime_t cur_time;
long long cur_time_ms;
struct qos_bound *pqosbound = get_qos_bound();
if (setinvalid) {
atomic64_set(&last_time_ms, -1);
atomic_set(&last_idx, -1);
return;
}
/*get current time*/
cur_time = ktime_get();
cur_time_ms = ktime_to_ms(cur_time);
atomic64_set(&last_time_ms, cur_time_ms);
if (pqosbound) {
do {
vIdx = pqosbound->idx;
} while (vIdx >= QOS_BOUND_BUF_SIZE || vIdx < 0);
atomic_set(&last_idx, vIdx);
}
}
struct qos_bound_stat *_gstats[QOS_BOUND_BUF_SIZE];
static struct workqueue_struct *_gpPOBQoSNtfWQ;
static struct hrtimer _pobqos_hrt;
static void pob_enable_timer(void)
{
ktime_t ktime;
ktime = ktime_set(0, ADJUST_INTERVAL_MS * MS_TO_NS);
hrtimer_start(&_pobqos_hrt, ktime, HRTIMER_MODE_REL);
}
static void pob_disable_timer(void)
{
hrtimer_cancel(&_pobqos_hrt);
}
static void pobqos_hrt_wq_cb(struct work_struct *psWork)
{
struct POBQOS_NTF_PUSH_TAG *vpPush =
POB_CONTAINER_OF(psWork,
struct POBQOS_NTF_PUSH_TAG, sWork);
struct qos_bound *pqosbound = get_qos_bound();
struct pob_qos_info pqi;
int vIdx;
int vLastIdx;
int vTmp = 0;
int i = 0;
int size = 0;
ktime_t cur_time;
long long cur_ms;
long long diff_ms;
long long last_ms;
if (unlikely(!psWork))
return;
/*get current time*/
cur_time = ktime_get();
cur_ms = ktime_to_ms(cur_time);
last_ms = atomic64_read(&last_time_ms);
vLastIdx = atomic_read(&last_idx);
if (last_ms == -1 || last_ms >= cur_ms || !pqosbound)
goto final;
if (vLastIdx == -1) {
do {
vLastIdx = pqosbound->idx;
} while (vLastIdx >= QOS_BOUND_BUF_SIZE ||
vLastIdx < 0);
atomic_set(&last_idx, vLastIdx);
goto final;
}
diff_ms = cur_ms - last_ms;
if (diff_ms < 2)
goto final;
else if (diff_ms > QOS_BOUND_BUF_SIZE - 2)
diff_ms = QOS_BOUND_BUF_SIZE - 2;
do {
vIdx = pqosbound->idx;
} while (vIdx >= QOS_BOUND_BUF_SIZE);
if (diff_ms == QOS_BOUND_BUF_SIZE - 2)
vLastIdx = (vIdx + 3) % QOS_BOUND_BUF_SIZE;
if (vLastIdx > vIdx) {
for (i = 0; vLastIdx + i < QOS_BOUND_BUF_SIZE; i++) {
_gstats[i] = &pqosbound->stats[vLastIdx + i];
size++;
}
vLastIdx = 0;
}
for (vTmp = size, i = 0; vLastIdx + i < vIdx; i++) {
_gstats[vTmp + i] = &pqosbound->stats[vLastIdx + i];
size++;
}
atomic64_set(&last_time_ms, cur_ms);
atomic_set(&last_idx, vIdx);
if (size) {
pqi.size = size;
pqi.pstats = &_gstats;
pob_qos_tracelog(POB_QOS_EMI_ALL, &pqi);
pob_qos_monitor_update(POB_QOS_EMI_ALL, &pqi);
}
final:
pob_trace("%s size=%d", __func__, size);
pob_free(vpPush);
}
static enum hrtimer_restart pobqos_hrt_cb(struct hrtimer *timer)
{
struct POBQOS_NTF_PUSH_TAG *vpPush = NULL;
ktime_t ktime;
ktime = ktime_set(0, ADJUST_INTERVAL_MS * MS_TO_NS);
hrtimer_add_expires(timer, ktime);
if (_gpPOBQoSNtfWQ)
vpPush =
(struct POBQOS_NTF_PUSH_TAG *)
pob_alloc_atomic(sizeof(struct POBQOS_NTF_PUSH_TAG));
if (vpPush) {
INIT_WORK(&vpPush->sWork, pobqos_hrt_wq_cb);
queue_work(_gpPOBQoSNtfWQ, &vpPush->sWork);
}
return HRTIMER_RESTART;
}
static int pob_pfm_qos_cb(struct notifier_block *nb,
unsigned long val, void *data)
{
struct qos_bound *bound = (struct qos_bound *) data;
struct qos_bound_stat *pstats[ADJUST_INTERVAL_MS];
switch (val) {
case QOS_BOUND_BW_FULL:
case QOS_BOUND_BW_CONGESTIVE:
case QOS_BOUND_BW_FREE:
if (!pob_qos_ind_client_isemtpy() && bound) {
struct pob_qos_info pqi;
int vLastIdx;
int vTmp = 0;
int i;
int ind_info;
do {
vLastIdx = bound->idx;
} while (vLastIdx >= QOS_BOUND_BUF_SIZE);
vTmp = ADJUST_INTERVAL_MS;
do {
i = vLastIdx + QOS_BOUND_BUF_SIZE + 1;
i -= vTmp;
i %= QOS_BOUND_BUF_SIZE;
pstats[ADJUST_INTERVAL_MS - vTmp] =
&bound->stats[i];
vTmp--;
} while (vTmp > 0);
pqi.size = ADJUST_INTERVAL_MS;
pqi.pstats = &pstats;
ind_info = POB_QOS_IND_BWBOUND_CONGESTIVE;
if (val == QOS_BOUND_BW_FREE)
ind_info = POB_QOS_IND_BWBOUND_FREE;
else if (val == QOS_BOUND_BW_FULL)
ind_info = POB_QOS_IND_BWBOUND_FULL;
pob_qos_ind_monitor_update(ind_info, &pqi);
}
break;
default:
break;
}
return NOTIFY_OK;
}
int __init pob_qos_pfm_init(void)
{
_gpPOBQoSNtfWQ = create_singlethread_workqueue("pobqos_ntf_wq");
if (_gpPOBQoSNtfWQ == NULL)
return -EFAULT;
hrtimer_init(&_pobqos_hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
_pobqos_hrt.function = pobqos_hrt_cb;
register_qos_notifier(&pob_pfm_qos_notifier);
qos_bound_init();
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
unregister_qos_notifier(&pob_pfm_qos_notifier);
}
int pob_qos_pfm_enable(void)
{
pob_qos_set_last_time_ms(0);
pob_enable_timer();
return 0;
}
int pob_qos_pfm_disable(void)
{
pob_disable_timer();
pob_qos_set_last_time_ms(1);
return 0;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
if (!super || !sub)
return -1;
*super = 0;
*sub = 0;
switch (pqbt) {
case PQBT_BOUND:
case PQBT_TOTAL:
if (pqbp == PQBP_EMI &&
pqbs == PQBS_MON)
*super = 1;
break;
#if 0
case PQBT_CPU:
case PQBT_MM:
/* case PQBT_MD: */
if (pqbp == PQBP_EMI &&
pqbs == PQBS_MON)
*super = 1;
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI &&
pqbs == PQBS_MON)
*super = 1;
break;
#endif
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
int pob_qosbm_get_stat(void *pstats,
int idx,
enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int issub,
int ssidx)
{
int super = 0, sub = 0;
int vRet = -1;
struct qos_bound_stat **bound =
(struct qos_bound_stat **) pstats;
if (!bound || !bound[idx])
return -1;
vRet = pob_qosbm_get_cap(pqbt, pqbp, pqbs, &super, &sub);
if (vRet)
return -1;
else if (issub && ssidx >= sub)
return -1;
else if (!issub && ssidx >= super)
return -1;
switch (pqbt) {
case PQBT_BOUND:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON) {
vRet = PQB_BW_CONGESTIVE;
if (bound[idx]->event == QOS_BOUND_BW_FREE)
vRet = PQB_BW_FREE;
else if (bound[idx]->event == QOS_BOUND_BW_FULL)
vRet = PQB_BW_FULL;
}
break;
case PQBT_TOTAL:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_TOTAL];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_TOTAL];
break;
#if 0
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
}
break;
case PQBT_MD:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MD];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_MD];
}
break;
#endif
default:
return -1;
}
return vRet;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
if (!super || !sub)
return -1;
*super = 0;
*sub = 0;
return -1;
}
int pob_qoslat_get_stat(void *pstats,
int idx,
enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int issub,
int ssidx)
{
int super = 0, sub = 0;
int vRet = -1;
int tg;
struct qos_bound_stat **bound =
(struct qos_bound_stat **) pstats;
if (!bound || !bound[idx])
return -1;
vRet = pob_qoslat_get_cap(pqlt, pqls, &super, &sub);
if (vRet)
return -1;
else if (issub && ssidx >= sub)
return -1;
else if (!issub && ssidx >= super)
return -1;
switch (pqlt) {
case PQLT_CPU:
if (pqls == PQLS_MON)
vRet = bound[idx]->lat_mon[QOS_LAT_CPU];
break;
case PQLT_VPU:
if (ssidx == 1)
tg = QOS_LAT_VPU1;
else
tg = QOS_LAT_VPU0;
if (pqls == PQLS_MON)
vRet = bound[idx]->lat_mon[tg];
break;
case PQLT_MDLA:
if (pqls == PQLS_MON)
vRet = bound[idx]->lat_mon[QOS_LAT_MDLA];
break;
default:
return -1;
}
return vRet;
}
int pob_qosseq_get(void *pstats, int idx)
{
struct qos_bound_stat **bound =
(struct qos_bound_stat **) pstats;
if (bound && bound[idx])
return bound[idx]->num;
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return get_qos_bound_bw_threshold(QOS_BOUND_BW_FULL);
}
int pob_qosbm_get_last_avg(int lastcount,
enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int issub,
int ssidx)
{
int vRet;
int super = 0, sub = 0;
struct qos_bound *bound = get_qos_bound();
int vLastIdx;
int vTmp = 0;
int vTotal = 0;
int i = 0;
vRet = pob_qosbm_get_cap(pqbt, pqbp, pqbs, &super, &sub);
if (vRet)
return -1;
else if (issub && ssidx >= sub)
return -1;
else if (!issub && ssidx >= super)
return -1;
if (!bound)
return 0;
do {
vLastIdx = bound->idx;
} while (vLastIdx >= QOS_BOUND_BUF_SIZE ||
vLastIdx < 0);
if (lastcount >= QOS_BOUND_BUF_SIZE)
lastcount = QOS_BOUND_BUF_SIZE - 1;
else if (lastcount <= 0)
lastcount = QOS_BOUND_BUF_SIZE >> 1;
vTmp = lastcount;
vRet = -1;
switch (pqbt) {
case PQBT_TOTAL:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON) {
do {
i = vLastIdx + QOS_BOUND_BUF_SIZE + 1;
i -= vTmp;
i %= QOS_BOUND_BUF_SIZE;
vTotal +=
bound->stats[i].emibw_mon[QOS_EMIBM_TOTAL];
vTmp--;
} while (vTmp > 0);
vRet = vTotal / lastcount;
}
break;
default:
break;
}
return vRet;
}