Author Topic: An XWorkplace CPU Temperature Widget for AMD CPUs  (Read 10006 times)

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
An XWorkplace CPU Temperature Widget for AMD CPUs
« on: March 02, 2025, 02:39:56 pm »
I am using XWorkplace 1.0.17 and recently I added the "CPU temperature" widget to XCenter to keep track of CPU temperature.
Unfortunately, it will always display 0 °C.
I am using an AMD CPU and I suppose, that is the problem. Needless to say that I have ACPI installed and working (but ACPI power management turned off, see below).

I have no clue what widget DLL implements the CPU temp widget and I don't know where I can find the source code.
1) can someone point me to the source code ? That could be my starting point of implementing a widget
2) does the existing widget build upon ACPI functionality to query temperature ? If yes, then I would suspect that this functionality does not work for AMD CPUs but I don't know. Does anyone have any insight ?
3) I currently have ACPI power management turned off (for performance reasons). Does power management have to be active so that CPU temperature can be queried via ACPI (if ACPI is involved) ?


Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #1 on: March 02, 2025, 03:10:20 pm »
In the meantime, I found the source code for the CPU Temperature Widget.
It uses ACPI to query temperature. I consequently tried "acpistat.exe" to see what it returns:

Quote
Thermal information:
  No Thermal information is available for this computer

Question is: why does ACPI not offer temp check ? When I start the computer, I can go into its BIOS and it will give me extended temperature info for CPU as well as for MB. Does that mean that querying the temperature is specific for this board and not covered by what ACPI offers ?

Enabling ACPI power management did not make a bit of a difference.

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1421
  • Karma: +28/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #2 on: March 02, 2025, 04:25:52 pm »
Hey Lars!

I am using XWorkplace 1.0.17 and recently I added the "CPU temperature" widget to XCenter to keep track of CPU temperature.
Unfortunately, it will always display 0 °C.
I am using an AMD CPU and I suppose, that is the problem. Needless to say that I have ACPI installed and working (but ACPI power management turned off, see below).

So as I understood the whole ACPI ecosystem it is not necessary for things like power management to be activated in order for the hardware to report runtime metrics.

Whether it is Intel, AMD or others (CPUs or chipsets) so long as the motherboard vendor implements the proper ACPI functionality, the subsequent OS or APP software should have the ability to query the various ACPI components.

Take a look at the officials specs https://uefi.org/specifications, ACPI is at 6.5a level now. They also show a good number of technical/whitepaper docs on there that help with digesting all of this.

I have no clue what widget DLL implements the CPU temp widget and I don't know where I can find the source code.
1) can someone point me to the source code ? That could be my starting point of implementing a widget

OK, so when installing ACPI support you have the option of installing the ACPI Toolkit. In my case the stuff sits in \acpi\toolkit where you'll find the header files, libs, some docs and a good measure of sample code.

2) does the existing widget build upon ACPI functionality to query temperature ? If yes, then I would suspect that this functionality does not work for AMD CPUs but I don't know. Does anyone have any insight ?

Great topic, so in the other thread (CPU shutdown) I mentioned that I was trying to digest the ACPI framework in order to expose this information, basically thinking along the lines of what you articulated in your post here.

So far here is how all of it appear to glue together using the TEMPERATURE topic as an example (this is very much WIP on my part, so I'm sure I'm missing some stuff and most likely misunderstanding things):

1) in the \acpi\toolkit\samples directory look at the acpitree.c code, where you'll find this section:

Code: [Select]
    if (DevInfo->Type == ACPI_TYPE_THERMAL)
    {
         printf(" Thermal State:\n");
         AcpiTkWalkResources(ObjHandle,
                           "_TMP",
                           internal_PrintResourceInfo,
                           (void *) NestingLevel);
    }

    if (DevInfo)
    {
        AcpiTkOsFree(DevInfo);
    }
    return AE_OK;

In particular the key here is that reference to "_TMP" in the AcpiTkWalkResources API call, which the toolkit docs explain as:

Code: [Select]
Parse an ACPI Resource List.

AcpiStatus = AcpiTkWalkResources(Device, &Name, UserFunction, &UserContext);
 
PARAMETERS
Device (ACPI_HANDLE) - input
A handle to the Device for which one of the resource lists will be walked:

Name (char *) - input
Name of a resource method (either a _CRS or _PRS method.)

UserFunction (ACPI_WALK_RESOURCE_CALLBACK *) - input
A pointer to a user-written function that is invoked for each resource object within the resource list. (See the interface specification for the user function below.)

UserContext (void *) - input
A value that will be passed as a parameter to the user function each time it is invoked.
 
RETURN VALUE

Status (ACPI_STATUS) - output
Exception code that indicates success or reason for failure.
 
Functional Description:

