Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Oct 2014 02:31:15 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273113 - head/sys/powerpc/powermac
Message-ID:  <201410150231.s9F2VFVo013510@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410150231.s9F2VFVo013510>