Bug 112997

Summary: [bsd.cpu.mk] [patch] Add note about the 'native' mtune option
Product: Base System Reporter: Scot Hetzel <swhetzel>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me Keywords: patch
Priority: Normal    
Version: 7.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
gcc_native.patch
none
gcc_native.patch none

Description Scot Hetzel 2007-05-25 16:20:02 UTC
On the AMD64 mailing list there was a discussion on what to set CPUTYPE
to for a users system.  During the discussion, the new 'native' mtune
option for gcc 4.2 was brought up.  This option allows gcc to automatically
tune the compile for the processor that the machine is being built on for
the x86 and AMD64 architectures.

We need to warn users to not set CPUTYPE to 'native' in /etc/make.conf,
as CPUTYPE is used to determine the value of MACHINE_CPU. But instead to use:

gcc -v -x c -E -mtune=native /dev/null -o /dev/null 2>&1 | grep mtune | sed -e 's/.*mtune=//'

to determine the value of CPUTYPE for their system.

Fix: apply attached patch to share/examples/etc/make.conf

Patch attached with submission follows:
Comment 1 Scot Hetzel 2007-05-25 16:37:37 UTC
The patch has one error, remove the second '-e' from the sed command.

[linimon note: I have gone ahead and done this in the above code]

-- 
DISCLAIMER:
No electrons were mamed while sending this message. Only slightly bruised.
Comment 2 Scot Hetzel 2007-08-28 07:04:24 UTC
I found another solution to this problem by patching share/mk/bsd.cpu.mk.

This patch adds code to share/mk/bsd.cpu.mk which uses gcc to change
the 'native' cpu_type to the a CPUTYPE that can be used to set the
correct MACHINE_CPU.

Scot

-- 
DISCLAIMER:
No electrons were mamed while sending this message. Only slightly bruised.
Comment 3 Remko Lodder freebsd_committer freebsd_triage 2007-08-28 07:49:25 UTC
Hello,

The attached patch was unreadable, can you perhaps copy paste it in, or
attach it as .txt file?

Thanks!



-- 
Kind regards,

     Remko Lodder               ** remko@elvandar.org
     FreeBSD                    ** remko@FreeBSD.org

     /* Quis custodiet ipsos custodes */
Comment 4 Scot Hetzel 2007-08-28 07:58:03 UTC
On 8/28/07, Remko Lodder <remko@freebsd.org> wrote:
>
> Hello,
>
> The attached patch was unreadable, can you perhaps copy paste it in, or
> attach it as .txt file?
>
I have to remember to add .txt when sending patches thru gmail.

Scot
Comment 5 Scot Hetzel 2007-08-28 08:24:07 UTC
On 8/28/07, Scot Hetzel <swhetzel@gmail.com> wrote:
> On 8/28/07, Remko Lodder <remko@freebsd.org> wrote:
> >
> > Hello,
> >
> > The attached patch was unreadable, can you perhaps copy paste it in, or
> > attach it as .txt file?
> >
> I have to remember to add .txt when sending patches thru gmail.
>
I give up, no ideal as to why gnats/gmail is converting the attachment
to base64 encoding, the patch is available in this post:

http://lists.freebsd.org/pipermail/freebsd-current/2007-August/076503.html

Scot
-- 
DISCLAIMER:
No electrons were mamed while sending this message. Only slightly bruised.
Comment 6 swell.k 2010-05-03 12:18:33 UTC
I disagree, native and ${YOUR_CPU} aren't equivalent. Here is what I get
on gcc45 + core2@amd64 system:

  $ cc -E -v -march=core2 - </dev/null |& fgrep cc1
  .../cc1 -E -quiet -v - -march=core2

  $ cc -E -v -mtune=core2 - </dev/null |& fgrep cc1
  .../cc1 -E -quiet -v - -mtune=core2 -march=x86-64

  $ cc -E -v -march=native - </dev/null |& fgrep cc1
  .../cc1 -E -quiet -v - -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=core2

  $ cc -E -v -mtune=native - </dev/null |& fgrep cc1
  .../cc1 -E -quiet -v - --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=core2 -march=x86-64

And bsd.cpu.mk is oblivious about gcc43+. It will degrade native to
nocona even though core2 is supported. Good example that overriding
CPUTYPE is bad idea.

Better leave CPUTYPE as is and populate MACHINE_CPU directly, smth like

  $ cat a.mk
  CPUTYPE = ${MACHINE_ARCH}
  MACHINE_CPU != echo ${MACHINE_ARCH}; ${CC} -E -dM -v -march=${CPUTYPE:S/amd64/x86-64/:S/i386/i486/} - </dev/null 2>&1 \
          | awk '/SSE|MMX/ && !/MATH/ { FS="__"; gsub("_",".",$$2); print tolower($$2) }'

  $ make -f a.mk -V MACHINE_CPU
  amd64 mmx sse2 sse
  $ make -f a.mk -V MACHINE_CPU CPUTYPE=native
  amd64 sse4.1 mmx sse2 ssse3 sse sse3
  $ make -f a.mk -V MACHINE_CPU CPUTYPE=native CC=/usr/bin/cc
  amd64 mmx sse sse2 sse3
Comment 7 b. f. 2010-09-05 02:22:03 UTC
It is very inefficient to invoke gcc, grep, and/or awk every time this
makefile is processed.  (In the past, we've gone to a great deal of
trouble to avoid this kind of thing:

http://lists.freebsd.org/pipermail/freebsd-ports/2008-July/049777.html
http://lists.freebsd.org/pipermail/cvs-ports/2008-July/153224.html

)  Instead, I think that comments in /etc/make.conf instructing users
to how to correctly specify their CPUTYPE would be appropriate.  The
list of overrides for the base system compiler should be expanded, and
perhaps relaxed if CC != cc.  But _all_ overrides cannot be removed,
and MACHINE_CPU cannot be expanded to include all features recognized
by compilers from ports, because the kernel lacks the necessary
support for things like SSE5/XOP+FMA4+CVT16, LWP, AVX, etc.

b.
Comment 8 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:37 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 9 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:39:14 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>