All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: W_Armin@gmx.de
Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 2/4] hwmon: (dell-smm) Rework SMM function debugging
Date: Sat, 14 Aug 2021 17:05:31 +0200	[thread overview]
Message-ID: <20210814150531.3ssa6dc22tqtmbdn@pali> (raw)
In-Reply-To: <20210814143637.11922-3-W_Armin@gmx.de>

On Saturday 14 August 2021 16:36:35 W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
> 
> Use IS_ENABLED() instead of #ifdef and use ktime_us_delta()
> for improved precision.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/hwmon/dell-smm-hwmon.c | 26 ++++++++++----------------
>  1 file changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
> index 68af95c1d90c..3aa09c1e4b1d 100644
> --- a/drivers/hwmon/dell-smm-hwmon.c
> +++ b/drivers/hwmon/dell-smm-hwmon.c
> @@ -158,17 +158,13 @@ static inline const char __init *i8k_get_dmi_data(int field)
>   */
>  static int i8k_smm_func(void *par)
>  {
> -	int rc;
>  	struct smm_regs *regs = par;
> -	int eax = regs->eax;
> -
> -#ifdef DEBUG
> -	int ebx = regs->ebx;
> -	unsigned long duration;
> -	ktime_t calltime, delta, rettime;
> +	int rc, eax = regs->eax, __maybe_unused ebx = regs->ebx;
> +	long long __maybe_unused duration;
> +	ktime_t __maybe_unused calltime;

I think that new coding style for declaring variables is
"reverse christmas tree", longer line before shorted line.

But here, I'm not sure if initializing more variables with its default
values should be at one line...

Also I'm not sure if usage of __maybe_unused is better than hiding
variable behind #ifdef. #ifdef guards variable to not be used when it
should not be.

> 
> -	calltime = ktime_get();
> -#endif
> +	if (IS_ENABLED(CONFIG_DEBUG))
> +		calltime = ktime_get();
> 
>  	/* SMM requires CPU 0 */
>  	if (smp_processor_id() != 0)
> @@ -230,13 +226,11 @@ static int i8k_smm_func(void *par)
>  	if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
>  		rc = -EINVAL;
> 
> -#ifdef DEBUG
> -	rettime = ktime_get();
> -	delta = ktime_sub(rettime, calltime);
> -	duration = ktime_to_ns(delta) >> 10;
> -	pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x  (took %7lu usecs)\n", eax, ebx,
> -		(rc ? 0xffff : regs->eax & 0xffff), duration);
> -#endif
> +	if (IS_ENABLED(CONFIG_DEBUG)) {
> +		duration = ktime_us_delta(ktime_get(), calltime);

But I like this ktime_us_delta() as it fixed conversion from ns to us!
Current conversion is incorrect (>>10 is /1024; but it should be /1000).

> +		pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x  (took %7lld usecs)\n", eax, ebx,
> +			 (rc ? 0xffff : regs->eax & 0xffff), duration);
> +	}
> 
>  	return rc;
>  }
> --
> 2.20.1
> 

  reply	other threads:[~2021-08-14 15:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14 14:36 [PATCH 0/4] hwmon: (dell-smm) Misc cleanups W_Armin
2021-08-14 14:36 ` [PATCH 1/4] hwmon: (dell-smm) Mark tables as __initconst W_Armin
2021-08-14 14:59   ` Pali Rohár
2021-08-14 17:49   ` Guenter Roeck
2021-08-14 14:36 ` [PATCH 2/4] hwmon: (dell-smm) Rework SMM function debugging W_Armin
2021-08-14 15:05   ` Pali Rohár [this message]
2021-08-14 15:29     ` Guenter Roeck
2021-08-14 15:39       ` Pali Rohár
2021-08-14 14:36 ` [PATCH 3/4] hwmon: (dell-smm) Enable automatic fan speed control for all channels W_Armin
2021-08-14 15:13   ` Pali Rohár
2021-08-14 15:32     ` Guenter Roeck
2021-08-14 14:36 ` [PATCH 4/4] hwmon: (dell-smm) Mark i8k_get_fan_nominal_speed as __init W_Armin
2021-08-14 14:59   ` Pali Rohár
2021-08-14 17:50   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210814150531.3ssa6dc22tqtmbdn@pali \
    --to=pali@kernel.org \
    --cc=W_Armin@gmx.de \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.