From 158c40e5ec6eb836574c36d6255aeac69338e2e0 Mon Sep 17 00:00:00 2001 From: Nikhil V Date: Mon, 11 Sep 2023 11:31:38 +0530 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks to support hibernation In case of hibernation with compression enabled, 'n' number of pages will be compressed to 'x' number of pages before being written to the disk. Keep a note of these compressed block counts so that bootloader can directly read 'x' pages and pass it on to the decompressor. An array will be maintained which will hold the count of these compressed blocks and later on written to the the disk as part of the hibernation image save process. The vendor hook '__tracepoint_android_vh_hibernated_do_mem_alloc' does the required memory allocations, for example, the array which is dynamically allocated based on the snapshot image size so as to hold the compressed block counts etc. This memory is later freed as part of PM_POST_HIBERNATION notifier call. The vendor hook '__tracepoint_android_vh_hibernate_save_cmp_len' saves the compressed block counts to the array which is later written to the disk. Bug: 335581841 Change-Id: I574b641e2d9f4cd503c7768a66a7be3142c2686b Signed-off-by: Nikhil V --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/bl_hib.h | 10 ++++++++++ kernel/power/swap.c | 14 +++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 016cd98b09bd..7135a5e45490 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -472,3 +472,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_init_adjust_zone_wmark); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_lock_folio_drop_mmap_start); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_lock_folio_drop_mmap_end); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_filemap_update_page); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_hibernated_do_mem_alloc); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_hibernate_save_cmp_len); diff --git a/include/trace/hooks/bl_hib.h b/include/trace/hooks/bl_hib.h index 50348b3e025a..7fdafa83342b 100644 --- a/include/trace/hooks/bl_hib.h +++ b/include/trace/hooks/bl_hib.h @@ -38,6 +38,16 @@ DECLARE_HOOK(android_vh_skip_swap_map_write, DECLARE_HOOK(android_vh_post_image_save, TP_PROTO(unsigned short root_swap), TP_ARGS(root_swap)); + +DECLARE_HOOK(android_vh_hibernated_do_mem_alloc, + TP_PROTO(unsigned long nr_pages, unsigned int swsusp_header_flags, + int *ret), + TP_ARGS(nr_pages, swsusp_header_flags, ret)); + +DECLARE_HOOK(android_vh_hibernate_save_cmp_len, + TP_PROTO(size_t cmp_len), + TP_ARGS(cmp_len)); + #endif /* _TRACE_HOOK_S2D_H */ /* This part must be outside protection */ #include diff --git a/kernel/power/swap.c b/kernel/power/swap.c index f3590032c18c..58f1e70ce671 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -879,6 +879,7 @@ static int save_compressed_image(struct swap_map_handle *handle, if (ret) goto out_finish; } + trace_android_vh_hibernate_save_cmp_len(data[thr].cmp_len + CMP_HEADER); } wait_event(crc->done, atomic_read_acquire(&crc->stop)); @@ -951,9 +952,20 @@ int swsusp_write(unsigned int flags) struct snapshot_handle snapshot; struct swsusp_info *header; unsigned long pages; - int error; + int error = 0; pages = snapshot_get_image_size(); + + /* + * The memory allocated by this vendor hook is later freed as part of + * PM_POST_HIBERNATION notifier call. + */ + trace_android_vh_hibernated_do_mem_alloc(pages, flags, &error); + if (error < 0) { + pr_err("Failed to allocate required memory\n"); + return error; + } + error = get_swap_writer(&handle); if (error) { pr_err("Cannot get swap writer\n");