| File: | kern/subr_suspend.c |
| Warning: | line 63, column 2 Value stored to 'error' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* $OpenBSD: subr_suspend.c,v 1.16 2023/07/12 18:40:06 cheloha Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> |
| 4 | * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> |
| 5 | * |
| 6 | * Permission to use, copy, modify, and distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #include <sys/param.h> |
| 20 | #include <sys/systm.h> |
| 21 | #include <sys/buf.h> |
| 22 | #include <sys/clockintr.h> |
| 23 | #include <sys/reboot.h> |
| 24 | #include <sys/sensors.h> |
| 25 | #include <sys/sysctl.h> |
| 26 | #include <sys/mount.h> |
| 27 | #include <sys/syscallargs.h> |
| 28 | #include <dev/wscons/wsdisplayvar.h> |
| 29 | #ifdef GPROF |
| 30 | #include <sys/gmon.h> |
| 31 | #endif |
| 32 | #ifdef HIBERNATE1 |
| 33 | #include <sys/hibernate.h> |
| 34 | #endif |
| 35 | |
| 36 | #include "softraid.h" |
| 37 | #include "wsdisplay.h" |
| 38 | |
| 39 | /* Number of (active) wakeup devices in the system. */ |
| 40 | u_int wakeup_devices; |
| 41 | |
| 42 | void |
| 43 | device_register_wakeup(struct device *dev) |
| 44 | { |
| 45 | wakeup_devices++; |
| 46 | } |
| 47 | |
| 48 | int |
| 49 | sleep_state(void *v, int sleepmode) |
| 50 | { |
| 51 | int error, s; |
| 52 | extern int perflevel; |
| 53 | size_t rndbuflen; |
| 54 | char *rndbuf; |
| 55 | #ifdef GPROF |
| 56 | int gmon_state; |
| 57 | #endif |
| 58 | #if NSOFTRAID1 > 0 |
| 59 | extern void sr_quiesce(void); |
| 60 | #endif |
| 61 | |
| 62 | top: |
| 63 | error = ENXIO6; |
Value stored to 'error' is never read | |
| 64 | rndbuf = NULL((void *)0); |
| 65 | rndbuflen = 0; |
| 66 | |
| 67 | if (sleepmode == SLEEP_SUSPEND0x01 && wakeup_devices == 0) |
| 68 | return EOPNOTSUPP45; |
| 69 | |
| 70 | if (sleep_showstate(v, sleepmode)) |
| 71 | return EOPNOTSUPP45; |
| 72 | #if NWSDISPLAY1 > 0 |
| 73 | wsdisplay_suspend(); |
| 74 | #endif |
| 75 | stop_periodic_resettodr(); |
| 76 | |
| 77 | #ifdef HIBERNATE1 |
| 78 | if (sleepmode == SLEEP_HIBERNATE0x02) { |
| 79 | /* |
| 80 | * Discard useless memory to reduce fragmentation, |
| 81 | * and attempt to create a hibernate work area |
| 82 | */ |
| 83 | hibernate_suspend_bufcache(); |
| 84 | uvmpd_hibernate(); |
| 85 | if (hibernate_alloc()) { |
| 86 | printf("failed to allocate hibernate memory\n"); |
| 87 | sleep_abort(v); |
| 88 | error = ENOMEM12; |
| 89 | goto fail_hiballoc; |
| 90 | } |
| 91 | } |
| 92 | #endif /* HIBERNATE */ |
| 93 | |
| 94 | sensor_quiesce(); |
| 95 | if (config_suspend_all(DVACT_QUIESCE2)) { |
| 96 | sleep_abort(v); |
| 97 | error = EIO5; |
| 98 | goto fail_quiesce; |
| 99 | } |
| 100 | |
| 101 | vfs_stall(curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self))); __ci;})->ci_curproc, 1); |
| 102 | #if NSOFTRAID1 > 0 |
| 103 | sr_quiesce(); |
| 104 | #endif |
| 105 | bufq_quiesce(); |
| 106 | #ifdef MULTIPROCESSOR1 |
| 107 | sched_stop_secondary_cpus(); |
| 108 | KASSERT(CPU_IS_PRIMARY(curcpu()))((((({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self ))); __ci;}))->ci_flags & 0x0008)) ? (void)0 : __assert ("diagnostic ", "/usr/src/sys/kern/subr_suspend.c", 108, "CPU_IS_PRIMARY(curcpu())" )); |
| 109 | #endif |
| 110 | #ifdef GPROF |
| 111 | gmon_state = gmoninit; |
| 112 | gmoninit = 0; |
| 113 | #endif |
| 114 | #ifdef MULTIPROCESSOR1 |
| 115 | sleep_mp(); |
| 116 | #endif |
| 117 | |
| 118 | #ifdef HIBERNATE1 |
| 119 | if (sleepmode == SLEEP_HIBERNATE0x02) { |
| 120 | /* |
| 121 | * We've just done various forms of syncing to disk |
| 122 | * churned lots of memory dirty. We don't need to |
| 123 | * save that dirty memory to hibernate, so release it. |
| 124 | */ |
| 125 | hibernate_suspend_bufcache(); |
| 126 | uvmpd_hibernate(); |
| 127 | } |
| 128 | #endif /* HIBERNATE */ |
| 129 | |
| 130 | resettodr(); |
| 131 | |
| 132 | s = splhigh()splraise(0xd); |
| 133 | intr_disable(); /* PSL_I for resume; PIC/APIC broken until repair */ |
| 134 | cold = 2; /* Force other code to delay() instead of tsleep() */ |
| 135 | |
| 136 | if (config_suspend_all(DVACT_SUSPEND3) != 0) { |
| 137 | sleep_abort(v); |
| 138 | error = EDEADLK11; |
| 139 | goto fail_suspend; |
| 140 | } |
| 141 | suspend_randomness(); |
| 142 | if (sleep_setstate(v)) { |
| 143 | sleep_abort(v); |
| 144 | error = ENOTBLK15; |
| 145 | goto fail_pts; |
| 146 | } |
| 147 | |
| 148 | if (sleepmode == SLEEP_SUSPEND0x01) { |
| 149 | /* |
| 150 | * XXX |
| 151 | * Flag to disk drivers that they should "power down" the disk |
| 152 | * when we get to DVACT_POWERDOWN. |
| 153 | */ |
| 154 | boothowto |= RB_POWERDOWN0x01000; |
| 155 | config_suspend_all(DVACT_POWERDOWN6); |
| 156 | boothowto &= ~RB_POWERDOWN0x01000; |
| 157 | |
| 158 | if (cpu_setperf != NULL((void *)0)) |
| 159 | cpu_setperf(0); |
| 160 | } |
| 161 | |
| 162 | error = gosleep(v); |
| 163 | |
| 164 | #ifdef HIBERNATE1 |
| 165 | if (sleepmode == SLEEP_HIBERNATE0x02) { |
| 166 | uvm_pmr_dirty_everything(); |
| 167 | hib_getentropy(&rndbuf, &rndbuflen); |
| 168 | } |
| 169 | #endif /* HIBERNATE */ |
| 170 | |
| 171 | fail_pts: |
| 172 | config_suspend_all(DVACT_RESUME4); |
| 173 | |
| 174 | fail_suspend: |
| 175 | cold = 0; |
| 176 | intr_enable(); |
| 177 | splx(s)spllower(s); |
| 178 | |
| 179 | inittodr(gettime()); |
| 180 | clockintr_cpu_init(NULL((void *)0)); |
| 181 | clockintr_trigger(); |
| 182 | |
| 183 | sleep_resume(v); |
| 184 | resume_randomness(rndbuf, rndbuflen); |
| 185 | #ifdef MULTIPROCESSOR1 |
| 186 | resume_mp(); |
| 187 | #endif |
| 188 | #ifdef GPROF |
| 189 | gmoninit = gmon_state; |
| 190 | #endif |
| 191 | #ifdef MULTIPROCESSOR1 |
| 192 | sched_start_secondary_cpus(); |
| 193 | #endif |
| 194 | vfs_stall(curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self))); __ci;})->ci_curproc, 0); |
| 195 | bufq_restart(); |
| 196 | |
| 197 | fail_quiesce: |
| 198 | config_suspend_all(DVACT_WAKEUP5); |
| 199 | sensor_restart(); |
| 200 | |
| 201 | #ifdef HIBERNATE1 |
| 202 | if (sleepmode == SLEEP_HIBERNATE0x02) { |
| 203 | hibernate_free(); |
| 204 | fail_hiballoc: |
| 205 | hibernate_resume_bufcache(); |
| 206 | } |
| 207 | #endif /* HIBERNATE */ |
| 208 | |
| 209 | start_periodic_resettodr(); |
| 210 | #if NWSDISPLAY1 > 0 |
| 211 | wsdisplay_resume(); |
| 212 | #endif |
| 213 | sys_sync(curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self))); __ci;})->ci_curproc, NULL((void *)0), NULL((void *)0)); |
| 214 | if (cpu_setperf != NULL((void *)0)) |
| 215 | cpu_setperf(perflevel); /* Restore hw.setperf */ |
| 216 | if (suspend_finish(v) == EAGAIN35) |
| 217 | goto top; |
| 218 | return (error); |
| 219 | } |