Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on M1 #26

Open
ghost opened this issue Mar 29, 2021 · 6 comments
Open

Crash on M1 #26

ghost opened this issue Mar 29, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Mar 29, 2021

This line crashes on M1 Macs because the try fails

public static var cpuFreq: Int64 { return try! Sysctl.value(ofType: Int64.self, forName: "hw.cpufrequency") }

@deirdresm
Copy link

In terminal, what does…

sysctl -n hw.cpufrequency

…produce on an M1?

@ghost
Copy link
Author

ghost commented Apr 7, 2021

@deirdresm just returns nothing and a 0 exit code:

Alex@MacBook-Pro ~ » sysctl -n hw.cpufrequency                            1 ↵
Alex@MacBook-Pro ~ » echo $?
0
Alex@MacBook-Pro ~ » 

@deirdresm
Copy link

Interesting. I was looking at the sources earlier on opensource.apple.com, but don't remember seeing M1-specific stuff relating to CPU speed, but I'll check it next time I'm in that codebase (which will likely be soon).

@deirdresm
Copy link

Weird, looks like it should be supported: https://github.com/EntityFX/anybench/blob/1209866ed4890276e449958c1b6845307c47581a/results/apple-arm-m1/Dhry.txt

I didn't notice the trailing 1 in your command on mobile, maybe try it without?

@ghost
Copy link
Author

ghost commented Apr 7, 2021

So as of right now, our software is compiling Intel only and compiles correctly (so runs in Rosetta). It just crashes when running on M1 because of that optional not unwrapping correctly. However, I just downloaded the project and tried to run the test on my M1 MacBook and got this compile error:


Showing Recent Messages

Build target CwlPreconditionTesting of project CwlPreconditionTesting with configuration Debug

CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')
CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstruction.swift:185:166: error: cannot find 'x86_THREAD_STATE64' in scope
                        thread_swap_exception_ports(mach_thread_self(), EXC_MASK_BAD_INSTRUCTION, currentExceptionPtr, Int32(bitPattern: UInt32(EXCEPTION_STATE) | MACH_EXCEPTION_CODES), x86_THREAD_STATE64, masksPtr, countPtr, portsPtr, behaviorsPtr, flavorsPtr)
                                                                                                                                                                                          ^~~~~~~~~~~~~~~~~~

CompileSwift normal arm64 CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')

/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift:44:59: error: cannot find type 'x86_thread_state64_t' in scope
public let x86_THREAD_STATE64_COUNT = UInt32(MemoryLayout<x86_thread_state64_t>.size / MemoryLayout<Int32>.size)
                                                          ^~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:63:47: error: cannot find 'x86_thread_state64_t' in scope
                var state = old_state.withMemoryRebound(to: x86_thread_state64_t.self, capacity: 1) { return $0.pointee }
                                                            ^~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:77:3: error: type of expression is ambiguous without more context
                withUnsafePointer(to: &f) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:82:35: error: cannot find 'x86_thread_state64_t' in scope
                new_state.withMemoryRebound(to: x86_thread_state64_t.self, capacity: 1) { $0.pointee = state }
                                                ^~~~~~~~~~~~~~~~~~~~

CompileSwift normal arm64 /Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')

/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift:44:59: error: cannot find type 'x86_thread_state64_t' in scope
public let x86_THREAD_STATE64_COUNT = UInt32(MemoryLayout<x86_thread_state64_t>.size / MemoryLayout<Int32>.size)
                                                          ^~~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant