Skip to content

Conversation

@toor1245
Copy link
Contributor

To add Windows Arm64 support was added detection of features via Windows API function IsProcessorFeaturePresent. Added _M_ARM64 to detect CPU_FEATURES_AARCH64 macro on Windows. Added initial code for Windows Arm64 testing and provided test for Raspberry PI 4. We can't use "define_introspection_and_hwcaps.inl" as a common file for all operating systems due to msvc compiler error C2099: initializer is not a constant, so as a workaround for Windows I used separate "define_introspection.inl"

Refs to review:
https://developer.arm.com/documentation/ddi0487/latest
https://sourceware.org/binutils/docs/as/AArch64-Extensions.html
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
Note: MicrosoftDocs/sdk-api#1409 created PR to update ms docs arm64 features and fix value for PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE

To add Windows Arm64 support was added detection of features via Windows API function IsProcessorFeaturePresent. Added _M_ARM64 to detect CPU_FEATURES_AARCH64 macro on Windows. Added initial code for Windows Arm64 testing and provided test for Raspberry PI 4. We can't use "define_introspection_and_hwcaps.inl" as a common file for all operating systems due to msvc compiler error C2099: initializer is not a constant, so as a workaround for Windows I used separate "define_introspection.inl"

See also: google#268, google#284, google#186
@Mizux
Copy link
Collaborator

Mizux commented Jan 23, 2023

Need to change

elseif(PROCESSOR_IS_AARCH64)
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_aarch64.h)
elseif(PROCESSOR_IS_X86)
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_x86.h)
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/internal/cpuid_x86.h)
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/internal/windows_utils.h)

internal/windows_utils.h should be also in the AARCH64 part


// A note on Windows AArch64 implementation:
// -----------------------------------------------------------
// Since getting of cpu info via EL1 system registers is not possible.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Getting cpu info via EL1 system registers is not possible, so we delegate it to the Windows API (i.e., IsProcessorFeaturePresent and GetNativeSystemInfo)."

// Hence, we delegate detection to info via Windows API methods such
// as `IsProcessorFeaturePresent` and `GetNativeSystemInfo`. The fields of
// `Aarch64Info` struct such as `implementer`, `variant` and `part` are not
// used, so they will always be 0. To get `revision` we use `wProcessorRevision`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The implementer, variant and part fields of the Aarch64Info struct are not used, so they are set to 0."

Also you may want to document this behaviour in include/cpuinfo_aarch64.h.

void SetWindowsNativeSystemInfoProcessorRevision(WORD wProcessorRevision) {
processor_revision_ = wProcessorRevision;
}
#endif // CPU_FEATURES_OS_WINDOWS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to close the #endif here to open it up again a few lines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was focused to leave space for the osx implementation 😄 (https://github.com/arkivm/cpu_features/blob/aarch64-darwin-support/test/cpuinfo_aarch64_test.cc#L50). Will update

// See the License for the specific language governing permissions and
// limitations under the License.

// A note on Windows AArch64 implementation:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment on the fields themselves so it's clear when we use the API?

Copy link
Contributor Author

@toor1245 toor1245 Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do yo mean like this:

typedef struct {
  Aarch64Features features;
  int implementer;  // We set 0 for Windows.
  int variant;      // We set 0 for Windows.
  int part;         // We set 0 for Windows.
  int revision;     // We use GetNativeSystemInfo to get processor revision for
                    // Windows.
} Aarch64Info;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this. Can you update the PR?

@gchatelet
Copy link
Collaborator

LGTM @toor1245 . Thx a lot for the PR !

@gchatelet
Copy link
Collaborator

Actually the comments on the struct fields in include/cpuinfo_aarch64.h is missing, but apart from that I think it's good to go.

Added comments to specify that implementer, part and variant we set 0 for Windows, since Win API does not provide a way to get information. For revision added comment that we use GetNativeSystemInfo
@gchatelet gchatelet merged commit a6bf4f9 into google:main Feb 23, 2023
@MichalPetryka
Copy link

Should the table in the readme be updated with this?

@gchatelet
Copy link
Collaborator

@MichalPetryka We would like to have a CI up and running before claiming we support Windows / Arm64.
Unfortunately it seems that github actions only allow these machines in self hosted mode 🫤
github/roadmap#616

@gchatelet gchatelet added the enhancement New feature or request label Apr 27, 2023
@gchatelet gchatelet added this to the v0.8.0 milestone Apr 27, 2023
NicSavichev added a commit to NicSavichev/cpu_features that referenced this pull request Jun 18, 2024
NicSavichev added a commit to NicSavichev/cpu_features that referenced this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants