Subject: Re: [PATCH] new option BEEP_ONHALT_FOREVER
To: =?iso-8859-15?B?TeF0eeFzIErhbm9z?= <jani@xoftware.de>
From: Arnaud Lacombe <al@sigfpe.info>
List: tech-kern
Date: 05/21/2006 22:57:17
--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On Sun, May 21, 2006 at 06:19:09PM +0200, Mátyás János wrote:
> Hi,
> 
> I attached a newer version. This little patch provides the missing
> functionality and hope it's already committable.  I leave the sysctl
> work to somebody else who is more familiar with NetBSD kernel
> programming. For me it's good enough to set it at compilation time.

I'm not really more familiar with the NetBSD kernel than you are, but I
think the attached patch is enough to add the sysctl to set number
of beep before halt (tested on i386, not on xen).

The only one problem I see with this patch is that with infinite beep
(beep_onhalt_count == -1), we are no longer able to reboot the machine
by pressing a key (and thus, the message printed just before is wrong).

regards,

Arnaud

ps: was there any reason to define function as 'static void' and not
just 'void' as it is done by other function in machdep.c ?

--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sysctl_beep_onhalt.diff"

Index: arch/i386/include/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/include/cpu.h,v
retrieving revision 1.123
diff -u -r1.123 cpu.h
--- arch/i386/include/cpu.h	16 Feb 2006 20:17:13 -0000	1.123
+++ arch/i386/include/cpu.h	21 May 2006 20:40:03 -0000
@@ -454,7 +454,8 @@
 #define CPU_TMLR_FREQUENCY	12 	/* int: current frequency */
 #define CPU_TMLR_VOLTAGE	13 	/* int: curret voltage */
 #define CPU_TMLR_PERCENTAGE	14	/* int: current clock percentage */
-#define	CPU_MAXID		15	/* number of valid machdep ids */
+#define CPU_BEEP_ONHALT_COUNT	15	/* int: number of beep before halt */
+#define	CPU_MAXID		16	/* number of valid machdep ids */
 
 #define	CTL_MACHDEP_NAMES { \
 	{ 0, 0 }, \
@@ -472,6 +473,7 @@
 	{ "tm_longrun_frequency", CTLTYPE_INT }, \
 	{ "tm_longrun_voltage", CTLTYPE_INT }, \
 	{ "tm_longrun_percentage", CTLTYPE_INT }, \
+	{ "beep_onhalt_count", CTLTYPE_INT }, \
 }
 
 /*
Index: arch/i386/i386/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.572
diff -u -r1.572 machdep.c
--- arch/i386/i386/machdep.c	14 Apr 2006 09:50:16 -0000	1.572
+++ arch/i386/i386/machdep.c	21 May 2006 20:40:04 -0000
@@ -190,6 +190,7 @@
 #include <machine/mpbiosvar.h>	/* XXX */
 #endif				/* XXX */
 
+#ifdef BEEP_ONHALT
 #ifndef BEEP_ONHALT_COUNT
 #define BEEP_ONHALT_COUNT 3
 #endif
@@ -200,6 +201,13 @@
 #define BEEP_ONHALT_PERIOD 250
 #endif
 
+int beep_onhalt_count = BEEP_ONHALT_COUNT;
+
+void beep_onhalt(void);
+void beep_onhalt_beep_once(void);
+#endif /* BEEP_ONHALT */
+
+
 /* the following is used externally (sysctl_hw) */
 char machine[] = "i386";		/* CPU "architecture" */
 char machine_arch[] = "i386";		/* machine == machine_arch */
@@ -677,6 +685,13 @@
 		       CTLTYPE_INT, "tm_longrun_percentage", NULL,
 		       sysctl_machdep_tm_longrun, 0, NULL, 0,
 		       CTL_MACHDEP, CPU_TMLR_PERCENTAGE, CTL_EOL);
+#ifdef BEEP_ONHALT
+	sysctl_createv(clog, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "beep_onhalt_count", NULL,
+		       NULL, 0, &beep_onhalt_count, 0,
+		       CTL_MACHDEP, CPU_BEEP_ONHALT_COUNT, CTL_EOL);
+#endif
 }
 
 void *
@@ -899,16 +914,7 @@
 		printf("Please press any key to reboot.\n\n");
 
 #ifdef BEEP_ONHALT
-		{
-			int c;
-			for (c = BEEP_ONHALT_COUNT; c > 0; c--) {
-				sysbeep(BEEP_ONHALT_PITCH,
-					BEEP_ONHALT_PERIOD * hz / 1000);
-				delay(BEEP_ONHALT_PERIOD * 1000);
-				sysbeep(0, BEEP_ONHALT_PERIOD * hz / 1000);
-				delay(BEEP_ONHALT_PERIOD * 1000);
-			}
-		}
+		beep_onhalt();
 #endif
 
 		cnpollc(1);	/* for proper keyboard command handling */
@@ -929,6 +935,31 @@
 	/*NOTREACHED*/
 }
 
