
hulk inclusion category:feature bugzilla:https://gitee.com/openeuler/kernel/issues/IC8KS8 CVE: NA -------------------------------- Introduce mem_sampling_sched_in() to control memory sampling based on task scheduling events. This function checks whether the incoming task has an associated mm (struct mm_struct). If so, sampling is started; otherwise, it is stopped. This ensures that memory access sampling is only active for user-space tasks. This hook enables integration with task scheduling to allow fine-grained, per-task memory sampling control. Signed-off-by: Ze Zuo <zuoze1@huawei.com> Signed-off-by: Tong Tiangen <tongtiangen@huawei.com> --- include/linux/mem_sampling.h | 3 +++ mm/mem_sampling.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/mem_sampling.h b/include/linux/mem_sampling.h index cf375ad35551..573c45cc929d 100644 --- a/include/linux/mem_sampling.h +++ b/include/linux/mem_sampling.h @@ -97,5 +97,8 @@ static inline bool spe_user_is_mem_sampling(void) { return __this_cpu_read(arm_spe_user) == SPE_USER_MEM_SAMPLING; } +void mem_sampling_sched_in(struct task_struct *prev, struct task_struct *curr); +#else +static inline void mem_sampling_sched_in(struct task_struct *prev, struct task_struct *curr) { } #endif /* CONFIG_MEM_SAMPLING */ #endif /* __MEM_SAMPLING_H */ diff --git a/mm/mem_sampling.c b/mm/mem_sampling.c index e9b2e14d28f1..9ebc14dee570 100644 --- a/mm/mem_sampling.c +++ b/mm/mem_sampling.c @@ -68,6 +68,18 @@ void mem_sampling_record_cb_unregister(mem_sampling_record_cb_type cb) } } +void mem_sampling_sched_in(struct task_struct *prev, struct task_struct *curr) +{ + + if (!mem_sampling_ops.sampling_start) + return; + + if (curr->mm) + mem_sampling_ops.sampling_start(); + else + mem_sampling_ops.sampling_stop(); +} + void mem_sampling_process(void) { int i, nr_records; -- 2.25.1