This function is equivalent to the AcpiWalkResources function described in the Intel ACPI Component Architecture User Guide and Programmer Reference.   

In other words, that "_TMP" is the "Name of a resource method" that you are interested in obtaining information about/from. Further on, if you look this up in the official ACPI docs you'll find that following:

11.4 (Thermal Objects) => 11.4.18 (_TMP Temperature)

...with the following (rather criptic details being shown):

Code: [Select]
11.4.18 _TMP (Temperature)
This control method returns the thermal zone’s current operating temperature.

Arguments:
None

Return Value:
An Integer containing the current temperature of the thermal zone (in tenths of degrees Kelvin)
The return value is the current temperature of the thermal zone in tenths of degrees Kelvin. For example, 300.0K is represented by the integer 3000.

OK, but not all is lost. There are other "resouce methods" you can use to obtain all the information you need, these are nicely listed in the main table at the start of 11.4 (Thermal Objects) section.

Soooo...I am thinking that what AOS (DavidA in particular) provided us with is the ability (through ACPI framework) to access such "resource methods". What I am not sure is whether ALL such ACPI currently defined methods are available, or just a subset.

With ACPI framework there is that whole notion of motherboard firmware (BIOS) needing to support the various ACPI calls, which in fact are pseudo-code (similar to how the JVM stuff works) and which the OS/APP layer issues and the firmware understands and is capable of responding to.

This is well documented in CH19 of that ACPI Specs document, as well as CH20 which talks about "ACPI MACHINE LANGUAGE (AML) SPECIFICATION".

What I am unclear about at this point in time is as to whether the ASL & AML stuff is completely transparent to us (at the API level for example)? I think the answer is YES, but yet our ACPI package ships with iasl.exe, which is:

Code: [Select]
Intel ACPI Component Architecture
ASL+ Optimizing Compiler/Disassembler version 20210331
Copyright (c) 2000 - 2021 Intel Corporation

Supports ACPI Specification Revision 6.3

Usage: iasl [Options] [Files]

....so the plot thickens!!! lol

NOTE: I think ASL is used to actually dynamically define & create the whole ACPI set of tables which can then be loaded into BIOS at runtime, thus allowing the OS to further customize the particular behaviour/functionality present on specific hardware. That way you could in fact "patch" faulty motherboard hardware and have the BIOS execute this stuff. This is a pure stipulation on my part though as I honestly do not understand this enough at this point in time...

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5344
  • Karma: +127/-1
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #3 on: March 02, 2025, 06:31:40 pm »
The source for the temperature widget I use is at http://os2.snc.ru/pub/SystemLoad/SL-src-20200302.zip. It does not use ACPI, which doesn't support this Intel box, but rather seems to directly read the temperature sensors on the CPU. You have to look at rdmsr.sys source.
Used to be and perhaps still is that a lot of these sensors were on the smbus and each chip set would need a driver.

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #4 on: March 02, 2025, 08:23:28 pm »
By now I found out that my system ACPI contains a _TZ_, a thermalzone device that is, but it does not contain a _TMP method. Looks like a different way is needed. I hope that AMD supports the same proprietary way to query the temperature sensors that the systemload widget uses.
« Last Edit: March 02, 2025, 08:27:09 pm by Lars »

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #5 on: March 03, 2025, 07:47:50 am »
Got a little further:

1) the "SystemLoad" temperature widget from Digi only works for Intel CPUs. He is reading from an MSR to query the temperature value. And that MSR does not exist on AMD CPUs (unfortunately not all MSRs are part of the base X86 architecture ...). The XCenter widget (I think) also leads to repeated traps on my system (CPU: FX-8350, which is a Vishera release of the Bulldozer architecture) once the WPS attempts to load until the system finally completely freezes.

2) stumbled across a Windows utility to read out temperatures. And for AMD, they say that they are reading a register from the Northbridge (and that seemingly works for many later AMD CPUs and should also include the FX-8350 and @Dariusz it should therefore also include the FX-8370 ...). In order to find the spec: is the Northbridge built into the CPU or is is part of a separate chipset ?
« Last Edit: March 03, 2025, 07:52:32 am by Lars »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1421
  • Karma: +28/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #6 on: March 04, 2025, 05:27:31 am »
Hey Lars!

1) the "SystemLoad" temperature widget from Digi only works for Intel CPUs. He is reading from an MSR to query the temperature value. And that MSR does not exist on AMD CPUs (unfortunately not all MSRs are part of the base X86 architecture ...). The XCenter widget (I think) also leads to repeated traps on my system (CPU: FX-8350, which is a Vishera release of the Bulldozer architecture) once the WPS attempts to load until the system finally completely freezes.

