xref: /openbmc/linux/fs/f2fs/iostat.h (revision 0ca37273)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2021 Google LLC
4  * Author: Daeho Jeong <daehojeong@google.com>
5  */
6 #ifndef __F2FS_IOSTAT_H__
7 #define __F2FS_IOSTAT_H__
8 
9 struct bio_post_read_ctx;
10 
11 #ifdef CONFIG_F2FS_IOSTAT
12 
13 #define DEFAULT_IOSTAT_PERIOD_MS	3000
14 #define MIN_IOSTAT_PERIOD_MS		100
15 /* maximum period of iostat tracing is 1 day */
16 #define MAX_IOSTAT_PERIOD_MS		8640000
17 
18 enum {
19 	READ_IO,
20 	WRITE_SYNC_IO,
21 	WRITE_ASYNC_IO,
22 	MAX_IO_TYPE,
23 };
24 
25 struct iostat_lat_info {
26 	unsigned long sum_lat[MAX_IO_TYPE][NR_PAGE_TYPE];	/* sum of io latencies */
27 	unsigned long peak_lat[MAX_IO_TYPE][NR_PAGE_TYPE];	/* peak io latency */
28 	unsigned int bio_cnt[MAX_IO_TYPE][NR_PAGE_TYPE];	/* bio count */
29 };
30 
31 extern int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
32 			void *offset);
33 extern void f2fs_reset_iostat(struct f2fs_sb_info *sbi);
34 extern void f2fs_update_iostat(struct f2fs_sb_info *sbi,
35 			enum iostat_type type, unsigned long long io_bytes);
36 
37 struct bio_iostat_ctx {
38 	struct f2fs_sb_info *sbi;
39 	unsigned long submit_ts;
40 	enum page_type type;
41 	struct bio_post_read_ctx *post_read_ctx;
42 };
43 
44 static inline void iostat_update_submit_ctx(struct bio *bio,
45 			enum page_type type)
46 {
47 	struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
48 
49 	iostat_ctx->submit_ts = jiffies;
50 	iostat_ctx->type = type;
51 }
52 
53 static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
54 {
55 	struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
56 
57 	return iostat_ctx->post_read_ctx;
58 }
59 
60 extern void iostat_update_and_unbind_ctx(struct bio *bio, int rw);
61 extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
62 		struct bio *bio, struct bio_post_read_ctx *ctx);
63 extern int f2fs_init_iostat_processing(void);
64 extern void f2fs_destroy_iostat_processing(void);
65 extern int f2fs_init_iostat(struct f2fs_sb_info *sbi);
66 extern void f2fs_destroy_iostat(struct f2fs_sb_info *sbi);
67 #else
68 static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
69 		enum iostat_type type, unsigned long long io_bytes) {}
70 static inline void iostat_update_and_unbind_ctx(struct bio *bio, int rw) {}
71 static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
72 		struct bio *bio, struct bio_post_read_ctx *ctx) {}
73 static inline void iostat_update_submit_ctx(struct bio *bio,
74 		enum page_type type) {}
75 static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
76 {
77 	return bio->bi_private;
78 }
79 static inline int f2fs_init_iostat_processing(void) { return 0; }
80 static inline void f2fs_destroy_iostat_processing(void) {}
81 static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
82 static inline void f2fs_destroy_iostat(struct f2fs_sb_info *sbi) {}
83 #endif
84 #endif /* __F2FS_IOSTAT_H__ */
85