blob: eb99d05cf27273be29a53078788c4ba3dd4c9a85 [file] [log] [blame]
Daeho Jeong52118742021-08-19 20:52:28 -07001/* 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
Daeho Jeonga4b68172021-08-20 15:29:09 -07009struct bio_post_read_ctx;
10
Yangtao Lid9bac032023-02-01 18:47:02 +080011enum iostat_lat_type {
12 READ_IO = 0,
Daeho Jeonga4b68172021-08-20 15:29:09 -070013 WRITE_SYNC_IO,
14 WRITE_ASYNC_IO,
15 MAX_IO_TYPE,
16};
17
Yangtao Lid9bac032023-02-01 18:47:02 +080018#ifdef CONFIG_F2FS_IOSTAT
19
20#define NUM_PREALLOC_IOSTAT_CTXS 128
21#define DEFAULT_IOSTAT_PERIOD_MS 3000
22#define MIN_IOSTAT_PERIOD_MS 100
23/* maximum period of iostat tracing is 1 day */
24#define MAX_IOSTAT_PERIOD_MS 8640000
25
Daeho Jeonga4b68172021-08-20 15:29:09 -070026struct iostat_lat_info {
27 unsigned long sum_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* sum of io latencies */
28 unsigned long peak_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* peak io latency */
29 unsigned int bio_cnt[MAX_IO_TYPE][NR_PAGE_TYPE]; /* bio count */
30};
31
Daeho Jeong52118742021-08-19 20:52:28 -070032extern int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
33 void *offset);
34extern void f2fs_reset_iostat(struct f2fs_sb_info *sbi);
Chao Yu34a23522022-08-20 11:04:41 +080035extern void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode,
Daeho Jeong52118742021-08-19 20:52:28 -070036 enum iostat_type type, unsigned long long io_bytes);
Daeho Jeonga4b68172021-08-20 15:29:09 -070037
38struct bio_iostat_ctx {
39 struct f2fs_sb_info *sbi;
40 unsigned long submit_ts;
41 enum page_type type;
42 struct bio_post_read_ctx *post_read_ctx;
43};
44
45static inline void iostat_update_submit_ctx(struct bio *bio,
46 enum page_type type)
47{
48 struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
49
50 iostat_ctx->submit_ts = jiffies;
51 iostat_ctx->type = type;
52}
53
54static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
55{
56 struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
57
58 return iostat_ctx->post_read_ctx;
59}
60
Yangtao Lid9bac032023-02-01 18:47:02 +080061extern void iostat_update_and_unbind_ctx(struct bio *bio);
Daeho Jeonga4b68172021-08-20 15:29:09 -070062extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
63 struct bio *bio, struct bio_post_read_ctx *ctx);
64extern int f2fs_init_iostat_processing(void);
65extern void f2fs_destroy_iostat_processing(void);
Daeho Jeong52118742021-08-19 20:52:28 -070066extern int f2fs_init_iostat(struct f2fs_sb_info *sbi);
Daeho Jeonga4b68172021-08-20 15:29:09 -070067extern void f2fs_destroy_iostat(struct f2fs_sb_info *sbi);
Daeho Jeong52118742021-08-19 20:52:28 -070068#else
Chao Yu34a23522022-08-20 11:04:41 +080069static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode,
Daeho Jeong52118742021-08-19 20:52:28 -070070 enum iostat_type type, unsigned long long io_bytes) {}
Yangtao Lid9bac032023-02-01 18:47:02 +080071static inline void iostat_update_and_unbind_ctx(struct bio *bio) {}
Daeho Jeonga4b68172021-08-20 15:29:09 -070072static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
73 struct bio *bio, struct bio_post_read_ctx *ctx) {}
74static inline void iostat_update_submit_ctx(struct bio *bio,
75 enum page_type type) {}
76static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
77{
78 return bio->bi_private;
79}
80static inline int f2fs_init_iostat_processing(void) { return 0; }
81static inline void f2fs_destroy_iostat_processing(void) {}
Daeho Jeong52118742021-08-19 20:52:28 -070082static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
Daeho Jeonga4b68172021-08-20 15:29:09 -070083static inline void f2fs_destroy_iostat(struct f2fs_sb_info *sbi) {}
Daeho Jeong52118742021-08-19 20:52:28 -070084#endif
85#endif /* __F2FS_IOSTAT_H__ */