[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240625100817.078318bf@rorschach.local.home>
Date: Tue, 25 Jun 2024 10:08:17 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: Akinobu Mita <akinobu.mita@...il.com>, Christoph Lameter <cl@...ux.com>,
David Rientjes <rientjes@...gle.com>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko
<andrii@...nel.org>, "Naveen N. Rao" <naveen.n.rao@...ux.ibm.com>, Anil S
Keshavamurthy <anil.s.keshavamurthy@...el.com>, "David S. Miller"
<davem@...emloft.net>, Masami Hiramatsu <mhiramat@...nel.org>, Mark Rutland
<mark.rutland@....com>, Jiri Olsa <jolsa@...nel.org>, Roman Gushchin
<roman.gushchin@...ux.dev>, Hyeonggon Yoo <42.hyeyoo@...il.com>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org, bpf@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/7] fault-inject: add support for static keys around
fault injection sites
On Thu, 20 Jun 2024 00:48:55 +0200
Vlastimil Babka <vbabka@...e.cz> wrote:
> +static int debugfs_prob_set(void *data, u64 val)
> +{
> + struct fault_attr *attr = data;
> +
> + mutex_lock(&probability_mutex);
> +
> + if (attr->active) {
> + if (attr->probability != 0 && val == 0) {
> + static_key_slow_dec(attr->active);
> + } else if (attr->probability == 0 && val != 0) {
> + static_key_slow_inc(attr->active);
> + }
> + }
So basically the above is testing if val to probability is going from
zero or non-zero. For such cases, I find it less confusing to have:
if (attr->active) {
if (!!attr->probability != !!val) {
if (val)
static_key_slow_inc(attr->active);
else
static_key_slow_dec(attr->active);
}
}
This does add a layer of nested ifs, but IMO it's a bit more clear in
what is happening, and it gets rid of the "else if".
Not saying you need to change it. This is more of an FYI.
-- Steve
> +
> + attr->probability = val;
> +
> + mutex_unlock(&probability_mutex);
> +
> + return 0;
> +}
Powered by blists - more mailing lists