Ahh, to be somewhat expected given that the "olden way" of getting at this info was to query specific hardware locations...so as you found out given the lack of industry standard, which to be honest I can't imagine any vendor to ever agree on this type of stuff, they all want to do stuff 'their way', would require you to hit the CPU/CHIPSET specific locations on the new hardware

2) stumbled across a Windows utility to read out temperatures. And for AMD, they say that they are reading a register from the Northbridge (and that seemingly works for many later AMD CPUs and should also include the FX-8350 and @Dariusz it should therefore also include the FX-8370 ...). In order to find the spec: is the Northbridge built into the CPU or is is part of a separate chipset ?

So for our Vishera CPUs the Northbridge is actually contained on the CPU die. This actually is composed of the System Request Interface, Memory Controller, DRAM Controllers and crossbar (Copy & Paste from the 'AMD Piledriver BIOS and Kernel Developer's Guide). There still is a motherboard Northbridge, but that functionality is nowhere what it used to be. Instead stuff like 990FXA (which my MSI 990FXA-GD80 board has) handles the connectivity between the CPU and the rest of the system, so think along the lines of PCIe lanes, HyperTransport, etc. Southbridge on the other hand handles stuff like SATA, RAID, USB, conventional PCI bus, etc.

Some motherboards of course provide alternatives, so USB3 for example being implemented through a different chipset altogether.

As it happens that AMD BIOS and Kernel Dev Guide has a full listing of ALL the availble registers. So you could look that up (it is a PDF) and see if you match against what that Windows util is using?

Now, I will say this: it would be awfully nice to have the acpidecode utility so that the dump of your ACPI tables (which can be obtained through the our APIC implementation with acpidump) could be translated to a more human readable mapping

Having said that, way back when, as in around ACPI 3.18 the ACPI utils used to be released as a binaries. Since then the AOS releases have gone to all of these utils being lumped into the "samples" directory of the Toolkit, which of course you can try compiling. I suppose that's probably my next step seeing that doing so would at least give me the most up-to-date versions for the ACPI system we have today.

Regardless, I've attached two outputs:

1) acpi_object
- this is the result of the old acpitest.exe

2) acpi_tree
- this is actually a version of the acpidump that gives you a nice hierarchical snapshot of what hardware you currently have an most importnatly of all, which devices support which ACPI methods!!!

So here is a little section of it:

Code: [Select]
+*_PR_ T:[Scope]
   |
   +*SSDT T:[Region]
   |
   +*DCOR T:[Integer]
   |
   +*TBLD T:[Integer]
   |
   +*NPSS T:[Integer]
   |
   +*HNDL T:[Integer]
   |
   +*APSS T:[Package]
   |
   +*P001 T:[Processor]
      |
      +*TYPE T:[Integer]
      |
      +*_PDC T:[Method]
   |
   +*P002 T:[Processor]
      |
      +*TYPE T:[Integer]
      |
      +*_PDC T:[Method]

This represents the processor table where each P00x object shows an available _PDC method, which the ACPI 6.5a specs document as follows: "Processor Driver Capabilities – inform AML of processor driver capabilities.".

Now, I do not know that this is the right place for the full answer...well, I do, and it is NOT (LOL), but it certainly seems like a viable path to pursue b/c now I could take some of the Toolkit sample source code and modify to get the specific details I'm after.

Digging into this a tad more I do actually find the 'Thermal Zones' scope in that ACPI tree:

Code: [Select]
+*_SB_ T:[Device]
 Current state:
 Possible State:
   |
   +*PR00 T:[Package]
   |
   +*AR00 T:[Package]
   |
   +*PR20 T:[Package]
   |
   +*AR20 T:[Package]
   |
   +*PR21 T:[Package]
...

So at least one can look up the very specific syntax to use in order to get the specific 'temperature' details we are interested in.

More to come on this for sure as unlocking the ACPI approach would get us CPU/chipset agnostic way to query up the information...the big assumption here of course being that the ACPI implementation we are using isn't just Intel specific, and seeing how ACPI is an industry standard these days, I'm thinking this should cover non-Intel stuff as well.

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #7 on: March 04, 2025, 09:08:38 am »
Hi Dariusz,

my ACPI is crippled, it's very old and does not support many of the new ACPI objects. And then, I don't know if with our ACPI.PSD there is a way to overload ACPI tables on the fly.

But this webpage gave me the clue how for AMD you can read temperature directly from PCI config space:
https://www.alcpu.com/CoreTemp/howitworks.html

Then I found the AMD BIOS Writer's Guide:
https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/programmer-references/42301_15h_Mod_00h-0Fh_BKDG.pdf

The register to read is the "Reported Temperature Control" PCI config space register Device 18h Function 3 Byte Offset A4h  (so yes, in principle, the ACPI tables could be extended by AML code that just reads that specific PCI config space register but I am far from an expert on ACPI).

