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,26 @@
#
# Copyright (C) 2019 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
obj-y += pob_main.o
obj-y += fpsgo_notify.o
obj-y += qos_notify.o
obj-y += nn_notify.o
obj-y += xpu_notify.o
obj-y += eara_thrm_notify.o
ifeq ($(CONFIG_MACH_MT6781),y)
obj-y += platform/mt6781/
else
obj-y += platform/$(MTK_PLATFORM)/
endif
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_eara_thrm_notifier: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
static BLOCKING_NOTIFIER_HEAD(pob_eara_thrm_notifier_list);
int pob_eara_thrm_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(
&pob_eara_thrm_notifier_list, nb);
}
int pob_eara_thrm_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(
&pob_eara_thrm_notifier_list, nb);
}
int pob_eara_thrm_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(
&pob_eara_thrm_notifier_list, val, v);
}
int pob_eara_thrm_stats_update(enum pob_eara_thrm_info_num infonum)
{
pob_eara_thrm_notifier_call_chain(infonum, NULL);
return 0;
}
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_fpsgo_notifier: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
static BLOCKING_NOTIFIER_HEAD(pob_fpsgo_notifier_list);
int pob_fpsgo_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pob_fpsgo_notifier_list, nb);
}
int pob_fpsgo_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pob_fpsgo_notifier_list, nb);
}
int pob_fpsgo_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&pob_fpsgo_notifier_list, val, v);
}
int pob_fpsgo_fstb_stats_update(unsigned long infonum,
struct pob_fpsgo_fpsstats_info *info)
{
pob_fpsgo_notifier_call_chain(infonum, info);
return 0;
}
int pob_fpsgo_qtsk_update(unsigned long infonum,
struct pob_fpsgo_qtsk_info *info)
{
pob_fpsgo_notifier_call_chain(infonum, info);
return 0;
}
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_nn: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
static BLOCKING_NOTIFIER_HEAD(pob_nn_notifier_list);
int pob_nn_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pob_nn_notifier_list, nb);
}
int pob_nn_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pob_nn_notifier_list, nb);
}
int pob_nn_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&pob_nn_notifier_list, val, v);
}
int pob_nn_update(enum pob_nn_info_num info_num, void *v)
{
pob_nn_notifier_call_chain(info_num, v);
return 0;
}
@@ -0,0 +1,17 @@
#
# Copyright (C) 2019 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
ifeq ($(CONFIG_MACH_MT6781),y)
obj-y += mt6781/
else
obj-y += $(MTK_PLATFORM)/
endif
@@ -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;
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6781/
obj-y += qos_pfm.o
@@ -0,0 +1,754 @@
// 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/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_MDLA:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDLA];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDLA];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6785/
obj-y += qos_pfm.o
@@ -0,0 +1,754 @@
/* 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"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_MDLA:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDLA];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDLA];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6833/
obj-y += qos_pfm.o
@@ -0,0 +1,742 @@
/* 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"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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;
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6853/
obj-y += qos_pfm.o
@@ -0,0 +1,748 @@
// 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/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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;
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;
#if BITS_PER_LONG == 64
do_div(vRet, lastcount);
#elif BITS_PER_LONG == 32
vRet /= lastcount;
#else
#error "unsigned long division is not supported for this architecture"
#endif
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6873/
obj-y += qos_pfm.o
@@ -0,0 +1,754 @@
// 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/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_MDLA:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDLA0];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDLA0];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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_MDLA0];
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6885/
obj-y += qos_pfm.o
@@ -0,0 +1,769 @@
// 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/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 2)
tg = QOS_SMIBM_VPU2;
else if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_MDLA:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_MDLA1;
else
tg = QOS_SMIBM_MDLA0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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 == 2)
tg = QOS_LAT_VPU2;
else 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 (ssidx == 1)
tg = QOS_LAT_MDLA1;
else
tg = QOS_LAT_MDLA0;
if (pqls == PQLS_MON)
vRet = bound[idx]->lat_mon[tg];
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,9 @@
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ccflags-y += -I$(MTK_TOP)/performance/observer
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/qos/mt6885/
obj-y += qos_pfm.o
@@ -0,0 +1,769 @@
// 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/ktime.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#ifdef CONFIG_MTK_QOS_FRAMEWORK
#include "mtk_qos_bound.h"
#endif
#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;
};
#ifdef CONFIG_MTK_QOS_FRAMEWORK
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);
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;
case PQBT_CPU:
case PQBT_MM:
case PQBT_MD:
if (pqbp == PQBP_EMI &&
(pqbs == PQBS_MON ||
pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_GPU:
if ((pqbp == PQBP_EMI || pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_APU:
case PQBT_MDLA:
case PQBT_VENC:
case PQBT_CAM:
case PQBT_IMG:
case PQBT_MDP:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*super = 1;
break;
case PQBT_VPU:
if ((pqbp == PQBP_SMI) &&
(pqbs == PQBS_MON || pqbs == PQBS_REQ))
*sub = 2;
break;
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;
case PQBT_CPU:
if (pqbp == PQBP_EMI && pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_CPU];
else if (pqbp == PQBP_EMI && pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_CPU];
break;
case PQBT_GPU:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[QOS_EMIBM_GPU];
} else if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_GPU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_GPU];
}
break;
case PQBT_MM:
if (pqbp == PQBP_EMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->emibw_mon[QOS_EMIBM_MM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->emibw_req[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;
case PQBT_APU:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_APU];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_APU];
}
break;
case PQBT_VPU:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 2)
tg = QOS_SMIBM_VPU2;
else if (ssidx == 1)
tg = QOS_SMIBM_VPU1;
else
tg = QOS_SMIBM_VPU0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_MDLA:
if (pqbp == PQBP_SMI) {
int tg;
if (ssidx == 1)
tg = QOS_SMIBM_MDLA1;
else
tg = QOS_SMIBM_MDLA0;
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[tg];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[tg];
}
break;
case PQBT_VENC:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_VENC];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_VENC];
}
break;
case PQBT_CAM:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_CAM];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_CAM];
}
break;
case PQBT_IMG:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_IMG];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_IMG];
}
break;
case PQBT_MDP:
if (pqbp == PQBP_SMI) {
if (pqbs == PQBS_MON)
vRet = bound[idx]->smibw_mon[QOS_SMIBM_MDP];
else if (pqbs == PQBS_REQ)
vRet = bound[idx]->smibw_req[QOS_SMIBM_MDP];
}
break;
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;
switch (pqlt) {
case PQLT_CPU:
case PQLT_MDLA:
if (pqls == PQLS_MON)
*super = 1;
break;
case PQLT_VPU:
if (pqls == PQLS_MON)
*sub = 2;
break;
default:
return -1;
}
if (*super == 0 && *sub == 0)
return -1;
return 0;
}
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 == 2)
tg = QOS_LAT_VPU2;
else 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 (ssidx == 1)
tg = QOS_LAT_MDLA1;
else
tg = QOS_LAT_MDLA0;
if (pqls == PQLS_MON)
vRet = bound[idx]->lat_mon[tg];
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;
do_div(vRet, lastcount);
}
break;
default:
break;
}
return vRet;
}
#else
int pob_qos_pfm_enable(void)
{
return 0;
}
int pob_qos_pfm_disable(void)
{
return 0;
}
int pob_qosseq_get(void *pstats, int idx)
{
return -1;
}
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{
return -1;
}
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)
{
return -1;
}
int pob_qos_get_max_bw_threshold(void)
{
return -1;
}
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)
{
return -1;
}
int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{
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)
{
return -1;
}
int __init pob_qos_pfm_init(void)
{
return 0;
}
void __exit pob_qos_pfm_exit(void)
{
}
#endif
void pob_qos_tracker(u64 wallclock)
{
}
@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef POB_INT_H
#define POB_INT_H
#include <linux/kobject.h>
#define POB_CONTAINER_OF(ptr, type, member) \
((type *)(((char *)ptr) - offsetof(type, member)))
void *pob_alloc_atomic(int i32Size);
void pob_free(void *pvBuf);
void pob_trace(const char *fmt, ...);
/* sysfs */
#define POB_SYSFS_MAX_BUFF_SIZE 1024
#define KOBJ_ATTR_RW(_name) \
struct kobj_attribute kobj_attr_##_name = \
__ATTR(_name, 0660, \
_name##_show, _name##_store)
void pob_sysfs_create_file(struct kobject *parent,
struct kobj_attribute *kobj_attr);
void pob_sysfs_remove_file(struct kobject *parent,
struct kobj_attribute *kobj_attr);
/* QoS */
int pob_qos_init(struct kobject *pob_kobj);
void pob_qos_exit(struct kobject *pob_kobj);
int pob_qos_ind_client_isemtpy(void);
void pob_qos_tracelog(unsigned long val, void *data);
#endif
@@ -0,0 +1,118 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#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/trace_events.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <asm/page.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/mm.h>
#define CREATE_TRACE_POINTS
#include <trace/events/pob.h>
#include "pob_int.h"
#define TRACELOG_SIZE 512
struct kobject *pob_kobj;
void *pob_alloc_atomic(int i32Size)
{
void *pvBuf;
if (i32Size <= PAGE_SIZE)
pvBuf = kmalloc(i32Size, GFP_ATOMIC);
else
pvBuf = vmalloc(i32Size);
return pvBuf;
}
void pob_free(void *pvBuf)
{
kvfree(pvBuf);
}
void pob_trace(const char *fmt, ...)
{
char log[TRACELOG_SIZE];
va_list args;
int len;
va_start(args, fmt);
len = vsnprintf(log, sizeof(log), fmt, args);
va_end(args);
if (len == TRACELOG_SIZE)
log[TRACELOG_SIZE - 1] = '\0';
preempt_disable();
trace_pob_log(log);
preempt_enable();
}
void pob_sysfs_create_file(struct kobject *parent,
struct kobj_attribute *kobj_attr)
{
int ret;
if (kobj_attr == NULL || pob_kobj == NULL)
return;
ret = sysfs_create_file(pob_kobj, &(kobj_attr->attr));
if (ret)
pr_debug("Failed to create sysfs file\n");
}
void pob_sysfs_remove_file(struct kobject *parent,
struct kobj_attribute *kobj_attr)
{
if (kobj_attr == NULL || pob_kobj == NULL)
return;
sysfs_remove_file(pob_kobj, &(kobj_attr->attr));
}
static int __init pob_init(void)
{
if (kernel_kobj == NULL)
return -1;
pob_kobj = kobject_create_and_add("pob", kernel_kobj);
if (pob_kobj == NULL)
return -1;
pob_qos_init(pob_kobj);
return 0;
}
static void __exit pob_exit(void)
{
pob_qos_exit(pob_kobj);
if (pob_kobj == NULL)
return;
kobject_put(pob_kobj);
pob_kobj = NULL;
}
module_init(pob_init);
module_exit(pob_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MediaTek Performance Observer");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef POB_PFM_H
#define POB_PFM_H
int pob_qos_pfm_init(void);
void pob_qos_pfm_exit(void);
int pob_qos_pfm_enable(void);
int pob_qos_pfm_disable(void);
#endif
@@ -0,0 +1,149 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __POB_QOS_H__
#define __POB_QOS_H__
enum pob_qosbm_type {
PQBT_BOUND = 0,
PQBT_TOTAL,
PQBT_CPU,
PQBT_GPU,
PQBT_MM,
PQBT_MD,
PQBT_APU,
PQBT_VPU,
PQBT_MDLA,
PQBT_VENC,
PQBT_CAM,
PQBT_IMG,
PQBT_MDP,
NR_PQBT
};
enum pob_qosbm_probe {
PQBP_EMI = 0,
PQBP_SMI,
NR_PQBP
};
enum pob_qosbm_source {
PQBS_MON = 0,
PQBS_REQ,
NR_PQBS
};
enum pob_qosbm_bound {
PQB_BW_FREE = 0,
PQB_BW_CONGESTIVE = 1,
PQB_BW_FULL = 2,
};
enum pob_qoslat_type {
PQLT_CPU,
PQLT_VPU,
PQLT_MDLA,
NR_PQLT
};
enum pob_qoslat_source {
PQLS_MON,
NR_PQLS
};
#if defined(CONFIG_MTK_PERF_OBSERVER)
int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub);
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 pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub);
int pob_qoslat_get_stat(void *pstats,
int idx,
enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int issub,
int ssidx);
int pob_qosseq_get(void *pstats, int idx);
int pob_qos_get_max_bw_threshold(void);
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);
#else
static inline int pob_qosbm_get_cap(enum pob_qosbm_type pqbt,
enum pob_qosbm_probe pqbp,
enum pob_qosbm_source pqbs,
int *super,
int *sub)
{ return -1; }
static inline 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)
{ return -1; }
static inline int pob_qoslat_get_cap(enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int *super,
int *sub)
{ return -1; }
static inline int pob_qoslat_get_stat(void *pstats,
int idx,
enum pob_qoslat_type pqlt,
enum pob_qoslat_source pqls,
int issub,
int ssidx)
{ return -1; }
static inline int pob_qosseq_get(void *pstats, int idx)
{ return -1; }
static inline int pob_qos_get_max_bw_threshold(void)
{ return -1; }
static inline 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)
{ return -1; }
#endif
#endif
@@ -0,0 +1,624 @@
// 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/trace_events.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/ktime.h>
#include <trace/events/pob.h>
#include "pob_int.h"
#include "pob_qos.h"
#include "pob_pfm.h"
#define TRACELOG_SIZE 512
struct pob_qos_trace_info {
uint32_t flag;
int typemap;
char *prefix;
void (*pHdlfun)(struct pob_qos_trace_info *pqti,
struct pob_qos_info *pqi);
};
static BLOCKING_NOTIFIER_HEAD(pob_qos_notifier_list);
static BLOCKING_NOTIFIER_HEAD(pob_qos_ind_notifier_list);
static DEFINE_MUTEX(pob_qos_ntf_mutex);
static int pob_qos_ntf_cnt;
static inline void _trace_pob_log(char *log)
{
preempt_disable();
trace_pob_log(log);
preempt_enable();
}
static void pob_fn_tracelog(void *pfn, char *prefix)
{
char log[TRACELOG_SIZE];
int tmplen;
tmplen = snprintf(log, TRACELOG_SIZE, "%s %pS",
prefix, pfn);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
_trace_pob_log(log);
}
static int __pob_dump_ntf_callchain(struct notifier_block **nl, char *prefix)
{
int ret = NOTIFY_DONE;
struct notifier_block *nb, *next_nb;
nb = rcu_dereference_raw(*nl);
while (nb) {
next_nb = rcu_dereference_raw(nb->next);
pob_fn_tracelog(nb->notifier_call, prefix);
nb = next_nb;
}
return ret;
}
static int pob_dump_ntf_callchain(struct blocking_notifier_head *nh,
char *prefix)
{
int ret = NOTIFY_DONE;
/*
* We check the head outside the lock, but if this access is
* racy then it does not matter what the result of the test
* is, we re-check the list after having taken the lock anyway:
*/
if (rcu_access_pointer(nh->head)) {
down_read(&nh->rwsem);
ret = __pob_dump_ntf_callchain(&nh->head, prefix);
up_read(&nh->rwsem);
}
return ret;
}
int pob_qos_register_client(struct notifier_block *nb)
{
mutex_lock(&pob_qos_ntf_mutex);
if (!pob_qos_ntf_cnt)
pob_qos_pfm_enable();
pob_qos_ntf_cnt++;
mutex_unlock(&pob_qos_ntf_mutex);
pob_fn_tracelog(nb->notifier_call, "pob_qos register_client");
pob_dump_ntf_callchain(&pob_qos_notifier_list,
"pob_qos register_client before");
return blocking_notifier_chain_register(&pob_qos_notifier_list, nb);
}
int pob_qos_unregister_client(struct notifier_block *nb)
{
mutex_lock(&pob_qos_ntf_mutex);
if (pob_qos_ntf_cnt)
pob_qos_ntf_cnt--;
if (!pob_qos_ntf_cnt)
pob_qos_pfm_disable();
mutex_unlock(&pob_qos_ntf_mutex);
pob_fn_tracelog(nb->notifier_call, "pob_qos unregister_client");
pob_dump_ntf_callchain(&pob_qos_notifier_list,
"pob_qos unregister_client before");
return blocking_notifier_chain_unregister(&pob_qos_notifier_list, nb);
}
int pob_qos_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&pob_qos_notifier_list, val, v);
}
int pob_qos_monitor_update(enum pob_qos_info_num info_num, void *v)
{
pob_qos_notifier_call_chain(info_num, v);
return 0;
}
int pob_qos_ind_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pob_qos_ind_notifier_list,
nb);
}
int pob_qos_ind_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pob_qos_ind_notifier_list,
nb);
}
int pob_qos_ind_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&pob_qos_ind_notifier_list,
val, v);
}
int pob_qos_ind_monitor_update(enum pob_qos_ind_info_num info_num, void *v)
{
pob_qos_ind_notifier_call_chain(info_num, v);
return 0;
}
int pob_qos_ind_client_isemtpy(void)
{
if (pob_qos_ind_notifier_list.head)
return 0;
return 1;
}
enum {
POB_QOS_DEBUG_QOSSEQ = 1U << 0,
POB_QOS_DEBUG_BWBOUND = 1U << 1,
POB_QOS_DEBUG_BWTOTAL = 1U << 2,
POB_QOS_DEBUG_BWCPU = 1U << 3,
POB_QOS_DEBUG_BWGPU = 1U << 4,
POB_QOS_DEBUG_BWMM = 1U << 5,
POB_QOS_DEBUG_BWMD = 1U << 6,
POB_QOS_DEBUG_BWAPU = 1U << 7,
POB_QOS_DEBUG_BWVPU = 1U << 8,
POB_QOS_DEBUG_BWMDLA = 1U << 9,
POB_QOS_DEBUG_BWCAM = 1U << 10,
POB_QOS_DEBUG_BWVENC = 1U << 11,
POB_QOS_DEBUG_BWIMG = 1U << 12,
POB_QOS_DEBUG_BWMDP = 1U << 13,
POB_QOS_DEBUG_LATCPU = 1U << 14,
POB_QOS_DEBUG_LATVPU = 1U << 15,
POB_QOS_DEBUG_LATMDLA = 1U << 16,
POB_QOS_DEBUG_MAX = 1U << 17,
};
static const char * const mask_string[] = {
"QOSSEQ",
"BWBOUND",
"BWTOTAL",
"BWCPU",
"BWGPU",
"BWMM",
"BWMD",
"BWAPU",
"BWVPU",
"BWMDLA",
"BWCAM",
"BWVENC",
"BWIMG",
"BWMDP",
"LATCPU",
"LATVPU",
"LATMDLA",
"MAX",
};
static const char * const PQBP_str[] = {
"EMI",
"SMI"
};
static const char * const PQBS_str[] = {
"MON",
"REQ"
};
static const char * const PQLS_str[] = {
"MON",
};
static void _pob_qos_seq_log(struct pob_qos_trace_info *pqti,
struct pob_qos_info *pqi)
{
int i;
char log[TRACELOG_SIZE];
char valuelog[8];
int tmplen;
int sublen;
tmplen = snprintf(log, TRACELOG_SIZE, "%s size=%d,",
pqti->prefix, pqi->size);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
for (i = 0; i < pqi->size; i++) {
sublen = snprintf(valuelog, 8, " %d",
pob_qosseq_get(pqi->pstats, i));
if (sublen >= 8)
break;
if (tmplen + sublen >= TRACELOG_SIZE - 1)
break;
strncpy(log + tmplen, valuelog,
TRACELOG_SIZE - 1 - tmplen);
tmplen += sublen;
}
_trace_pob_log(log);
}
static void _pob_qos_bm_log(struct pob_qos_trace_info *pqti,
struct pob_qos_info *pqi)
{
int i, j, k;
int x;
int super, sub;
char log[TRACELOG_SIZE];
char valuelog[8];
int tmplen;
int vRet;
int sublen;
for (i = 0; i < NR_PQBP; i++) {
for (j = 0; j < NR_PQBS; j++) {
vRet = pob_qosbm_get_cap(pqti->typemap, i, j,
&super, &sub);
if (vRet)
continue;
if (super) {
tmplen = snprintf(log, TRACELOG_SIZE,
"%s probe=%s, source=%s, size=%d,",
pqti->prefix,
PQBP_str[i], PQBS_str[j], pqi->size);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
for (k = 0; k < pqi->size; k++) {
sublen = snprintf(valuelog, 8, " %d",
pob_qosbm_get_stat(pqi->pstats,
k, pqti->typemap,
i, j, 0, 0));
if (sublen >= 8)
break;
if (tmplen + sublen >=
TRACELOG_SIZE - 1)
break;
strncpy(log + tmplen, valuelog,
TRACELOG_SIZE - 1 - tmplen);
tmplen += sublen;
}
_trace_pob_log(log);
}
for (x = 0; x < sub; x++) {
tmplen = snprintf(log, TRACELOG_SIZE,
"%s%d probe=%s, source=%s, size=%d,",
pqti->prefix, x,
PQBP_str[i], PQBS_str[j], pqi->size);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
for (k = 0; k < pqi->size; k++) {
sublen = snprintf(valuelog, 8, " %d",
pob_qosbm_get_stat(pqi->pstats,
k, pqti->typemap,
i, j, 1, x));
if (sublen >= 8)
break;
if (tmplen + sublen >=
TRACELOG_SIZE - 1)
break;
strncpy(log + tmplen, valuelog,
TRACELOG_SIZE - 1 - tmplen);
tmplen += sublen;
}
_trace_pob_log(log);
}
}
}
}
static void _pob_qos_lat_log(struct pob_qos_trace_info *pqti,
struct pob_qos_info *pqi)
{
int i, k;
int x;
int super, sub;
char log[TRACELOG_SIZE];
char valuelog[8];
int tmplen;
int vRet;
int sublen;
for (i = 0; i < NR_PQLS; i++) {
vRet = pob_qoslat_get_cap(pqti->typemap, i,
&super, &sub);
if (vRet)
continue;
if (super) {
tmplen = snprintf(log, TRACELOG_SIZE,
"%s source=%s, size=%d,",
pqti->prefix,
PQLS_str[i], pqi->size);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
for (k = 0; k < pqi->size; k++) {
sublen = snprintf(valuelog, 8, " %d",
pob_qoslat_get_stat(pqi->pstats,
k, pqti->typemap,
i, 0, 0));
if (sublen >= 8)
break;
if (tmplen + sublen >=
TRACELOG_SIZE - 1)
break;
strncpy(log + tmplen, valuelog,
TRACELOG_SIZE - 1 - tmplen);
tmplen += sublen;
}
_trace_pob_log(log);
}
for (x = 0; x < sub; x++) {
tmplen = snprintf(log, TRACELOG_SIZE,
"%s%d source=%s, size=%d,",
pqti->prefix, x,
PQLS_str[i], pqi->size);
if (tmplen < 0 || tmplen >= sizeof(log))
return;
for (k = 0; k < pqi->size; k++) {
sublen = snprintf(valuelog, 8, " %d",
pob_qoslat_get_stat(pqi->pstats,
k, pqti->typemap,
i, 1, x));
if (sublen >= 8)
break;
if (tmplen + sublen >=
TRACELOG_SIZE - 1)
break;
strncpy(log + tmplen, valuelog,
TRACELOG_SIZE - 1 - tmplen);
tmplen += sublen;
}
_trace_pob_log(log);
}
}
}
static struct pob_qos_trace_info pqti[] = {
{POB_QOS_DEBUG_QOSSEQ, -1, "QOS_SEQ",
_pob_qos_seq_log},
{POB_QOS_DEBUG_BWBOUND, PQBT_BOUND, "BW_BOUND",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWTOTAL, PQBT_TOTAL, "BW_TOTAL",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWCPU, PQBT_CPU, "BW_CPU",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWGPU, PQBT_GPU, "BW_GPU",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWMM, PQBT_MM, "BW_MM",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWMD, PQBT_MD, "BW_MD",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWAPU, PQBT_APU, "BW_APU",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWVPU, PQBT_VPU, "BW_VPU",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWMDLA, PQBT_MDLA, "BW_MDLA",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWCAM, PQBT_CAM, "BW_CAM",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWVENC, PQBT_VENC, "BW_VENC",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWIMG, PQBT_IMG, "BW_IMG",
_pob_qos_bm_log},
{POB_QOS_DEBUG_BWMDP, PQBT_MDP, "BW_MDP",
_pob_qos_bm_log},
{POB_QOS_DEBUG_LATCPU, PQLT_CPU, "LAT_CPU",
_pob_qos_lat_log},
{POB_QOS_DEBUG_LATVPU, PQLT_VPU, "LAT_VPU",
_pob_qos_lat_log},
{POB_QOS_DEBUG_LATMDLA, PQLT_MDLA, "LAT_MDLA",
_pob_qos_lat_log},
{POB_QOS_DEBUG_MAX, -1, NULL, 0},
};
static uint32_t pob_qos_systrace_mask;
static uint32_t pob_qos_forceon;
void pob_qos_tracelog(unsigned long val, void *data)
{
int i;
struct pob_qos_info *pqi = (struct pob_qos_info *) data;
switch (val) {
case POB_QOS_EMI_ALL:
for (i = 0; pqti[i].flag != POB_QOS_DEBUG_MAX; i++) {
if (pob_qos_systrace_mask & pqti[i].flag)
pqti[i].pHdlfun(&pqti[i], pqi);
}
break;
default:
break;
}
}
static int _pob_qos_cb(struct notifier_block *nb,
unsigned long val, void *data)
{
return NOTIFY_OK;
}
static struct notifier_block pob_qos_notifier = {
.notifier_call = _pob_qos_cb,
};
static inline void _pob_qos_enable(void)
{
pob_qos_register_client(&pob_qos_notifier);
}
static inline void _pob_qos_disable(void)
{
pob_qos_unregister_client(&pob_qos_notifier);
}
static ssize_t pob_mask_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int i;
char temp[POB_SYSFS_MAX_BUFF_SIZE];
int pos = 0;
int length;
length = scnprintf(temp + pos, POB_SYSFS_MAX_BUFF_SIZE - pos,
" Current enabled systrace:\n");
pos += length;
for (i = 0; (1U << i) < POB_QOS_DEBUG_MAX; i++) {
length = scnprintf(temp + pos, POB_SYSFS_MAX_BUFF_SIZE - pos,
" %-*s ... %s\n", 12, mask_string[i],
pob_qos_systrace_mask & (1U << i) ?
"On" : "Off");
pos += length;
}
return scnprintf(buf, PAGE_SIZE, "%s", temp);
}
static ssize_t pob_mask_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int val = -1;
char acBuffer[POB_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < POB_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, POB_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0)
val = arg;
else
return count;
}
}
val = val & (POB_QOS_DEBUG_MAX - 1U);
pob_qos_systrace_mask = val;
return count;
}
KOBJ_ATTR_RW(pob_mask);
static ssize_t pob_forceon_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int val = -1;
val = pob_qos_forceon;
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t pob_forceon_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int val = -1;
char acBuffer[POB_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < POB_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, POB_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0)
val = arg;
else
return count;
}
}
if (val > 1 || val < 0)
return count;
if (val && !pob_qos_forceon)
_pob_qos_enable();
else if (!val && pob_qos_forceon)
_pob_qos_disable();
pob_qos_forceon = val;
return count;
}
KOBJ_ATTR_RW(pob_forceon);
int __init pob_qos_init(struct kobject *pob_kobj)
{
if (pob_qos_pfm_init())
return -EFAULT;
pob_qos_systrace_mask =
POB_QOS_DEBUG_QOSSEQ |
POB_QOS_DEBUG_BWBOUND |
POB_QOS_DEBUG_BWTOTAL;
if (!pob_kobj)
return -ENODEV;
pob_sysfs_create_file(pob_kobj, &kobj_attr_pob_forceon);
pob_sysfs_create_file(pob_kobj, &kobj_attr_pob_mask);
return 0;
}
void __exit pob_qos_exit(struct kobject *pob_kobj)
{
pob_sysfs_remove_file(pob_kobj, &kobj_attr_pob_forceon);
pob_sysfs_remove_file(pob_kobj, &kobj_attr_pob_mask);
pob_qos_pfm_exit();
}
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#define pr_fmt(fmt) "pob_xpu: " fmt
#include <linux/notifier.h>
#include <mt-plat/mtk_perfobserver.h>
static BLOCKING_NOTIFIER_HEAD(pob_xpufreq_notifier_list);
int pob_xpufreq_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pob_xpufreq_notifier_list, nb);
}
EXPORT_SYMBOL(pob_xpufreq_register_client);
int pob_xpufreq_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pob_xpufreq_notifier_list,
nb);
}
EXPORT_SYMBOL(pob_xpufreq_unregister_client);
int pob_xpufreq_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&pob_xpufreq_notifier_list, val, v);
}
int pob_xpufreq_update(enum pob_xpufreq_info_num info_num,
struct pob_xpufreq_info *v)
{
pob_xpufreq_notifier_call_chain(info_num, v);
return 0;
}
EXPORT_SYMBOL(pob_xpufreq_update);