blob: 22a2d01f57ef3b6116491502ef01a9c15dc167af [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
Daeho Jeong52118742021-08-19 20:52:28 -070011#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
Daeho Jeonga4b68172021-08-20 15:29:09 -070018enum {
19 READ_IO,
20 WRITE_SYNC_IO,
21 WRITE_ASYNC_IO,
22 MAX_IO_TYPE,
23};
24
25struct 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
Daeho Jeong52118742021-08-19 20:52:28 -070031extern int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
32 void *offset);
33extern void f2fs_reset_iostat(struct f2fs_sb_info *sbi);
34extern void f2fs_update_iostat(struct f2fs_sb_info *sbi,
35 enum iostat_type type, unsigned long long io_bytes);
Daeho Jeonga4b68172021-08-20 15:29:09 -070036
37struct 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
44static 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
53static 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
60extern void iostat_update_and_unbind_ctx(struct bio *bio, int rw);
61extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
62 struct bio *bio, struct bio_post_read_ctx *ctx);
63extern int f2fs_init_iostat_processing(void);
64extern void f2fs_destroy_iostat_processing(void);
Daeho Jeong52118742021-08-19 20:52:28 -070065extern int f2fs_init_iostat(struct f2fs_sb_info *sbi);
Daeho Jeonga4b68172021-08-20 15:29:09 -070066extern void f2fs_destroy_iostat(struct f2fs_sb_info *sbi);
Daeho Jeong52118742021-08-19 20:52:28 -070067#else
68static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
69 enum iostat_type type, unsigned long long io_bytes) {}
Daeho Jeonga4b68172021-08-20 15:29:09 -070070static inline void iostat_update_and_unbind_ctx(struct bio *bio, int rw) {}
71static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
72 struct bio *bio, struct bio_post_read_ctx *ctx) {}
73static inline void iostat_update_submit_ctx(struct bio *bio,
74 enum page_type type) {}
75static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
76{
77 return bio->bi_private;
78}
79static inline int f2fs_init_iostat_processing(void) { return 0; }
80static inline void f2fs_destroy_iostat_processing(void) {}
Daeho Jeong52118742021-08-19 20:52:28 -070081static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
Daeho Jeonga4b68172021-08-20 15:29:09 -070082static inline void f2fs_destroy_iostat(struct f2fs_sb_info *sbi) {}
Daeho Jeong52118742021-08-19 20:52:28 -070083#endif
84#endif /* __F2FS_IOSTAT_H__ */