All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Mario Limonciello <superm1@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>, Jonathan Corbet <corbet@lwn.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H . Peter Anvin" <hpa@zytor.com>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Yazen Ghannam <yazen.ghannam@amd.com>,
	Mario Limonciello <mario.limonciello@amd.com>
Subject: Re: [PATCH v2 2/2] x86/CPU/AMD: Print the reason for the last reset
Date: Tue, 8 Apr 2025 22:31:15 +0200	[thread overview]
Message-ID: <Z_WHk4jP0inUSt7T@gmail.com> (raw)
In-Reply-To: <20250408174726.3999817-2-superm1@kernel.org>


* Mario Limonciello <superm1@kernel.org> wrote:

> +static inline char *get_s5_reset_reason(u32 value)
> +{
> +	if (value & BIT(0))
> +		return "trip of thermal pin BP_THERMTRIP_L";
> +	if (value & BIT(1))
> +		return "power button";
> +	if (value & BIT(2))
> +		return "shutdown pin";
> +	if (value & BIT(4))
> +		return "remote ASF power off command";
> +	if (value & BIT(9))
> +		return "internal CPU thermal trip";
> +	if (value & BIT(16))
> +		return "user reset via BP_SYS_RST_L pin";
> +	if (value & BIT(17))
> +		return "PCI reset";
> +	if (value & BIT(18) ||
> +	    value & BIT(19) ||
> +	    value & BIT(20))
> +		return "CF9 reset";
> +	if (value & BIT(21))
> +		return "power state of acpi state transition";
> +	if (value & BIT(22))
> +		return "keyboard reset pin KB_RST_L";
> +	if (value & BIT(23))
> +		return "internal CPU shutdown";
> +	if (value & BIT(24))
> +		return "failed boot timer";
> +	if (value & BIT(25))
> +		return "watchdog timer";
> +	if (value & BIT(26))
> +		return "remote ASF reset command";
> +	if (value & BIT(27))
> +		return "data fabric sync flood event due to uncorrected error";
> +	if (value & BIT(29))
> +		return "MP1 watchdog timer timeout";
> +	if (value & BIT(30))
> +		return "parity error";
> +	if (value & BIT(31))
> +		return "software sync flood event";
> +	return "unknown reason";

Can multiple bits be set in principle, belonging to different reasons?

Also, wouldn't a clean, readable text array and find_first_bit() result 
in more readable and more maintainable code?

Which can be initialized thusly:

  static const char *s6_reset_reason_txt[] = {

	[0] = "trip of thermal pin BP_THERMTRIP_L",
	[1] = "power button",
	[2] = "shutdown pin",
	[4] = "remote ASF power off command",
	[9] = "internal CPU thermal trip",
	...

  };

Also the text should probably be expanded into standard noun+verb 
sentences or so, to make it all less ambiguous:

  static const char *s6_reset_reason_txt[] = {

	[0] = "thermal pin BP_THERMTRIP_L was tripped",
	[1] = "power button was pressed",
	[2] = "shutdown pin was shorted",
	[4] = "remote ASF power off command was received",
	[9] = "internal CPU thermal limit was tripped",
	...
  };

etc. Note the deliberate use of past tense, to make it clear this 
refers to a previous event, while usually syslog events indicate 
current events.

> +	/*
> +	 * FCH::PM::S5_RESET_STATUS
> +	 * PM Base = 0xFED80300
> +	 * S5_RESET_STATUS offset = 0xC0
> +	 */
> +	addr = ioremap(0xFED803C0, sizeof(value));

0xFED803C0 is a magic number, please define a symbol for it.

> +	if (!addr)
> +		return 0;
> +	value = ioread32(addr);
> +	iounmap(addr);
> +
> +	pr_info("System was reset due to %s (0x%08x)\n",
> +		get_s5_reset_reason(value), value);

Please make the source of this printout a bit more specific, something 
like:

      x86/amd/Fam17h: Previous system reset reason [%0x08x]: %s

or so? Also note how grepped output will be easier to read due to 
flipping the fixed-width numeric and the variable-length text output:

 # Before:

        x86/amd/Fam17h: Previous system reset reason: thermal pin BP_THERMTRIP_L was tripped (0x00000001)
        x86/amd/Fam17h: Previous system reset reason: power button was pressed (0x00000002)
        x86/amd/Fam17h: Previous system reset reason: shutdown pin was shorted (0x00000004)
        x86/amd/Fam17h: Previous system reset reason: remote ASF power off command was received (0x00000010)
        x86/amd/Fam17h: Previous system reset reason: internal CPU thermal limit was tripped (0x00000200)

 # After:

        x86/amd/Fam17h: Previous system reset reason: [0x00000001]: thermal pin BP_THERMTRIP_L was tripped
        x86/amd/Fam17h: Previous system reset reason: [0x00000002]: power button was pressed
        x86/amd/Fam17h: Previous system reset reason: [0x00000004]: shutdown pin was shorted
        x86/amd/Fam17h: Previous system reset reason: [0x00000010]: remote ASF power off command was received
        x86/amd/Fam17h: Previous system reset reason: [0x00000200]: internal CPU thermal limit was tripped

Thanks,

	Ingo

      parent reply	other threads:[~2025-04-08 20:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 17:47 [PATCH v2 1/2] Documentation: Add AMD Zen debugging document Mario Limonciello
2025-04-08 17:47 ` [PATCH v2 2/2] x86/CPU/AMD: Print the reason for the last reset Mario Limonciello
2025-04-08 18:14   ` Borislav Petkov
2025-04-08 18:19     ` Mario Limonciello
2025-04-08 18:28       ` Dave Hansen
2025-04-08 18:34         ` Mario Limonciello
2025-04-08 19:00       ` Borislav Petkov
2025-04-08 20:31   ` Ingo Molnar [this message]

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=Z_WHk4jP0inUSt7T@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mingo@redhat.com \
    --cc=superm1@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yazen.ghannam@amd.com \
    /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.