From owner-svn-src-all@freebsd.org Sun Jan 13 02:19:02 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6AF88148380F; Sun, 13 Jan 2019 02:19:02 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0775B83643; Sun, 13 Jan 2019 02:19:02 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F0062C897; Sun, 13 Jan 2019 02:19:01 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x0D2J1HG035852; Sun, 13 Jan 2019 02:19:01 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x0D2J1Ik035850; Sun, 13 Jan 2019 02:19:01 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201901130219.x0D2J1Ik035850@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Sun, 13 Jan 2019 02:19:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r342981 - stable/12/usr.sbin/powerd X-SVN-Group: stable-12 X-SVN-Commit-Author: avos X-SVN-Commit-Paths: stable/12/usr.sbin/powerd X-SVN-Commit-Revision: 342981 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0775B83643 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.998,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jan 2019 02:19:02 -0000 Author: avos Date: Sun Jan 13 02:19:01 2019 New Revision: 342981 URL: https://svnweb.freebsd.org/changeset/base/342981 Log: MFC r342810: powerd(8): allow to force a method of battery state query This change allows to determine power source via sysctl or /dev/apm when devd(8) is running (used by default). Based on patch from PR; other changes on top of it: - '-f' (force) -> '-s' (source) parameter renaming; - allow 'apm' -> 'devd' transition when '-s devd' is set (if APM is enabled); - man page update. PR: 125707 Submitted by: Konstantin Stepanov Reviewed by: bcr, imp Differential Revision: https://reviews.freebsd.org/D18742 Modified: stable/12/usr.sbin/powerd/powerd.8 stable/12/usr.sbin/powerd/powerd.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/powerd/powerd.8 ============================================================================== --- stable/12/usr.sbin/powerd/powerd.8 Sun Jan 13 00:38:55 2019 (r342980) +++ stable/12/usr.sbin/powerd/powerd.8 Sun Jan 13 02:19:01 2019 (r342981) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 4, 2013 +.Dd January 13, 2019 .Dt POWERD 8 .Os .Sh NAME @@ -41,6 +41,7 @@ .Op Fl p Ar ival .Op Fl P Ar pidfile .Op Fl r Ar percent +.Op Fl s Ar source .Op Fl v .Sh DESCRIPTION The @@ -117,6 +118,14 @@ The default is Specifies the CPU load percent level where adaptive mode should consider the CPU running and increase performance. The default is 75% or higher. +.It Fl s Ar source +Enforces method for AC line state refresh; by default, it is chosen +automatically. +The set of valid methods is +.Cm sysctl , devd +and +.Cm apm +(i386 only). .It Fl v Verbose mode. Messages about power changes will be printed to stdout and Modified: stable/12/usr.sbin/powerd/powerd.c ============================================================================== --- stable/12/usr.sbin/powerd/powerd.c Sun Jan 13 00:38:55 2019 (r342980) +++ stable/12/usr.sbin/powerd/powerd.c Sun Jan 13 02:19:01 2019 (r342981) @@ -113,14 +113,16 @@ static int vflag; static volatile sig_atomic_t exit_requested; static power_src_t acline_status; -static enum { +typedef enum { ac_none, ac_sysctl, ac_acpi_devd, #ifdef USE_APM ac_apm, #endif -} acline_mode; +} acline_mode_t; +static acline_mode_t acline_mode; +static acline_mode_t acline_mode_user = ac_none; #ifdef USE_APM static int apm_fd = -1; #endif @@ -286,21 +288,28 @@ get_freq_id(int freq, int *freqs, int numfreqs) static void acline_init(void) { + int skip_source_check; + acline_mib_len = 4; acline_status = SRC_UNKNOWN; + skip_source_check = (acline_mode_user == ac_none || + acline_mode_user == ac_acpi_devd); - if (sysctlnametomib(ACPIAC, acline_mib, &acline_mib_len) == 0) { + if ((skip_source_check || acline_mode_user == ac_sysctl) && + sysctlnametomib(ACPIAC, acline_mib, &acline_mib_len) == 0) { acline_mode = ac_sysctl; if (vflag) warnx("using sysctl for AC line status"); #ifdef __powerpc__ - } else if (sysctlnametomib(PMUAC, acline_mib, &acline_mib_len) == 0) { + } else if ((skip_source_check || acline_mode_user == ac_sysctl) && + sysctlnametomib(PMUAC, acline_mib, &acline_mib_len) == 0) { acline_mode = ac_sysctl; if (vflag) warnx("using sysctl for AC line status"); #endif #ifdef USE_APM - } else if ((apm_fd = open(APMDEV, O_RDONLY)) >= 0) { + } else if ((skip_source_check || acline_mode_user == ac_apm) && + (apm_fd = open(APMDEV, O_RDONLY)) >= 0) { if (vflag) warnx("using APM for AC line status"); acline_mode = ac_apm; @@ -360,7 +369,17 @@ acline_read(void) } #endif /* try to (re)connect to devd */ - if (acline_mode == ac_sysctl) { +#ifdef USE_APM + if ((acline_mode == ac_sysctl && + (acline_mode_user == ac_none || + acline_mode_user == ac_acpi_devd)) || + (acline_mode == ac_apm && + acline_mode_user == ac_acpi_devd)) { +#else + if (acline_mode == ac_sysctl && + (acline_mode_user == ac_none || + acline_mode_user == ac_acpi_devd)) { +#endif struct timeval now; gettimeofday(&now, NULL); @@ -426,6 +445,21 @@ parse_mode(char *arg, int *mode, int ch) } static void +parse_acline_mode(char *arg, int ch) +{ + if (strcmp(arg, "sysctl") == 0) + acline_mode_user = ac_sysctl; + else if (strcmp(arg, "devd") == 0) + acline_mode_user = ac_acpi_devd; +#ifdef USE_APM + else if (strcmp(arg, "apm") == 0) + acline_mode_user = ac_apm; +#endif + else + errx(1, "bad option: -%c %s", (char)ch, optarg); +} + +static void handle_sigs(int __unused sig) { @@ -437,7 +471,7 @@ usage(void) { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-n mode] [-p ival] [-r %%] [-s source] [-P pidfile]\n"); exit(1); } @@ -468,13 +502,16 @@ main(int argc, char * argv[]) if (geteuid() != 0) errx(1, "must be root to run"); - while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:v")) != -1) + while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:s:v")) != -1) switch (ch) { case 'a': parse_mode(optarg, &mode_ac, ch); break; case 'b': parse_mode(optarg, &mode_battery, ch); + break; + case 's': + parse_acline_mode(optarg, ch); break; case 'i': cpu_idle_mark = atoi(optarg);