-/* $OpenBSD: acpi.c,v 1.399 2021/07/20 00:41:54 mlarkin Exp $ */
+/* $OpenBSD: acpi.c,v 1.400 2021/10/30 23:24:46 deraadt Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
case APM_IOC_GETPOWER:
/* A/C */
pi->ac_state = APM_AC_UNKNOWN;
+// XXX replace with new power code
SLIST_FOREACH(ac, &sc->sc_ac, aac_link) {
if (ac->aac_softc->sc_ac_stat == PSR_ONLINE)
pi->ac_state = APM_AC_ON;
-/* $OpenBSD: acpiac.c,v 1.33 2020/06/10 22:26:40 jca Exp $ */
+/* $OpenBSD: acpiac.c,v 1.34 2021/10/30 23:24:47 deraadt Exp $ */
/*
* Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
*
acpiac_attach(struct device *parent, struct device *self, void *aux)
{
struct acpiac_softc *sc = (struct acpiac_softc *)self;
+ extern int hw_power;
struct acpi_attach_args *aa = aux;
sc->sc_acpi = (struct acpi_softc *)parent;
printf("offline\n");
else
printf("in unknown state\n");
+ hw_power = (sc->sc_ac_stat == PSR_ONLINE);
strlcpy(sc->sc_sensdev.xname, DEVNAME(sc),
sizeof(sc->sc_sensdev.xname));
acpiac_notify(struct aml_node *node, int notify_type, void *arg)
{
struct acpiac_softc *sc = arg;
+ extern int hw_power;
dnprintf(10, "acpiac_notify: %.2x %s\n", notify_type,
DEVNAME(sc));
dnprintf(10, "A/C status: %d\n", sc->sc_ac_stat);
break;
}
+ hw_power = (sc->sc_ac_stat == PSR_ONLINE);
return (0);
}
-/* $OpenBSD: kern_sysctl.c,v 1.395 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.396 2021/10/30 23:24:48 deraadt Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
*/
char *hw_vendor, *hw_prod, *hw_uuid, *hw_serial, *hw_ver;
int allowpowerdown = 1;
+int hw_power = 1;
/* morally const values reported by sysctl_bounded_arr */
static int byte_order = BYTE_ORDER;
{HW_BYTEORDER, &byte_order, SYSCTL_INT_READONLY},
{HW_PAGESIZE, &page_size, SYSCTL_INT_READONLY},
{HW_DISKCOUNT, &disk_count, SYSCTL_INT_READONLY},
+ {HW_POWER, &hw_power, SYSCTL_INT_READONLY},
};
int
-/* $OpenBSD: sched_bsd.c,v 1.69 2021/09/09 18:41:39 mpi Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.70 2021/10/30 23:24:48 deraadt Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
void schedcpu(void *);
uint32_t decay_aftersleep(uint32_t, uint32_t);
-void
-scheduler_start(void)
-{
- static struct timeout schedcpu_to;
-
- /*
- * We avoid polluting the global namespace by keeping the scheduler
- * timeouts static in this function.
- * We setup the timeout here and kick schedcpu once to make it do
- * its job.
- */
- timeout_set(&schedcpu_to, schedcpu, &schedcpu_to);
-
- rrticks_init = hz / 10;
- schedcpu(&schedcpu_to);
-}
-
/*
* Force switch among equal priority processes every 100ms.
*/
#define PERFPOL_AUTO 1
#define PERFPOL_HIGH 2
int perflevel = 100;
-int perfpolicy = PERFPOL_MANUAL;
+int perfpolicy = PERFPOL_AUTO;
#ifndef SMALL_KERNEL
/*
void setperf_auto(void *);
struct timeout setperf_to = TIMEOUT_INITIALIZER(setperf_auto, NULL);
+extern int hw_power;
void
setperf_auto(void *v)
{
static uint64_t *idleticks, *totalticks;
static int downbeats;
-
- int i, j;
- int speedup;
+ int i, j = 0;
+ int speedup = 0;
CPU_INFO_ITERATOR cii;
struct cpu_info *ci;
- uint64_t idle, total, allidle, alltotal;
+ uint64_t idle, total, allidle = 0, alltotal = 0;
if (perfpolicy != PERFPOL_AUTO)
return;
+ if (cpu_setperf == NULL)
+ return;
+
+ if (hw_power) {
+ speedup = 1;
+ goto faster;
+ }
+
if (!idleticks)
if (!(idleticks = mallocarray(ncpusfound, sizeof(*idleticks),
M_DEVBUF, M_NOWAIT | M_ZERO)))
sizeof(*idleticks) * ncpusfound);
return;
}
-
- alltotal = allidle = 0;
- j = 0;
- speedup = 0;
CPU_INFO_FOREACH(cii, ci) {
if (!cpu_is_online(ci))
continue;
downbeats = 5;
if (speedup && perflevel != 100) {
+faster:
perflevel = 100;
cpu_setperf(perflevel);
} else if (!speedup && perflevel != 0 && --downbeats <= 0) {
return 0;
}
#endif
+
+void
+scheduler_start(void)
+{
+ static struct timeout schedcpu_to;
+
+ /*
+ * We avoid polluting the global namespace by keeping the scheduler
+ * timeouts static in this function.
+ * We setup the timeout here and kick schedcpu once to make it do
+ * its job.
+ */
+ timeout_set(&schedcpu_to, schedcpu, &schedcpu_to);
+
+ rrticks_init = hz / 10;
+ schedcpu(&schedcpu_to);
+
+#ifndef SMALL_KERNEL
+ if (perfpolicy == PERFPOL_AUTO)
+ timeout_add_msec(&setperf_to, 200);
+#endif
+}
+
-/* $OpenBSD: sysctl.h,v 1.218 2021/05/17 17:54:31 claudio Exp $ */
+/* $OpenBSD: sysctl.h,v 1.219 2021/10/30 23:24:48 deraadt Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
#define HW_PERFPOLICY 23 /* set performance policy */
#define HW_SMT 24 /* int: enable SMT/HT/CMT */
#define HW_NCPUONLINE 25 /* int: number of cpus being used */
-#define HW_MAXID 26 /* number of valid hw ids */
+#define HW_POWER 26 /* int: machine has wall-power */
+#define HW_MAXID 27 /* number of valid hw ids */
#define CTL_HW_NAMES { \
{ 0, 0 }, \
{ "perfpolicy", CTLTYPE_STRING }, \
{ "smt", CTLTYPE_INT }, \
{ "ncpuonline", CTLTYPE_INT }, \
+ { "power", CTLTYPE_INT }, \
}
/*