From 0d28ba7a343167daf6a7ccae6ce690c86fd0241c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 21 Sep 2025 18:20:37 +0000 Subject: [PATCH 1/2] Refactor: Replace gboolean with stdbool Replaced all instances of `gboolean`, `TRUE`, and `FALSE` with `bool`, `true`, and `false` from ``. This is to modernize the codebase and remove the dependency on GLib's boolean type in favor of the C standard. For GLib callbacks that required a `gboolean` return type, the function signatures have been updated to return `int` (which is what `gboolean` is a typedef for) with `1` for `true` and `0` for `false` to maintain compatibility with the GLib API, while still removing the explicit use of the `gboolean` type name. --- btstats.c | 5 +++-- statplug/d2c.c | 9 +++++---- statplug/i2c.c | 5 +++-- statplug/pluging.c | 7 ++++--- statplug/q2c.c | 7 ++++--- trace_reader/trace.c | 11 ++++++----- trace_reader/trace.h | 9 +++++---- trace_reader/trace_ata_piix.c | 17 +++++++++-------- 8 files changed, 39 insertions(+), 31 deletions(-) diff --git a/btstats.c b/btstats.c index 2dcf8a6..ab3fed4 100644 --- a/btstats.c +++ b/btstats.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -21,7 +22,7 @@ struct time_range { struct args { GHashTable *devs_ranges; - gboolean total; + bool total; char *d2c_det; unsigned trc_rdr; char *i2c_oio; @@ -189,7 +190,7 @@ void handle_args(int argc, char **argv, struct args *a) file = optarg; break; case 't': - a->total = TRUE; + a->total = true; break; case 'd': a->d2c_det = optarg; diff --git a/statplug/d2c.c b/statplug/d2c.c index 901ad7e..d1ca925 100644 --- a/statplug/d2c.c +++ b/statplug/d2c.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -42,7 +43,7 @@ static void D(struct blk_io_trace *t, void *data) } } -static void __account_reqs(struct d2c_data *d2c, gboolean finished) +static void __account_reqs(struct d2c_data *d2c, bool finished) { d2c->outstanding--; if (d2c->outstanding == 0 || finished) { @@ -124,7 +125,7 @@ static void C(struct blk_io_trace *t, void *data) g_tree_remove(d2c->prospect_ds, &dtrace->sector); g_free(dtrace); - __account_reqs(d2c, FALSE); + __account_reqs(d2c, false); } } @@ -141,7 +142,7 @@ static void R(struct blk_io_trace *t, void *data) g_tree_remove(d2c->prospect_ds, &dtrace->sector); g_free(dtrace); - __account_reqs(d2c, FALSE); + __account_reqs(d2c, false); } } @@ -157,7 +158,7 @@ void d2c_print_results(const void *data) { DECL_ASSIGN_D2C(d2c, data); - __account_reqs(d2c, TRUE); + __account_reqs(d2c, true); if (d2c->d2ctime > 0) { double t_time_msec = ((double)d2c->d2ctime) / 1e6; diff --git a/statplug/i2c.c b/statplug/i2c.c index 13f799a..3c3401b 100644 --- a/statplug/i2c.c +++ b/statplug/i2c.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -76,13 +77,13 @@ static void init_oio_data(struct oio_data *oio, int n) } } -static gboolean add_to_matrix(__u64 *__unused, struct blk_io_trace *t, +static int add_to_matrix(__u64 *__unused, struct blk_io_trace *t, struct i2c_data *i2c) { gsl_histogram_increment(i2c->oio[i2c->outstanding].op[IS_WRITE(t)], (double)(t->bytes / BLK_SIZE)); - return FALSE; + return 0; } static void oio_change(struct i2c_data *i2c, struct blk_io_trace *t, int inc) diff --git a/statplug/pluging.c b/statplug/pluging.c index 8516837..827b2ef 100644 --- a/statplug/pluging.c +++ b/statplug/pluging.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -15,7 +16,7 @@ struct pluging_data { __u64 nplugs; __u64 plug_time; - gboolean plugged; + bool plugged; }; static void P(struct blk_io_trace *t, void *data) @@ -24,7 +25,7 @@ static void P(struct blk_io_trace *t, void *data) if (!plug->plugged) { plug->plug_time = t->time; - plug->plugged = TRUE; + plug->plugged = true; } } @@ -41,7 +42,7 @@ static void U(struct blk_io_trace *t, void *data) plug->min = MIN(plug->min, time); plug->max = MAX(plug->max, time); - plug->plugged = FALSE; + plug->plugged = false; plug->plug_time = 0; } } diff --git a/statplug/q2c.c b/statplug/q2c.c index 0913b68..d583499 100644 --- a/statplug/q2c.c +++ b/statplug/q2c.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,7 @@ struct proc_q_arg { struct q2c_data *q2c; }; -static gboolean proc_q(gpointer __unused, gpointer tp, gpointer pqap) +static int proc_q(gpointer __unused, gpointer tp, gpointer pqap) { struct blk_io_trace *t = (struct blk_io_trace *)tp; struct proc_q_arg *pqa = (struct proc_q_arg *)pqap; @@ -49,9 +50,9 @@ static gboolean proc_q(gpointer __unused, gpointer tp, gpointer pqap) pqa->q2c->start = this_ts; pqa->q2c->processed++; pqa->q2c->outstanding--; - return TRUE; + return 1; } else { - return FALSE; + return 0; } } diff --git a/trace_reader/trace.c b/trace_reader/trace.c index b6f75cb..3826d46 100644 --- a/trace_reader/trace.c +++ b/trace_reader/trace.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,7 @@ void correct_time(gpointer data, gpointer dt_arg) tf->t.time -= dt->genesis; } -gboolean not_real_event(struct blk_io_trace *t) +bool not_real_event(struct blk_io_trace *t) { return (t->action & BLK_TC_ACT(BLK_TC_NOTIFY)) || (t->action & BLK_TC_ACT(BLK_TC_DISCARD)) || @@ -66,7 +67,7 @@ void read_next(struct trace_file *tf, __u64 genesis) do { e = read(tf->fd, &tf->t, sizeof(struct blk_io_trace)); if (e == 0) { - tf->eof = TRUE; + tf->eof = true; break; } else if (e == -1 || e != sizeof(struct blk_io_trace)) { perror_exit("Reading trace\n"); @@ -179,17 +180,17 @@ void trace_destroy(struct trace *dt) g_free(dt); } -gboolean trace_read_next(const struct trace *dt, struct blk_io_trace *t) +bool trace_read_next(const struct trace *dt, struct blk_io_trace *t) { struct trace_file *min = NULL; g_slist_foreach(dt->files, min_time, &min); if (!min) - return FALSE; + return false; else { *t = min->t; read_next(min, dt->genesis); - return TRUE; + return true; } } diff --git a/trace_reader/trace.h b/trace_reader/trace.h index 7cd0234..9c35e66 100644 --- a/trace_reader/trace.h +++ b/trace_reader/trace.h @@ -3,11 +3,12 @@ #include #include +#include struct trace_file { struct blk_io_trace t; int fd; - gboolean eof; + bool eof; }; struct trace { @@ -15,17 +16,17 @@ struct trace { __u64 genesis; }; -typedef gboolean (*trace_reader_t)(const struct trace *, struct blk_io_trace *); +typedef bool (*trace_reader_t)(const struct trace *, struct blk_io_trace *); /* constructor and destructor */ struct trace *trace_create(const char *dev); void trace_destroy(struct trace *dt); /* default trace reader */ -gboolean trace_read_next(const struct trace *dt, struct blk_io_trace *t); +bool trace_read_next(const struct trace *dt, struct blk_io_trace *t); /* reader for devices with ata_piix controller */ -gboolean trace_ata_piix_read_next(const struct trace *dt, +bool trace_ata_piix_read_next(const struct trace *dt, struct blk_io_trace *t); /* diff --git a/trace_reader/trace_ata_piix.c b/trace_reader/trace_ata_piix.c index 7811085..e6263d3 100644 --- a/trace_reader/trace_ata_piix.c +++ b/trace_reader/trace_ata_piix.c @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -8,22 +9,22 @@ #include static struct blk_io_trace at; -static gboolean send_p_d = FALSE; +static bool send_p_d = false; static int out_reqs = 0; static __u64 blks; -gboolean trace_ata_piix_read_next(const struct trace *dt, +bool trace_ata_piix_read_next(const struct trace *dt, struct blk_io_trace *t) { - gboolean r; + bool r; if (send_p_d) { /* if we have a pending D event, * we first send this before the next one */ *t = at; - send_p_d = FALSE; - return TRUE; + send_p_d = false; + return true; } else { reread: r = trace_read_next(dt, t); @@ -31,12 +32,12 @@ gboolean trace_ata_piix_read_next(const struct trace *dt, /* if the trace reach the end */ if (!r) - return FALSE; + return false; switch (t->action & 0xffff) { case __BLK_TA_COMPLETE: if (out_reqs == 2) { - send_p_d = TRUE; + send_p_d = true; /* setting the time to the next D * to be the time of the complete (ns) @@ -72,6 +73,6 @@ gboolean trace_ata_piix_read_next(const struct trace *dt, out_reqs -= out_reqs > 0 ? 1 : 0; break; } - return TRUE; + return true; } } From d11a30e18a48593a5bcb7ffe0574f48456031a8e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 21 Sep 2025 19:09:29 +0000 Subject: [PATCH 2/2] Refactor: Replace gboolean with stdbool Replaced all instances of `gboolean`, `TRUE`, and `FALSE` with `bool`, `true`, and `false` from ``. This is to modernize the codebase and remove the dependency on GLib's boolean type in favor of the C standard. For GLib callbacks that required a `gboolean` return type, the function signatures have been updated to use wrapper functions to handle the `bool` to `gboolean` conversion, maintaining compatibility with the GLib API. --- statplug/i2c.c | 24 ++++++++++++++++-------- statplug/q2c.c | 13 +++++++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/statplug/i2c.c b/statplug/i2c.c index 3c3401b..af0cc0f 100644 --- a/statplug/i2c.c +++ b/statplug/i2c.c @@ -77,13 +77,21 @@ static void init_oio_data(struct oio_data *oio, int n) } } -static int add_to_matrix(__u64 *__unused, struct blk_io_trace *t, - struct i2c_data *i2c) +static bool add_to_matrix_impl(gpointer __unused, gpointer t, gpointer i2c_arg) { - gsl_histogram_increment(i2c->oio[i2c->outstanding].op[IS_WRITE(t)], - (double)(t->bytes / BLK_SIZE)); + struct i2c_data *i2c = (struct i2c_data *)i2c_arg; + struct blk_io_trace *trace = (struct blk_io_trace *)t; - return 0; + gsl_histogram_increment(i2c->oio[i2c->outstanding].op[IS_WRITE(trace)], + (double)(trace->bytes / BLK_SIZE)); + + return false; +} + +static gboolean add_to_matrix_wrapper(gpointer key, gpointer value, + gpointer data) +{ + return add_to_matrix_impl(key, value, data) ? TRUE : FALSE; } static void oio_change(struct i2c_data *i2c, struct blk_io_trace *t, int inc) @@ -109,7 +117,7 @@ static void oio_change(struct i2c_data *i2c, struct blk_io_trace *t, int inc) } i2c->maxouts = MAX(i2c->maxouts, i2c->outstanding); - g_tree_foreach(i2c->is, (GTraverseFunc)add_to_matrix, i2c); + g_tree_foreach(i2c->is, add_to_matrix_wrapper, i2c); write_outs(i2c, t); } @@ -121,7 +129,7 @@ static void C(struct blk_io_trace *t, void *data) if (g_tree_lookup(i2c->is, &t->sector) != NULL) { g_tree_remove(i2c->is, &t->sector); - oio_change(i2c, t, FALSE); + oio_change(i2c, t, false); } } @@ -133,7 +141,7 @@ static void I(struct blk_io_trace *t, void *data) DECL_DUP(struct blk_io_trace, new_t, t); g_tree_insert(i2c->is, &new_t->sector, new_t); - oio_change(i2c, t, TRUE); + oio_change(i2c, t, true); } } diff --git a/statplug/q2c.c b/statplug/q2c.c index d583499..dee248b 100644 --- a/statplug/q2c.c +++ b/statplug/q2c.c @@ -37,7 +37,7 @@ struct proc_q_arg { struct q2c_data *q2c; }; -static int proc_q(gpointer __unused, gpointer tp, gpointer pqap) +static bool proc_q_impl(gpointer __unused, gpointer tp, gpointer pqap) { struct blk_io_trace *t = (struct blk_io_trace *)tp; struct proc_q_arg *pqa = (struct proc_q_arg *)pqap; @@ -50,12 +50,17 @@ static int proc_q(gpointer __unused, gpointer tp, gpointer pqap) pqa->q2c->start = this_ts; pqa->q2c->processed++; pqa->q2c->outstanding--; - return 1; + return true; } else { - return 0; + return false; } } +static gboolean proc_q_wrapper(gpointer key, gpointer value, gpointer data) +{ + return proc_q_impl(key, value, data) ? TRUE : FALSE; +} + static void restart_ongoing(struct q2c_data *q2c) { /* restart ongoing period */ @@ -72,7 +77,7 @@ static void C(struct blk_io_trace *t, void *data) if (t->time > q2c->end) q2c->end = t->time; - g_hash_table_foreach_remove(q2c->qs, proc_q, &pqa); + g_hash_table_foreach_remove(q2c->qs, proc_q_wrapper, &pqa); if (q2c->outstanding == 0 && q2c->processed > 0) { q2c->q2c_time += q2c->end - q2c->start; restart_ongoing(q2c);