+#ifdef BEEP_ONHALT
+void
+beep_onhalt()
+{
+	if (beep_onhalt_count == -1) {
+		for (;;)
+			beep_onhalt_beep_once();
+		/*NOTREACHED*/
+	} else {
+		int c;
+		for (c = beep_onhalt_count; c > 0; c--)
+			beep_onhalt_beep_once();
+	}
+}
+
+void
+beep_onhalt_beep_once()
+{
+	sysbeep(BEEP_ONHALT_PITCH, BEEP_ONHALT_PERIOD * hz / 1000);
+	delay(BEEP_ONHALT_PERIOD * 1000);
+	sysbeep(0, BEEP_ONHALT_PERIOD * hz / 1000);
+	delay(BEEP_ONHALT_PERIOD * 1000);
+}
+#endif
+
 /*
  * These variables are needed by /sbin/savecore
  */
Index: arch/xen/include/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/arch/xen/include/cpu.h,v
retrieving revision 1.12
diff -u -r1.12 cpu.h
--- arch/xen/include/cpu.h	16 Feb 2006 20:17:15 -0000	1.12
+++ arch/xen/include/cpu.h	21 May 2006 20:40:04 -0000
@@ -459,7 +459,8 @@
 #define CPU_TMLR_FREQUENCY	12 	/* int: current frequency */
 #define CPU_TMLR_VOLTAGE	13 	/* int: curret voltage */
 #define CPU_TMLR_PERCENTAGE	14	/* int: current clock percentage */
-#define	CPU_MAXID		15	/* number of valid machdep ids */
+#define CPU_BEEP_ONHALT_COUNT  15  /* int: number of beep before halt */
+#define	CPU_MAXID		16	/* number of valid machdep ids */
 
 #define	CTL_MACHDEP_NAMES { \
 	{ 0, 0 }, \
@@ -477,6 +478,7 @@
 	{ "tm_longrun_frequency", CTLTYPE_INT }, \
 	{ "tm_longrun_voltage", CTLTYPE_INT }, \
 	{ "tm_longrun_percentage", CTLTYPE_INT }, \
+	{ "beep_onhalt_count", CTLTYPE_INT }, \
 }
 
 /*
Index: arch/xen/i386/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/xen/i386/machdep.c,v
retrieving revision 1.27
diff -u -r1.27 machdep.c
--- arch/xen/i386/machdep.c	9 Apr 2006 19:28:01 -0000	1.27
+++ arch/xen/i386/machdep.c	21 May 2006 20:40:05 -0000
@@ -212,6 +212,7 @@
 void xen_dbglow_init(void);
 #endif
 
+#ifdef BEEP_ONHALT
 #ifndef BEEP_ONHALT_COUNT
 #define BEEP_ONHALT_COUNT 3
 #endif
@@ -222,6 +223,12 @@
 #define BEEP_ONHALT_PERIOD 250
 #endif
 
+int beep_onhalt_count = BEEP_ONHALT_COUNT;
+
+void beep_onhalt(void);
+void beep_onhalt_beep_once(void);
+#endif /* BEEP_ONHALT */
+
 /* the following is used externally (sysctl_hw) */
 char machine[] = "i386";		/* CPU "architecture" */
 char machine_arch[] = "i386";		/* machine == machine_arch */
@@ -637,6 +644,13 @@
 		       CTLTYPE_INT, "tm_longrun_percentage", NULL,
 		       sysctl_machdep_tm_longrun, 0, NULL, 0,
 		       CTL_MACHDEP, CPU_TMLR_PERCENTAGE, CTL_EOL);
+#ifdef BEEP_ONHALT
+	sysctl_createv(clog, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "beep_onhalt_count", NULL,
+		       NULL, 0, &beep_onhalt_count, 0,
+		       CTL_MACHDEP, CPU_BEEP_ONHALT_COUNT, CTL_EOL);
+#endif
 }
 
 void *
@@ -853,16 +867,7 @@
 		printf("Please press any key to reboot.\n\n");
 
 #ifdef BEEP_ONHALT
-		{
-			int c;
-			for (c = BEEP_ONHALT_COUNT; c > 0; c--) {
-				sysbeep(BEEP_ONHALT_PITCH,
-				        BEEP_ONHALT_PERIOD * hz / 1000);
-				delay(BEEP_ONHALT_PERIOD * 1000);
-				sysbeep(0, BEEP_ONHALT_PERIOD * hz / 1000);
-				delay(BEEP_ONHALT_PERIOD * 1000);
-			}
-		}
+		beep_onhalt();
 #endif
 
 		cnpollc(1);	/* for proper keyboard command handling */
@@ -883,6 +888,31 @@
 	/*NOTREACHED*/
 }
 
+#ifdef BEEP_ONHALT
+void
+beep_onhalt()
+{
+	if (beep_onhalt_count == -1) {
+		for (;;)
+			beep_onhalt_beep_once();
+		/*NOTREACHED*/
+	} else {
+		int c;
+		for (c = beep_onhalt_count; c > 0; c--)
+			beep_onhalt_beep_once();
+	}
+}                                                                                                                                                      
+
+void
+beep_onhalt_beep_once()
+{
+	sysbeep(BEEP_ONHALT_PITCH, BEEP_ONHALT_PERIOD * hz / 1000);
+	delay(BEEP_ONHALT_PERIOD * 1000);
+	sysbeep(0, BEEP_ONHALT_PERIOD * hz / 1000);
+	delay(BEEP_ONHALT_PERIOD * 1000);
+}
+#endif
+
 /*
  * These variables are needed by /sbin/savecore
  */

--IJpNTDwzlM2Ie8A6--