From owner-svn-src-all@FreeBSD.ORG Wed Oct 15 02:31:15 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 62D35301; Wed, 15 Oct 2014 02:31:15 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E204B0C; Wed, 15 Oct 2014 02:31:15 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9F2VFHF013511; Wed, 15 Oct 2014 02:31:15 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9F2VFVo013510; Wed, 15 Oct 2014 02:31:15 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201410150231.s9F2VFVo013510@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Wed, 15 Oct 2014 02:31:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273113 - head/sys/powerpc/powermac X-SVN-Group: head 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.18-1 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: Wed, 15 Oct 2014 02:31:15 -0000 Author: jhibbits Date: Wed Oct 15 02:31:14 2014 New Revision: 273113 URL: https://svnweb.freebsd.org/changeset/base/273113 Log: Add a sysctl to allow disabling the monitoring thread. Summary: If a user uses powerd, or doesn't want to use the cycles monitoring, they can now suspend the monitoring thread. While here, reorganize the added prototypes to match existing groupings. Reviewers: nwhitehorn, #powerpc, rpaulo Reviewed By: #powerpc, rpaulo Differential Revision: https://reviews.freebsd.org/D944 X-MFC-with: r273009 MFC after: 3 weeks Modified: head/sys/powerpc/powermac/pmu.c Modified: head/sys/powerpc/powermac/pmu.c ============================================================================== --- head/sys/powerpc/powermac/pmu.c Wed Oct 15 01:22:56 2014 (r273112) +++ head/sys/powerpc/powermac/pmu.c Wed Oct 15 02:31:14 2014 (r273113) @@ -104,6 +104,10 @@ static int pmu_acline_state(SYSCTL_HANDL static int pmu_query_battery(struct pmu_softc *sc, int batt, struct pmu_battstate *info); static int pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS); +static int pmu_battmon(SYSCTL_HANDLER_ARGS); +static void pmu_battquery_proc(void); +static void pmu_battery_notify(struct pmu_battstate *batt, + struct pmu_battstate *old); /* * List of battery-related sysctls we might ask for @@ -184,9 +188,6 @@ static int pmu_send(void *cookie, int cm static uint8_t pmu_read_reg(struct pmu_softc *sc, u_int offset); static void pmu_write_reg(struct pmu_softc *sc, u_int offset, uint8_t value); static int pmu_intr_state(struct pmu_softc *); -static void pmu_battquery_proc(void); -static void pmu_battery_notify(struct pmu_battstate *batt, - struct pmu_battstate *old); /* these values shows that number of data returned after 'send' cmd is sent */ static signed char pm_send_cmd_type[] = { @@ -260,6 +261,7 @@ static signed char pm_receive_cmd_type[] -1, -1, -1, -1, -1, -1, -1, -1, }; +static int pmu_battmon_enabled = 1; static struct proc *pmubattproc; static struct kproc_desc pmu_batt_kp = { "pmu_batt", @@ -434,6 +436,11 @@ pmu_attach(device_t dev) /* Only start the battery monitor if we have a battery. */ kproc_start(&pmu_batt_kp); SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "monitor_batteries", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + pmu_battmon, "I", "Post battery events to devd"); + + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD, sc, 0, pmu_acline_state, "I", "AC Line Status"); @@ -931,12 +938,14 @@ static void pmu_battery_notify(struct pmu_battstate *batt, struct pmu_battstate *old) { char notify_buf[16]; - int acline; + int new_acline, old_acline; - acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0; - if (acline != (old->state & PMU_PWR_AC_PRESENT)) { + new_acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0; + old_acline = (old->state & PMU_PWR_AC_PRESENT) ? 1 : 0; + + if (new_acline != old_acline) { snprintf(notify_buf, sizeof(notify_buf), - "notify=0x%02x", acline); + "notify=0x%02x", new_acline); devctl_notify("PMU", "POWER", "ACLINE", notify_buf); } } @@ -951,8 +960,9 @@ pmu_battquery_proc() sc = device_get_softc(pmu); - error = pmu_query_battery(sc, 0, &cur_batt); + bzero(&cur_batt, sizeof(cur_batt)); while (1) { + kproc_suspend_check(curproc); error = pmu_query_battery(sc, 0, &batt); pmu_battery_notify(&batt, &cur_batt); cur_batt = batt; @@ -961,6 +971,29 @@ pmu_battquery_proc() } static int +pmu_battmon(SYSCTL_HANDLER_ARGS) +{ + struct pmu_softc *sc; + int error, result; + + sc = arg1; + result = pmu_battmon_enabled; + + error = sysctl_handle_int(oidp, &result, 0, req); + + if (error || !req->newptr) + return (error); + + if (!result && pmu_battmon_enabled) + error = kproc_suspend(pmubattproc, hz); + else if (result && pmu_battmon_enabled == 0) + error = kproc_resume(pmubattproc); + pmu_battmon_enabled = (result != 0); + + return (error); +} + +static int pmu_acline_state(SYSCTL_HANDLER_ARGS) { struct pmu_softc *sc;