# Finally some success with suspend/resume



## Crivens (Oct 30, 2014)

Hello world,

I finally had some progress with my laptop which would not resume. Resume from S3 would result in a forced power cycle after watching a black screen until bored.

What did the trick for me was to set 
	
	



```
hw.usb.no_suspend_wait=1
```
 and now it works a lot better. Well, this is easy considering it did not work at all before that. And it only works when in the console, not X11. That is a bit strange, the console is using the new vt driver, so basically there should be little difference, yes?

Anyway, I post this here so some other users may have a try at this. The most interesting point is that suspend/resume would also hang when USB was disabled in the BIOS and no driver was loaded. Now it would be interesting what else that sysctl affects, but that is "more research required".


----------



## Crivens (Nov 4, 2014)

To be more detailed: I cleaned up my sysctl.conf after the success to remove old crud from a long history of getting this to work. And what could possibly go wrong? It did no longer work. You also need these entries:

```
hw.pci.do_power_suspend=0
hw.pci.do_power_nodriver=1
```
The last one, I am not sure about. But I have restored them from a backup and it now works. So you need more than one setting, and why these are connected is not really obvious (to me).


----------



## jrm@ (Nov 4, 2014)

What laptop is it?  It could  be helpful for others if you had these tips added to the Laptop Wiki Page.


----------



## Crivens (Nov 4, 2014)

It's an ASUS F8P. The ACPI seems to be, well, seems to have much room for improvements on any ASUS hardware I have. This might be normal, as I do not switch my hardware like some fashion victim, it has to work some years before being even considered old. So my experience with newer hardware (<5 years) is very limited. Maybe it is much better these days, maybe not.


----------



## Juanitou (Nov 4, 2014)

jrm said:


> What laptop is it?  It could  be helpful for others if you had these tips added to the Laptop Wiki Page.


I opened a ticket on this matter but it has not been triaged yet. Do you know of a way to ping a developer about this (only they can modify the wiki).


----------



## Juanitou (Nov 4, 2014)

Also, do you know why there are no memstick images of FreeBSD-11.0-CURRENT for amd64 or i386 here?


----------



## jrm@ (Nov 5, 2014)

I asked Glen Barber and he said there is a problem.  They should be back soon.


----------



## Crivens (Nov 14, 2014)

Crivens said:


> To be more detailed: I cleaned up my sysctl.conf after the success to remove old crud from a long history of getting this to work. And what could possibly go wrong? It did no longer work. You also need these entries:
> 
> The last one, I am not sure about. But I have restored them from a backup and it now works. So you need more than one setting, and why these are connected is not really obvious (to me).


And I found something which I consider worth mentioning: you not only need to disable the power management for suspend, but you have to keep the power management for resume!

So this is my current sysctl.conf:

```
#do this to keep suspend from hanging the system at resume
hw.usb.no_suspend_wait=1
hw.pci.do_power_suspend=0

#just to make sure...
hw.pci.do_power_resume=1

hw.pci.do_power_nodriver=3

hw.acpi.lid_switch_state=S3
```
Also I would like to take this chance to praise ZFS for its robustness while trying things out - no file system damage from not resuming is a great thing.


----------



## Crivens (Jan 9, 2015)

Well, when I discovered 2 days ago that I was running a system from november, I did an update to 10.1-STABLE  r276813, but now suspend is completely borked. When it was a good chance that the resume would work 2 out of three times, it now does not even suspend correctly. Just the screen goes dark, and that's it. Setting  debug.acpi.suspend_bounce to 1 does not give information, it also simply turns the screen off and does nothing. And that is even the case when all settings I had done before are removed. So, sadly I am worse off than before, but I will not give up. Who knows, in the end this might motivate me enough to work on some suspend-to-disc.


----------



## Crivens (Jan 25, 2015)

Okay - I was at the point where the system will not even suspend. One good tip for anyone trying to get suspend/resume to work is this: get rid of VESA support in your kernel config!

After removing this by the use of a nooptions VESA line in my kernel config (you see, I include GENERIC and strip out anything I do not need) I can now suspend and resume again. This worked in 100% of attempts (N=1, so there is more testing needed!), but all in all this looks like it can be the problem.


----------



## merkata (Jan 26, 2016)

I'm writing in this thread, because I found it while on my quest to get my suspend/resume working (again) on my Sony VAIO VPCYB3V1E - it wasn't working on 10.1, so I updated to -CURRENT and things were looking pretty great (suspend/resume working with some graphics issues on resuming that were fixed in later commits). Now this is some months ago and update after update things were the same or better. I hadn't updated -CURRENTcurrent on my laptop in about a month as of this writing, so I updated, but after that suspending failed. It is quite odd, since I haven't changed anything in my setup or configurations. Following the suspend hints in the wiki, I tried to narrow down the possible reasons by eliminating unnecessary kernel modules, though I wasn't able to remove the bluetooth modules, ng_bluetooth and others. I put a WITHOUT_BLUETOOTH=yes in my /etc/src.conf and rebuild world and kernel, a reboot later my worries were gone - the system suspends just fine now. Hopefully it can save someone with similar troubles some time.


----------



## Crivens (Jan 27, 2016)

Worth a try - I have been faced with a broken suspend/resume again for some time, but do not know which update brought it in again. I use it seldom, but when I do I would like it to work. If I knew it would work, I would use it more.

I also tried -current, but that made no difference. I do not even know which driver in particular does the breaking. Some more testing will be in order there. But I will definitely give the removal of bluetooth a try.


----------



## jrm@ (Jan 27, 2016)

Now that frequent -CURRENT snapshots are released, it's easier to narrow down the commit that introduced the problem.  Unfortunately, you still have to bisect the problem by wiping and installing your system some number of times.


----------



## gofer_touch (Feb 17, 2016)

Is there anyone out there using FreeBSD 10.2 or higher with working suspend resume for the Thinkpad X230?


----------



## lme@ (Feb 17, 2016)

gofer_touch said:


> Is there anyone out there using FreeBSD 10.2 or higher with working suspend resume for the Thinkpad X230?


Works almost flawlessly here. Only issue is the dead SD card reader after resuming.


----------



## gofer_touch (Feb 17, 2016)

WOW! This is great news then. Are your USB ports still functional after resume? Did you have to do any specific tuning/tweaks/configs to get this to work or does it work out of the box?

I am asking these questions because if this is the case I can switch over my main workstation which is a laptop to FreeBSD.


----------



## lme@ (Feb 18, 2016)

You need to use vt instead of sc. Apart from that no further configuration is needed IIRC. USB still works after resuming. That was fixed some time ago.


----------



## Seagate (Jan 9, 2017)

Crivens said:


> And I found something which I consider worth mentioning: you not only need to disable the power management for suspend, but you have to keep the power management for resume!
> 
> So this is my current sysctl.conf:
> 
> ...



i've try with your sysctl.conf in Thinkpad T420. suspend and resume is work but resuming with black screen.
how to fix that ?


----------



## hph (Mar 7, 2021)

Would someone (lme@) be interested in sharing their settings for the x230 for the current 12.2 release
I'm at loss with my configs, since both audio and usb after suspend doesn't work that nicely as before.

Thanks and best regards


----------



## Mjölnir (Mar 7, 2021)

hph said:


> Would someone (lme@) be interested in sharing their settings for the x230 for the current 12.2 release
> I'm at loss with my configs, since both audio and usb after suspend doesn't work that nicely as before


