From ec8c8f6e331c2d3f9502c03f4a523a13e35b94de Mon Sep 17 00:00:00 2001 From: Liujie Xie Date: Mon, 24 Apr 2023 11:20:20 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add hook account_process_tick_gran this hook will allow to account tick in every third of more ticks to save cpu time for accounting Bug: 279549765 Change-Id: I5d18e0167fdce076d13aecc653dcf6387bcb25f2 Signed-off-by: Liujie Xie --- include/trace/hooks/sched.h | 4 ++++ kernel/sched/cputime.c | 11 ++++++++--- kernel/sched/vendor_hooks.c | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/trace/hooks/sched.h b/include/trace/hooks/sched.h index 5b393f5a4807..e15ce7aba0f8 100644 --- a/include/trace/hooks/sched.h +++ b/include/trace/hooks/sched.h @@ -347,6 +347,10 @@ DECLARE_HOOK(android_vh_sched_setaffinity_early, TP_PROTO(struct task_struct *p, const struct cpumask *new_mask, bool *retval), TP_ARGS(p, new_mask, retval)); +DECLARE_HOOK(android_vh_account_process_tick_gran, + TP_PROTO(int user_tick, int *ticks), + TP_ARGS(user_tick, ticks)); + /* macro versions of hooks are no longer required */ #endif /* _TRACE_HOOK_SCHED_H */ diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index a485f3b0201c..39b570d9464c 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -492,23 +492,28 @@ EXPORT_SYMBOL_GPL(thread_group_cputime_adjusted); #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE: */ /* - * Account a single tick of CPU time. + * Account a single tick or a few ticks of CPU time. * @p: the process that the CPU time gets accounted to * @user_tick: indicates if the tick is a user or a system tick */ void account_process_tick(struct task_struct *p, int user_tick) { u64 cputime, steal; + int ticks = 1; + + trace_android_vh_account_process_tick_gran(user_tick, &ticks); + if (!ticks) + return; if (vtime_accounting_enabled_this_cpu()) return; if (sched_clock_irqtime) { - irqtime_account_process_tick(p, user_tick, 1); + irqtime_account_process_tick(p, user_tick, ticks); return; } - cputime = TICK_NSEC; + cputime = TICK_NSEC * ticks; steal = steal_account_process_time(ULONG_MAX); if (steal >= cputime) diff --git a/kernel/sched/vendor_hooks.c b/kernel/sched/vendor_hooks.c index 8f8249ad1380..13009305381c 100644 --- a/kernel/sched/vendor_hooks.c +++ b/kernel/sched/vendor_hooks.c @@ -89,3 +89,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sched_pelt_multiplier); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_map_util_freq); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_cpus_allowed_comm); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sched_setaffinity_early); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_account_process_tick_gran);