Comments (19)
In case anyone finds it useful, I made a little open source tool that adds the following CLI commands:
battery charging on
: sets CH0B to 00 (allow charging)
battery charging off
: sets CH0B to 02 (disallow charging)
Open source and without warranty.
from bclm.
Just something I discovered while looking into Asahi Linux (source):
/*
* CH0I/CH0C are "hard" controls that will allow the battery to run down to 0.
* CH0K/CH0B are "soft" controls that are reset to 0 when SOC drops below 50%;
* we don't expose these yet.
*/
These could be useful for the bclm tool I guess.
from bclm.
Apple silicon support implemented via CHWA in release v0.1.0.
from bclm.
It seems that for Apple Silicon chips, we are only able to enable/disable charging. A polling solution would be required which would be quite different to how bclm behaves currently. As well, ince other tooling seems to have been developed and optimized battery charging exists for Apple Silicon, it doesn't make sense to me to add it to bclm.
Now there is a solution for Apple Silicon, see a naive implementation here using CHWA
flag. It sets a 80% (fixed) limit managed by the firmware that is maintained while sleeping. Kudos to Asahi team
from bclm.
Now there is a solution for Apple Silicon, see a naive implementation here using
CHWA
flag.
Thanks @double-thinker for calling my attention to this! While the key does not take a specified value like BCLM
, I believe this is an acceptable compromise that fits well into the original model of bclm
. This is a much better path forward for Apple Silicon and I am willing to implement this.
Since last update, I now have Apple Silicon hardware which will expedite development and testing. Expect updates in the coming days. Reopening this issue.
from bclm.
In the (linked) long discussion, this is the first comment, where the new SMC key CH0B
first was mentioned: AppHouseKitchen/AlDente-Charge-Limiter#52 (comment) (see also the following).
As it seems (according to this discussion), writing 00
into SMC key CH0B
enables charging and writing 02
disables charging.
This is also the way AlDente seems to use, see this line: https://github.com/davidwernhart/AlDente/blob/0abfeafbd2232d16116c0fe5a6fbd0acb6f9826b/AlDente/Helper.swift#L227
Also the behaviour seems to be different than the current BCLM
value where you set a charging maximum value (and let the charging logic decide when to turn actually on or off charging). This new CH0B
seems to directly simply turn on/off charging (at any level).
from bclm.
Apologies for not getting around to this sooner.
Never apologise for open source work :)
Looking at the changes, am I correct that for M1 we are only able to enable/disable charging as opposed to Intel where we set a max charging value?
Can't speak for @johnzweng but I am solidly not this familiar with how macs manage their hardware.
I can help with a digest of the above thread though:
TL;DR: Aldente thread
My cursory read:
pmset -g batt
is able to read battery/charge state.
Setting CH0C
to 01
stops charging (but retains adapter power usage) and 00
continues charging. But for some reason Aldente uses the CH0B
key. Not sure what the difference is. convo source.
This script shared by @thloh85 illustrated a potential approach:
while [ true ];
do
BATT_PERCENT=`pmset -g batt | tail -n1 | awk '{print $3}' | sed s:\%\;::`
echo Battery percent : $BATT_PERCENT
if [ $BATT_PERCENT -ge 43 ]; then
./smc -k CH0C -w 01
else
./smc -k CH0C -w 00
fi
sleep 60
done
@joelucid made a GUI app here.
It appears Aldente does have to force the system into an awake state:
@inprealpha From my knowledge, it is not possible for an application to get any CPU time while the system is asleep. Since this necessary for the M1 version because charge has to be inhibited in just the right moment, AlDente stops the System from going to sleep until the desired value is reached. This is done using IOPMAssertions. source
from bclm.
@johnzweng so you have some resources on how SMC
values are written? If this repo stagnates I could write a script to do something similar.
from bclm.
Apologies for not getting around to this sooner. Looking at the changes, am I correct that for M1 we are only able to enable/disable charging as opposed to Intel where we set a max charging value? These seem like unrelated ideas to me. If so, is there really a reason to enable/disable charging manually, especially without something polling battery percentage?
from bclm.
@zackelia how would you feel about using the above info to simply include a "enable/disable charging" toggle?
I think many M1 users such as myself would already be very happy to be able to do that from CLI.
from bclm.
From my knowledge, it is not possible for an application to get any CPU time while the system is asleep.
If you can trigger a dark wake I think you will get cpu time then. I have a suspicion that when native battery optimization is enabled, there is a periodic wake up scheduled at which point the charging state is changed.
But this seems like a worse design from a hardware perspective compared to the older behavior where the SMC could manage the target charge state... no idea what Apple was thinking.
from bclm.
Oooh @aykevl that is super cool to know. I'm currently writing both values, but it sounds like CH0C
is the "master switch" for practical purposes?
Also do you know by heart the function of CH0I
and CH0K
?
from bclm.
I really don't know, I just looked through the Linux kernel source to make an AlDente equivalent for Linux (haven't done that yet, but I did find the values exposed in /sys
so it should be simple). The Apple Silicon wizard here is @marcan.
from bclm.
while [ true ]; do BATT_PERCENT=`pmset -g batt | tail -n1 | awk '{print $3}' | sed s:\%\;::` echo Battery percent : $BATT_PERCENT if [ $BATT_PERCENT -ge 43 ]; then ./smc -k CH0C -w 01 else ./smc -k CH0C -w 00 fi sleep 60 done
Thanks for this tip, I've been using this manually to just toggle charging. It works well.
from bclm.
It seems that for Apple Silicon chips, we are only able to enable/disable charging. A polling solution would be required which would be quite different to how bclm behaves currently. As well, ince other tooling seems to have been developed and optimized battery charging exists for Apple Silicon, it doesn't make sense to me to add it to bclm.
from bclm.
See https://github.com/double-thinker/battery/
from bclm.
"support for Apple ARM M1":
Would this by chance also support ARM M2?
from bclm.
@seamusdemora While I have only personally tested it on an M1 chip, I see no reason why it wouldn't work on M2. If it doesn't work, please let know so I can document that!
from bclm.
roger that!
from bclm.
Related Issues (20)
- BCLM not working on M1 Macs (potentially M2 too, all ARM architecture) HOT 2
- keyNotFound(code: "BCLM") HOT 2
- BCLM persist failing on launch with code -9 HOT 2
- Feature request: use Homebrew Services for `persist` HOT 1
- On Apple Silicon Macs, the charge indicator light won't turn green HOT 6
- Should Apple's "Optimized Battery Charging" be disabled before installing bclm? HOT 3
- Apple Silicon macOS Ventura - persist seems to be misbehaving HOT 7
- Create directory for release installs before copying file
- There is a sound of electric current HOT 4
- Idea for an addition to your readme and/or the BCLM console information
- Persisting doesn't work. HOT 2
- Battery of watch being limited
- Computer doesn't sleep HOT 3
- It stopped working after upgrade to Sonoma 14.4 HOT 9
- how to enable bclm directly from macOS? HOT 2
- On a 2017 Intel MacBook Pro, how to make the battery level drop from 100 to 80? HOT 1
- bclm becomes /usr/local/bin
- Suggested improvements HOT 4
- How to unistall? HOT 1
- bclm read get error about CHWA key not found HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bclm.