Commit 2be7b16e authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Convert bch2_pd_controller_print_debug() to a printbuf

Fewer random on-stack char arrays.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent eb7bd15f
...@@ -484,36 +484,44 @@ void bch2_pd_controller_init(struct bch_pd_controller *pd) ...@@ -484,36 +484,44 @@ void bch2_pd_controller_init(struct bch_pd_controller *pd)
pd->backpressure = 1; pd->backpressure = 1;
} }
size_t bch2_pd_controller_print_debug(struct bch_pd_controller *pd, char *buf) void bch2_pd_controller_debug_to_text(struct printbuf *out, struct bch_pd_controller *pd)
{ {
/* 2^64 - 1 is 20 digits, plus null byte */ out->tabstops[0] = 20;
char rate[21];
char actual[21]; pr_buf(out, "rate:");
char target[21]; pr_tab(out);
char proportional[21]; bch2_hprint(out, pd->rate.rate);
char derivative[21]; pr_newline(out);
char change[21];
s64 next_io; pr_buf(out, "target:");
pr_tab(out);
bch2_hprint(&PBUF(rate), pd->rate.rate); bch2_hprint(out, pd->last_target);
bch2_hprint(&PBUF(actual), pd->last_actual); pr_newline(out);
bch2_hprint(&PBUF(target), pd->last_target);
bch2_hprint(&PBUF(proportional), pd->last_proportional); pr_buf(out, "actual:");
bch2_hprint(&PBUF(derivative), pd->last_derivative); pr_tab(out);
bch2_hprint(&PBUF(change), pd->last_change); bch2_hprint(out, pd->last_actual);
pr_newline(out);
next_io = div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC);
pr_buf(out, "proportional:");
return sprintf(buf, pr_tab(out);
"rate:\t\t%s/sec\n" bch2_hprint(out, pd->last_proportional);
"target:\t\t%s\n" pr_newline(out);
"actual:\t\t%s\n"
"proportional:\t%s\n" pr_buf(out, "derivative:");
"derivative:\t%s\n" pr_tab(out);
"change:\t\t%s/sec\n" bch2_hprint(out, pd->last_derivative);
"next io:\t%llims\n", pr_newline(out);
rate, target, actual, proportional,
derivative, change, next_io); pr_buf(out, "change:");
pr_tab(out);
bch2_hprint(out, pd->last_change);
pr_newline(out);
pr_buf(out, "next io:");
pr_tab(out);
pr_buf(out, "%llims", div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC));
pr_newline(out);
} }
/* misc: */ /* misc: */
......
...@@ -582,7 +582,7 @@ struct bch_pd_controller { ...@@ -582,7 +582,7 @@ struct bch_pd_controller {
void bch2_pd_controller_update(struct bch_pd_controller *, s64, s64, int); void bch2_pd_controller_update(struct bch_pd_controller *, s64, s64, int);
void bch2_pd_controller_init(struct bch_pd_controller *); void bch2_pd_controller_init(struct bch_pd_controller *);
size_t bch2_pd_controller_print_debug(struct bch_pd_controller *, char *); void bch2_pd_controller_debug_to_text(struct printbuf *, struct bch_pd_controller *);
#define sysfs_pd_controller_attribute(name) \ #define sysfs_pd_controller_attribute(name) \
rw_attribute(name##_rate); \ rw_attribute(name##_rate); \
...@@ -605,8 +605,10 @@ do { \ ...@@ -605,8 +605,10 @@ do { \
sysfs_print(name##_rate_d_term, (var)->d_term); \ sysfs_print(name##_rate_d_term, (var)->d_term); \
sysfs_print(name##_rate_p_term_inverse, (var)->p_term_inverse); \ sysfs_print(name##_rate_p_term_inverse, (var)->p_term_inverse); \
\ \
if (attr == &sysfs_##name##_rate_debug) \ if (attr == &sysfs_##name##_rate_debug) { \
return bch2_pd_controller_print_debug(var, buf); \ bch2_pd_controller_debug_to_text(&out, var); \
return out.pos - buf; \
} \
} while (0) } while (0)
#define sysfs_pd_controller_store(name, var) \ #define sysfs_pd_controller_store(name, var) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment