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,54 @@
#
# Copyright (C) 2017 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
MTK_TOP = $(srctree)/drivers/misc/mediatek/
ifeq ($(CONFIG_MACH_MT6893),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6877),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6781),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6739),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6833),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6768),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6771),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6785),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else ifeq ($(CONFIG_MACH_MT6885),y)
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3_topology/fstb/
else
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3/base/include/
ccflags-y += -I$(MTK_TOP)/performance/fpsgo_v3/fstb/
endif
obj-y += gbe1_main.o
obj-y += gbe2_main.o
obj-y += gbe_common.o
obj-y += gbe_sysfs.o
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#ifndef GBE1_H
#define GBE1_H
extern void gbe1_exit(void);
extern int gbe1_init(void);
#endif
@@ -0,0 +1,462 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#include <linux/sched/clock.h>
#include <linux/sched/mm.h>
#include <linux/sched/numa_balancing.h>
#include <linux/sched/task_stack.h>
#include <linux/sched/task.h>
#include <linux/sched/cputime.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/kallsyms.h>
#include <linux/trace_events.h>
#include "cpu_ctrl.h"
#include <linux/workqueue.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include "gbe1_usedext.h"
#include "fstb_usedext.h"
#include "gbe_common.h"
#include "gbe_sysfs.h"
enum GBE_NOTIFIER_PUSH_TYPE {
GBE_NOTIFIER_SWITCH_GBE = 0x00,
GBE_NOTIFIER_RTID = 0x01,
};
struct GBE_NOTIFIER_PUSH_TAG {
enum GBE_NOTIFIER_PUSH_TYPE ePushType;
struct hlist_head *list;
int enable;
struct work_struct sWork;
};
static DEFINE_MUTEX(gbe_list_lock);
static DEFINE_MUTEX(gbe_enable1_lock);
static struct workqueue_struct *g_psNotifyWorkQueue;
static int gbe_enable;
/* TODO: event register & dispatch */
int gbe_is_enable(void)
{
int enable;
mutex_lock(&gbe_enable1_lock);
enable = gbe_enable;
mutex_unlock(&gbe_enable1_lock);
return enable;
}
void enable_gbe(int enable)
{
pr_debug("[GBE] enable:%d %p\n", enable, &gbe_enable1_lock);
mutex_lock(&gbe_enable1_lock);
gbe_enable = !!enable;
mutex_unlock(&gbe_enable1_lock);
}
static unsigned long long gbe_get_time(void)
{
unsigned long long temp;
preempt_disable();
temp = cpu_clock(smp_processor_id());
preempt_enable();
return temp;
}
/***********************************************************/
/*main logic*/
static void gbe_ctrl2comp_fstb_poll(struct hlist_head *list)
{
struct GBE_FSTB_TID_LIST *iter;
struct task_struct *tsk, *gtsk, *sib;
struct GBE_BOOST_LIST *gbe_list_iter = NULL;
struct hlist_node *t;
int tid = 0;
int tgid = 0;
int boost = 0;
if (!gbe_is_enable()) {
gbe_boost(KIR_GBE1, 0);
return;
}
mutex_lock(&gbe_list_lock);
hlist_for_each_entry(iter, list, hlist) {
tid = iter->tid;
rcu_read_lock();
tsk = find_task_by_vpid(tid);
if (!tsk) {
rcu_read_unlock();
continue;
}
get_task_struct(tsk);
gtsk = tsk->group_leader;
if (!gtsk) {
put_task_struct(tsk);
rcu_read_unlock();
continue;
}
get_task_struct(gtsk);
tgid = gtsk->pid;
list_for_each_entry(sib, &gtsk->thread_group, thread_group) {
if (!sib)
continue;
get_task_struct(sib);
hlist_for_each_entry(gbe_list_iter,
&gbe_boost_list, hlist) {
if ((!strncmp("*",
gbe_list_iter->process_name, 1) ||
!strncmp(gtsk->comm,
gbe_list_iter->process_name, 15)) &&
!strncmp(sib->comm,
gbe_list_iter->thread_name, 15)) {
gbe_list_iter->pid = tgid;
gbe_list_iter->tid = sib->pid;
gbe_list_iter->now_task_runtime =
task_sched_runtime(sib);
}
}
put_task_struct(sib);
}
put_task_struct(gtsk);
put_task_struct(tsk);
rcu_read_unlock();
}
hlist_for_each_entry(gbe_list_iter, &gbe_boost_list, hlist) {
gbe_list_iter->cur_ts = gbe_get_time();
gbe_list_iter->runtime_percent =
1000ULL *
#if BITS_PER_LONG == 32
div_u64((gbe_list_iter->now_task_runtime -
gbe_list_iter->last_task_runtime),
(gbe_list_iter->cur_ts - gbe_list_iter->last_ts));
#else
(gbe_list_iter->now_task_runtime -
gbe_list_iter->last_task_runtime) /
(gbe_list_iter->cur_ts - gbe_list_iter->last_ts);
#endif
if (gbe_list_iter->runtime_percent)
gbe_trace_count(gbe_list_iter->tid, 0,
gbe_list_iter->runtime_percent,
"runtime_percent");
gbe_list_iter->last_task_runtime =
gbe_list_iter->now_task_runtime;
gbe_list_iter->last_ts = gbe_list_iter->cur_ts;
if (gbe_list_iter->runtime_percent >
gbe_list_iter->runtime_thrs) {
boost = 1;
gbe_list_iter->boost_cnt++;
gbe_trace_count(gbe_list_iter->tid, 0, 1, "gbe_boost");
}
}
hlist_for_each_entry_safe(iter, t,
&gbe_fstb_tid_list, hlist) {
hlist_del(&iter->hlist);
kfree(iter);
}
gbe_boost(KIR_GBE1, boost);
mutex_unlock(&gbe_list_lock);
}
/***********************************************************/
static void gbe_notifier_wq_cb_rtid(struct hlist_head *list)
{
if (!gbe_is_enable()) {
gbe_boost(KIR_GBE1, 0);
return;
}
gbe_ctrl2comp_fstb_poll(list);
}
#define GBE_CONTAINER_OF(ptr, type, member) \
((type *)(((char *)ptr) - offsetof(type, member)))
static void gbe_notifier_wq_cb(struct work_struct *psWork)
{
struct GBE_NOTIFIER_PUSH_TAG *vpPush =
GBE_CONTAINER_OF(psWork,
struct GBE_NOTIFIER_PUSH_TAG, sWork);
switch (vpPush->ePushType) {
case GBE_NOTIFIER_RTID:
gbe_notifier_wq_cb_rtid(vpPush->list);
break;
default:
break;
}
kfree(vpPush);
}
void gbe_notify_fstb_poll(struct hlist_head *list)
{
struct GBE_NOTIFIER_PUSH_TAG *vpPush;
struct GBE_FSTB_TID_LIST *gbe_iter;
struct FSTB_FRAME_INFO *fstb_iter;
if (!gbe_is_enable())
return;
vpPush =
(struct GBE_NOTIFIER_PUSH_TAG *)
kmalloc(sizeof(struct GBE_NOTIFIER_PUSH_TAG), GFP_ATOMIC);
if (!vpPush)
return;
if (!g_psNotifyWorkQueue) {
kfree(vpPush);
return;
}
hlist_for_each_entry(fstb_iter, list, hlist) {
gbe_iter = kzalloc(sizeof(*gbe_iter), GFP_KERNEL);
if (gbe_iter) {
gbe_iter->tid = fstb_iter->pid;
hlist_add_head(&gbe_iter->hlist, &gbe_fstb_tid_list);
}
}
vpPush->ePushType = GBE_NOTIFIER_RTID;
vpPush->list = &gbe_fstb_tid_list;
INIT_WORK(&vpPush->sWork, gbe_notifier_wq_cb);
queue_work(g_psNotifyWorkQueue, &vpPush->sWork);
}
#define MAX_GBE_BOOST_LIST_LENGTH 20
static int gbe_boost_list_length;
int set_gbe_boost_list(char *proc_name,
char *thrd_name, unsigned long long runtime_thrs)
{
struct GBE_BOOST_LIST *new_gbe_boost_list;
int retval = 0;
mutex_lock(&gbe_list_lock);
if (!strncmp("0", proc_name, 1) &&
!strncmp("0", thrd_name, 1) &&
runtime_thrs == 0) {
struct GBE_BOOST_LIST *iter;
struct hlist_node *t;
hlist_for_each_entry_safe(iter, t,
&gbe_boost_list, hlist) {
hlist_del(&iter->hlist);
kfree(iter);
}
gbe_boost_list_length = 0;
goto out;
}
if (gbe_boost_list_length >= MAX_GBE_BOOST_LIST_LENGTH) {
retval = -ENOMEM;
goto out;
}
new_gbe_boost_list =
kzalloc(sizeof(*new_gbe_boost_list), GFP_KERNEL);
if (new_gbe_boost_list == NULL) {
retval = -ENOMEM;
goto out;
}
if (!strncpy(
new_gbe_boost_list->process_name,
proc_name, 16)) {
kfree(new_gbe_boost_list);
retval = -ENOMEM;
goto out;
}
new_gbe_boost_list->process_name[15] = '\0';
if (!strncpy(
new_gbe_boost_list->thread_name,
thrd_name, 16)) {
kfree(new_gbe_boost_list);
retval = -ENOMEM;
goto out;
}
new_gbe_boost_list->thread_name[15] = '\0';
new_gbe_boost_list->runtime_thrs = runtime_thrs;
hlist_add_head(&new_gbe_boost_list->hlist,
&gbe_boost_list);
gbe_boost_list_length++;
out:
mutex_unlock(&gbe_list_lock);
return retval;
}
static ssize_t gbe_enable1_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", gbe_is_enable());
}
static ssize_t gbe_enable1_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
int val = 0;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0)
val = arg;
else
return count;
}
}
enable_gbe(val);
return count;
}
static KOBJ_ATTR_RW(gbe_enable1);
static ssize_t gbe_boost_list1_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
struct GBE_BOOST_LIST *gbe_list_iter = NULL;
char temp[GBE_SYSFS_MAX_BUFF_SIZE] = "";
int pos = 0;
int length;
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
"process_name",
"thread_name",
"pid",
"tid",
"runtime_thrs",
"runtime_percent",
"now_task_runtime",
"boost_cnt");
pos += length;
hlist_for_each_entry(gbe_list_iter, &gbe_boost_list, hlist) {
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"%s\t%s\t%d\t%d\t%llu\t\t%llu\t\t%llu\t\t%llu\n",
gbe_list_iter->process_name,
gbe_list_iter->thread_name,
gbe_list_iter->pid,
gbe_list_iter->tid,
gbe_list_iter->runtime_thrs,
gbe_list_iter->runtime_percent,
gbe_list_iter->now_task_runtime,
gbe_list_iter->boost_cnt);
pos += length;
}
return scnprintf(buf, PAGE_SIZE, "%s", temp);
}
static ssize_t gbe_boost_list1_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int ret = count;
char proc_name[16], thrd_name[16];
unsigned long long runtime_thrs;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
acBuffer[count] = '\0';
if (sscanf(acBuffer, "%15s %15s %llu",
proc_name,
thrd_name,
&runtime_thrs) != 3) {
goto err;
}
if (set_gbe_boost_list(proc_name,
thrd_name, runtime_thrs))
goto err;
}
}
err:
return ret;
}
static KOBJ_ATTR_RW(gbe_boost_list1);
int init_gbe_common(void)
{
gbe_sysfs_create_file(&kobj_attr_gbe_enable1);
gbe_sysfs_create_file(&kobj_attr_gbe_boost_list1);
return 0;
}
void gbe1_exit(void)
{
gbe_sysfs_remove_file(&kobj_attr_gbe_enable1);
gbe_sysfs_remove_file(&kobj_attr_gbe_boost_list1);
}
int gbe1_init(void)
{
gbe_fstb2gbe_poll_fp = gbe_notify_fstb_poll;
g_psNotifyWorkQueue =
create_singlethread_workqueue("gbe_notifier_wq");
init_gbe_common();
return 0;
}
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MediaTek GBE");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#ifndef GBE_USEDEXT_H
#define GBE_USEDEXT_H
extern void (*gbe_fstb2gbe_poll_fp)(struct hlist_head *list);
struct GBE_BOOST_LIST {
struct hlist_node hlist;
char process_name[16];
char thread_name[16];
unsigned long long runtime_thrs;
unsigned long long runtime_percent;
unsigned long long last_task_runtime;
unsigned long long now_task_runtime;
unsigned long long cur_ts;
unsigned long long last_ts;
int pid;
int tid;
unsigned long long boost_cnt;
};
struct GBE_FSTB_TID_LIST {
struct hlist_node hlist;
int tid;
};
static HLIST_HEAD(gbe_boost_list);
static HLIST_HEAD(gbe_fstb_tid_list);
#endif
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#ifndef GBE2_H
#define GBE2_H
#if defined(CONFIG_MTK_GBE)
void fpsgo_comp2gbe_frame_update(int pid, unsigned long long bufID);
#else
static inline void fpsgo_comp2gbe_frame_update(int pid,
unsigned long long bufID) { }
#endif
extern void gbe2_exit(void);
extern int gbe2_init(void);
#endif
@@ -0,0 +1,693 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#include <linux/sched/clock.h>
#include <linux/sched/mm.h>
#include <linux/sched/numa_balancing.h>
#include <linux/sched/task_stack.h>
#include <linux/sched/task.h>
#include <linux/sched/cputime.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/kallsyms.h>
#include <linux/trace_events.h>
#include "cpu_ctrl.h"
#include "eas_ctrl.h"
#include <linux/workqueue.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include "gbe2_usedext.h"
#include "gbe_common.h"
#include "gbe_sysfs.h"
#include <linux/pm_qos.h>
#define MAX_DEP_NUM 30
#define MAIN_LOG_SIZE 256
#define DEFAULT_TIMER1_MS 100
#define DEFAULT_TIMER2_MS 1000
#define DEFAULT_MAX_BOOST_CNT 5
#define DEFAULT_LOADING_TH 20
static HLIST_HEAD(gbe_boost_units);
static DEFINE_MUTEX(gbe_lock);
static int gbe_enable;
static int fg_pid;
static int TIMER1_MS = DEFAULT_TIMER1_MS;
static int TIMER2_MS = DEFAULT_TIMER2_MS;
static int MAX_BOOST_CNT = DEFAULT_MAX_BOOST_CNT;
static int LOADING_TH = DEFAULT_LOADING_TH;
enum {
NEW_RENDER = 0,
FPS_UPDATE,
BOOSTING,
FREE,
};
struct gbe_boost_unit {
int pid;
unsigned long long bufID;
int state;
int boost_cnt;
int dep_num;
struct gbe_runtime dep[MAX_DEP_NUM]; //latest dep, no accumulate
unsigned long long q_ts_ms;
unsigned long long runtime_ts_ns;
struct hrtimer timer1;
struct hrtimer timer2;
struct work_struct work1;
struct work_struct work2;
struct hlist_node hlist;
};
static void gbe_boost_cpu(void)
{
struct gbe_boost_unit *iter;
int boost = 0;
hlist_for_each_entry(iter, &gbe_boost_units, hlist) {
if (iter->boost_cnt) {
boost = 1;
break;
}
}
gbe_boost(KIR_GBE2, boost);
}
static void update_runtime(struct gbe_boost_unit *iter)
{
int i;
struct task_struct *p;
iter->runtime_ts_ns = ktime_to_ns(ktime_get());
for (i = 0; i < iter->dep_num; i++) {
rcu_read_lock();
p = find_task_by_vpid(iter->dep[i].pid);
if (!p) {
iter->dep[i].runtime = 0;
rcu_read_unlock();
} else {
get_task_struct(p);
rcu_read_unlock();
iter->dep[i].runtime = task_sched_runtime(p);
put_task_struct(p);
}
}
}
static int check_dep_run_and_update(struct gbe_boost_unit *iter)
{
int i;
int ret = 0;
struct task_struct *p;
unsigned long long cur_ts_ns = ktime_to_ns(ktime_get());
char dep_str[MAIN_LOG_SIZE] = {"\0"};
char temp[MAIN_LOG_SIZE] = {"\0"};
unsigned long long new_runtime = 0;
int tmplen;
for (i = 0; i < iter->dep_num; i++) {
rcu_read_lock();
p = find_task_by_vpid(iter->dep[i].pid);
if (!p) {
iter->dep[i].runtime = 0;
iter->dep[i].loading = 0;
rcu_read_unlock();
} else {
get_task_struct(p);
rcu_read_unlock();
//iter->dep[i].runtime = p->se.avg.util_avg;
new_runtime = task_sched_runtime(p);
put_task_struct(p);
iter->dep[i].loading =
#if BITS_PER_LONG == 32
div_u64((new_runtime - iter->dep[i].runtime) * 100,
(cur_ts_ns - iter->runtime_ts_ns));
#else
(new_runtime - iter->dep[i].runtime) * 100
/ (cur_ts_ns - iter->runtime_ts_ns);
#endif
iter->dep[i].runtime = new_runtime;
}
}
iter->runtime_ts_ns = cur_ts_ns;
for (i = 0; i < iter->dep_num; i++) {
if (iter->dep[i].loading >= LOADING_TH)
ret = 1;
if (strlen(dep_str) == 0)
tmplen = snprintf(temp, sizeof(temp), "%d(%llu)",
iter->dep[i].pid, iter->dep[i].loading);
else
tmplen = snprintf(temp, sizeof(temp), ",%d(%llu)",
iter->dep[i].pid, iter->dep[i].loading);
if (tmplen < 0 || tmplen >= sizeof(temp))
return ret;
if (strlen(dep_str) + strlen(temp) < MAIN_LOG_SIZE)
strncat(dep_str, temp, strlen(temp));
}
gbe_trace_printk(iter->pid, "gbe", dep_str);
gbe_trace_count(iter->pid, iter->bufID, ret, "gbe_dep_run");
return ret;
}
static void gbe_do_timer2(struct work_struct *work)
{
struct gbe_boost_unit *iter;
unsigned long long cur_ts_ms = ktime_to_ms(ktime_get());
iter = container_of(work, struct gbe_boost_unit, work2);
mutex_lock(&gbe_lock);
if (iter->state == FREE) {
hlist_del(&iter->hlist);
kfree(iter);
} else if (iter->boost_cnt > MAX_BOOST_CNT) {
iter->state = FREE;
iter->boost_cnt = 0;
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
gbe_boost_cpu();
hrtimer_cancel(&iter->timer2);
hrtimer_start(&iter->timer2,
ms_to_ktime(TIMER2_MS), HRTIMER_MODE_REL);
} else if (check_dep_run_and_update(iter)) {
if (cur_ts_ms - iter->q_ts_ms > TIMER1_MS) {
iter->boost_cnt++;
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
hrtimer_cancel(&iter->timer2);
hrtimer_start(&iter->timer2,
ms_to_ktime(TIMER2_MS), HRTIMER_MODE_REL);
} else {
iter->state = FPS_UPDATE;
iter->boost_cnt = 0;
gbe_boost_cpu();
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
hrtimer_cancel(&iter->timer1);
hrtimer_start(&iter->timer1,
ms_to_ktime(TIMER1_MS), HRTIMER_MODE_REL);
}
} else {
iter->state = FREE;
iter->boost_cnt = 0;
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
gbe_boost_cpu();
hrtimer_cancel(&iter->timer2);
hrtimer_start(&iter->timer2,
ms_to_ktime(TIMER2_MS), HRTIMER_MODE_REL);
}
mutex_unlock(&gbe_lock);
}
static enum hrtimer_restart gbe_timer2_tfn(struct hrtimer *timer)
{
struct gbe_boost_unit *iter;
iter = container_of(timer, struct gbe_boost_unit, timer2);
schedule_work(&iter->work2);
return HRTIMER_NORESTART;
}
static inline void gbe_init_timer2(struct gbe_boost_unit *iter)
{
if (iter == NULL)
return;
hrtimer_init(&iter->timer2, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
iter->timer2.function = &gbe_timer2_tfn;
INIT_WORK(&iter->work2, gbe_do_timer2);
}
static void gbe_do_timer1(struct work_struct *work)
{
struct gbe_boost_unit *iter;
iter = container_of(work, struct gbe_boost_unit, work1);
mutex_lock(&gbe_lock);
if (check_dep_run_and_update(iter)) {
iter->state = BOOSTING;
iter->boost_cnt = 1;
gbe_boost_cpu();
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
hrtimer_start(&iter->timer2, ms_to_ktime(TIMER2_MS),
HRTIMER_MODE_REL);
} else {
iter->state = FREE;
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
hrtimer_start(&iter->timer2, ms_to_ktime(TIMER2_MS),
HRTIMER_MODE_REL);
}
mutex_unlock(&gbe_lock);
}
static enum hrtimer_restart gbe_timer1_tfn(struct hrtimer *timer)
{
struct gbe_boost_unit *iter;
iter = container_of(timer, struct gbe_boost_unit, timer1);
schedule_work(&iter->work1);
return HRTIMER_NORESTART;
}
static inline void gbe_init_timer1(struct gbe_boost_unit *iter)
{
if (iter == NULL)
return;
hrtimer_init(&iter->timer1, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
iter->timer1.function = &gbe_timer1_tfn;
INIT_WORK(&iter->work1, gbe_do_timer1);
}
static int ignore_nonfg(int pid)
{
struct task_struct *tsk;
int ret = 0;
int process_id = 0;
rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (tsk) {
get_task_struct(tsk);
process_id = tsk->tgid;
put_task_struct(tsk);
} else {
rcu_read_unlock();
goto out;
}
rcu_read_unlock();
ret = (fg_pid != process_id);
out:
return ret;
}
void fpsgo_comp2gbe_frame_update(int pid, unsigned long long bufID)
{
struct gbe_boost_unit *iter;
mutex_lock(&gbe_lock);
if (!gbe_enable || ignore_nonfg(pid)) {
mutex_unlock(&gbe_lock);
return;
}
hlist_for_each_entry(iter, &gbe_boost_units, hlist) {
if (iter->pid == pid && iter->bufID == bufID)
break;
}
if (iter == NULL) {
iter =
kzalloc(sizeof(*iter), GFP_KERNEL);
if (iter == NULL)
goto out;
iter->pid = pid;
iter->bufID = bufID;
iter->state = NEW_RENDER;
iter->boost_cnt = 0;
hlist_add_head(&iter->hlist,
&gbe_boost_units);
}
switch (iter->state) {
case NEW_RENDER:
iter->dep_num = gbe2xgf_get_dep_list_num(pid, bufID);
iter->dep_num = iter->dep_num > MAX_DEP_NUM ?
MAX_DEP_NUM : iter->dep_num;
gbe2xgf_get_dep_list(pid, iter->dep_num, iter->dep, bufID);
update_runtime(iter);
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
iter->state = FPS_UPDATE;
gbe_trace_count(iter->pid, iter->bufID,
iter->boost_cnt, "gbe_boost_cnt");
gbe_trace_count(iter->pid, iter->bufID,
iter->state, "gbe_state");
gbe_init_timer1(iter);
gbe_init_timer2(iter);
hrtimer_start(&iter->timer1, ms_to_ktime(TIMER1_MS),
HRTIMER_MODE_REL);
break;
case FPS_UPDATE:
iter->dep_num = gbe2xgf_get_dep_list_num(pid, bufID);
iter->dep_num = iter->dep_num > MAX_DEP_NUM ?
MAX_DEP_NUM : iter->dep_num;
gbe2xgf_get_dep_list(pid, iter->dep_num, iter->dep, bufID);
update_runtime(iter);
hrtimer_cancel(&iter->timer1);
hrtimer_start(&iter->timer1, ms_to_ktime(TIMER1_MS),
HRTIMER_MODE_REL);
break;
case BOOSTING:
iter->q_ts_ms = ktime_to_ms(ktime_get());
break;
case FREE:
break;
default:
break;
}
out:
mutex_unlock(&gbe_lock);
}
static ssize_t gbe2_timer1_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = TIMER1_MS;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe2_timer1_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
if (arg >= 0 && arg <= 1000)
TIMER1_MS = arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe2_timer1);
static ssize_t gbe2_timer2_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = TIMER2_MS;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe2_timer2_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
if (arg >= 0 && arg <= 10000)
TIMER2_MS = arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe2_timer2);
static ssize_t gbe2_max_boost_cnt_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = MAX_BOOST_CNT;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe2_max_boost_cnt_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
if (arg > 0 && arg <= 15)
MAX_BOOST_CNT = arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe2_max_boost_cnt);
static ssize_t gbe2_loading_th_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = LOADING_TH;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe2_loading_th_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
if (arg >= 0 && arg <= 100)
LOADING_TH = arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe2_loading_th);
static ssize_t gbe_enable2_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = gbe_enable;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe_enable2_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
gbe_enable = !!arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe_enable2);
static ssize_t gbe2_fg_pid_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
int val;
mutex_lock(&gbe_lock);
val = fg_pid;
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t gbe2_fg_pid_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0) {
mutex_lock(&gbe_lock);
fg_pid = arg;
mutex_unlock(&gbe_lock);
}
}
}
return count;
}
static KOBJ_ATTR_RW(gbe2_fg_pid);
static ssize_t gbe_boost_list2_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
struct gbe_boost_unit *iter;
int i;
char temp[GBE_SYSFS_MAX_BUFF_SIZE] = "";
int pos = 0;
int length;
mutex_lock(&gbe_lock);
hlist_for_each_entry(iter, &gbe_boost_units, hlist) {
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"%s\t%s\t%s\t%s\n",
"pid",
"state",
"boost_cnt",
"dep_num");
pos += length;
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"%d\t%d\t%d\t%d\n",
iter->pid,
iter->state,
iter->boost_cnt,
iter->dep_num);
pos += length;
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"dep-list:\n");
pos += length;
for (i = 0; i < iter->dep_num; i++) {
length =
scnprintf(temp + pos,
GBE_SYSFS_MAX_BUFF_SIZE - pos,
"%d ", iter->dep[i].pid);
pos += length;
}
length = scnprintf(temp + pos, GBE_SYSFS_MAX_BUFF_SIZE - pos,
"\n");
pos += length;
}
mutex_unlock(&gbe_lock);
return scnprintf(buf, PAGE_SIZE, "%s", temp);
}
static KOBJ_ATTR_RO(gbe_boost_list2);
void gbe2_exit(void)
{
gbe_sysfs_remove_file(&kobj_attr_gbe_enable2);
gbe_sysfs_remove_file(&kobj_attr_gbe2_fg_pid);
gbe_sysfs_remove_file(&kobj_attr_gbe_boost_list2);
gbe_sysfs_remove_file(&kobj_attr_gbe2_timer1);
gbe_sysfs_remove_file(&kobj_attr_gbe2_timer2);
gbe_sysfs_remove_file(&kobj_attr_gbe2_max_boost_cnt);
gbe_sysfs_remove_file(&kobj_attr_gbe2_loading_th);
}
int gbe2_init(void)
{
gbe_sysfs_create_file(&kobj_attr_gbe_enable2);
gbe_sysfs_create_file(&kobj_attr_gbe2_fg_pid);
gbe_sysfs_create_file(&kobj_attr_gbe_boost_list2);
gbe_sysfs_create_file(&kobj_attr_gbe2_timer1);
gbe_sysfs_create_file(&kobj_attr_gbe2_timer2);
gbe_sysfs_create_file(&kobj_attr_gbe2_max_boost_cnt);
gbe_sysfs_create_file(&kobj_attr_gbe2_loading_th);
return 0;
}
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MediaTek GBE");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#ifndef GBE_USEDEXT_H
#define GBE_USEDEXT_H
#include "fpsgo_base.h"
extern int gbe2xgf_get_dep_list_num(int pid, unsigned long long bufID);
extern int gbe2xgf_get_dep_list(int pid, int count,
struct gbe_runtime *arr, unsigned long long bufID);
#endif
@@ -0,0 +1,284 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#include <linux/sched/clock.h>
#include <linux/sched/mm.h>
#include <linux/sched/numa_balancing.h>
#include <linux/sched/task_stack.h>
#include <linux/sched/task.h>
#include <linux/sched/cputime.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/kallsyms.h>
#include <linux/trace_events.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/miscdevice.h> /* for misc_register, and SYNTH_MINOR */
#include <linux/proc_fs.h>
#include "cpu_ctrl.h"
#include "eas_ctrl.h"
#include <linux/workqueue.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/pm_qos.h>
#include "gbe_common.h"
#include "gbe1.h"
#include "gbe2.h"
#include "gbe_sysfs.h"
static DEFINE_MUTEX(gbe_lock);
static int boost_set[KIR_NUM];
static unsigned long policy_mask;
enum GBE_BOOST_DEVICE {
GBE_BOOST_UNKNOWN = -1,
GBE_BOOST_CPU = 0,
GBE_BOOST_EAS = 1,
GBE_BOOST_VCORE = 2,
GBE_BOOST_IO = 3,
GBE_BOOST_HE = 4,
GBE_BOOST_GPU = 5,
GBE_BOOST_LLF = 6,
GBE_BOOST_NUM = 7,
};
static unsigned long __read_mostly tracing_mark_write_addr;
static inline void __mt_update_tracing_mark_write_addr(void)
{
if (unlikely(tracing_mark_write_addr == 0))
tracing_mark_write_addr =
kallsyms_lookup_name("tracing_mark_write");
}
void gbe_trace_printk(int pid, char *module, char *string)
{
__mt_update_tracing_mark_write_addr();
preempt_disable();
event_trace_printk(tracing_mark_write_addr, "%d [%s] %s\n",
pid, module, string);
preempt_enable();
}
void gbe_trace_count(int tid, unsigned long long bufID,
int val, const char *fmt, ...)
{
char log[32];
va_list args;
int len;
memset(log, ' ', sizeof(log));
va_start(args, fmt);
len = vsnprintf(log, sizeof(log), fmt, args);
va_end(args);
if (unlikely(len < 0))
return;
else if (unlikely(len == 32))
log[31] = '\0';
__mt_update_tracing_mark_write_addr();
preempt_disable();
if (!strstr(CONFIG_MTK_PLATFORM, "mt8")) {
if (!bufID)
event_trace_printk(tracing_mark_write_addr, "C|%d|%s|%d\n",
tid, log, val);
else
event_trace_printk(tracing_mark_write_addr, "C|%d|%s|%d|0x%llx\n",
tid, log, val, bufID);
} else {
event_trace_printk(tracing_mark_write_addr, "C|%s|%d\n",
log, val);
}
preempt_enable();
}
struct k_list {
struct list_head queue_list;
int gbe2pwr_cmd;
int gbe2pwr_value1;
int gbe2pwr_value2;
};
static LIST_HEAD(head);
static int condition_get_cmd;
static DEFINE_MUTEX(gbe2pwr_lock);
static DECLARE_WAIT_QUEUE_HEAD(pwr_queue);
void gbe_sentcmd(int cmd, int value1, int value2)
{
static struct k_list *node;
mutex_lock(&gbe2pwr_lock);
node = kmalloc(sizeof(*node), GFP_KERNEL);
if (node == NULL)
goto out;
node->gbe2pwr_cmd = cmd;
node->gbe2pwr_value1 = value1;
node->gbe2pwr_value2 = value2;
list_add_tail(&node->queue_list, &head);
condition_get_cmd = 1;
out:
mutex_unlock(&gbe2pwr_lock);
wake_up_interruptible(&pwr_queue);
}
void gbe_ctrl2base_get_pwr_cmd(int *cmd, int *value1, int *value2)
{
static struct k_list *node;
wait_event_interruptible(pwr_queue, condition_get_cmd);
mutex_lock(&gbe2pwr_lock);
if (!list_empty(&head)) {
node = list_first_entry(&head, struct k_list, queue_list);
*cmd = node->gbe2pwr_cmd;
*value1 = node->gbe2pwr_value1;
*value2 = node->gbe2pwr_value2;
list_del(&node->queue_list);
kfree(node);
}
if (list_empty(&head))
condition_get_cmd = 0;
mutex_unlock(&gbe2pwr_lock);
}
void gbe_boost(enum GBE_KICKER kicker, int boost)
{
int i;
int boost_final = 0;
int cpu_boost = 0, eas_boost = -1, vcore_boost = -1,
io_boost = 0, he_boost = 0, gpu_boost = 0,
llf_boost = 0;
mutex_lock(&gbe_lock);
if (boost_set[kicker] == !!boost)
goto out;
boost_set[kicker] = !!boost;
for (i = 0; i < KIR_NUM; i++)
if (boost_set[i] == 1) {
boost_final = 1;
break;
}
if (boost_final) {
cpu_boost = 1;
eas_boost = 100;
vcore_boost = 0;
io_boost = 1;
he_boost = 1;
gpu_boost = 1;
llf_boost = 1;
}
if (test_bit(GBE_BOOST_CPU, &policy_mask))
gbe_sentcmd(GBE_BOOST_CPU, cpu_boost, -1);
if (test_bit(GBE_BOOST_EAS, &policy_mask))
gbe_sentcmd(GBE_BOOST_EAS, eas_boost, -1);
if (test_bit(GBE_BOOST_VCORE, &policy_mask))
gbe_sentcmd(GBE_BOOST_VCORE, vcore_boost, -1);
if (test_bit(GBE_BOOST_IO, &policy_mask))
gbe_sentcmd(GBE_BOOST_IO, io_boost, -1);
if (test_bit(GBE_BOOST_HE, &policy_mask))
gbe_sentcmd(GBE_BOOST_HE, he_boost, -1);
if (test_bit(GBE_BOOST_GPU, &policy_mask))
gbe_sentcmd(GBE_BOOST_GPU, gpu_boost, -1);
if (test_bit(GBE_BOOST_LLF, &policy_mask))
gbe_sentcmd(GBE_BOOST_LLF, llf_boost, -1);
out:
mutex_unlock(&gbe_lock);
}
static ssize_t gbe_policy_mask_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", policy_mask);
}
static ssize_t gbe_policy_mask_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
int val = 0;
char acBuffer[GBE_SYSFS_MAX_BUFF_SIZE];
int arg;
int cpu_boost = 0, eas_boost = -1, vcore_boost = -1,
io_boost = 0, he_boost = 0, gpu_boost = 0,
llf_boost = 0;
if ((count > 0) && (count < GBE_SYSFS_MAX_BUFF_SIZE)) {
if (scnprintf(acBuffer, GBE_SYSFS_MAX_BUFF_SIZE, "%s", buf)) {
if (kstrtoint(acBuffer, 0, &arg) == 0)
val = arg;
else
return count;
}
}
if (val > 1 << GBE_BOOST_NUM || val < 0)
return count;
mutex_lock(&gbe_lock);
policy_mask = val;
gbe_sentcmd(GBE_BOOST_CPU, cpu_boost, -1);
gbe_sentcmd(GBE_BOOST_EAS, eas_boost, -1);
gbe_sentcmd(GBE_BOOST_VCORE, vcore_boost, -1);
gbe_sentcmd(GBE_BOOST_IO, io_boost, -1);
gbe_sentcmd(GBE_BOOST_HE, he_boost, -1);
gbe_sentcmd(GBE_BOOST_GPU, gpu_boost, -1);
gbe_sentcmd(GBE_BOOST_LLF, llf_boost, -1);
mutex_unlock(&gbe_lock);
return count;
}
static KOBJ_ATTR_RW(gbe_policy_mask);
static void __exit gbe_common_exit(void)
{
gbe_sysfs_remove_file(&kobj_attr_gbe_policy_mask);
gbe_sysfs_exit();
}
struct dentry *gbe_debugfs_dir;
static int __init gbe_common_init(void)
{
gbe_get_cmd_fp = gbe_ctrl2base_get_pwr_cmd;
gbe_sysfs_init();
gbe1_init();
gbe2_init();
gbe_sysfs_create_file(&kobj_attr_gbe_policy_mask);
set_bit(GBE_BOOST_CPU, &policy_mask);
set_bit(GBE_BOOST_EAS, &policy_mask);
set_bit(GBE_BOOST_VCORE, &policy_mask);
set_bit(GBE_BOOST_HE, &policy_mask);
return 0;
}
module_init(gbe_common_init);
module_exit(gbe_common_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MediaTek GBE");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
*/
#ifndef GBE_H
#define GBE_H
enum GBE_KICKER {
KIR_GBE1,
KIR_GBE2,
KIR_NUM,
};
void gbe_boost(enum GBE_KICKER kicker, int boost);
void gbe_trace_printk(int pid, char *module, char *string);
void gbe_trace_count(int tid, unsigned long long bufID,
int val, const char *fmt, ...);
extern void (*gbe_get_cmd_fp)(int *cmd, int *value1, int *value2);
extern struct dentry *gbe_debugfs_dir;
#endif
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include "gbe_sysfs.h"
#define GBE_SYSFS_DIR_NAME "gbe"
static struct kobject *gbe_kobj;
// --------------------------------------------------
void gbe_sysfs_create_file(struct kobj_attribute *kobj_attr)
{
if (kobj_attr == NULL || gbe_kobj == NULL) {
pr_debug("Failed to create '%s' sysfs file kobj_attr=NULL\n");
return;
}
if (sysfs_create_file(gbe_kobj, &(kobj_attr->attr))) {
pr_debug("Failed to create sysfs file\n");
return;
}
}
// --------------------------------------------------
void gbe_sysfs_remove_file(struct kobj_attribute *kobj_attr)
{
if (kobj_attr == NULL || gbe_kobj == NULL)
return;
sysfs_remove_file(gbe_kobj, &(kobj_attr->attr));
}
// --------------------------------------------------
void gbe_sysfs_init(void)
{
gbe_kobj = kobject_create_and_add(GBE_SYSFS_DIR_NAME,
kernel_kobj);
if (!gbe_kobj) {
pr_debug("Failed to create '%s' sysfs root directory\n",
GBE_SYSFS_DIR_NAME);
}
}
// --------------------------------------------------
void gbe_sysfs_exit(void)
{
kobject_put(gbe_kobj);
gbe_kobj = NULL;
}
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#ifndef __GED_SYSFS_H__
#define __GED_SYSFS_H__
#include <linux/kobject.h>
//#include "gbe_type.h"
#define GBE_SYSFS_MAX_BUFF_SIZE 1024
#define KOBJ_ATTR_RW(_name) \
struct kobj_attribute kobj_attr_##_name = \
__ATTR(_name, 0660, \
_name##_show, _name##_store)
#define KOBJ_ATTR_RO(_name) \
struct kobj_attribute kobj_attr_##_name = \
__ATTR(_name, 0440, \
_name##_show, NULL)
void gbe_sysfs_create_file(struct kobj_attribute *kobj_attr);
void gbe_sysfs_remove_file(struct kobj_attribute *kobj_attr);
void gbe_sysfs_init(void);
void gbe_sysfs_exit(void);
extern struct kobject *kernel_kobj;
#endif