Bug 268510 - databases/mongodb50: make AVX/Sandybridge requirement optional
Summary: databases/mongodb50: make AVX/Sandybridge requirement optional
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Ronald Klop
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-22 10:19 UTC by Borja Marcos
Modified: 2023-01-13 19:03 UTC (History)
2 users (show)

See Also:
ronald: maintainer-feedback+


Attachments
Patch to add an option disabling AVX instructions (545 bytes, patch)
2022-12-28 13:42 UTC, Borja Marcos
no flags Details | Diff
patch for databases/mongodb5 (421 bytes, patch)
2023-01-02 13:04 UTC, Borja Marcos
no flags Details | Diff
patch for databases/mongodb6 (506 bytes, patch)
2023-01-02 13:05 UTC, Borja Marcos
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Borja Marcos 2022-12-22 10:19:33 UTC
The developers of MongoDB have decided to require AVX instructions for MongoDB 5.x and upwards.

It would be a good idea to make this optimization optional.

The optimization option is in SConstruct as part of a list of so called experimental optimizations. 

/////
experimental_optimizations = [
    'O3',
    'builtin-memcmp',
    'fnsi',
    'nofp',
    'nordyn',
    'sandybridge',
    'tbaa',
    'treevec',
    'vishidden',
]
/////
Comment 1 Borja Marcos 2022-12-22 10:37:16 UTC
The same would apply to databases/mongodb60 actually.

By default it uses arch=sandybridge.
Comment 2 Ronald Klop freebsd_committer freebsd_triage 2022-12-24 07:28:49 UTC
Some messages about this are on the mongodb forum also.  

https://www.mongodb.com/community/forums/t/mongodb-5-0-cpu-intel-g4650-compatibility/116610

Are you able to create a patch and show that it works?
Comment 3 Borja Marcos 2022-12-28 07:32:23 UTC
I'm on it, updating a system. I will post it once it works.
Comment 4 Ronald Klop freebsd_committer freebsd_triage 2022-12-28 10:20:08 UTC
(In reply to Borja Marcos from comment #3)
Thank you for looking into it.
Out of curiosity I googled AVX & Sandybridge and the technology seems about 10 years old (2011). What kind of hardware are you trying to run MongoDB 5 on?
Comment 5 Borja Marcos 2022-12-28 11:06:03 UTC
(In reply to Ronald Klop from comment #4)
Testing patch, turns out to be trivial once you know scons (I must admit I am and old Makefile guy).

Added a NOAVX option to the port Makefile that adds
--experimental-optimization="-sandybridge" to the scons options.

I am testing right now making sure it works. 

I've named the option "NOAVX" because Mongodb by default enables it despite being labelled as "experimental" on the SCons file. 

The same happens with MongoDB 6.

As for the hardware, my development/testing platform is old. But from what I've digged, some hypervisors won't support the AVX instructions either, so the problem can be more widespread than it seems. 


In my case,
CPU: Intel(R) Xeon(R) CPU           L5640  @ 2.27GHz (2266.86-MHz K8-class CPU)
  Origin="GenuineIntel"  Id=0x206c2  Family=0x6  Model=0x2c  Stepping=2
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0x29ee3ff<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,POPCNT,AESNI>
  AMD Features=0x2c100800<SYSCALL,NX,Page1GB,RDTSCP,LM>
  AMD Features2=0x1<LAHF>
  VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
  TSC: P-state invariant, performance statistics
Comment 6 Borja Marcos 2022-12-28 13:42:34 UTC
Created attachment 239085 [details]
Patch to add an option disabling AVX instructions
Comment 7 Borja Marcos 2022-12-28 13:53:48 UTC
Comment on attachment 239085 [details]
Patch to add an option disabling AVX instructions

*** Makefile.orig	Wed Dec 28 10:00:29 2022
--- Makefile	Wed Dec 28 13:51:49 2022
***************
*** 59,66 ****
  USERS=		mongodb
  GROUPS=		mongodb
  
! OPTIONS_DEFINE=			LTO SASL SSL
  OPTIONS_DEFAULT=		LTO SASL SSL
  
  LTO_MAKE_ARGS=	--lto=on
  
--- 59,70 ----
  USERS=		mongodb
  GROUPS=		mongodb
  
! OPTIONS_DEFINE=			LTO SASL SSL NOAVX
  OPTIONS_DEFAULT=		LTO SASL SSL
+ 
+ NOAVX_DESC= 	"Disable AVX instructions on amd64 (Sandybridge+)"
+ 
+ NOAVX_MAKE_ARGS=  --experimental-optimization="-sandybridge"
  
  LTO_MAKE_ARGS=	--lto=on
Comment 8 Ronald Klop freebsd_committer freebsd_triage 2023-01-01 13:48:59 UTC
The patch did not apply cleanly. It does not look like a "unified" diff.
I applied the changed manually and it looks good to me.
Comment 9 Borja Marcos 2023-01-02 13:04:26 UTC
Created attachment 239209 [details]
patch for databases/mongodb5
Comment 10 Borja Marcos 2023-01-02 13:05:12 UTC
Created attachment 239210 [details]
patch for databases/mongodb6
Comment 11 commit-hook freebsd_committer freebsd_triage 2023-01-03 12:05:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=fb2179e9408960e3715e49ef32cf1b71aed191f9

commit fb2179e9408960e3715e49ef32cf1b71aed191f9
Author:     Borja Marcos <borjam@sarenet.es>
AuthorDate: 2023-01-01 12:22:15 +0000
Commit:     Ronald Klop <ronald@FreeBSD.org>
CommitDate: 2023-01-03 12:05:18 +0000

    databases/mongodb50: optionally support pre-AVX CPUs

    Upstream defaults to Sandybridge+ CPUs for amd64.
    It is reported to still work with older CPUs.
    No revision bump as the change does not impact the default build.

    PR:     268510
    Approved by: rene (mentor)
    Differential Revision: https://reviews.freebsd.org/D37924

 databases/mongodb50/Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Comment 12 Ronald Klop freebsd_committer freebsd_triage 2023-01-03 12:11:49 UTC
Committed. Thanks for your work!
I will piggyback the mongodb60 change on a future update of that port.
Comment 13 commit-hook freebsd_committer freebsd_triage 2023-01-13 19:03:15 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=146e6a4b49a196747bff0edbe6fee3f21069faa8

commit 146e6a4b49a196747bff0edbe6fee3f21069faa8
Author:     Ronald Klop <ronald@FreeBSD.org>
AuthorDate: 2023-01-03 13:46:13 +0000
Commit:     Ronald Klop <ronald@FreeBSD.org>
CommitDate: 2023-01-13 19:01:46 +0000

    databases/mongodb60: update to 6.0.3

    - Trivial version bump.
    - Mark IGNORE as it fails on runtime. Upstream has an issue on this open. (See: PR #267668)
    - Add option NOAVX to support building for older CPUs. (Thanks to Borja Marcos)
    - Make portmft/portlint/portclippy even more happy.

    PR:     268510
    Approved by: rene (mentor)
    Differential Revision: https://reviews.freebsd.org/D38016

 databases/mongodb60/Makefile | 23 ++++++++++++++---------
 databases/mongodb60/distinfo |  6 +++---
 2 files changed, 17 insertions(+), 12 deletions(-)