ANDROID: GKI: add percpu_rwsem vendor hooks

When a writer has set sem->block and is waiting for active readers
to complete, we still allow some specific new readers to entry
the critical section, which can help prevent priority inversion
from impacting system responsiveness and performance.

Bug: 334851707

Change-Id: I9e2a7df1efb326763487423d64bcf74d8dec23f8
Signed-off-by: zhujingpeng <zhujingpeng@vivo.com>
(cherry picked from commit 458cdb59f7719f81504d392daa95a8c99c30c276)
(cherry picked from commit b74701f8daa1a415c3ea2e819237d1bff59736eb)
This commit is contained in:
zhujingpeng 2024-04-15 21:22:50 +08:00 committed by Treehugger Robot
parent 2521fb1dd7
commit 8884166229
3 changed files with 25 additions and 1 deletions

View File

@ -551,6 +551,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_uprobes_replace_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_record_rwsem_reader_owned);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_clear_rwsem_reader_owned);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_clear_rwsem_writer_owned);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_percpu_rwsem_down_read);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_percpu_rwsem_up_write);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_percpu_rwsem_wait_complete);
/*
* For type visibility
*/

View File

@ -103,6 +103,15 @@ struct percpu_rw_semaphore;
DECLARE_HOOK(android_vh_percpu_rwsem_wq_add,
TP_PROTO(struct percpu_rw_semaphore *sem, bool reader),
TP_ARGS(sem, reader));
DECLARE_HOOK(android_vh_percpu_rwsem_down_read,
TP_PROTO(struct percpu_rw_semaphore *sem, bool try, bool *ret),
TP_ARGS(sem, try, ret));
DECLARE_HOOK(android_vh_percpu_rwsem_up_write,
TP_PROTO(struct percpu_rw_semaphore *sem),
TP_ARGS(sem));
DECLARE_RESTRICTED_HOOK(android_rvh_percpu_rwsem_wait_complete,
TP_PROTO(struct percpu_rw_semaphore *sem, long state, bool *complete),
TP_ARGS(sem, state, complete), 1);
DECLARE_HOOK(android_vh_exit_check,
TP_PROTO(struct task_struct *tsk, long code, int group_dead),

View File

@ -181,9 +181,15 @@ static void percpu_rwsem_wait(struct percpu_rw_semaphore *sem, bool reader)
bool __percpu_down_read(struct percpu_rw_semaphore *sem, bool try)
{
bool ret = false;
if (__percpu_down_read_trylock(sem))
return true;
trace_android_vh_percpu_rwsem_down_read(sem, try, &ret);
if (ret)
return true;
if (try)
return false;
@ -230,6 +236,8 @@ static bool readers_active_check(struct percpu_rw_semaphore *sem)
void percpu_down_write(struct percpu_rw_semaphore *sem)
{
bool complete = false;
might_sleep();
rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
@ -252,7 +260,9 @@ void percpu_down_write(struct percpu_rw_semaphore *sem)
*/
/* Wait for all active readers to complete. */
rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE);
trace_android_rvh_percpu_rwsem_wait_complete(sem, TASK_UNINTERRUPTIBLE, &complete);
if (!complete)
rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE);
trace_android_vh_record_pcpu_rwsem_starttime(current, jiffies);
}
EXPORT_SYMBOL_GPL(percpu_down_write);
@ -261,6 +271,8 @@ void percpu_up_write(struct percpu_rw_semaphore *sem)
{
rwsem_release(&sem->dep_map, _RET_IP_);
trace_android_vh_percpu_rwsem_up_write(sem);
/*
* Signal the writer is done, no fast path yet.
*