Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

[Apple M1] Force an execution on a specific core

Hello everyone,


I have a very technical question. I am actually following a course about core performances in a French engineer school. I have a MacBook Pro 13 M1.

I actually need to calculate multi-thread performances with the openmp library. The problem is that I need to know the clock speed of my processor. But I know that the Apple M1 CPU has 8 cores, but 4 Firestorm cores and 4 Icestorm cores. Definitely, those two types of cores don't have the same clock speed. The problem is here : some threads will be executed on a Firestorm core, some others on an Icestorm one, so I am not able to make a right measurement. So I would like to force the execution on a single specific core.


I am actually searching for a solution with my teacher. This is what we know for the moment :

  • A command like 'taskset' on Linux does not exist on MacOS.
  • Functions like sched_affinity are absents from MacOS
  • The Apple Affinity API seems to be obsolete.
  • The pthread.h library is present, but there is no function that could help us.
  • On Instruments->Preferences->CPU, I can't change the number of active CPUs. By the way, I tried all others methods to do that, and all failed.


I know that my question is very specific, but if someone is able to help me, my teacher and me would be very grateful !

MacBook Pro Retina

Posted on Mar 5, 2021 10:44 AM

Reply
Question marked as Best reply

Posted on Mar 5, 2021 11:42 AM

florian_ch wrote:

I have a very technical question.

I bet it is even more technical than you think.

I am actually following a course about core performances in a French engineer school. I have a MacBook Pro 13 M1.
I actually need to calculate multi-thread performances with the openmp library.

I doubt that is possible. Those open source projects are very slow to support even new Mac operating system versions. This is a new platform altogether. Much of that parallel scientific software stack may not exist yet.

The problem is that I need to know the clock speed of my processor.

Why? Clock speed is not necessarily the most important factor.

But I know that the Apple M1 CPU has 8 cores, but 4 Firestorm cores and 4 Icestorm cores. Definitely, those two types of cores don't have the same clock speed.

How do you know that if you don't know what those speeds are yet?

The problem is here : some threads will be executed on a Firestorm core, some others on an Icestorm one, so I am not able to make a right measurement. So I would like to force the execution on a single specific core.

Now we're getting closer. As far as I know, it is impossible to "force" the execution on a single specific core. You can provide quality-of-service hints, but the operating system will ultimately manage those cores as it sees fit.

I am actually searching for a solution with my teacher. This is what we know for the moment :
A command• like 'taskset' on Linux does not exist on MacOS.
• Functions like sched_affinity are absents from MacOS
• The Apple Affinity API seems to be obsolete.
• The pthread.h library is present, but there is no function that could help us.
• On Instruments->Preferences->CPU, I can't change the number of active CPUs. By the way, I tried all others methods to do that, and all failed.

I know that my question is very specific, but if someone is able to help me, my teacher and me would be very grateful !

A better question is to ask what you are trying to do, in an overall sense. What's the "big picture"?


Modern macOS is a mongrel operating system made from Mac OS, NeXTSTEP, Mach, BSD, iOS, and even a little bit of Windows. At this low level, many of those older APIs and the "standard" UNIX APIs won't help. These days macOS is almost entirely iOS.


I think you could probably get the clock speeds of the cores using IOKit. When I check using "ioreg -l", on an M1, I see multiple "frequency" fields. Which one is the one you need? And is it fixed? There is a "fixed-frequency" and a "clock-frequency", and 3 other "frequencies". There is no documentation for what any of those values mean or how they might change.


If you wanted to try quality-of-service, you may have to use Apple's GCD APIs. I don't know if that is accessible through the BSD layers, or any cross-platform parallel toolkits.


I'm afraid that Apple platforms are a better area of study for social scientists than computer scientists.

Similar questions

2 replies
Question marked as Best reply

Mar 5, 2021 11:42 AM in response to florian_ch

florian_ch wrote:

I have a very technical question.

I bet it is even more technical than you think.

I am actually following a course about core performances in a French engineer school. I have a MacBook Pro 13 M1.
I actually need to calculate multi-thread performances with the openmp library.

I doubt that is possible. Those open source projects are very slow to support even new Mac operating system versions. This is a new platform altogether. Much of that parallel scientific software stack may not exist yet.

The problem is that I need to know the clock speed of my processor.

Why? Clock speed is not necessarily the most important factor.

But I know that the Apple M1 CPU has 8 cores, but 4 Firestorm cores and 4 Icestorm cores. Definitely, those two types of cores don't have the same clock speed.

