1 /* SPDX-License-Identifier: GPL-2.0
3 * Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT.
4 * Do not use in new code.
6 #include "blk-cgroup-rwstat.h"
8 int blkg_rwstat_init(struct blkg_rwstat
*rwstat
, gfp_t gfp
)
12 ret
= percpu_counter_init_many(rwstat
->cpu_cnt
, 0, gfp
, BLKG_RWSTAT_NR
);
16 for (i
= 0; i
< BLKG_RWSTAT_NR
; i
++)
17 atomic64_set(&rwstat
->aux_cnt
[i
], 0);
20 EXPORT_SYMBOL_GPL(blkg_rwstat_init
);
22 void blkg_rwstat_exit(struct blkg_rwstat
*rwstat
)
24 percpu_counter_destroy_many(rwstat
->cpu_cnt
, BLKG_RWSTAT_NR
);
26 EXPORT_SYMBOL_GPL(blkg_rwstat_exit
);
29 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
30 * @sf: seq_file to print to
31 * @pd: policy private data of interest
32 * @rwstat: rwstat to print
34 * Print @rwstat to @sf for the device assocaited with @pd.
36 u64
__blkg_prfill_rwstat(struct seq_file
*sf
, struct blkg_policy_data
*pd
,
37 const struct blkg_rwstat_sample
*rwstat
)
39 static const char *rwstr
[] = {
40 [BLKG_RWSTAT_READ
] = "Read",
41 [BLKG_RWSTAT_WRITE
] = "Write",
42 [BLKG_RWSTAT_SYNC
] = "Sync",
43 [BLKG_RWSTAT_ASYNC
] = "Async",
44 [BLKG_RWSTAT_DISCARD
] = "Discard",
46 const char *dname
= blkg_dev_name(pd
->blkg
);
53 for (i
= 0; i
< BLKG_RWSTAT_NR
; i
++)
54 seq_printf(sf
, "%s %s %llu\n", dname
, rwstr
[i
],
57 v
= rwstat
->cnt
[BLKG_RWSTAT_READ
] +
58 rwstat
->cnt
[BLKG_RWSTAT_WRITE
] +
59 rwstat
->cnt
[BLKG_RWSTAT_DISCARD
];
60 seq_printf(sf
, "%s Total %llu\n", dname
, v
);
63 EXPORT_SYMBOL_GPL(__blkg_prfill_rwstat
);
66 * blkg_prfill_rwstat - prfill callback for blkg_rwstat
67 * @sf: seq_file to print to
68 * @pd: policy private data of interest
69 * @off: offset to the blkg_rwstat in @pd
71 * prfill callback for printing a blkg_rwstat.
73 u64
blkg_prfill_rwstat(struct seq_file
*sf
, struct blkg_policy_data
*pd
,
76 struct blkg_rwstat_sample rwstat
= { };
78 blkg_rwstat_read((void *)pd
+ off
, &rwstat
);
79 return __blkg_prfill_rwstat(sf
, pd
, &rwstat
);
81 EXPORT_SYMBOL_GPL(blkg_prfill_rwstat
);
84 * blkg_rwstat_recursive_sum - collect hierarchical blkg_rwstat
85 * @blkg: blkg of interest
86 * @pol: blkcg_policy which contains the blkg_rwstat
87 * @off: offset to the blkg_rwstat in blkg_policy_data or @blkg
88 * @sum: blkg_rwstat_sample structure containing the results
90 * Collect the blkg_rwstat specified by @blkg, @pol and @off and all its
91 * online descendants and their aux counts. The caller must be holding the
92 * queue lock for online tests.
94 * If @pol is NULL, blkg_rwstat is at @off bytes into @blkg; otherwise, it
95 * is at @off bytes into @blkg's blkg_policy_data of the policy.
97 void blkg_rwstat_recursive_sum(struct blkcg_gq
*blkg
, struct blkcg_policy
*pol
,
98 int off
, struct blkg_rwstat_sample
*sum
)
100 struct blkcg_gq
*pos_blkg
;
101 struct cgroup_subsys_state
*pos_css
;
104 lockdep_assert_held(&blkg
->q
->queue_lock
);
106 memset(sum
, 0, sizeof(*sum
));
108 blkg_for_each_descendant_pre(pos_blkg
, pos_css
, blkg
) {
109 struct blkg_rwstat
*rwstat
;
111 if (!pos_blkg
->online
)
115 rwstat
= (void *)blkg_to_pd(pos_blkg
, pol
) + off
;
117 rwstat
= (void *)pos_blkg
+ off
;
119 for (i
= 0; i
< BLKG_RWSTAT_NR
; i
++)
120 sum
->cnt
[i
] += blkg_rwstat_read_counter(rwstat
, i
);
124 EXPORT_SYMBOL_GPL(blkg_rwstat_recursive_sum
);