152118743SDaeho Jeong /* SPDX-License-Identifier: GPL-2.0 */
252118743SDaeho Jeong /*
352118743SDaeho Jeong * Copyright 2021 Google LLC
452118743SDaeho Jeong * Author: Daeho Jeong <daehojeong@google.com>
552118743SDaeho Jeong */
652118743SDaeho Jeong #ifndef __F2FS_IOSTAT_H__
752118743SDaeho Jeong #define __F2FS_IOSTAT_H__
852118743SDaeho Jeong
9a4b68176SDaeho Jeong struct bio_post_read_ctx;
10a4b68176SDaeho Jeong
11*d9bac032SYangtao Li enum iostat_lat_type {
12*d9bac032SYangtao Li READ_IO = 0,
13a4b68176SDaeho Jeong WRITE_SYNC_IO,
14a4b68176SDaeho Jeong WRITE_ASYNC_IO,
15a4b68176SDaeho Jeong MAX_IO_TYPE,
16a4b68176SDaeho Jeong };
17a4b68176SDaeho Jeong
18*d9bac032SYangtao Li #ifdef CONFIG_F2FS_IOSTAT
19*d9bac032SYangtao Li
20*d9bac032SYangtao Li #define NUM_PREALLOC_IOSTAT_CTXS 128
21*d9bac032SYangtao Li #define DEFAULT_IOSTAT_PERIOD_MS 3000
22*d9bac032SYangtao Li #define MIN_IOSTAT_PERIOD_MS 100
23*d9bac032SYangtao Li /* maximum period of iostat tracing is 1 day */
24*d9bac032SYangtao Li #define MAX_IOSTAT_PERIOD_MS 8640000
25*d9bac032SYangtao Li
26a4b68176SDaeho Jeong struct iostat_lat_info {
27a4b68176SDaeho Jeong unsigned long sum_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* sum of io latencies */
28a4b68176SDaeho Jeong unsigned long peak_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* peak io latency */
29a4b68176SDaeho Jeong unsigned int bio_cnt[MAX_IO_TYPE][NR_PAGE_TYPE]; /* bio count */
30a4b68176SDaeho Jeong };
31a4b68176SDaeho Jeong
3252118743SDaeho Jeong extern int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
3352118743SDaeho Jeong void *offset);
3452118743SDaeho Jeong extern void f2fs_reset_iostat(struct f2fs_sb_info *sbi);
3534a23525SChao Yu extern void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode,
3652118743SDaeho Jeong enum iostat_type type, unsigned long long io_bytes);
37a4b68176SDaeho Jeong
38a4b68176SDaeho Jeong struct bio_iostat_ctx {
39a4b68176SDaeho Jeong struct f2fs_sb_info *sbi;
40a4b68176SDaeho Jeong unsigned long submit_ts;
41a4b68176SDaeho Jeong enum page_type type;
42a4b68176SDaeho Jeong struct bio_post_read_ctx *post_read_ctx;
43a4b68176SDaeho Jeong };
44a4b68176SDaeho Jeong
iostat_update_submit_ctx(struct bio * bio,enum page_type type)45a4b68176SDaeho Jeong static inline void iostat_update_submit_ctx(struct bio *bio,
46a4b68176SDaeho Jeong enum page_type type)
47a4b68176SDaeho Jeong {
48a4b68176SDaeho Jeong struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
49a4b68176SDaeho Jeong
50a4b68176SDaeho Jeong iostat_ctx->submit_ts = jiffies;
51a4b68176SDaeho Jeong iostat_ctx->type = type;
52a4b68176SDaeho Jeong }
53a4b68176SDaeho Jeong
get_post_read_ctx(struct bio * bio)54a4b68176SDaeho Jeong static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
55a4b68176SDaeho Jeong {
56a4b68176SDaeho Jeong struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
57a4b68176SDaeho Jeong
58a4b68176SDaeho Jeong return iostat_ctx->post_read_ctx;
59a4b68176SDaeho Jeong }
60a4b68176SDaeho Jeong
61*d9bac032SYangtao Li extern void iostat_update_and_unbind_ctx(struct bio *bio);
62a4b68176SDaeho Jeong extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
63a4b68176SDaeho Jeong struct bio *bio, struct bio_post_read_ctx *ctx);
64a4b68176SDaeho Jeong extern int f2fs_init_iostat_processing(void);
65a4b68176SDaeho Jeong extern void f2fs_destroy_iostat_processing(void);
6652118743SDaeho Jeong extern int f2fs_init_iostat(struct f2fs_sb_info *sbi);
67a4b68176SDaeho Jeong extern void f2fs_destroy_iostat(struct f2fs_sb_info *sbi);
6852118743SDaeho Jeong #else
f2fs_update_iostat(struct f2fs_sb_info * sbi,struct inode * inode,enum iostat_type type,unsigned long long io_bytes)6934a23525SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode,
7052118743SDaeho Jeong enum iostat_type type, unsigned long long io_bytes) {}
iostat_update_and_unbind_ctx(struct bio * bio)71*d9bac032SYangtao Li static inline void iostat_update_and_unbind_ctx(struct bio *bio) {}
iostat_alloc_and_bind_ctx(struct f2fs_sb_info * sbi,struct bio * bio,struct bio_post_read_ctx * ctx)72a4b68176SDaeho Jeong static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
73a4b68176SDaeho Jeong struct bio *bio, struct bio_post_read_ctx *ctx) {}
iostat_update_submit_ctx(struct bio * bio,enum page_type type)74a4b68176SDaeho Jeong static inline void iostat_update_submit_ctx(struct bio *bio,
75a4b68176SDaeho Jeong enum page_type type) {}
get_post_read_ctx(struct bio * bio)76a4b68176SDaeho Jeong static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
77a4b68176SDaeho Jeong {
78a4b68176SDaeho Jeong return bio->bi_private;
79a4b68176SDaeho Jeong }
f2fs_init_iostat_processing(void)80a4b68176SDaeho Jeong static inline int f2fs_init_iostat_processing(void) { return 0; }
f2fs_destroy_iostat_processing(void)81a4b68176SDaeho Jeong static inline void f2fs_destroy_iostat_processing(void) {}
f2fs_init_iostat(struct f2fs_sb_info * sbi)8252118743SDaeho Jeong static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
f2fs_destroy_iostat(struct f2fs_sb_info * sbi)83a4b68176SDaeho Jeong static inline void f2fs_destroy_iostat(struct f2fs_sb_info *sbi) {}
8452118743SDaeho Jeong #endif
8552118743SDaeho Jeong #endif /* __F2FS_IOSTAT_H__ */
86