Just post your your /boot/loader.conf, /etc/sysctl.conf and the output of `sysrc {kld_list,{economy,performance}_cx_lowest}`.  Put short output inside [CODE]like this (let's say up to 20 lines +/- X)[/CODE], long output as attachment.  Maybe you have to cheat the file ending to be .txt. Alternative to attachment: put in [SPOILER=filename.conf]
config knob
plethora of more config knobs ...
[/SPOILER]
PS if you have any *.local config files, naturally we need to see those, too, at least what is related to the issue.  You're running 12.2-RELEASE-p4, correct? Else please post the [ICODE]output of the command 'uname -aU'[/ICODE]


----------



## hph (Mar 11, 2021)

Thanks Mjölnir

`uname -aU` returns
> FreeBSD fravia.freebsd.mkf 12.2-RELEASE-p4 FreeBSD 12.2-RELEASE-p4 GENERIC  amd64 1202000

Brace yourself
(I somewhat heavily commented, sourced configs from different places, not sure if that's helpful or only spaghetti )
here's my

loader.conf


```
###############################################################################
# /boot/loader.conf configuration file for x230 thinkpad                      #
###############################################################################
### Structure
## SYSTEM
# General
# -
# Networking
# Specific
# Disabled

# General
# Dtrace system state information
security.bsd.allow_destructive_dtrace=0

# Asynchronous I/O
aio_load="YES"


## System dependent
# enable LCD backlight control, ThinkPad buttons, etc
acpi_ibm_load="YES"

#increase inactivity periods by reducing the interrupt rate
kern.hz="100"
hint.atrtc.0.clock="0"

# Disk organization mgmgt
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"

# filesystems support
zfs_load="YES"
# Load MMC/SD card-reader support
mmc_load="YES"
mmcsd_load="YES"
sdhci_load="YES"
# Filesystems in Userspace
fuse_load="YES"
# desktop-ish filesystems, webcam driver, etc
cuse4bsd_load="YES"

# Handle Unicode on removable media
libiconv_load="YES"
libmchain_load="YES"
cd9660_iconv_load="YES"
msdosfs_iconv_load="YES"

# Access ATAPI devices through the CAM subsystem
atapicam_load="YES"


## kernel
# Boot-time kernel tuning
kern.ipc.shmseg=1024
kern.ipc.shmmni=1024
kern.maxproc=100000

# Bootup, Startup
boot_mute="YES"
autoboot_delay=5


## audio
hw.syscons.bell=0
kern.vt.enable_bell=0
snd_hda_load="YES"


## virtualization
# Skip the often slow memory tests in VMs
hw.memtest.tests=0

## Synaptics
# Enable psm configuration interface for trackpad/trackpoint:
hw.psm.synaptics_support=1
hw.psm.trackpoint_support=1


## Networking
# increase the network interface queue link default (50) is way too low
net.link.ifqmaxlen="2048" # 1024
#WiFi
iwn6000g2afw_load="YES"
#if_iwn_load="YES"
legal.intel_iwn.license_ack=1
#WLAN
wlan_wep_load="YES"
wlan_ccmp_load="YES"
wlan_tkip_load="YES"
# Load the H-TCP algorithm. It has a more aggressive ramp-up to max
cc_htcp_load="YES"


## CPU
# enable CPU firmware updates
cpuctl_load="YES"

## Power management
# Disable acpi throttle by default, fixes issues with powerd and later AMDs
hint.acpi_throttle.0.disabled="1"
# Intel Core thermal sensors
coretemp_load="YES"

hint.p4tcc.1.disabled=1
hint.acpi.0.diabled="0"
hint.acpi_throttle.0.disabled="1"
hint.ahcich.0.pm_level="5"
hint.ahcich.1.pm_level="5"
hint.ahcich.2.pm_level="5"
hint.ahcich.3.pm_level="5"
hint.ahcich.4.pm_level="5"
hint.ahcich.5.pm_level="5"

# suspend on lid close
hw.acpi.lid_switch_state=s3

# Any PCI devices that do not have a driver put into ACPI D3 power state (off)
hw.pci.do_power_nodriver=3

#higher sound card buffering latency
hw.snd.latency=4 #7

hint.pcm.0.buffersize=65536
hint.pcm.1.buffersize=65536
hint.pcm.2.buffersize=65536
hw.snd.feeder_buffersize=65536

# Enable GPU power-saving idle states
compat.linuxkpi.enable_rc6=7

## virtualization
vboxdrv_load="YES"
vfs.aio.max_buf_aio=8192
vfs.aio.max_aio_queue_per_proc=65536
vfs.aio.max_aio_per_proc=8192
vfs.aio.max_aio_queue=65536

# Enable NewCons / vt
kern.vty=vt
# enable i915 kernel mode setting:
i915kms_load="YES"

################################################################################
# p4tcc Intel-Relict of netburst ages
hint.p4tcc.0.disabled=1
hint.p4tcc.1.disabled=1

hint.acpi_throttle.0.disabled="1"
hint.ahcich.0.pm_level="5"
hint.ahcich.1.pm_level="5"
hint.ahcich.2.pm_level="5"
hint.ahcich.3.pm_level="5"
hint.ahcich.4.pm_level="5"
hint.ahcich.5.pm_level="5"

# Devil worship in loader logo
#loader_logo="beastie"

# Boot-time kernel tuning
kern.ipc.shmseg=1024
kern.ipc.shmmni=1024
kern.maxproc=60000

# In-memory filesystems
tmpfs_load="YES"

# Intel i915 tunables (many of those are often default in Linux distros)
#enable power savings
drm.i915.powersave="1"
#enable render C-state 6.
drm.i915.enable_rc6="7"
#enable Intel IOMMU,
drm.i915.intel_iommu_enabled="1"
#enable LVDS downlock,
drm.i915.lvds_downclock=1
#use semaphores for inter-ring sync
drm.i915.semaphores="1"
#enable framebuffer compression
drm.i915.enable_fbc="1"

#enable LCD screen brightness control (see below)
#acpi_video_load="YES"  #suppressed

#limit ZFS ARC (4G instead of default  half=8Gb out of 16)
vfs.zfs.arc_max="4G"

#enable CPU freq monitoring
cpufreq_load="YES"
#enable temperature monitoring
coretemp_load="YES"

#kern.vt.fb.default_mode="1366x768"

# Disable legacy p4 and acpi power management
hint.p4tcc.0.disabled=1
hint.acpi_throttle.0.disabled=1

# Enable GPU power-saving idle states
compat.linuxkpi.enable_rc6=7

###################################################

umass_load="YES"
hint.acpi.0.disabled="0"
hint.pcm.0.buffersize=65536
hint.pcm.1.buffersize=66536
hw.snd.feeder_buffersize=65536
#hw.psm.synaptics_support="1"

# Load Linux compat
linux_load="YES"

sysctlinfo_load="YES"

# enable
aesni_load="YES"

### Disabled
#opensolaris_load="YES"
```

sysctl.conf

```
# $FreeBSD: releng/12.2/sbin/sysctl/sysctl.conf 337624 2018-08-11 13:28:03Z brd $
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#

# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0
security.bsd.see_other_uids=0
security.bsd.see_other_gids=0
security.bsd.see_jail_proc=0
security.bsd.unprivileged_read_msgbuf=0
security.bsd.unprivileged_proc_debug=0
kern.randompid=1
vfs.zfs.min_auto_ashift=12

# increase laptop speaker volume
hw.snd.default_auto=1
hw.snd.vpc_0db=30 #45 (origval)
hw.snd.latency=0

# Fix resume from suspend
hw.usb.no_suspend_wait=1
hw.pci.do_power_suspend=0
hw.pci.do_power_resume=1
hw.pci.do_power_nodriver=3

# suspend when lid is closed
hw.acpi.lid_switch_state=S3
hw.syscons.sc_no_suspend_vtswitch=1
dev.acpi_ibm.0.events=1

# Enhance shared memory X11 interface
kern.ipc.shmmax=67108864
kern.ipc.shmall=32768

# Enhance desktop responsiveness under high CPU use (200/224)
kern.sched.preempt_thresh=224

# Bump up maximum number of open files
kern.maxfiles=200000

# Disable PC Speaker
hw.syscons.bell=0

# Enable shared memory (for Chromium)
kern.ipc.shm_allow_removed=1

# Allow users to mount disks
vfs.usermount=1


# vfs VirtualBox
vfs.aio.max_buf_aio=8192
vfs.aio.max_aio_queue_per_proc=4096
vfs.aio.max_aio_per_proc=8192
vfs.aio.max_aio_queue=8192

# stop scattered core files
kern.corefile=/tmp/%N.core

############################################################3
net.local.stream.recvspace=65536
net.local.stream.sendspace=65536



# Enhance shared memory X11 interface
kern.ipc.shmmax=67108864
kern.ipc.shmall=32768



# Enhance desktop responsiveness under high CPU use (200/224)
kern.sched.preempt_thresh=224




# Bump up maximum number of open files
kern.maxfiles=200000



# increase UFS readahead
vfs.read_max=128

# needed for chromium to work
kern.ipc.shm_allow_removed=1
hw.syscons.bell=0
kern.vt.enable_bell=0

# performance and behaviour
kern.metadelay=8
kern.filedelay=10
kern.filedelay=13


#attinutation to prevent clipping
hw.snd.vpc_0db=1
hw.snd.vpc_mixer_bypass=1
hw.snd.latency=5
hw.snd.feeder_rate_quality=4
```


----------



## Mjölnir (Mar 11, 2021)

Mjölnir said:


> You're running 12.2-RELEASE-p4, correct? Else please post the [ICODE]output of the command 'uname -aU'[/ICODE]


hph `uname -aU >> forum`
How can the contents of a singe file be _"sourced configs from different places"_?
What is the meaning of _"Brace yourself"_?  Never heard that before.


----------



## Snurg (Mar 11, 2021)

Mjölnir , I guess he intended to say something like "be prepared for something", as the configs look like (at least in my impression) a highly convoluted collection from the internet, which he also said in other words.

If I may give hph an advice... boil down all that to what originally was there, eg leave only the ashift setting.
Nobody can tell whether some of these settings disrupt your computer from resuming correctly.
Then re-enable step-by-step to find the offender.

If you then still have problems, read the Wiki (it's partly obsolete, but still a must read).
Don't worry, on Thinkpads with Intel graphics suspend/resume usually works fine.


----------



## Mjölnir (Mar 11, 2021)

Well, I asked exactly the questions I asked for a reason.


----------



## hph (Mar 12, 2021)

@Mjölnir thank you, I updated the report
@Snurg  thanks for translating  - will try that

Sorry for not pointing this out before.
Hope I didn't derail the thread, my suspend and resume work nicely (aside from pulling an external devices before suspend now and then) but my audio is kind of broken since I upgraded the Release - I can connect via device.hints but my mixer setting/audio
is reacting strange.

If someone has a working setup with 12.2-RELEASE-p4, I'd happy to get your configs. 

Thanks again


----------



## Snurg (Mar 12, 2021)

Then I'd suggest to first reduce the convoluted configuration to the absolute minimum (the only really necessary setting is probably zfs ashift).
If that does not fix the issue, then open a new thread with a concise title "Upgrade to 12.2: Audio no longer works after suspend/resume", which indicates that you had it working, and that the problem is possibly-probably caused by the upgrade, and include your configuration in spoilers (see the editor menu, click the hamburger, then choose spoiler).


----------



## Mjölnir (Mar 12, 2021)

OK so this is the working set of configs of your X230 laptop, suspend/resume works, but you're not happy with your sound setup, it's not doing what you expect.  Correct?

The default `kern.hz=1000`, olli@ recommends setting that to a common multiple of video frequencies, thus my recommendation is 1200 or 1800, and
the general guideline is to keep loader.conf(5) as minimal as possible, only load kernel modules from there that are needed to boot _the BeaSD_ (reasonable exception: `cpu_microcode_load="YES"`), and the sysctl(8) knobs that can't be set @runtime later.  So you should move most of your knobs to either sysctl.conf(5) or rc.conf(5) (`foreach xxx_load do` `sysrc kld_list+=" xxx"`)
Then, the sound issues should go to a new or continue an existent thread IMHO.


----------



## Mjölnir (Mar 12, 2021)

PS I want to maintain some structure in my rc.conf(5), thus I'm doing in each commented section like this:
`kld_list="$kld_list cuse"    # cuse(4) needed by webcamd(8)`
instead of having all kernel modules in one long `kld_list`.


----------



## olli@ (Mar 15, 2021)

Mjölnir said:


> The default `kern.hz=1000`, olli@ recommends setting that to a common multiple of video frequencies, thus my recommendation is 1200 or 1800


Actually, I would rather advise to _decrease_ it to 600 or even 300, especially on a mobile machine (laptop, notebook) that may potentially run on battery, in order to give the CPU more opportunity to enter power-saving P-states. I even run my normal desktop workstation with HZ=300. Increasing the HZ value does _not_ improve interactivity for a normal desktop machine.


----------



## Snurg (Mar 15, 2021)

olli@ said:


> Actually, I would rather advise to _decrease_ it to 600 or even 300, especially on a mobile machine (laptop, notebook) that may potentially run on battery, in order to give the CPU more opportunity to enter power-saving P-states. I even run my normal desktop workstation with HZ=300. Increasing the HZ value does _not_ improve interactivity for a normal desktop machine.


Wasn't the default HZ=100 on earlier FreeBSD versions?
I only had to increase that a bit for playing Diablo 2 in a window, back in the 32bit age, to avoid the mouse cursor getting jerky.

1000 is really extreme...
Damn good suggestion to reduce this.  
Maybe a hint to this could be added to the Environmentalist thread...


----------



## Mjölnir (Mar 15, 2021)

olli@ said:


> Actually, I would rather advise to _decrease_ it to 600 or even 300, especially on a mobile machine (laptop, notebook) that may potentially run on battery, in order to give the CPU more opportunity to enter power-saving P-states. I even run my normal desktop workstation with HZ=300. Increasing the HZ value does _not_ improve interactivity for a normal desktop machine.


Ok took me some time to get that... is this correct?

the interactivity/responsiveness is mainly affected by the sysctl(8) knobs `kern.sched.{static_boost,preempt_thresh,interact,slice}`.
the accuracy of timings for multimedia is (can be set) better with a higher `kern.hz`.
if you want to enable polling(4) on a network iface, the recommendation is to set `kern.hz >= 1000`; polling(4) saves IRQs, thus it helps with interactivity.


----------



## olli@ (Mar 15, 2021)

Actually, I would not touch _any_ of those settings. FreeBSD works pretty well out of the box for desktop systems. The only thing that _might_ help somewhat is setting `kern.sched.preempt_thresh=224`, but even this is not strictly necessary if you have adequate hardware.

I should also mention that the polling(4) manual page might be somewhat unclear. Polling was designed to improve responsiveness for heavy-loaded servers that are running > 90 % on IRQ for I/O, potentially even deadlocking the system. It was not designed for desktop machines, and I doubt that it improves interactivity at all. When your system does not have a high IRQ load, then polling won’t help at all. Check the output from `vmstat -i` – If you get 5 digit numbers or larger in the last column (i.e. >= 10,000), then you might benefit from polling. Otherwise don’t bother.


----------



## Mjölnir (Mar 15, 2021)

Then why was the default `kern.hz` increased from 100 to 1000 at all?
What about the timings for multimedia stuff?
Can I use `dev.pcm.*.bitperfect=1` with `kern.hz < 1000`
Sidenote: maybe I "tuned" & managed to mess up some of my `hw.snd`, `dev.pcm` & timing (`kern.timecounter.alloweddeviation`) sysctl(8) knobs, because I suspected sub-optimal default settings, but now I found out my 3m long audio cable has a slack joint...


----------



## Snurg (Mar 15, 2021)

On the 8088 PC with 4.77MHz the 18 ticks/sec already was a considerable load, depending on the chain of installed interrupt handlers.
Nowadays with GHz clocks and modern processors, 1000 are not much.

The issue is more with the constant waking up from sleep, usually not necessary with normal desktop usage.
But on laptop on battery you care about a few minutes more capacity.


----------

