benbender / x1c6-hackintosh

READMEs, Clover, OpenCore configurations, patches, and notes for the Thinkpad X1 Carbon 6th Gen 2018 Hackintosh
https://tylernguyen.github.io/x1c6-hackintosh/
MIT License
26 stars 2 forks source link

Incorrect BAT remaining time. #1

Closed tylernguyen closed 3 years ago

tylernguyen commented 3 years ago

Per our discussion, with the new battery patch: energy and info readings are correct. However, remaining time seems to be absurdly off.

EDIT: Machine: X1C6 20KH*

velaar commented 3 years ago

@tylernguyen seen this bug. Please remove (disable) SMC Battery Manager kext. Doesn't seem to be needed.

However some data seems to be off on 20KH image

benbender commented 3 years ago

@velaar I don't think so. OSX reads the Battery from SMC which is attached via SBS (https://en.wikipedia.org/wiki/Smart_Battery_System) on genuine macs. OSX doesn't use batteries via ACPI. I would suspect you have the kext in the cache (check with kextstat).

velaar commented 3 years ago

@benbender my bad. It is indeed loaded. Data still looks unusual but I have correct running times most of the time.

tylernguyen commented 3 years ago

@velaar Yeah, it doesn't happen on every boot. Just once in a while, and it doesn't normalize after some time and needs reboots.

benbender commented 3 years ago

Notes to myself:

benbender commented 3 years ago

@velaar @tylernguyen Please test the latest commit https://github.com/benbender/x1c6-hackintosh/commit/e3159d1f94178fda4a0aac596bf01f430771bd31 and report back. Thanks!

tylernguyen commented 3 years ago

Tried the new revision, did a ton of reboots just to make sure and remaining time seems to be calculated correctly now. It does take a while to do so, but that's just a matter of playing with the sleep time until we find the sweet spot.

benbender commented 3 years ago

@tylernguyen It never happened to me, but first order of business would be to find out if the root-cause is the mutex or the EC. If you're having time and fun, remove the sleep()-call from BATX and try again. If the bug doesn't reappear, it is the mutex and we'll have to think :)

tylernguyen commented 3 years ago

@benbender

I'm still on Catalina. At first I thought it was an iStats menu issue, but after trying CoconutBattery, BatteryHealth, and the old battery patch again, I was able to isolate it.

I'll remove sleep and check if it's the mutex.

benbender commented 3 years ago

@tylernguyen @velaar Small update in https://github.com/benbender/x1c6-hackintosh/commit/7be933100c96137a5019c46b32f897179982e507. I moved EC-access into the scope of the BATX-device after having strange race-conditions (which didn't produce any errors but simply stopped the SSDT from loading/running). Please update before doing further tests.

Besides that, its the start of dual-batt-support even if it doesnt implement much yet.

velaar commented 3 years ago

Testing the current version got this: image I don't think it is failing. image

Also got a couple times "Low power" when unplug the laptop with full charge

benbender commented 3 years ago

@velaar I think I know the causes for both issues. will update in the next days with - hopefully - all bigger challenges sorted out.

benbender commented 3 years ago

Hey @tylernguyen, @velaar - here it is! Revision 5 should fix all known issues, is complete self-contained, handles dual-batteries completely transparent, is further optimized and should (hopefully) be great for everybody :)

Get it while it's hot: https://github.com/benbender/x1c6-hackintosh/blob/experimental/EFI/OC/dsl/SSDT-BATX.dsl

Charlyo commented 3 years ago

@benbender can this also work with T460? Might take a look if dsdt naming is the same.

benbender commented 3 years ago

@Charlyo It should, yes. The only thing it needs is following EC-layout:

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBRC,   16, 
                SBFC,   16, 
                SBAE,   16, 
                SBRS,   16, 
                SBAC,   16, 
                SBVO,   16, 
                SBAF,   16, 
                SBBS,   16
            }

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBBM,   16, 
                SBMD,   16, 
                SBCC,   16
            }

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBDC,   16, 
                SBDV,   16, 
                SBOM,   16, 
                SBSI,   16, 
                SBDT,   16, 
                SBSN,   16
            }

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBCH,   32
            }

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBMN,   128
            }

            Field (ECOR, ByteAcc, NoLock, Preserve)
            {
                Offset (0xA0), 
                SBDN,   128
            }

