Skip to content

Implement the thread policy API#6

Merged
JohnTitor merged 5 commits intoJohnTitor:mainfrom
StephanvanSchaik:thread-policy
Mar 5, 2022
Merged

Implement the thread policy API#6
JohnTitor merged 5 commits intoJohnTitor:mainfrom
StephanvanSchaik:thread-policy

Conversation

@StephanvanSchaik
Copy link
Contributor

This PR implements part of the thread policy API used to retrieve and request the policy for any given thread. More specifically, while this can be used to indicate to Mac OS that the thread is computationally intensive or rather a background thread, this API can also be used to set up latency-based or throughput-based QoS. Furthermore, Mac OS provides an affinity policy that allows one to indirectly set the affinity of threads to indicate whether certain CPU resources such as the L2 cache should or should not be shared between threads. Therefore, the affinity policy can be used as a hint to the scheduler for thread placement.

@StephanvanSchaik
Copy link
Contributor Author

Checking out the main branch as follows and running the same test as in the Github workflow as follows also results in this error:

git clone https://github.com/JohnTitor/mach2
cd mach2
TARGET=aarch64-apple-darwin RUST_VERSION=nightly ci/run.sh

That is, the main branch without this PR currently seems to fail on the same issue as well. This might be a problem with Rust nightly.

@JohnTitor
Copy link
Owner

That is, the main branch without this PR currently seems to fail on the same issue as well. This might be a problem with Rust nightly.

Nah, https://github.com/JohnTitor/mach2/runs/5379204089?check_suite_focus=true shows a lot of errors about thread_standard_policy. Note that mach-test only runs on nightly.

@StephanvanSchaik
Copy link
Contributor Author

StephanvanSchaik commented Mar 2, 2022

That is, the main branch without this PR currently seems to fail on the same issue as well. This might be a problem with Rust nightly.

Nah, https://github.com/JohnTitor/mach2/runs/5379204089?check_suite_focus=true shows a lot of errors about thread_standard_policy. Note that mach-test only runs on nightly.

Apparently, TARGET=aarch64-apple-darwin is not supposed to work, but running the following works fine on the Apple M1:

git clone https://github.com/JohnTitor/mach2
cd mach2
TARGET=x86_64-apple-darwin RUST_VERSION=nightly ci/run.sh

It looks like mach-test tries to compare the Rust code against the C header, which is nice, it just wasn't clear to me initially. I fixed the struct names in mach-test/build.rs, added use mach2::thread_policy::*; to mach-test/src/main.rs and then fixed the issues in src/thread_policy.rs. Then I ran: TARGET=x86_64-apple-darwin RUST_VERSION=nightly ci/run.sh to ensure that the tests pass.

Thanks for the pointer.

Copy link
Owner

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

Thanks! Yeah, I personally don't have an ARM Mac and CI env isn't also ready for it, unfortunately.
Anyway the test passes, I'm going to merge :)

@JohnTitor JohnTitor merged commit 66b73bd into JohnTitor:main Mar 5, 2022
@StephanvanSchaik StephanvanSchaik deleted the thread-policy branch September 12, 2022 04:00
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

Successfully merging this pull request may close these issues.

2 participants