From owner-svn-src-all@freebsd.org Sat Mar 14 06:57:52 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 44A322797FA; Sat, 14 Mar 2020 06:57:52 +0000 (UTC) (envelope-from cperciva@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 48fYKq6jczz4Dv9; Sat, 14 Mar 2020 06:57:51 +0000 (UTC) (envelope-from cperciva@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 B0B031B0FE; Sat, 14 Mar 2020 06:57:51 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02E6vpw7032964; Sat, 14 Mar 2020 06:57:51 GMT (envelope-from cperciva@FreeBSD.org) Received: (from cperciva@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02E6vpW1032962; Sat, 14 Mar 2020 06:57:51 GMT (envelope-from cperciva@FreeBSD.org) Message-Id: <202003140657.02E6vpW1032962@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cperciva set sender to cperciva@FreeBSD.org using -f From: Colin Percival Date: Sat, 14 Mar 2020 06:57:51 +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: r358990 - stable/12/usr.sbin/powerd X-SVN-Group: stable-12 X-SVN-Commit-Author: cperciva X-SVN-Commit-Paths: stable/12/usr.sbin/powerd X-SVN-Commit-Revision: 358990 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Sat, 14 Mar 2020 06:57:52 -0000 Author: cperciva Date: Sat Mar 14 06:57:50 2020 New Revision: 358990 URL: https://svnweb.freebsd.org/changeset/base/358990 Log: MFC r358478: Add -N option to powerd(8) to ignore "nice" time. 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 Sat Mar 14 06:36:03 2020 (r358989) +++ stable/12/usr.sbin/powerd/powerd.8 Sat Mar 14 06:57:50 2020 (r358990) @@ -37,6 +37,7 @@ .Op Fl i Ar percent .Op Fl m Ar freq .Op Fl M Ar freq +.Op Fl N .Op Fl n Ar mode .Op Fl p Ar ival .Op Fl P Ar pidfile @@ -102,6 +103,10 @@ The default is 50% or lower. Specifies the minimum frequency to throttle down to. .It Fl M Ar freq Specifies the maximum frequency to throttle up to. +.It Fl N +Treat "nice" time as idle for the purpose of load calculation; +i.e. do not increase the CPU frequency if the CPU is only busy +with "nice" processes. .It Fl n Ar mode Selects the .Ar mode Modified: stable/12/usr.sbin/powerd/powerd.c ============================================================================== --- stable/12/usr.sbin/powerd/powerd.c Sat Mar 14 06:36:03 2020 (r358989) +++ stable/12/usr.sbin/powerd/powerd.c Sat Mar 14 06:57:50 2020 (r358990) @@ -86,7 +86,7 @@ static const char *modes[] = { #define DEVDPIPE "/var/run/devd.pipe" #define DEVCTL_MAXBUF 1024 -static int read_usage_times(int *load); +static int read_usage_times(int *load, int nonice); static int read_freqs(int *numfreqs, int **freqs, int **power, int minfreq, int maxfreq); static int set_freq(int freq); @@ -135,15 +135,17 @@ static struct timeval tried_devd; * This function returns summary load of all CPUs. It was made so * intentionally to not reduce performance in scenarios when several * threads are processing requests as a pipeline -- running one at - * a time on different CPUs and waiting for each other. + * a time on different CPUs and waiting for each other. If nonice + * is nonzero, only user+sys+intr time will be counted as load; any + * nice time will be treated as if idle. */ static int -read_usage_times(int *load) +read_usage_times(int *load, int nonice) { static long *cp_times = NULL, *cp_times_old = NULL; static int ncpus = 0; size_t cp_times_len; - int error, cpu, i, total; + int error, cpu, i, total, excl; if (cp_times == NULL) { cp_times_len = 0; @@ -175,8 +177,12 @@ read_usage_times(int *load) } if (total == 0) continue; - *load += 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] - - cp_times_old[cpu * CPUSTATES + CP_IDLE]) * 100 / total; + excl = cp_times[cpu * CPUSTATES + CP_IDLE] - + cp_times_old[cpu * CPUSTATES + CP_IDLE]; + if (nonice) + excl += cp_times[cpu * CPUSTATES + CP_NICE] - + cp_times_old[cpu * CPUSTATES + CP_NICE]; + *load += 100 - excl * 100 / total; } } @@ -473,7 +479,7 @@ usage(void) { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-n mode] [-p ival] [-r %%] [-s source] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-N] [-n mode] [-p ival] [-r %%] [-s source] [-P pidfile]\n"); exit(1); } @@ -490,6 +496,7 @@ main(int argc, char * argv[]) int ch, mode, mode_ac, mode_battery, mode_none, idle, to; uint64_t mjoules_used; size_t len; + int nonice; /* Default mode for all AC states is adaptive. */ mode_ac = mode_none = MODE_HIADAPTIVE; @@ -499,12 +506,13 @@ main(int argc, char * argv[]) poll_ival = DEFAULT_POLL_INTERVAL; mjoules_used = 0; vflag = 0; + nonice = 0; /* User must be root to control frequencies. */ if (geteuid() != 0) errx(1, "must be root to run"); - while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:s:v")) != -1) + while ((ch = getopt(argc, argv, "a:b:i:m:M:Nn:p:P:r:s:v")) != -1) switch (ch) { case 'a': parse_mode(optarg, &mode_ac, ch); @@ -539,6 +547,9 @@ main(int argc, char * argv[]) usage(); } break; + case 'N': + nonice = 1; + break; case 'n': parse_mode(optarg, &mode_none, ch); break; @@ -584,7 +595,7 @@ main(int argc, char * argv[]) err(1, "lookup freq_levels"); /* Check if we can read the load and supported freqs. */ - if (read_usage_times(NULL)) + if (read_usage_times(NULL, nonice)) err(1, "read_usage_times"); if (read_freqs(&numfreqs, &freqs, &mwatts, minfreq, maxfreq)) err(1, "error reading supported CPU frequencies"); @@ -766,7 +777,7 @@ main(int argc, char * argv[]) } /* Adaptive mode; get the current CPU usage times. */ - if (read_usage_times(&load)) { + if (read_usage_times(&load, nonice)) { if (vflag) warn("read_usage_times() failed"); continue;