To my knowledge it should be the same (at least) down to T/X440 models. You can check for yourself in your DSDT.

Charlyo commented 3 years ago

Perfect! Thank you @benbender !

benbender commented 3 years ago

@Charlyo Please report back - Would like to add a compatibility-section to the abstract of the SSDT if some data arrives :)

Charlyo commented 3 years ago

Sure!! I'll try it tomorrow / monday once I get access to the computer!

Just to be 100% sure, we don't need the SMC Battery Manager kext anymore, right?

Thank you anyways!

benbender commented 3 years ago

No, you need SMCBatteryManager. It is the "bridge" between the BATX-ACPI-device and the SMC-keys which OSX reads.

Background: Genuine apple hardware doesn't use the ACPI-Battery-interface but SBS (smart battery system) directly instead.

tylernguyen commented 3 years ago

@benbender

Awesome! Thanks again for your work.

I think I'm ready to push these changes to the main repo after the new Acidanethera releases comes out.

Charlyo commented 3 years ago

Hello again @benbender !

I already applied the changes. EC layout matches T460's one. Removed BATT / BATC + NTFY SSDT's and added BATX one. Latest versions VirtualSMC/ SMCBatteryManager (1.1.7) are loaded. However I do not have any battery icon.

I'm sure I'm doing something wrong. I share my ACPI + config.plist in case you want to check and spot something wrong.

Again, Thank you for your invaluable time and effort developing all this and helping us at the same time.

ACPI.zip DSDT.zip

Config.plist.zip

benbender commented 3 years ago

@Charlyo Your LPC Controller has a different path. Please change every occurrence of SB.PCI0.LPCB into SB.PCI0.LPC (note the missing b at the end.)

Never thought of that but there is nothing I can do without doubling the file-size. Will add a note though.

(https://github.com/benbender/x1c6-hackintosh/blob/experimental/EFI/OC/dsl/SSDT-BATX.dsl#L45 Line 45 - 62, 7 occurrences)

Charlyo commented 3 years ago

Dammit! I had multiple SSDT's with that mistake! Thank you for noticing that. Now seems to work correctly!!

Charlyo commented 3 years ago

At the moment the only thing that might be off are battery characteristics (Displaying 2342):

Battery Information:

Model Information: Serial Number: 16436 / 228 Manufacturer: SONY / SANYO Device Name: 45N1111 / 45N1775 Pack Lot Code: 2342 PCB Lot Code: 2342 Firmware Version: 2342 Hardware Revision: 2342 Cell Revision: 2342 Charge Information: Charge Remaining (mAh): 2059 Fully Charged: No Charging: Yes Full Charge Capacity (mAh): 3604 Health Information: Cycle Count: 453 Condition: Normal Battery Installed: Yes Amperage (mA): 1842 Voltage (mV): 12064

benbender commented 3 years ago

Those "2342"-values and the battery-temperature are "faked" as those values aren't available from the EC (or I couldn't find them ^^). So its expected.

Charlyo commented 3 years ago

No worries then! Thank you for the clarification!

velaar commented 3 years ago

@benbender I wonder if I'm missing something now. The % battery is correct. The discharge rate seems reasonable. And yet 20h estimate is there for the last hour or so.

image
benbender commented 3 years ago

@velaar x1c6 single-battery? If you are on catalina, could you get me a screenshot of the system information tab for power? Is it consistent or a one time problem?

velaar commented 3 years ago

@benbender a number can be different and is somehow related to sleep/wake cycle.

image
tylernguyen commented 3 years ago

@benbender

Can confirm the same issue started appearing again, though not often.

Screenshot_2020-11-02 20 18 35_hCKxGc

@velaar Is there an issue with your charging status as well? When I plug in my charger:

However, the status would say not charging.

benbender commented 3 years ago

@tylernguyen @velaar Please do the following things to help me to fix those issues:

If you've done the steps above and an error appears, please run the following command and attach the log here:

sudo dmesg | egrep -i "ACPI Debug|battery" > batx.log

tylernguyen commented 3 years ago

@benbender

Hasn't been able to replicate the time remaining issue, but here is the logs for the battery status not charging issue: Screenshot_2020-11-03 02 20 27_ZicdwP

benbender commented 3 years ago

