From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 30 22:37:33 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 529C31065687 for ; Tue, 30 Sep 2008 22:37:33 +0000 (UTC) (envelope-from gelraen.ua@gmail.com) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by mx1.freebsd.org (Postfix) with ESMTP id CE20C8FC13 for ; Tue, 30 Sep 2008 22:37:32 +0000 (UTC) (envelope-from gelraen.ua@gmail.com) Received: by nf-out-0910.google.com with SMTP id h3so133645nfh.33 for ; Tue, 30 Sep 2008 15:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=om4mDfsVI5T5O2byVNtnMHsGNGEBSRECGC5WwOEYwls=; b=puAAAgLIIkiRmRNWWtHCfBYvjTL5iQvxabAutdbrX0eApDqotnktdUVgT1MWebpems aUN75qMd/hHUTc4PIXC99nZY1HUdm3lZZq/ZcTgJbHADmilMlKEXaRUtIotMC6kAajU1 Lmi4GVS5DHvSqu/fRsPjQM0cdeE/OTB25e19U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=Np4h6xXMN6rGMAs40yTCRlQVQIfObKArPdJnwy9nLSBlTnsGKOVSnDAkoQj1ej3JZ+ ldHwXe5/4YCszgHS9RdrqJaIT+5k0dIe0eMfiXrPmsxrrOR9V50/27eROkavFgaPiwIY xIRxxrBmomVX6RELB9Vq2H/krnixMHyKWB9e8= Received: by 10.210.110.5 with SMTP id i5mr8608252ebc.138.1222812811374; Tue, 30 Sep 2008 15:13:31 -0700 (PDT) Received: by 10.210.138.19 with HTTP; Tue, 30 Sep 2008 15:13:31 -0700 (PDT) Message-ID: Date: Wed, 1 Oct 2008 01:13:31 +0300 From: gelraen To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: [powerd] Adding different adaptive-mode settings for each power source X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Sep 2008 22:37:33 -0000 Hi, I've needed to set different idle levels for adaptive mode while on battery or on AC power. Cause powerd can only set mode (min, max, adp) for each power source, I've added this ability and it seems to be a good idea to share this improvement with others. Best regards, gelraen. P.S.: Sorry for my bad English :) --- usr.sbin/powerd/powerd.c.orig 2008-09-30 18:19:04.000000000 +0300 +++ usr.sbin/powerd/powerd.c 2008-10-01 00:49:52.000000000 +0300 @@ -66,6 +66,8 @@ SRC_UNKNOWN, } power_src_t; +#define SRCS_COUNT 3 /* Number of different power sources */ + const char *modes[] = { "AC", "battery", @@ -95,8 +97,8 @@ static int acline_mib[3]; /* Configuration */ -static int cpu_running_mark; -static int cpu_idle_mark; +static int cpu_running_mark[SRCS_COUNT]; +static int cpu_idle_mark[SRCS_COUNT]; static int poll_ival; static int vflag; @@ -357,7 +359,7 @@ { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-A %%:%%] [-B %%:%%] [-i %%] [-n mode] [-N %%:%%] [-p ival] [-r %%] [-P pidfile]\n"); exit(1); } @@ -377,8 +379,11 @@ /* Default mode for all AC states is adaptive. */ mode_ac = mode_battery = mode_none = MODE_ADAPTIVE; - cpu_running_mark = DEFAULT_ACTIVE_PERCENT; - cpu_idle_mark = DEFAULT_IDLE_PERCENT; + for(i=0;i 100) { + warnx("%d is not a valid percent", + cpu_running_mark[SRC_AC]); + usage(); + } + cpu_idle_mark[SRC_AC] = atoi(optarg+i+1); + if (cpu_idle_mark[SRC_AC] < 0 || cpu_idle_mark[SRC_AC] > 100) { + warnx("%d is not a valid percent", + cpu_idle_mark[SRC_AC]); + usage(); + } + break; + case 'B': + i=0; + while (optarg[i]!='\0' && optarg[i]!=':') i++; + if (optarg[i]!=':') + { + warnx("%s is not a valid setting",optarg); + usage(); + } + optarg[i]='\0'; + cpu_running_mark[SRC_BATTERY] = atoi(optarg); + optarg[i]=':'; + if (cpu_running_mark[SRC_BATTERY] < 0 || cpu_running_mark[SRC_BATTERY] > 100) { + warnx("%d is not a valid percent", + cpu_running_mark[SRC_BATTERY]); + usage(); + } + cpu_idle_mark[SRC_BATTERY] = atoi(optarg+i+1); + if (cpu_idle_mark[SRC_BATTERY] < 0 || cpu_idle_mark[SRC_BATTERY] > 100) { + warnx("%d is not a valid percent", + cpu_idle_mark[SRC_BATTERY]); + usage(); + } + break; + case 'N': + i=0; + while (optarg[i]!='\0' && optarg[i]!=':') i++; + if (optarg[i]!=':') + { + warnx("%s is not a valid setting",optarg); + usage(); + } + optarg[i]='\0'; + cpu_running_mark[SRC_UNKNOWN] = atoi(optarg); + optarg[i]=':'; + if (cpu_running_mark[SRC_UNKNOWN] < 0 || cpu_running_mark[SRC_UNKNOWN] > 100) { + warnx("%d is not a valid percent", + cpu_running_mark[SRC_UNKNOWN]); + usage(); + } + cpu_idle_mark[SRC_UNKNOWN] = atoi(optarg+i+1); + if (cpu_idle_mark[SRC_UNKNOWN] < 0 || cpu_idle_mark[SRC_UNKNOWN] > 100) { + warnx("%d is not a valid percent", + cpu_idle_mark[SRC_UNKNOWN]); + usage(); + } + break; case 'i': - cpu_idle_mark = atoi(optarg); - if (cpu_idle_mark < 0 || cpu_idle_mark > 100) { + cpu_idle_mark[0] = atoi(optarg); + if (cpu_idle_mark[0] < 0 || cpu_idle_mark[0] > 100) { warnx("%d is not a valid percent", - cpu_idle_mark); + cpu_idle_mark[0]); usage(); } + else + { + for(i=1;i 100) { + cpu_running_mark[0] = atoi(optarg); + if (cpu_running_mark[0] < 0 || cpu_running_mark[0] > 100) { warnx("%d is not a valid percent", - cpu_running_mark); + cpu_running_mark[0]); usage(); } + else + { + for(i=0;i (total * cpu_idle_mark) / 100 && + } else if (idle > (total * cpu_idle_mark[acline_status]) / 100 && curfreq > freqs[numfreqs - 1]) { i++; if (vflag) { printf("idle time > %d%%, decreasing clock" " speed from %d MHz to %d MHz\n", - cpu_idle_mark, curfreq, freqs[i]); + cpu_idle_mark[acline_status], curfreq, freqs[i]); } if (set_freq(freqs[i]) != 0) warn("error setting CPU frequency %d", --- usr.sbin/powerd/powerd.8.orig 2008-09-30 21:33:01.000000000 +0300 +++ usr.sbin/powerd/powerd.8 2008-10-01 00:52:15.000000000 +0300 @@ -34,8 +34,11 @@ .Nm .Op Fl a Ar mode .Op Fl b Ar mode +.Op Fl A Ar percent:percent +.Op Fl B Ar percent:percent .Op Fl i Ar percent .Op Fl n Ar mode +.Op Fl N Ar percent:percent .Op Fl p Ar ival .Op Fl P Ar pidfile .Op Fl r Ar percent @@ -93,6 +96,13 @@ adaptive mode should consider the CPU running and increase performance. The default is 65% or lower. +.It Fl A Ar percent:percent +Specifies parameters for adaptive mode while on AC power. +Default values in this notation will look as 65:90. Empty values treated as 0 +.It Fl B Ar percent:percent +Specifies parameters for adaptive mode while on battery. +.It Fl N Ar percent:percent +Specifies parameters for adaptive mode when AC line state is unknown. .It Fl v Verbose mode. Messages about power changes will be printed to stdout and