How do you know that if you don't know what those speeds are yet?

The problem is here : some threads will be executed on a Firestorm core, some others on an Icestorm one, so I am not able to make a right measurement. So I would like to force the execution on a single specific core.

Now we're getting closer. As far as I know, it is impossible to "force" the execution on a single specific core. You can provide quality-of-service hints, but the operating system will ultimately manage those cores as it sees fit.

I am actually searching for a solution with my teacher. This is what we know for the moment :
A command• like 'taskset' on Linux does not exist on MacOS.
• Functions like sched_affinity are absents from MacOS
• The Apple Affinity API seems to be obsolete.
• The pthread.h library is present, but there is no function that could help us.
• On Instruments->Preferences->CPU, I can't change the number of active CPUs. By the way, I tried all others methods to do that, and all failed.

I know that my question is very specific, but if someone is able to help me, my teacher and me would be very grateful !

A better question is to ask what you are trying to do, in an overall sense. What's the "big picture"?


Modern macOS is a mongrel operating system made from Mac OS, NeXTSTEP, Mach, BSD, iOS, and even a little bit of Windows. At this low level, many of those older APIs and the "standard" UNIX APIs won't help. These days macOS is almost entirely iOS.


I think you could probably get the clock speeds of the cores using IOKit. When I check using "ioreg -l", on an M1, I see multiple "frequency" fields. Which one is the one you need? And is it fixed? There is a "fixed-frequency" and a "clock-frequency", and 3 other "frequencies". There is no documentation for what any of those values mean or how they might change.


If you wanted to try quality-of-service, you may have to use Apple's GCD APIs. I don't know if that is accessible through the BSD layers, or any cross-platform parallel toolkits.


I'm afraid that Apple platforms are a better area of study for social scientists than computer scientists.

Mar 5, 2021 12:55 PM in response to etresoft

Thanks a lot for your very complete answer !

I doubt that is possible. Those open source projects are very slow to support even new Mac operating system versions. This is a new platform altogether. Much of that parallel scientific software stack may not exist yet.

I have no problem with OpenMP and with the performance measurement algorithm (written by my teacher).

Why? Clock speed is not necessarily the most important factor.

To be honest, I don't know how my teacher wrote his program. But it works and it prints some measurements in GFLOP/S for each sort of operations (for example : additions, copy of vectors...). My work is just to write different types of algorithms and operation, and measure their performance with my teacher's program. I just have one thing to add to my teacher's program : my processor's nominal frequency.

How do you know that if you don't know what those speeds are yet?

I know their maximal frequencies, but you're right, I don't know their working frequency (of course firestorms cores aren't working all the time at their max. frequency).

A better question is to ask what you are trying to do, in an overall sense. What's the "big picture"?

Sorry for being very confused... As I just resumed, I need a fixed frequency when my program is executing, otherwise, the measurements will be wrong. But I didn't find anything about my cores frequency, so an idea was to force the execution on an Icestorm core and take its max frequency (2.06 GHz according to Wikipedia) for our measurements. By this way, we could be at least sure that the threads will be executed on same-frequencies cores.

I think you could probably get the clock speeds of the cores using IOKit. When I check using "ioreg -l", on an M1, I see multiple "frequency" fields. Which one is the one you need? And is it fixed? There is a "fixed-frequency" and a "clock-frequency", and 3 other "frequencies". There is no documentation for what any of those values mean or how they might change.

I just tried this one. I didn't know it so thank you ! I will show this to my teacher. But I think that it is a good way to solve our problem. You're right, there is a "general" clock-frequency, one fixed-frequency and 8 clock-frequency (I suppose that there is one frequency per core). And all have the same value : <00366e01>. After few searches, I found that this value was in kHz, and presented as little-endian ! So this value is in fact : 0x016e3600 kHz = 2,4 GHz.

This is strange, it is more than the max Icestorm cores frequency, and all cores have this frequency. Maybe it is an "average" frequency of all cores ? And maybe I can use this value for my problem... I will discuss about that with my teacher.

I'm afraid that Apple platforms are a better area of study for social scientists than computer scientists.

Haha I think that's the general opinion. But I like Apple and I like challenges...


Anyways, thank you a lot, maybe the ioreg output is what my teacher is searching for. I mark this problem as "resolved" as you answered my question :

As far as I know, it is impossible to "force" the execution on a single specific core.

Have a nice day !

[Apple M1] Force an execution on a specific core

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.