New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always reads battery state as discharging, thus stuck on "powersave" governor on Lenovo laptop #234
Comments
Same bug |
grep . /sys/class/power_supply/A*/online What's the output of these when that happens? I kinda already know the fix but I'm curious about what your ac adapter state is. |
|
Batteries don't have an online file. What's indeed weird is your ac adapter not showing up, which is what's triggering this behaviour. That and a regression introduced somewhere down the line, this odd case should have been covered. Just for the sake of knowledge, what's your output of: |
$ sudo dmidecode --type 39
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.
Handle 0x0032, DMI type 39, 22 bytes
System Power Supply
Location: OEM Define 0
Name: OEM Define 1
Manufacturer: OEM Define 2
Serial Number: OEM Define 3
Asset Tag: OEM Define 4
Model Part Number: OEM Define 5
Revision: OEM Define 6
Max Power Capacity: 75 W
Status: Not Present
Type: Regulator
Input Voltage Range Switching: Auto-switch
Plugged: No
Hot Replaceable: No |
Maybe there's a problem with my ac adapter's driver, it doesn't show up and my battery state is often Maybe fixing this issue will fix auto-cpufreq too? |
Yeah there's a firmware issue.
It would definitely fix it. But at the same time the charging detection (auto-cpufreq) could be improved and imo should fallback to using the available battery info so even if your ac adapter isn't detected auto-cpufreq could work correctly, but if your battery state is often unknown then it couldn't work reliably either. |
Thanks! |
I really wanna be sure about something, are the unknown values thrown by your battery really random? For example, I know some newer machines show unkown values when fully charged and system has switched to using ac power instead, specially batteries on laptops where you can config charging limits, if that's the case then I think there's a possible solution for auto-cpufreq for these edge cases. I did a quick search and what I found suggested that it could be a kernel version problem. Here's the link to a working solution for someone with a laptop from Lenovo. It's not precisely the same model (330 instead of 330s) but maybe they have this in common. I hope this helps. 🤞 |
The battery percentage values are not really random, they're just a little bit off. |
Now when I think about it, I've used GNOME for a long time and haven't had any issues like this. |
Maybe you Linux kernel got updated along the installation of Qtile? Hardware detection and reporting is handled by the kernel. |
That's unlikely, I uninstalled GNOME a long time after I installed Qtile, and it kept working. Strange thing I noticed, was that the built-in Qtile battery widget is somehow not reflecting this problem: Maybe there's another way to read the battery state? |
Yes there is, and it's similar to what auto-cpufreq already does. The problem (although we could read also from this other place) is a logic regression introduced a while ago. Part of the pr involved in the regression introduced functionality that detects the chassis type of the pc. My take is that we could do without it (it also comes with it's own problems) but I'm still waiting for some clarification about it before I submit a pr. |
Cool, thanks a lot! BTW, what's the other way to do it? (so I can use it in my Qtile config) |
Just read from /sys/class/power_supply/BATX/current_now, if it's 0 you can assume it's charging. |
Cool, thanks! |
I'm sorry, I just noticed what I said was very misleading. With my last comment I meant "charging" in the context of auto-cpufreq, ie. fed through the ac adapter. If current 0 is reported that means the battery is neither charging nor discharging, so one could assume the battery is full and the pc is being fed power through the ac adapter only. |
I came across the same issue. The "else" branch of the code that checks the charging works reliably for me on a Dell XPS 15 running kernel 5.14, so I just added a "not" in the initial check. Here's the one: auto-cpufreq/auto_cpufreq/core.py Line 162 in ffc0bf0
This is a very quick and dirty fix for my particular use case, although it does prove that psutil works in this odd instance |
Yep, that's the logic regression I was talking about. If chassis type is of the portable variety auto-cpufreq doesn't bother to check the battery, it just checks the ac adapter state. Problems could arise if either the detected chassis type is not correct or the ac adapter isn't properly detected by the kernel, which seems is a fairly common occurrence. What you did was bypass the ac reading and go for the battery one, but in reality there's no reason we shouldn't just check both (the previous behaviour). @AdnanHodzic This is the gist of the discussion over in #168. I don't really want to spam both places so I'll ask here, do you remember the advantage of reading chassis type over assuming pc was of desktop type if no AC or BAT was found? I've wanted to submit a pr but still don't get what I would be messing up if I forwent the dmidecode chassis type detection. |
If this truly fixes the issue consider creating a PR for it.
@Haptein because Hence what I would propose is that you nest the logic, where after chassis-type check (or in case it's not detected) it goes to do another check if AC or BAT are found. Looking forward to your PR :) |
With v1.7.0 release it's now possible to manually define some of the settings instead of leaving everything to be picked up automatically. Could you try tweaking some of the available options and report back on how that worked for you? Thanks |
It didn't really make a difference, because auto-cpufreq thinks my battery is always discharging, even when I'm charging. I tried to make a config file but it didn't help. |
Thinking about this, will writing a simple script that changes the governor when the charger is connected or disconnected be more efficient than my current situation? |
What's the point of doing this when auto-cpufreq does this among other things. Except it doesn't seem to work for you in some case. Hence if you go down this path I would encourage you to add extend this part, create a PR and get credit as one of the next releases :) |
Changes to this problem are now part of 1.7.2 release, this release also included @AmitGolden changes as part of #274 which will resolve this issue. With that said, I'm closing the issue, if the problem persists feel free to re-open it. |
Problem:
I'm using auto-cpufreq on a Lenovo ideapad 330s.
My laptop is charged, and full, but auto-cpufreq stays on "powersave" governor.
I updated my BIOS recently.
My battery state:
System information:
The text was updated successfully, but these errors were encountered: