8

I have solved the problem of my laptop waking in 20 seconds like this - see links there. I would like to understand how this works.

That solution is to somehow modify a variable in /sys/power/mem_sleep, namely s2idle to deep.

Looking at that file it contained this single line:

s2idle [deep]

which was already confusing , given both variables seemed mentioned there, one in brackets.

I didn't need to decide anything though, because, as instructed in the second comment, I haven't tried to change that file as such, but I have used the command:

echo deep | sudo tee -a /sys/power/mem_sleep

Looking again at that file it seemed unchanged though.

After restart the waking from suspend is instantaneous, but that file has the same single line s2idle [deep] that it had in the first place.

I have trusted that solution but:

  • I don't know how to reverse that in case I had to

  • The file seems unchanged so what changing/reversing could mean?


Maybe interesting to notice, there is a file at that location sys/power/wakeup_count which contains this single line: 20. Could those be the 20 seconds that I had experienced before?

cipricus
  • 3,444
  • 2
  • 34
  • 85
  • 1
    This command wrote deep to the file. But it had already deep selected. It is a default value. The value in brackets shows the value selected. You can try to write s2idle and see what happens. – Pilot6 Oct 10 '22 at 14:24
  • @Pilot6 - Could it be that in a buggy way that option was not "read" and became active after my command? – cipricus Oct 10 '22 at 14:28
  • Well, it could be the case... – Pilot6 Oct 10 '22 at 14:28
  • @user68186 - Indeed that file and all the others at the same location/folder are marked as recently modified. But the file looks like it was before my command although the suspend/wake behavior is different. – cipricus Oct 10 '22 at 14:30
  • @Pilot6 - This command wrote deep to the file. - try to write s2idle and see what happens. You mean to run echo s2idle | sudo tee -a /sys/power/mem_sleep? And should that trigger the line [s2sleep] deep? – cipricus Oct 10 '22 at 14:33
  • Yes, this is correct. – Pilot6 Oct 10 '22 at 14:33
  • HOW TO CHANGE!? IS EDITING THE FILE ALLOWED? It appears not. – mathtick May 27 '23 at 13:14
  • @mathtick - All that remain obscure, the document cannot be manually changed, but it can be changed by that command as seen in my linked answer (see first line of the question) . By the way: don't use uppercase letters. – cipricus May 27 '23 at 19:16

1 Answers1

4

You wrote deep to that system file. That file has fixed values that you can see. The one in brackets is the selected value. So it doesn't look like you changed anything.

The meaning of the values is:

The /sys/power/mem_sleep file controls the operating mode of system suspend. Reading from it returns the available modes as "s2idle" (always present), "shallow" and "deep" (present if supported). The mode that will be used on subsequent attempts to suspend the system (by writing "mem" to the /sys/power/state file described above) is enclosed in square brackets.

  Writing one of the above strings to this file causes the mode
  represented by it to be used on subsequent attempts to suspend the system.
  See Documentation/admin-guide/pm/sleep-states.rst for more
  information.

The /sys/power/wakeup_count file allows user space to put the system into a sleep state while taking into account the concurrent arrival of wakeup events. Reading from it returns the current number of registered wakeup events and it blocks if some wakeup events are being processed at the time the file is read from. Writing to it will only succeed if the current number of wakeup events is equal to the written value and, if successful, will make the kernel abort a subsequent transition to a sleep state if any wakeup events are reported after the write has returned.

Source: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-power

Pilot6
  • 90,100
  • 91
  • 213
  • 324
  • (you seem to have posted twice). Do you know what each variable means? "s2idle" (always present), "shallow" and "deep" (present if supported) - I might test them but maybe that is risky? – cipricus Oct 10 '22 at 14:38
  • Oops. I'll fix it. The second part is about wakeup_count. – Pilot6 Oct 10 '22 at 14:39
  • After doing the s2idle selection the file was changed as expected (brackets moved onto that). But that didn't change the behavior of my laptop regarding wakeup time. It's still instant. So the problem was different in the first place. Now I don't know what option is better. In the initial comment that provided the solution it says deep maybe helpful for power consumption etc. But the initial problem seems buggy, fixed now, but which I cannot track anymore. – cipricus Oct 10 '22 at 14:46
  • The second part is about wakeup_count - my secondary question was in fact "what is wakeup count?" And by the way what is the difference between deep and s2idle - and shallow? – cipricus Oct 10 '22 at 14:47
  • 1
    deep is default if present. Explanation of wakeup_count has been added. – Pilot6 Oct 10 '22 at 15:04
  • This looks like a bug (after some update, the initial problem re-appeared and was fixed in the same way: the file /sys/power/mem_sleep was already in the form that the command is supposed to trigger, but the latter is needed nonetheless. - Do you have an idea against what package this could be reported (or checked if already reported) as a bug? – cipricus Oct 18 '22 at 06:19
  • It can be reported against kernel. ubuntu-bug linux. – Pilot6 Oct 18 '22 at 07:25
  • In fact it seems that after a while in 22.04 and always in 22.10 the opposite command echo s2idle | sudo tee -a /sys/power/mem_sleep is the one that is needed! - Very odd and very hard to track. Updated here. – cipricus Mar 01 '23 at 06:40
  • This question contains the pertinent info I was trying to get about what those commands do: deep was supposed to trigger a longer wake-up time in the first place and lower battery use, s2idle is supposed to give short wake-up time and use more energy. Something was wrong in 22.04 and then was fixed. At some point a new problem appeared where s2idle was not remembered across reboots (I have to run that command at startup now.) – cipricus Aug 28 '23 at 06:47