Counting cycles and instructions on the Apple M1 processor
lemire.me
lemire.me
If it's of interest, these performance events (and the whitelist for this API), are described by Apple at https://github.com/apple/darwin-xnu/blob/main/osfmk/arm64/kp...
Instruments.app is the official way to access performance counters. I believe it can use a few more (non-whitelisted) events, which are described in /usr/share/kpep/a14.plist - I couldn't figure out how to hijack the single-consumer API that I think it's using. (Edit: it seems it just shows non-whitelisted events in the GUI, but doesn't let me use them.)
(And, for my own measurements, I use a kernel module to bypass the whitelist, which is even more likely to blow up the computer, and definitely not recommended: https://github.com/dougallj/applecpu/tree/main/timer-hacks )
I'd rather be running this kind of instrumentation on Linux (or without a kernel, e.g. using m1n1), but I haven't set that up yet. (It'd be nice to lock the CPU to a frequency, and pin threads to cores, etc.)
# parsing random numbers model: generate random numbers uniformly in the interval [0.000000,1.000000]
volume: 10000 floats
volume = 0.0762939 MB
strtod 376.04 instructions/float (+/- 0.0 %)
75.53 cycles/float (+/- 0.0 %)
4.98 instructions/cycle
88.95 branches/float (+/- 0.0 %)
0.6005 mis. branches/float
fastfloat 162.01 instructions/float (+/- 0.0 %) 22.01 cycles/float (+/- 0.0 %)
7.36 instructions/cycle
38.00 branches/float (+/- 0.0 %)
0.0001 mis. branches/floathttps://lemire.me/blog/2021/03/24/counting-cycles-and-instru...
I have definitely changed my thoughts and if apple can solve getting more ram in their systems (it’s pretty shameful that in 2021 you max out at 16gb on a MacBook Pro), I feel like they are going to knock it out of the park with their new architecture.
Sometimes I look at activity monitor and it is swapping a bit but I don’t notice any perf degradation so I stopped thinking about it.. shrug
Percentage Used: 0%
Data Units Read: 12,515,207 [6.40 TB]
Data Units Written: 13,202,995 [6.75 TB]
Host Read Commands: 264,092,805
Host Write Commands: 158,635,815
Controller Busy Time: 0
Power Cycles: 188
Power On Hours: 223
The % used is (I think) the lost capacity due to wear, I've fairly hammered it so far and it's not even at 1%.. I'm pretty sure I'll get at least a few years out of it based on that..On the low end assuming 200TBW that means you have used about 3.3% of the life of your SSD and on the high side you have used 6.75%. Lets say you got your M1 on release in November, that would mean you are using about 1.68%/month on the high end and .84%/month on the low end.
Assume it lasts 200TBW, which I don't think they will, you would be on track for a 8 year lifespan of the SSD. Otherwise 4 years on the low end, assuming the write amount stays the same (which won't likely happen), which would imply you are using the same or less swap.
Every year, I find that I use about 1-2gb more on average, so for me/my usage patterns I almost find the 16gb of memory in the MBPs to be a slap in the face. I have a 13'' and a 16'' MBP with 32/64gb respectively and I don't think I would find anything less acceptable. Right now, my typical memory usage is around 30-40gb when I run docker, vscode, chrome, slack, zoom, etc. I am not even running any VMs(other than the docker vm), I typically will spin those up elsewhere.
For reference, this is my 16'' daily MBP after nearly a year (4.84TB write) and I typically pull down lots of logs/data.
Available Spare: 100%
Available Spare Threshold: 99%
Percentage Used: 0%
Data Units Read: 4,406,559 [2.25 TB]
Data Units Written: 9,454,881 [4.84 TB]
Host Read Commands: 183,307,692
Host Write Commands: 406,821,556My 3.5-year old MacBook Pro has 119 TB of writes, and still claims 79% "available spare":
Available Spare: 79%
Available Spare Threshold: 2%
Percentage Used: 15%
Data Units Read: 256,111,725 [131 TB]
Data Units Written: 232,470,299 [119 TB]
Host Read Commands: 2,872,362,421
Host Write Commands: 1,547,764,735
That said, my 1-month old M1 MacBook Air is already up to 7 TB writes, so seems to be writing at a significantly higher rate. Both are 8GB machines.As Flash cells start to fail they are replaced by spare. Because of write leveling this is delayed for a while, but then as each cell reaches its 300 or 3,000 writes, they all start to fail.
brew install smartmontools
smartctl -a disk0Battery life is the true game changer though. When I went out with the 16” I had to make sure I had 100% charge, if I wanted to use it for ~3-4 hours while out. With the Air I can grab it with 25% battery left and be fine for the same amount of time.
The “actual” pro machines with M1 derivatives are going to be incredible…so long as apple doesn’t make another Touchbar/butterfly keyboard-esq mistake.
I was lucky if I could even make it to 4 hours battery on the 16", but the real killer for me was heat and noise. It was like sitting in front of a little aeroplane all day long, and because the video out is wired up through the dedicated GPU, just plugging it into an external monitor added an extra 20W to dissipate. It also had weird sleep issues the entire time, if I left it connected to a monitor overnight I'd often sit down at my desk the next morning to find it burning hot, fans blasting, with the lid closed.
So happy to see the back of that piece of crap. It got reasonable reviews at the time, I can only imagine that either no-one tested it with external monitors, or because it was the first model to drop the butterfly keyboard people just gave it a pass on everything else.
When I loaded up a new game with minimal assets (it easily fit with the 16GB of RAM I had) the MBA played C:S smoother than my i7/1080ti gaming machine. I think if I can get a laptop with at least 32GB of RAM I won't have to maintain a Windows gaming machine and will be able to consolidate everything onto an M powered MacBook Pro.
Now if Apple would just produce a 5K external monitor life would be perfect :)
And that's on special customization option, that a handful of hardcores ever got...
For work the $400 difference between 16GB and 32GB is pretty negligible over the course of 3 yrs. Consider the cost of each engineer and $400 / 3yrs for even a tiny improvement in productivity is worth it.
Marcan recently found custom instructions to handle memory compression / decompression in hardware.
My theory is that Apple has specific hardware for much faster and better memory compression and decompression. macOS has always had memory compression but I think those are done with Software on CPU.
You may also get some additional memory from Unified Memory. ( Not sure how it worked previously on macOS, so this is a reference from PC perspective. )
But Yes generally I agree, That's just too much for my old dog to wrap my mind around.
The M1 Macs come with very fast SSDs. I think what’s really going on here is that, with write speeds exceeding 2GB/s, macOS can use NVM almost as if it is RAM with little performance penalty.
It works. With 8GB, my MacBook Air feels as if it has a lot more RAM than it does.
The downside is increased wear on the SSD. My 512GB SSD has accumulated 7 TB of writes in the few weeks I’ve owned it.
[1] https://appleinsider.com/articles/18/05/17/intels-first-10nm...
[2] https://appleinsider.com/articles/18/07/12/apple-refreshes-m...
[3] https://www.apple.com/shop/buy-mac/macbook-pro/13-inch-space...
There were definitely PC laptops available with 32gb of ram, but the wired powered consumption doubles from ~6 to ~11/12 watts [1] [2]
Reviews of pc laptops at the time (eg: Skylake) with 32/64gb of ram showed some detrimental battery life and it appears in Apple's case it wasn't a tradeoff they were willing to make.
To me it seems as though Apple gave up and just put DDR4 into their laptop anyway and also increased the battery W-h from 76Wh in the 2016 model [3] to 83.6Wh in the 2018 [4] thus offsetting some of the battery life issues but there may have been other hardware improvements that reclaimed some battery life.
As for the 13 inch MBP, the 2020 model was the first to include LPDDR4X and could allow the bump to go to 32gb but is much more battery constrained at 58Wh. [5]
[1] https://macdaddy.io/macbook-pro-limited-16gb-ram/ [2] https://www.crucial.com/support/articles-faq-memory/how-much... [3] https://support.apple.com/kb/SP749?locale=en_US [4] https://support.apple.com/kb/SP776?locale=en_US [5] https://www.apple.com/macbook-pro-13/specs/
But I said I would get the first production-ready ARM Laptop chip... It had to be an Apple, here I am writing this on an M1 Laptop now (to my credit I am trying to minimize as much of the home phoning via various means, albeit I understand I'm using complete spyware).
ARM/RISC is the future.
What makes you say that? There is relatively little phoning home in MacOS
https://sneak.berlin/20201112/your-computer-isnt-yours/
> On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a log of your activity being transmitted and stored.
> It turns out that in the current version of the macOS, the OS sends to Apple a hash (unique identifier) of each and every program you run, when you run it. Lots of people didn’t realize this, because it’s silent and invisible and it fails instantly and gracefully when you’re offline, but today the server got really slow and it didn’t hit the fail-fast code path, and everyone’s apps failed to open if they were connected to the internet.
> Because it does this using the internet, the server sees your IP, of course, and knows what time the request came in. An IP address allows for coarse, city-level and ISP-level geolocation...
> Apple (or anyone else) can, of course, calculate these hashes for common programs: everything in the App Store, the Creative Cloud, Tor Browser, cracking or reverse engineering tools, whatever.
> This means that Apple knows when you’re at home. When you’re at work. What apps you open there, and how often. They know when you open Premiere over at a friend’s house on their Wi-Fi, and they know when you open Tor Browser in a hotel on a trip to another city.
A series of {release hash, launch timestamp} events could be used to build a much more precise profile of your computing habits than just {app ID, launch timestamp} events would.
Also, you're ignoring the power-law: while yes, the majority of software exists in a long-tail of ISVs, most of the apps that people use are made by big corps that make a lot of apps each. 80% of the apps on any computer (Windows or macOS) are Microsoft or Apple or Adobe apps. When you're using any of those, all Apple gets is {Apple, timestamp} or {Google, timestamp} or {Adobe, timestamp}. That's... not very useful for profiling. Especially the first two. Safari and iTunes are both just "Apple" through this system. Are you working? Relaxing? Who knows?
It's also incredibly unlikely. I'm just trying to picture what this server that does no kind of user identification at all looks like. What value would it possibly offer? Just to count how many times an application is opened? How can any kind of analytic application function without some kind of user profiling mechanism and a place to store that data for analysis?
It sounds too good to be true, so it probably is.
[1] https://www.eff.org/deeplinks/2019/03/facebook-doubles-down-...
Facebook operates a free service that they use to collect data about you to sell for advertising purposes. Apple sells expensive personal electronics directly to consumers, and has made it a part of their core brand to be privacy-conscious. They’re certainly not perfect, and they’ve clearly made missteps along the way, but they’ve done more than virtually any other public company to further their customers’ privacy and demonstrably collect as little data as possible. When they have made mistakes, they’ve carefully explained what circumstances led to it and have generally gone above and beyond in ensuring that kind of mistake can’t happen again.
Your perspective is little different than the indefensible “both sides” mentality many people have toward politics. Apple is not Facebook, and there is a massive difference to anyone actually paying attention.
Relying on Apple to do the right thing when they're sent a bunch of data which has some use to them, and to their users, if they keep it and run statistical analysis against it, is like relying on that handshake agreement to store some of your belonging in your kindly old neighbors shed. Sure, you trust him, but he's not going to be around forever, and who's to say what will happen to it if someone takes over his property after he's gone. And if that kind neighbor had a habit of cleaning up the stuff your kids left in your yard for you by putting the items in that shed of his... well it's nice that he allows your kids to get their stuff from there whenever they want, but still, that's just asking for problems down the line.
No, it's relying on this being disaligned with their profit incentives. They've made a selling point of their products being privacy-focused, and actions that go against that directly impact the profitability of these products.
There have been several cases where data was mistakenly collected. Nobody's perfect! And in every one of those cases, they've gone above and beyond in explaining what went wrong and how they'll prevent those situations from occurring in the future. In several cases, they've even published white papers pushing forward the current state of the art on preserving privacy while collecting the minimal data necessary for services to function.
Apple is not Google and Facebook. The latter two have direct profit incentive to maximize data collection and analysis of you, personally. Apple wants to sell you consumer devices, and—outside of specific counterexamples like Siri—collecting your data rarely aligns with those profit incentives.
"We do not use data from these checks to learn what individual users are launching or running on their devices.
Notarization checks if the app contains known malware using an encrypted connection that is resilient to server failures.
These security checks have never included the user’s Apple ID or the identity of their device. To further protect privacy, we have stopped logging IP addresses associated with Developer ID certificate checks, and we will ensure that any collected IP addresses are removed from logs.
In addition, over the the next year we will introduce several changes to our security checks:
A new encrypted protocol for Developer ID certificate revocation checks
Strong protections against server failure
A new preference for users to opt out of these security protections"
Hmm, was that statement released before or after their servers failed?
In my mind, no phoning home, and open-source at the very least. So to me, it's spyware indeed, because as you just said yourself, it phones home.
One could argue that these hashes should be downloaded and then checked against a local database and I can't really argue against that, sounds like a standard anti-virus MO and I would prefer that.
You can block those connections if they bother you.
Is this ripe for being manipulated by an infected system though? By keeping it central to the home office, they have control over the single location rather than trying to ensure every single system stays current.
In any case, defaults matter.
> One could argue
Could and should.
I ask out of honest curiosity. I tinkered with LS a year ago or so, but it made me wonder just how many bad-actors are really out there.
Cheers!
So no, nothing too worrisome.
https://www.theverge.com/2019/11/5/20948092/microsoft-surfac...
It uses a Qualcomm laptop processor.
Also, unlike the M1, if your SSD goes bad because of excessive usage [2] you can just swap it with a screwdriver [1]
[0] https://en.wikipedia.org/wiki/Surface_Pro_X
[1] https://www.ifixit.com/Teardown/Microsoft+Surface+Pro+X+Tear...
[2] https://www.macrumors.com/2021/02/23/m1-mac-users-report-exc...
Do netbooks count as laptops? Because I've used the Efika MX (https://genesi.company/products/smartbook), which is an ARM netbook older than the Surface.
http://www.computinghistory.org.uk/det/22807/Acorn-A4-Laptop