Live data from Hacker News

Memory access on the Apple M1 processor

lemire.me

11–20 of 278 posts

Re: Memory access on the Apple M1 processor

#11
post #3

What's the precision of these ns level measurements?

Clock_gettime(CLOCK_REALTIME) on macos provides nanosecond-level precision.

I seem to recall OSX didn't used to have clock_gettime, so it's news to me that it even exists -- I might have been away from OSX too long.

Is there any performance difference between that and mach_absolute_time() ?

Re: Memory access on the Apple M1 processor

#12
post #6

What is the cache line size and page table size in M1? sysconf(_SC_PAGESIZE); /* posix */ Can you get direct processor information like LEVEL1_ICACHE_ASSOC and LEVEL1_ICACHE_LINESIZE from the M1??

`getconf PAGESIZE` returns 16384 on the base M1 MacBook Air. The L1 cache values aren't there. The macOS `getconf` doesn't support -a (listing all variables), so they may just be under a different name. edit: see replies for `sysctl -a` output

Is it possibly exposed via sysctl, which does support a flag to list all variables?

Re: Memory access on the Apple M1 processor

#13
For people who know more about this stuff than me: are these sorts optimizations only possible because Apple controls the whole stack and can make the hardware & OS/software perfectly match up with one another or is this something that Intel can do but doesn't for some reasons (tradeoffs)?

Re: Memory access on the Apple M1 processor

#14
post #11

Earlier quoted context omitted.

Clock_gettime(CLOCK_REALTIME) on macos provides nanosecond-level precision.

I seem to recall OSX didn't used to have clock_gettime, so it's news to me that it even exists -- I might have been away from OSX too long. Is there any performance difference between that and mach_absolute_time() ?

It was added some years ago, and I believe mach_absolute_time is actually now implemented in terms of (the implementation of) clock_gettime. The documentation on mach_absolute_time now even says you should use clock_gettime_nsec_np(CLOCK_UPTIME_RAW) instead.

macOS also has clock constants for a monotonic clock that increases while sleeping (unlike CLOCK_UPTIME_RAW and mach_absolute_time).

Re: Memory access on the Apple M1 processor

#15
Is the article saying that the M1 is slower than we would have expected in this case?

My understanding, based on the article, is that a normal processor, we would have expected arr[idx] + arr[idx+1] and arr[idx] to take the same amount of time.

But the M1 is so parallelized that it goes to grab both arr[idx] and arr[idx+1] separately. So we have to wait for both of those two return. Meanwhile, on a less parallelized processor, we would have done arr[idx] first and waited for it to return, and the processor would realize that it already had arr[idx+1] without having to do the second fetch.

Am I understanding this right?

Re: Memory access on the Apple M1 processor

#16

Earlier quoted context omitted.

`getconf PAGESIZE` returns 16384 on the base M1 MacBook Air. The L1 cache values aren't there. The macOS `getconf` doesn't support -a (listing all variables), so they may just be under a different name. edit: see replies for `sysctl -a` output

Is it possibly exposed via sysctl, which does support a flag to list all variables?

From sysctl -a on my M1:

    hw.cachelinesize: 128
    hw.l1icachesize: 131072
    hw.l1dcachesize: 65536
    hw.l2cachesize: 4194304
EDIT: also, when run under Rosetta hw.cachelinesize is halved:

    hw.cachelinesize: 64
    hw.l1icachesize: 131072
    hw.l1dcachesize: 65536
    hw.l2cachesize: 4194304

Re: Memory access on the Apple M1 processor

#17

For people who know more about this stuff than me: are these sorts optimizations only possible because Apple controls the whole stack and can make the hardware & OS/software perfectly match up with one another or is this something that Intel can do but doesn't for some reasons (tradeoffs)?

[deleted]

Re: Memory access on the Apple M1 processor

#18
post #2

Great practical information. Nice to see people who know what they are talking about putting data out there. I hope eventually these persistent HN memes about M1 memory will die: that it's "on-die" (it's not), that it's the only CPU using LPDDR4X-4267 (it's not), or that it's faster because the memory is 2mm closer to the CPU (not that either). It's faster because it has more microarchitectural resources. It can load…

In other words, it’s better architecture. If anything this makes it seem more impressive to me.

Re: Memory access on the Apple M1 processor

#19
post #11

Earlier quoted context omitted.

Clock_gettime(CLOCK_REALTIME) on macos provides nanosecond-level precision.

I seem to recall OSX didn't used to have clock_gettime, so it's news to me that it even exists -- I might have been away from OSX too long. Is there any performance difference between that and mach_absolute_time() ?

It's new in macOS Sierra. I believe mach_absolute_time is slightly faster but not by much–both just read the commpage these days to save on a syscall.

Re: Memory access on the Apple M1 processor

#20
post #2

Great practical information. Nice to see people who know what they are talking about putting data out there. I hope eventually these persistent HN memes about M1 memory will die: that it's "on-die" (it's not), that it's the only CPU using LPDDR4X-4267 (it's not), or that it's faster because the memory is 2mm closer to the CPU (not that either). It's faster because it has more microarchitectural resources. It can load…

This seems to be a recurring theme with the M1, and one that, in a sense, actually baffles me even more than the alternative. There is no "magic" at play here, it's just lots and lots of raw muscle. They just seem to have a freakishly successful strategy for choosing what aspects of the processor to throw that muscle at.

Why is that strategy simultaneously remarkably efficient and remarkably high-performance? What enabled/led them to make those choices where others haven't?

Post reply on HN