Now I need some time to "borrow" the XWorkplace Temperature Widget code and hack together a widget for AMD.
And then I have to find out exactly what AMD CPUs support that PCI config space register. Don't want to crash anyone's system ...


« Last Edit: March 04, 2025, 09:14:55 am by Lars »

Rich Walsh

  • Sr. Member
  • ****
  • Posts: 398
  • Karma: +30/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #8 on: March 04, 2025, 10:15:58 am »
Run 'testlog acpi' then look at the last 5000+ lines: it's all there. Also, run 'iasl.exe' to see if any of its many options are of use to you.

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #9 on: March 04, 2025, 11:32:58 am »
Run 'testlog acpi' then look at the last 5000+ lines: it's all there. Also, run 'iasl.exe' to see if any of its many options are of use to you.

It is there if your ACPI supports it. It does not work on my system: ACPI is of no help on my system. I also used "acpimanager" to get a visual representation of my ACPI. Nothing of use can be found in my ACPI tables.
I will need to use proprietary methods to read CPU temperature and AMD works differently than Intel: AMD uses PCI config space and Intel uses a dedicated MSR.

AcpiManager: https://hobbesarchive.com/Home/Download?path=/Hobbes/pub/os2/util/power/ACPIManager_00-14.zip
« Last Edit: March 04, 2025, 02:00:04 pm by Lars »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1421
  • Karma: +28/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #10 on: March 05, 2025, 12:24:34 am »
Hey Lars!

my ACPI is crippled, it's very old and does not support many of the new ACPI objects. And then, I don't know if with our ACPI.PSD there is a way to overload ACPI tables on the fly.

Not sure the age of your hardware, but the early years of ACPI were plagued by buggy BIOS firmware, etc., so this may not be all that surprising.

Then I found the AMD BIOS Writer's Guide:
https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/programmer-references/42301_15h_Mod_00h-0Fh_BKDG.pdf

The register to read is the "Reported Temperature Control" PCI config space register Device 18h Function 3 Byte Offset A4h  (so yes, in principle, the ACPI tables could be extended by AML code that just reads that specific PCI config space register but I am far from an expert on ACPI).

Yeah, spot on. I was thinking to myself that if ACPI is not workable then querrying up the right register might still get you to the right spot. That PDF is the bible for the FX CPUs. Keep the following in mind: there really are TWO CPU temperatures: core and package. The core stuff does not store/output an actual temperature, rather it is an offset from what AMD considers the MAX safe temp for this particular CPU. Which means you need to do a little bit of a calculation to try to either get it back to a F/C-degree scale, or you can simply call this value out as "xx Deg. away from MAX Temp". The ACPI logic (as well as the processor itself) use this information to determine when a critical thermal shutdown needs to be initiated. The PDF describes this as well.

And then I have to find out exactly what AMD CPUs support that PCI config space register. Don't want to crash anyone's system ...

LOL, I know the feeling...I trapped my box yesterday as I ran the acpistat command from that 3.18 ACPI release against my current installed ACPI base...oops...you'd think it would perhaps fail a bit more gracefuly!

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #11 on: March 05, 2025, 01:40:31 am »
Hi Dariusz,

by now I have hacked together a proof of concept. Since you have a FX 8380 CPU (I think), would you be willing to test ? Beware, the test prog has no strict error checking but I can provide the source code to you ...

You will also need to install:
https://hobbesarchive.com/Home/Download?path=/Hobbes/pub/os2/system/drivers/misc/SysCall_3-0.wpi

which is my driver + DLL to execute code in Ring 0 (necessary for the test program to read MSRs, also used to map physical to linear address).


Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1421
  • Karma: +28/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #12 on: March 06, 2025, 04:06:53 am »
Lars!

..by now I have hacked together a proof of concept. Since you have a FX 8380 CPU (I think), would you be willing to test ? Beware, the test prog has no strict error checking but I can provide the source code to you ...

You will also need to install:
https://hobbesarchive.com/Home/Download?path=/Hobbes/pub/os2/system/drivers/misc/SysCall_3-0.wpi

which is my driver + DLL to execute code in Ring 0 (necessary for the test program to read MSRs, also used to map physical to linear address).

OK, so the install of that SysCall WPI is done...but everything in that source tree is dated Dec-2020 and earliert, so I'm guessing this does not contain any of the stuff you were working on...or am I missing something?

In other words: happy to test, I just don't know what it is that I should be trying to test???

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #13 on: March 06, 2025, 06:29:49 pm »
Correct, the test proggie I will still need to attach here. Will do so.

Lars

  • Hero Member
  • *****
  • Posts: 1423
  • Karma: +72/-0
    • View Profile
Re: An XWorkplace CPU Temperature Widget for AMD CPUs
« Reply #14 on: March 06, 2025, 10:44:35 pm »
Find attached.