2021-10-22 10:55:06

by Li Zhijian

[permalink] [raw]
Subject: [PATCH 1/2] refscale: simplify the errexit checkpoint

Signed-off-by: Li Zhijian <[email protected]>
---
kernel/rcu/refscale.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index 66dc14cf5687..2cbe2a2ba387 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -698,26 +698,25 @@ static int main_func(void *arg)
// Print the average of all experiments
SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");

- if (!errexit) {
- buf[0] = 0;
- strcat(buf, "\n");
- strcat(buf, "Runs\tTime(ns)\n");
- }
+ if (errexit)
+ goto err;
+
+ buf[0] = 0;
+ strcat(buf, "\n");
+ strcat(buf, "Runs\tTime(ns)\n");

for (exp = 0; exp < nruns; exp++) {
u64 avg;
u32 rem;

- if (errexit)
- break;
avg = div_u64_rem(result_avg[exp], 1000, &rem);
sprintf(buf1, "%d\t%llu.%03u\n", exp + 1, avg, rem);
strcat(buf, buf1);
}

- if (!errexit)
- SCALEOUT("%s", buf);
+ SCALEOUT("%s", buf);

+err:
// This will shutdown everything including us.
if (shutdown) {
shutdown_start = 1;
--
2.33.0




2021-10-22 23:13:24

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH 1/2] refscale: simplify the errexit checkpoint

On Fri, Oct 22, 2021 at 06:51:10PM +0800, Li Zhijian wrote:
> Signed-off-by: Li Zhijian <[email protected]>

Good catch!

But given that errexit is only set once at the beginning, why not
eliminate this local variable in favor of a goto at the point that it
is currently assigned to? That would permit further simplification.

Thanx, Paul

> ---
> kernel/rcu/refscale.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
> index 66dc14cf5687..2cbe2a2ba387 100644
> --- a/kernel/rcu/refscale.c
> +++ b/kernel/rcu/refscale.c
> @@ -698,26 +698,25 @@ static int main_func(void *arg)
> // Print the average of all experiments
> SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
>
> - if (!errexit) {
> - buf[0] = 0;
> - strcat(buf, "\n");
> - strcat(buf, "Runs\tTime(ns)\n");
> - }
> + if (errexit)
> + goto err;
> +
> + buf[0] = 0;
> + strcat(buf, "\n");
> + strcat(buf, "Runs\tTime(ns)\n");
>
> for (exp = 0; exp < nruns; exp++) {
> u64 avg;
> u32 rem;
>
> - if (errexit)
> - break;
> avg = div_u64_rem(result_avg[exp], 1000, &rem);
> sprintf(buf1, "%d\t%llu.%03u\n", exp + 1, avg, rem);
> strcat(buf, buf1);
> }
>
> - if (!errexit)
> - SCALEOUT("%s", buf);
> + SCALEOUT("%s", buf);
>
> +err:
> // This will shutdown everything including us.
> if (shutdown) {
> shutdown_start = 1;
> --
> 2.33.0
>
>
>

2021-10-24 13:37:09

by Li Zhijian

[permalink] [raw]
Subject: Re: [PATCH 1/2] refscale: simplify the errexit checkpoint


on 2021/10/23 7:10, Paul E. McKenney wrote:
> On Fri, Oct 22, 2021 at 06:51:10PM +0800, Li Zhijian wrote:
>> Signed-off-by: Li Zhijian <[email protected]>
> Good catch!
>
> But given that errexit is only set once at the beginning, why not
> eliminate this local variable in favor of a goto at the point that it
> is currently assigned to? That would permit further simplification.

It sounds pretty good, i will update it later.

Thanks
Zhijian


> Thanx, Paul
>
>> ---
>> kernel/rcu/refscale.c | 17 ++++++++---------
>> 1 file changed, 8 insertions(+), 9 deletions(-)
>>
>> diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
>> index 66dc14cf5687..2cbe2a2ba387 100644
>> --- a/kernel/rcu/refscale.c
>> +++ b/kernel/rcu/refscale.c
>> @@ -698,26 +698,25 @@ static int main_func(void *arg)
>> // Print the average of all experiments
>> SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
>>
>> - if (!errexit) {
>> - buf[0] = 0;
>> - strcat(buf, "\n");
>> - strcat(buf, "Runs\tTime(ns)\n");
>> - }
>> + if (errexit)
>> + goto err;
>> +
>> + buf[0] = 0;
>> + strcat(buf, "\n");
>> + strcat(buf, "Runs\tTime(ns)\n");
>>
>> for (exp = 0; exp < nruns; exp++) {
>> u64 avg;
>> u32 rem;
>>
>> - if (errexit)
>> - break;
>> avg = div_u64_rem(result_avg[exp], 1000, &rem);
>> sprintf(buf1, "%d\t%llu.%03u\n", exp + 1, avg, rem);
>> strcat(buf, buf1);
>> }
>>
>> - if (!errexit)
>> - SCALEOUT("%s", buf);
>> + SCALEOUT("%s", buf);
>>
>> +err:
>> // This will shutdown everything including us.
>> if (shutdown) {
>> shutdown_start = 1;
>> --
>> 2.33.0
>>
>>
>>
>