@tylernguyen Please attach the logfile instead of a screenshot :) (Use sudo dmesg | egrep -i "ACPI Debug|battery" > batx.log). Thx!

tylernguyen commented 3 years ago

@benbender Here you go :) Same issue, charger plugged in but status says not charging

batx.log

benbender commented 3 years ago

Could you please test that fix: SSDT-BATX-fixed.dsl.zip

tylernguyen commented 3 years ago

@benbender

Same issue:

batx.log

If it let it sit long enough, the status will eventually switch to charging. But it takes a while to do so, seems the EC is out of whack

benbender commented 3 years ago

If it let it sit long enough, the status will eventually switch to charging. But it takes a while to do so, seems the EC is out of whack

@tylernguyen Hmm, can you quantify "long enough"? Is it 1min, 5min, 1hour? Big Sur or Catalina? Could you add another file: log show --last boot|egrep -i "AppleACPIPlatform|AppleSmartBatteryManager|acpib|pmrd" > batx-syslog.log

tylernguyen commented 3 years ago

@benbender

Definitely less than 5 minute, somewhere between 1 and 2 minutes.

batx-syslog.log

benbender commented 3 years ago

@tylernguyen Big Sur or Catalina? Do you have AppleACPIACAdapter attached to the AC-Device in IOReg?

Background: It doesn't seem to be a direct problem in BATX anymore. It seems like the ACPI-notification of the plug-event doesn't seem to trigger the refresh of SMCBatteryManager as it does for me. So the battery don't update update until the next poll which is only every few minutes (depending on the state before) because of disabled QuickPoll.

tylernguyen commented 3 years ago

@tylernguyen Catalina 10.15.7

Can't seem to find AppleACPIACAdapter, where exactly is it located? and was there a reason to disable QuickPoll?

benbender commented 3 years ago

@tylernguyen See acpi-ac

Edit: Opened an issue on your repo with a suggested fix: https://github.com/tylernguyen/x1c6-hackintosh/issues/90

benbender commented 3 years ago

and was there a reason to disable QuickPoll?

Lower load and more native. I'm trying to get as native as possible. But that also means that breaks are more likely if some parts are broken ^^

@tylernguyen Did the ACAdapter fix the issue for you?

tylernguyen commented 3 years ago

@tylernguyen Did the ACAdapter fix the issue for you?

Unfortunately no, it's still there.

benbender commented 3 years ago

Can you enable Line 1339 (https://github.com/benbender/x1c6-hackintosh/blob/7e69d7f632c6c06b1a41ee7a1b13ad41cfe8d880/EFI/OC/dsl/SSDT-BATX.dsl#L1339) and disable Line 1341 and see if the behaviour changes?

buyddy commented 3 years ago

I have the same issue. Battery remaining time showing 20 hours.

buyddy commented 3 years ago

Can you enable Line 1339 (

https://github.com/benbender/x1c6-hackintosh/blob/7e69d7f632c6c06b1a41ee7a1b13ad41cfe8d880/EFI/OC/dsl/SSDT-BATX.dsl#L1339

) and disable Line 1341 and see if the behaviour changes?

This seems to fix the issue.

benbender commented 3 years ago

Yes, it seem to "mask" it. This switch makes SMCBatteryManager poll the battery more often. The underlying problem seems to be some race-condition/EC-not-ready-thing. So if quick-poll is disabled, Virtual-SMC does not update the static infos of the battery once it got (in this case: wrong) data and the 20h remain visible. If its enabled, virtualsmc polls the ec frequently and fetches correct data as soon as the EC is available. Couldn't pin down the exact problem yet though.

PS: same problem should exist in nearly every other implementation... ;)

buyddy commented 3 years ago

@benbender Find another issue. I set the charging upper limit in Windows to be 95%. When I charge in Mac, it works fine and charge to 95%. However on the next reboot, the battery level is shown as 99%. The same battery is shown as 94% in Windows.

benbender commented 3 years ago

@buyddy did you notice this behaviour only with BATX or also with the legacy battery-patches?

buyddy commented 3 years ago

@buyddy did you notice this behaviour only with BATX or also with the legacy battery-patches?

Actually no idea. Because I never tested it the charging limit in the past. But pretty sure it was an issue back then too because my battery percentage never matched Windows. My guess is there are more than 2 capacities in EC? There is design capacity, full charge capacity, and maybe another setup capacity?