ANDROID: vendor_hooks: Add hooks for oem futex optimization

If an important task is going to sleep through do_futex(),
find out it's futex-owner by the pid comes from userspace,
and boost the owner by some means to shorten the sleep time.
How to boost? Depends on these hooks:
commit 53e809978443 ("ANDROID: vendor_hooks: Add hooks for scheduler")

Bug: 243110112
Signed-off-by: xieliujie <xieliujie@oppo.com>
Change-Id: I9a315cfb414fd34e0ef7a2cf9d57df50d4dd984f
This commit is contained in:
xieliujie
2025-02-12 14:45:59 +08:00
committed by Treehugger Robot
parent 501e135ecf
commit 4f417c9c41
4 changed files with 40 additions and 0 deletions
+7
View File
@@ -7,6 +7,7 @@
*/ */
#include <linux/iova.h> #include <linux/iova.h>
#include <linux/pm_qos.h> #include <linux/pm_qos.h>
#include <linux/futex.h>
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
#include <trace/hooks/vendor_hooks.h> #include <trace/hooks/vendor_hooks.h>
@@ -254,6 +255,12 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_hibernation_swap);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_cpu_resume); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_cpu_resume);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_hib_resume_bdev); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_hib_resume_bdev);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_futex_plist_add); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_futex_plist_add);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_futex);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_futex_wait_start);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_futex_wait_end);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_futex_wake_traverse_plist);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_futex_wake_this);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_futex_wake_up_q_finish);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_report_bug); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_report_bug);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_logbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_logbuf);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_acct_update_power); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_acct_update_power);
+24
View File
@@ -17,6 +17,30 @@ DECLARE_HOOK(android_vh_alter_futex_plist_add,
struct plist_head *head, struct plist_head *head,
bool *already_on_hb), bool *already_on_hb),
TP_ARGS(node, head, already_on_hb)); TP_ARGS(node, head, already_on_hb));
DECLARE_HOOK(android_vh_do_futex,
TP_PROTO(int cmd,
unsigned int *flags,
u32 __user *uaddr2),
TP_ARGS(cmd, flags, uaddr2));
DECLARE_HOOK(android_vh_futex_wait_start,
TP_PROTO(unsigned int flags,
u32 bitset),
TP_ARGS(flags, bitset));
DECLARE_HOOK(android_vh_futex_wait_end,
TP_PROTO(unsigned int flags,
u32 bitset),
TP_ARGS(flags, bitset));
DECLARE_HOOK(android_vh_futex_wake_traverse_plist,
TP_PROTO(struct plist_head *chain, int *target_nr,
union futex_key key, u32 bitset),
TP_ARGS(chain, target_nr, key, bitset));
DECLARE_HOOK(android_vh_futex_wake_this,
TP_PROTO(int ret, int nr_wake, int target_nr,
struct task_struct *p),
TP_ARGS(ret, nr_wake, target_nr, p));
DECLARE_HOOK(android_vh_futex_wake_up_q_finish,
TP_PROTO(int nr_wake, int target_nr),
TP_ARGS(nr_wake, target_nr));
#endif /* _TRACE_HOOK_FUTEX_H */ #endif /* _TRACE_HOOK_FUTEX_H */
/* This part must be outside protection */ /* This part must be outside protection */
#include <trace/define_trace.h> #include <trace/define_trace.h>
+2
View File
@@ -4,6 +4,7 @@
#include <linux/time_namespace.h> #include <linux/time_namespace.h>
#include "futex.h" #include "futex.h"
#include <trace/hooks/futex.h>
/* /*
* Support for robust futexes: the kernel cleans up held futexes at * Support for robust futexes: the kernel cleans up held futexes at
@@ -94,6 +95,7 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
return -ENOSYS; return -ENOSYS;
} }
trace_android_vh_do_futex(cmd, &flags, uaddr2);
switch (cmd) { switch (cmd) {
case FUTEX_WAIT: case FUTEX_WAIT:
val3 = FUTEX_BITSET_MATCH_ANY; val3 = FUTEX_BITSET_MATCH_ANY;
+7
View File
@@ -6,6 +6,7 @@
#include <linux/freezer.h> #include <linux/freezer.h>
#include "futex.h" #include "futex.h"
#include <trace/hooks/futex.h>
/* /*
* READ this before attempting to hack on futexes! * READ this before attempting to hack on futexes!
@@ -159,6 +160,7 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
union futex_key key = FUTEX_KEY_INIT; union futex_key key = FUTEX_KEY_INIT;
DEFINE_WAKE_Q(wake_q); DEFINE_WAKE_Q(wake_q);
int ret; int ret;
int target_nr;
if (!bitset) if (!bitset)
return -EINVAL; return -EINVAL;
@@ -178,6 +180,7 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
spin_lock(&hb->lock); spin_lock(&hb->lock);
trace_android_vh_futex_wake_traverse_plist(&hb->chain, &target_nr, key, bitset);
plist_for_each_entry_safe(this, next, &hb->chain, list) { plist_for_each_entry_safe(this, next, &hb->chain, list) {
if (futex_match (&this->key, &key)) { if (futex_match (&this->key, &key)) {
if (this->pi_state || this->rt_waiter) { if (this->pi_state || this->rt_waiter) {
@@ -189,6 +192,7 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
if (!(this->bitset & bitset)) if (!(this->bitset & bitset))
continue; continue;
trace_android_vh_futex_wake_this(ret, nr_wake, target_nr, this->task);
this->wake(&wake_q, this); this->wake(&wake_q, this);
if (++ret >= nr_wake) if (++ret >= nr_wake)
break; break;
@@ -197,6 +201,7 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
spin_unlock(&hb->lock); spin_unlock(&hb->lock);
wake_up_q(&wake_q); wake_up_q(&wake_q);
trace_android_vh_futex_wake_up_q_finish(nr_wake, target_nr);
return ret; return ret;
} }
@@ -691,6 +696,7 @@ int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time
struct restart_block *restart; struct restart_block *restart;
int ret; int ret;
trace_android_vh_futex_wait_start(flags, bitset);
to = futex_setup_timer(abs_time, &timeout, flags, to = futex_setup_timer(abs_time, &timeout, flags,
current->timer_slack_ns); current->timer_slack_ns);
@@ -714,6 +720,7 @@ int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time
return set_restart_fn(restart, futex_wait_restart); return set_restart_fn(restart, futex_wait_restart);
} }
trace_android_vh_futex_wait_end(flags, bitset);
return ret; return ret;
} }