NOFIXADE / NOPRINTADE

Started by Neil Conwayover 21 years ago5 messages
#1Neil Conway
neilc@samurai.com

There's a bunch of very ugly code in backend/main/main.c that involves
the preprocessor constants "NOFIXADE" and "NOPRINTADE". The code seems
to be related to support for Alpha and/or ultrix4. NOFIXADE is defined
by port/osf.h and port/ultrix4.h, while NOPRINTADE is not defined as far
as I can tell (... unless some system header defines it?)

Does anyone have any idea what this code is intended to do, and why it
is necessary? It would be nice to remove it, but even if that's not
possible we can at least explain why it is necessary.

The code in question is:

#if defined(__alpha) /* no __alpha__ ? */
#ifdef NOFIXADE
int buffer[] = {SSIN_UACPROC, UAC_SIGBUS};
#endif /* NOFIXADE */
#ifdef NOPRINTADE
int buffer[] = {SSIN_UACPROC, UAC_NOPRINT};
#endif /* NOPRINTADE */
#endif /* __alpha */

#ifdef WIN32
char *env_locale;
#endif

#if defined(NOFIXADE) || defined(NOPRINTADE)

#if defined(ultrix4)
syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
#endif

#if defined(__alpha) /* no __alpha__ ? */
if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
(unsigned long) NULL) < 0)
write_stderr("%s: setsysinfo failed: %s\n",
argv[0], strerror(errno));
#endif
#endif /* NOFIXADE || NOPRINTADE */

-Neil

#2Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Neil Conway (#1)
Re: NOFIXADE / NOPRINTADE

No idea. That code came in at a time when we weren't as good at
documenting platform-specific stuff. (We never expected to be this
popular or to be playing with this code 8 years later.) :-)

I just found this:

http://joshua.raleigh.nc.us/docs/linux-2.4.10_html/87660.html

Want to update the C comments?

---------------------------------------------------------------------------

Neil Conway wrote:

There's a bunch of very ugly code in backend/main/main.c that involves
the preprocessor constants "NOFIXADE" and "NOPRINTADE". The code seems
to be related to support for Alpha and/or ultrix4. NOFIXADE is defined
by port/osf.h and port/ultrix4.h, while NOPRINTADE is not defined as far
as I can tell (... unless some system header defines it?)

Does anyone have any idea what this code is intended to do, and why it
is necessary? It would be nice to remove it, but even if that's not
possible we can at least explain why it is necessary.

The code in question is:

#if defined(__alpha) /* no __alpha__ ? */
#ifdef NOFIXADE
int buffer[] = {SSIN_UACPROC, UAC_SIGBUS};
#endif /* NOFIXADE */
#ifdef NOPRINTADE
int buffer[] = {SSIN_UACPROC, UAC_NOPRINT};
#endif /* NOPRINTADE */
#endif /* __alpha */

#ifdef WIN32
char *env_locale;
#endif

#if defined(NOFIXADE) || defined(NOPRINTADE)

#if defined(ultrix4)
syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
#endif

#if defined(__alpha) /* no __alpha__ ? */
if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
(unsigned long) NULL) < 0)
write_stderr("%s: setsysinfo failed: %s\n",
argv[0], strerror(errno));
#endif
#endif /* NOFIXADE || NOPRINTADE */

-Neil

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#1)
Re: NOFIXADE / NOPRINTADE

Neil Conway <neilc@samurai.com> writes:

Does anyone have any idea what this code is intended to do, and why it
is necessary?

A bit of googling (I used "SSIN_UACPROC") will turn up enough info to
clue you in. Apparently, on these machines an unaligned memory access
causes a trap to the kernel, but the default behavior of the kernel is
to emulate the desired memory access and then return control. Fine,
but *really* *slow*. So good programming practice is to disable the
emulation and fix any thereby-revealed bugs in your code instead.
Which is what we're doing in this code.

The UAC_SIGBUS option turns off the emulation and makes an unaligned
access result in SIGBUS instead. The UAC_NOPRINT option suppresses
the "unaligned access" warning message that the kernel may helpfully
print about it. I'm not sure why we have the latter as dead code
(it is dead, because NOPRINTADE doesn't get defined anywhere).
The code samples I found on the net mostly tended to go
int buffer[] = {SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT};

I would be inclined to get rid of the separate NOPRINTADE code and make
NOFIXADE select both flags.

The MIPS_FIXADE seems to be the same deal but a different OS' API.

regards, tom lane

#4Neil Conway
neilc@samurai.com
In reply to: Tom Lane (#3)
1 attachment(s)
Re: NOFIXADE / NOPRINTADE

On Fri, 2004-09-24 at 00:35, Tom Lane wrote:

I would be inclined to get rid of the separate NOPRINTADE code and make
NOFIXADE select both flags.

Barring any objections, I intend to apply the attached patch to HEAD
later today.

-Neil

Attachments:

fixade-1.patchtext/x-patch; charset=iso-8859-1; name=fixade-1.patchDownload
Index: src/backend/main/main.c
===================================================================
RCS file: /home/neilc/private-cvsroot/pgsql-server/src/backend/main/main.c,v
retrieving revision 1.89
diff -c -r1.89 main.c
*** src/backend/main/main.c	29 Aug 2004 05:06:43 -0000	1.89
--- src/backend/main/main.c	24 Sep 2004 02:30:03 -0000
***************
*** 71,88 ****
  
  #if defined(__alpha)			/* no __alpha__ ? */
  #ifdef NOFIXADE
! 	int			buffer[] = {SSIN_UACPROC, UAC_SIGBUS};
! #endif   /* NOFIXADE */
! #ifdef NOPRINTADE
! 	int			buffer[] = {SSIN_UACPROC, UAC_NOPRINT};
! #endif   /* NOPRINTADE */
  #endif   /* __alpha */
  
  #ifdef WIN32
  	char	   *env_locale;
  #endif
  
! #if defined(NOFIXADE) || defined(NOPRINTADE)
  
  #if defined(ultrix4)
  	syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
--- 71,93 ----
  
  #if defined(__alpha)			/* no __alpha__ ? */
  #ifdef NOFIXADE
! 	int			buffer[] = {SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT};
! #endif
  #endif   /* __alpha */
  
  #ifdef WIN32
  	char	   *env_locale;
  #endif
  
! 	/*
! 	 * On some platforms, unaligned memory accesses result in a kernel
! 	 * trap; the default kernel behavior is to emulate the memory
! 	 * access, but this results in a significant performance
! 	 * penalty. We ought to fix PG not to make such unaligned memory
! 	 * accesses, so this code disables the kernel emulation: unaligned
! 	 * accesses will result in SIGBUS instead.
! 	 */
! #ifdef NOFIXADE
  
  #if defined(ultrix4)
  	syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
***************
*** 94,100 ****
  		write_stderr("%s: setsysinfo failed: %s\n",
  					 argv[0], strerror(errno));
  #endif
! #endif   /* NOFIXADE || NOPRINTADE */
  
  #if defined(WIN32)
  	{
--- 99,105 ----
  		write_stderr("%s: setsysinfo failed: %s\n",
  					 argv[0], strerror(errno));
  #endif
! #endif   /* NOFIXADE */
  
  #if defined(WIN32)
  	{
#5Neil Conway
neilc@samurai.com
In reply to: Neil Conway (#4)
Re: NOFIXADE / NOPRINTADE

On Fri, 2004-09-24 at 12:30, Neil Conway wrote:

Barring any objections, I intend to apply the attached patch to HEAD
later today.

Applied to HEAD.

-Neil