diff options
| author | mh27603 <none@none> | 2006-11-01 12:29:40 -0800 |
|---|---|---|
| committer | mh27603 <none@none> | 2006-11-01 12:29:40 -0800 |
| commit | c42872d4489d6f0fbccfabe2a62f3c976ee1e5d6 (patch) | |
| tree | d75c27324c2799748fb32ff7639c78182148b054 /usr/src/cmd/power | |
| parent | 9aa9fab90ce3f906a8a5591b744a385ed10a510e (diff) | |
| download | illumos-joyent-c42872d4489d6f0fbccfabe2a62f3c976ee1e5d6.tar.gz | |
6260724 PSARC/2005/067 CPU Power Management independent of autopm
6483153 pmconfig/dtpower/sysidpm should be lint-clean
Diffstat (limited to 'usr/src/cmd/power')
| -rw-r--r-- | usr/src/cmd/power/handlers.c | 71 | ||||
| -rw-r--r-- | usr/src/cmd/power/parse.c | 9 | ||||
| -rw-r--r-- | usr/src/cmd/power/pmconfig.h | 9 | ||||
| -rw-r--r-- | usr/src/cmd/power/power_all.xcl | 9 | ||||
| -rw-r--r-- | usr/src/cmd/power/powerd.c | 41 | ||||
| -rw-r--r-- | usr/src/cmd/power/sysstat.c | 10 |
6 files changed, 104 insertions, 45 deletions
diff --git a/usr/src/cmd/power/handlers.c b/usr/src/cmd/power/handlers.c index 1c3b2ff00e..44df1f5c30 100644 --- a/usr/src/cmd/power/handlers.c +++ b/usr/src/cmd/power/handlers.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -56,6 +55,42 @@ static char always_on[] = "always-on"; /* + * Check for valid cpupm behavior and communicate it to the kernel. + */ +int +cpupm(void) +{ + struct btoc { + char *behavior; + int cmd; + int Errno; + }; + static struct btoc blist[] = { + "disable", PM_STOP_CPUPM, EINVAL, + "enable", PM_START_CPUPM, EBUSY, + NULL, 0, 0 + }; + struct btoc *bp; + char *behavior; + + for (behavior = LINEARG(1), bp = blist; bp->cmd; bp++) { + if (strcmp(behavior, bp->behavior) == 0) + break; + } + if (bp->cmd == 0) { + mesg(MERR, "invalid cpupm behavior \"%s\"\n", behavior); + return (NOUP); + } + if (ioctl(pm_fd, bp->cmd, NULL) == -1 && errno != bp->Errno) { + mesg(MERR, "cpupm %s failed, %s\n", + behavior, strerror(errno)); + return (NOUP); + } + return (OKUP); +} + + +/* * Check for valid autopm behavior and save after ioctl success. */ int @@ -673,10 +708,10 @@ sfpath(void) /* - * Try setting system threshold. + * Common function to set a system or cpu threshold. */ -int -systhr(void) +static int +cmnthr(int req) { int value, nerr = 0, upval = OKUP; char *thresh = LINEARG(1); @@ -688,11 +723,31 @@ systhr(void) upval = NOUP; } if (upval == OKUP) - (void) ioctl(pm_fd, PM_SET_SYSTEM_THRESHOLD, value); + (void) ioctl(pm_fd, req, value); return (upval); } +/* + * Try setting system threshold. + */ +int +systhr(void) +{ + return (cmnthr(PM_SET_SYSTEM_THRESHOLD)); +} + + +/* + * Try setting cpu threshold. + */ +int +cputhr(void) +{ + return (cmnthr(PM_SET_CPU_THRESHOLD)); +} + + int tchars(void) { diff --git a/usr/src/cmd/power/parse.c b/usr/src/cmd/power/parse.c index 0d291f9257..650e2154cb 100644 --- a/usr/src/cmd/power/parse.c +++ b/usr/src/cmd/power/parse.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -56,6 +55,8 @@ prmup_t pm_status = { 0, OKUP, "pm" }; static cinfo_t conftab[] = { "autopm", autopm, &pm_status, NULL, 2, 0, 1, "autoshutdown", autosd, &cpr_status, as_cmt, 5, 0, 1, + "cpu-threshold", cputhr, &pm_status, NULL, 2, 0, 1, + "cpupm", cpupm, &pm_status, NULL, 2, 0, 1, "device-dependency-property", ddprop, &pm_status, NULL, 3, 1, 1, "device-dependency", devdep, &pm_status, NULL, 3, 1, 1, diff --git a/usr/src/cmd/power/pmconfig.h b/usr/src/cmd/power/pmconfig.h index db59d2adf5..e48c9a0289 100644 --- a/usr/src/cmd/power/pmconfig.h +++ b/usr/src/cmd/power/pmconfig.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -121,6 +120,8 @@ extern void parse_conf_file(char *, vact_t); */ extern int autopm(void); extern int autosd(void); +extern int cpupm(void); +extern int cputhr(void); extern int ddprop(void); extern int devdep(void); extern int devthr(void); diff --git a/usr/src/cmd/power/power_all.xcl b/usr/src/cmd/power/power_all.xcl index d8c0221c71..61baf7b7a4 100644 --- a/usr/src/cmd/power/power_all.xcl +++ b/usr/src/cmd/power/power_all.xcl @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -112,3 +111,5 @@ msgid "pm ioctl, cmd %d, errno %d\n" msgid "got scaled value %d\n" msgid "threshold list" msgid "idle path" +msgid "cpu-threshold" +msgid "cpupm" diff --git a/usr/src/cmd/power/powerd.c b/usr/src/cmd/power/powerd.c index de58520025..19e137ce02 100644 --- a/usr/src/cmd/power/powerd.c +++ b/usr/src/cmd/power/powerd.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -109,7 +108,9 @@ static int autoshutdown_en; static int do_idlecheck; static int got_sighup; static int estar_v2_prop; +#ifdef sparc static int estar_v3_prop; +#endif static int log_power_cycles_error = 0; static int log_system_board_date_error = 0; static int log_no_autoshutdown_warning = 0; @@ -139,7 +140,7 @@ static void check_idleness(time_t *, hrtime_t *); static int last_system_activity(hrtime_t *); static int run_idlecheck(void); static void set_alarm(time_t); -static int poweroff(char *, char **); +static int poweroff(const char *, char **); static int is_ok2shutdown(time_t *); static int get_prom(int, prom_node_t, char *, char *, size_t); static void power_button_monitor(void *); @@ -153,9 +154,9 @@ static void *attach_devices(void *); #endif -/* VARARGS0 */ +/* PRINTFLIKE1 */ static void -logerror(char *fmt, ...) +logerror(const char *fmt, ...) { va_list args; @@ -217,7 +218,7 @@ main(int argc, char *argv[]) pm_fd = open(PM, O_RDWR); if (pm_fd == -1) { - (void) sprintf(errmsg, "%s: %s", prog, PM); + (void) snprintf(errmsg, sizeof (errmsg), "%s: %s", prog, PM); perror(errmsg); exit(EXIT_FAILURE); } @@ -234,7 +235,7 @@ main(int argc, char *argv[]) } if ((info = (pwr_info_t *)malloc(sizeof (pwr_info_t))) == NULL) { - (void) sprintf(errmsg, "%s: malloc", prog); + (void) snprintf(errmsg, sizeof (errmsg), "%s: malloc", prog); perror(errmsg); exit(EXIT_FAILURE); } @@ -720,7 +721,7 @@ is_ok2shutdown(time_t *now) /* * Allow 10% of power_cycle_limit as free cycles. */ - free_cycles = power_cycle_limit * 0.1; + free_cycles = power_cycle_limit / 10; power_cycles = atoi(power_cycles_st); if (power_cycles < 0) @@ -758,8 +759,8 @@ is_ok2shutdown(time_t *now) * need to spread (power_cycle_limit - free_cycles) over the entire * 7-year life span instead of (lifetime - date free_cycles ended). */ - scaled_cycles = ((float)life_passed / (float)LIFETIME_SECS) * - (power_cycle_limit - free_cycles); + scaled_cycles = (int)(((float)life_passed / (float)LIFETIME_SECS) * + (power_cycle_limit - free_cycles)); if (no_power_cycles) goto ckdone; @@ -912,7 +913,7 @@ set_alarm(time_t now) } static int -poweroff(char *msg, char **cmd_argv) +poweroff(const char *msg, char **cmd_argv) { struct stat statbuf; pid_t pid, child; @@ -1193,14 +1194,14 @@ static int open_pidfile(char *me) { int fd; - char *e1 = "%s: Cannot open pid file for read: "; - char *e2 = "%s: Cannot unlink obsolete pid file: "; - char *e3 = "%s: Cannot open /proc for pid %ld: "; - char *e4 = "%s: Cannot read /proc for pid %ld: "; - char *e5 = "%s: Another instance (pid %ld) is trying to exit" + const char *e1 = "%s: Cannot open pid file for read: "; + const char *e2 = "%s: Cannot unlink obsolete pid file: "; + const char *e3 = "%s: Cannot open /proc for pid %ld: "; + const char *e4 = "%s: Cannot read /proc for pid %ld: "; + const char *e5 = "%s: Another instance (pid %ld) is trying to exit" "and may be hung. Please contact sysadmin.\n"; - char *e6 = "%s: Another daemon is running\n"; - char *e7 = "%s: Cannot create pid file: "; + const char *e6 = "%s: Another daemon is running\n"; + const char *e7 = "%s: Cannot create pid file: "; again: if ((fd = open(pidpath, O_CREAT | O_EXCL | O_WRONLY, 0444)) == -1) { diff --git a/usr/src/cmd/power/sysstat.c b/usr/src/cmd/power/sysstat.c index c1b0806665..a6bc12d1b0 100644 --- a/usr/src/cmd/power/sysstat.c +++ b/usr/src/cmd/power/sysstat.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -589,6 +588,7 @@ static void fail(char *fmt, ...) { char new_fmt[256]; + const char *fmtptr = new_fmt; va_list args; size_t len; @@ -597,7 +597,7 @@ fail(char *fmt, ...) if (snprintf(new_fmt, len, "powerd: %s", fmt) > len) syslog(LOG_ERR, "powerd: syslog message too large"); else - vsyslog(LOG_ERR, new_fmt, args); + vsyslog(LOG_ERR, fmtptr, args); va_end(args); thr_exit((void *) 0); |
