Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] X crashes or freezes when returning from susupend (Read 1362 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

[SOLVED] X crashes or freezes when returning from susupend

Hello,

I have a beautiful Artix Linux installation on a laptop that works pretty well except X11 crashes or freezes when the system suspends (I close the lid).

Things I Have Tried:
  • Adding "amd_iommu=off" to the command line as suggested in a similar post.
  • Trying different kernels (I'm using linux-zen but have tried linux-lts and linux).
  • Installing drivers (xf86-video-amdgpu)
  • Adding "dbus-launch" to ~/.xinitrc
  • Editing "/etc/elogind/login.conf" to disable all options to hibernate

Specific Description of the Problem:
This is a fresh install, not many extra applications are installed. This is a base install with only a basic window manager and web browser added. I do not use swap. I am using openrc. When running "startx," closing the lid of the computer, and then opening it again I am presented with one of two options: a screen with a cursor (underscore) in the top left corner which blinks once then nothing (a blank screen), or a TTY informing me that X has crashed. The issue does not occur when I suspend from the TTY by either closing the lid or by running "sudo loginctl suspend."

I have been working on this for several hours and am stumped. I have attached some system information below. If I should provide any more information please let me know and thank you for your help.

Re: X crashes or freezes when returning from susupend

Reply #1
It seems like X crashes the first time and freezes the second time when returning from suspend. I have attached the logs from each situation below. When it freezes the system is unresponsive unless the power button is pressed - then it wakes up and shuts down normally showing the usual messages when powering off.

Re: X crashes or freezes when returning from susupend

Reply #2
Hello,
Is your root partition encrypted ?
Code: [Select]
ID-1: / size: 468.38 GiB used: 4.87 GiB (1.0%) fs: ext4 dev: /dev/dm-0 mapped: cryptroot

inxi can't find swap, maybe X11 too :
Code: [Select]
swap:
   Alert: No swap data was found.

Re: X crashes or freezes when returning from susupend

Reply #3
Thank you for your response! Yes, my root partition is encrypted. I do not use swap currently, but I have also disabled hibernation in `/etc/elogind/logind.conf.` Is a swap file necessary for suspending the system to RAM? I can try to add swap tomorrow to see if that fixes the issue.

Re: X crashes or freezes when returning from susupend

Reply #4
Thank you for your response! Yes, my root partition is encrypted. I do not use swap currently, but I have also disabled hibernation in `/etc/elogind/logind.conf.`
Ok, you have disabled hibernation.
That was the question I was asking myself.


Quote
Is a swap file necessary for suspending the system to RAM? I can try to add swap tomorrow to see if that fixes the issue.
Probably not :
https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate

Someone had the same problem and finally solved it :
https://forum.artixlinux.org/index.php/topic,4587.msg29446.html#msg29446

Do a search for "suspend" in this forum, you will find a lot of discussions about it.

I leave the specialists to find possible leads to follow..

Re: X crashes or freezes when returning from susupend

Reply #5
There are a lot of people who have had similar problems that I have found, but their solutions have not worked for me. A lot of the problems are related to NVIDIA (I don't use NVIDIA), and the most of the rest are generally solved by a kernel update or something like "it just started working." I can try the solution you linked by installing a system logger like metalog and see if that fixes the issue, but I don't know if I would really consider that a solution because it shouldn't depend on a program like that to suspend properly. I should be able to get back with results later today. If nothing else I'll be able to better log what is happening to the system when it suspends and post it.

Re: X crashes or freezes when returning from susupend

Reply #6
I have tried those things, and the issue persists. I tried enabling swap, installing metalog, and reinstalling the entire system. At least it doesn't freeze when suspending from loginctl, so I have posted the output from dmesg after suspending a bunch of times. It doesn't seem t give me much useful information though. None of the warnings it shows seem pertinent to suspending.

Is there anything else I can try to fix this issue? I am guessing it is probably hardware related.

I have recorded a video of the installation process that shows the problem. I can find a way to upload it if that would be helpful.

Thank you.

Re: X crashes or freezes when returning from susupend

Reply #7
I do use nvidia. For a long time using the 'official' methods worked sporadically.
Suspend tended to have more success than hibernate but often that broke as well.
A fail was the system came back but the screen did not. I just checked and using KDE to suspend (sleep they call it?) is not working on my system.

Bizarrely sending the commands directly to the kernel did, and does work.
eg suspend:
Code: [Select]
su
echo "mem" > /sys/power/state
Hibernate:
Code: [Select]
su
echo "platform" > /sys/power/disk
echo "disk" > /sys/power/state
It's worth a try. If it works there's a way I make it more convenient

Re: X crashes or freezes when returning from susupend

Reply #8
Bizarrely sending the commands directly to the kernel did, and does work.
eg suspend:
Code: [Select]
su
echo "mem" > /sys/power/state
Hibernate:
Code: [Select]
su
echo "platform" > /sys/power/disk
echo "disk" > /sys/power/state
It's worth a try. If it works there's a way I make it more convenient


That does work, bizarrely.  Thank you! What is this way you said you could make it more convenient?

Why does it work though? And how do I get it to do that by default? And why is it so fast ??? loginctl takes about 10 or 20 seconds to suspend where that does so instantly.

Thanks for your reply. I will see if I can apply that solution to get the system to suspend right when the laptop lid is closed.

Re: X crashes or freezes when returning from susupend

Reply #9
F**k knows  :)
Something other methods do (I've tried a few) must overcomplicate things ?

I'll post my solution in a minute.


Re: X crashes or freezes when returning from susupend

Reply #10
C code adapted from a tutorial.
Suspend:
Code: [Select]
   #include <stdio.h>
   #include <stdlib.h>
   #include <sys/types.h>
   #include <unistd.h>

int main() {
    #define word "mem"

    // creating file pointer to work with files
    FILE *fptr;
setuid(0);
    // opening file in writing mode
    fptr = fopen("/sys/power/state", "w");

    // exiting program
    if (fptr == NULL) {
        printf("Error!");
        exit(1);
    }
    fprintf(fptr, "%s", word);
    fclose(fptr);
    return 0;
}
Hibernate
Code: [Select]
   #include <stdio.h>
   #include <stdlib.h>
   #include <sys/types.h>
   #include <unistd.h>

int main() {
    #define word1 "disk"
    #define word2 "platform"
    // creating file pointer to work with files
    FILE *fptr;
FILE *fptr2;
setuid(0);
    // opening file in writing mode
    fptr2 = fopen("/sys/power/disk", "w");
    fptr = fopen("/sys/power/state", "w");

    fprintf(fptr2, "%s", word2);
    fprintf(fptr, "%s", word1);
    fclose(fptr2);
    fclose(fptr);
    return 0;
}

For example save the suspend one as mysuspend.c and compile
Code: [Select]
cc mysuspend.c -o mysuspend
Set SUID
Code: [Select]
sudo chown root:root mysuspend
sudo chmod u+s mysuspend

Now running that program as a normal user will suspend.
What I do is copy them to /usr/local/bin and I've set up KDE keyboard shortcuts to point at both (CTRL-ALT-SHIFT-s for suspend)

Ideally you'd want to find what is run when the lid is closed and intercept it , redirect it, to mysuspend.
Maybe someone who uses a laptop regularly will know how ?

Re: X crashes or freezes when returning from susupend

Reply #11
Thank you for the code. I will try it if I have time tomorrow. I wonder if I should make a separate thread to ask what script is run by elogind/loginctl when it suspends so I may replace it if I can't find it on my own.

The only other thing that concerns me is if loginctl takes a long time to suspend because of some safety guards it has and if this raw method of suspending is less safe for my data?

Thank you again, I'll come back to share the results with you after I try this.

Re: X crashes or freezes when returning from susupend

Reply #12
I wonder if I should make a separate thread to ask what script is run by elogind/loginctl when it suspends so I may replace it if I can't find it on my own.
Might be an idea.
Quote
The only other thing that concerns me is if loginctl takes a long time to suspend because of some safety guards it has and if this raw method of suspending is less safe for my data?
Your data should be saved and backed up several places to be considered safe!
All I can say is it's caused me no harm and I can see from the timestamp I made those programs over two years ago and use the suspend one most evenings.

Edit:
I got to wondering. Though not a huge amount of information there's some explanation of why it's faster, and possible issues here https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Low_level_interfaces.
Linked from that page https://wiki.archlinux.org/title/Acpid might be useful in controlling lid close actions ?

 

Re: X crashes or freezes when returning from susupend

Reply #13
That provides an alternative to logind, even though it involves disabling loginctl. I'll continue to try to figure out what the issue is with loginctl, but that provides a solution for now. Thank you!