[v4,1/3] config/arm: avoid mcpu and march conflicts

Message ID 20240221202018.14179-1-pbhagavatula@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v4,1/3] config/arm: avoid mcpu and march conflicts |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Pavan Nikhilesh Bhagavatula Feb. 21, 2024, 8:20 p.m. UTC
  From: Pavan Nikhilesh <pbhagavatula@marvell.com>

The compiler options march and mtune are a subset
of mcpu and will lead to conflicts if improper march
is chosen for a given mcpu.
To avoid conflicts, discard part number march when
mcpu is available and is supported by the compiler.

Example:
	march = armv9-a
	mcpu = neoverse-n2

	mcpu supported, march supported
	machine_args = ['-mcpu=neoverse-n2']

	mcpu supported, march not supported
	machine_args = ['-mcpu=neoverse-n2']

	mcpu not supported, march supported
	machine_args = ['-march=armv9-a']

	mcpu not supported, march not supported
	machine_args = ['-march=armv8.6-a']

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
v2 Changes:
- Cleanup march inconsistencies. (Juraj Linkes)
- Unify fallback march selection. (Juraj Linkes)
- Tag along ARM WFE patch.
v3 Changes:
- Fix missing 'fallback_march' key check.
v4 Changes:
- Discard march when mcpu is supported.

 config/arm/meson.build | 107 +++++++++++++++++++++++++++--------------
 1 file changed, 70 insertions(+), 37 deletions(-)

--
2.25.1
  

Comments

Juraj Linkeš Feb. 22, 2024, 9:37 a.m. UTC | #1
> diff --git a/config/arm/meson.build b/config/arm/meson.build
> index 36f21d2259..e77b696d8e 100644
> --- a/config/arm/meson.build
> +++ b/config/arm/meson.build
<snip>
> @@ -695,13 +698,31 @@ if update_flags
>
>      machine_args = [] # Clear previous machine args
>
> +    candidate_mcpu = ''
> +    if part_number_config.has_key('mcpu')
> +        mcpu = part_number_config['mcpu']
> +        if (cc.has_argument('-mcpu=' + mcpu))
> +            candidate_mcpu = mcpu
> +        endif
> +    endif
> +
> +    march_features = []
> +    if part_number_config.has_key('march_features')
> +        march_features += part_number_config['march_features']
> +    endif
> +    if soc_config.has_key('extra_march_features')
> +        march_features += soc_config['extra_march_features']
> +    endif
> +
>      # probe supported archs and their features
>      candidate_march = ''
> -    if part_number_config.has_key('march')
> +    if part_number_config.has_key('march') and candidate_mcpu == ''

If we reorganize the code a bit it would read better I think:
if candidate_mcpu != ''
    <mcpu code>
elif part_number_config.has_key('march')
    <march code>
else
    error(no mcpu and no march) # not sure whether this is needed or
wanted though

This would also match the order before - first process mcpu, then
march. Come to think of it, maybe we should put the march_features
code before the candidate_mcpu code since that is common code and
would thus also read a bit better (common, then mcpu, then march).

>          if part_number_config.get('force_march', false)
> -            candidate_march = part_number_config['march']
> +            if cc.has_argument('-march=' +  part_number_config['march'])
> +                candidate_march = part_number_config['march']
> +            endif
>          else
> -            supported_marchs = ['armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-a',
> +            supported_marchs = ['armv9-a', 'armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-a',
>                                  'armv8.2-a', 'armv8.1-a', 'armv8-a']
>              check_compiler_support = false
>              foreach supported_march: supported_marchs
  
Pavan Nikhilesh Bhagavatula Feb. 22, 2024, 9:49 a.m. UTC | #2
> > diff --git a/config/arm/meson.build b/config/arm/meson.build
> > index 36f21d2259..e77b696d8e 100644
> > --- a/config/arm/meson.build
> > +++ b/config/arm/meson.build
> <snip>
> > @@ -695,13 +698,31 @@ if update_flags
> >
> >      machine_args = [] # Clear previous machine args
> >
> > +    candidate_mcpu = ''
> > +    if part_number_config.has_key('mcpu')
> > +        mcpu = part_number_config['mcpu']
> > +        if (cc.has_argument('-mcpu=' + mcpu))
> > +            candidate_mcpu = mcpu
> > +        endif
> > +    endif
> > +
> > +    march_features = []
> > +    if part_number_config.has_key('march_features')
> > +        march_features += part_number_config['march_features']
> > +    endif
> > +    if soc_config.has_key('extra_march_features')
> > +        march_features += soc_config['extra_march_features']
> > +    endif
> > +
> >      # probe supported archs and their features
> >      candidate_march = ''
> > -    if part_number_config.has_key('march')
> > +    if part_number_config.has_key('march') and candidate_mcpu == ''
> 
> If we reorganize the code a bit it would read better I think:
> if candidate_mcpu != ''
>     <mcpu code>
> elif part_number_config.has_key('march')
>     <march code>
> else
>     error(no mcpu and no march) # not sure whether this is needed or
> wanted though
> 
> This would also match the order before - first process mcpu, then
> march. Come to think of it, maybe we should put the march_features
> code before the candidate_mcpu code since that is common code and
> would thus also read a bit better (common, then mcpu, then march).

Ack, I will reorganize in v5.

Thanks,
Pavan. 

> 
> >          if part_number_config.get('force_march', false)
> > -            candidate_march = part_number_config['march']
> > +            if cc.has_argument('-march=' +  part_number_config['march'])
> > +                candidate_march = part_number_config['march']
> > +            endif
> >          else
> > -            supported_marchs = ['armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-
> a',
> > +            supported_marchs = ['armv9-a', 'armv8.6-a', 'armv8.5-a', 'armv8.4-
> a', 'armv8.3-a',
> >                                  'armv8.2-a', 'armv8.1-a', 'armv8-a']
> >              check_compiler_support = false
> >              foreach supported_march: supported_marchs
  

Patch

diff --git a/config/arm/meson.build b/config/arm/meson.build
index 36f21d2259..e77b696d8e 100644
--- a/config/arm/meson.build
+++ b/config/arm/meson.build
@@ -58,18 +58,18 @@  implementer_generic = {
 }

 part_number_config_arm = {
-    '0xd03': {'compiler_options':  ['-mcpu=cortex-a53']},
-    '0xd04': {'compiler_options':  ['-mcpu=cortex-a35']},
-    '0xd05': {'compiler_options':  ['-mcpu=cortex-a55']},
-    '0xd07': {'compiler_options':  ['-mcpu=cortex-a57']},
-    '0xd08': {'compiler_options':  ['-mcpu=cortex-a72']},
-    '0xd09': {'compiler_options':  ['-mcpu=cortex-a73']},
-    '0xd0a': {'compiler_options':  ['-mcpu=cortex-a75']},
-    '0xd0b': {'compiler_options':  ['-mcpu=cortex-a76']},
+    '0xd03': {'mcpu': 'cortex-a53'},
+    '0xd04': {'mcpu': 'cortex-a35'},
+    '0xd05': {'mcpu': 'cortex-a55'},
+    '0xd07': {'mcpu': 'cortex-a57'},
+    '0xd08': {'mcpu': 'cortex-a72'},
+    '0xd09': {'mcpu': 'cortex-a73'},
+    '0xd0a': {'mcpu': 'cortex-a75'},
+    '0xd0b': {'mcpu': 'cortex-a76'},
     '0xd0c': {
         'march': 'armv8.2-a',
         'march_features': ['crypto', 'rcpc'],
-        'compiler_options':  ['-mcpu=neoverse-n1'],
+        'mcpu': 'neoverse-n1',
         'flags': [
             ['RTE_MACHINE', '"neoverse-n1"'],
             ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -81,7 +81,7 @@  part_number_config_arm = {
     '0xd40': {
         'march': 'armv8.4-a',
         'march_features': ['sve'],
-        'compiler_options':  ['-mcpu=neoverse-v1'],
+        'mcpu': 'neoverse-v1',
         'flags': [
             ['RTE_MACHINE', '"neoverse-v1"'],
             ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -92,8 +92,9 @@  part_number_config_arm = {
         'march': 'armv8.4-a',
     },
     '0xd49': {
+        'march': 'armv9-a',
         'march_features': ['sve2'],
-        'compiler_options': ['-mcpu=neoverse-n2'],
+        'mcpu': 'neoverse-n2',
         'flags': [
             ['RTE_MACHINE', '"neoverse-n2"'],
             ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -127,21 +128,23 @@  implementer_cavium = {
     ],
     'part_number_config': {
         '0xa1': {
-            'compiler_options': ['-mcpu=thunderxt88'],
+            'mcpu': 'thunderxt88',
             'flags': flags_part_number_thunderx
         },
         '0xa2': {
-            'compiler_options': ['-mcpu=thunderxt81'],
+            'mcpu': 'thunderxt81',
             'flags': flags_part_number_thunderx
         },
         '0xa3': {
-            'compiler_options': ['-march=armv8-a+crc', '-mcpu=thunderxt83'],
+            'march': 'armv8-a',
+            'march_features': ['crc'],
+            'mcpu': 'thunderxt83',
             'flags': flags_part_number_thunderx
         },
         '0xaf': {
             'march': 'armv8.1-a',
             'march_features': ['crc', 'crypto'],
-            'compiler_options': ['-mcpu=thunderx2t99'],
+            'mcpu': 'thunderx2t99',
             'flags': [
                 ['RTE_MACHINE', '"thunderx2"'],
                 ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -153,7 +156,7 @@  implementer_cavium = {
         '0xb2': {
             'march': 'armv8.2-a',
             'march_features': ['crc', 'crypto', 'lse'],
-            'compiler_options': ['-mcpu=octeontx2'],
+            'mcpu': 'octeontx2',
             'flags': [
                 ['RTE_MACHINE', '"cn9k"'],
                 ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -176,7 +179,7 @@  implementer_ampere = {
         '0x0': {
             'march': 'armv8-a',
             'march_features': ['crc', 'crypto'],
-            'compiler_options':  ['-mtune=emag'],
+            'mcpu': 'emag',
             'flags': [
                 ['RTE_MACHINE', '"eMAG"'],
                 ['RTE_MAX_LCORE', 32],
@@ -186,7 +189,7 @@  implementer_ampere = {
         '0xac3': {
             'march': 'armv8.6-a',
             'march_features': ['crc', 'crypto'],
-            'compiler_options':  ['-mcpu=ampere1'],
+            'mcpu': 'ampere1',
             'flags': [
                 ['RTE_MACHINE', '"AmpereOne"'],
                 ['RTE_MAX_LCORE', 320],
@@ -206,7 +209,7 @@  implementer_hisilicon = {
         '0xd01': {
             'march': 'armv8.2-a',
             'march_features': ['crypto'],
-            'compiler_options': ['-mtune=tsv110'],
+            'mcpu': 'tsv110',
             'flags': [
                 ['RTE_MACHINE', '"Kunpeng 920"'],
                 ['RTE_ARM_FEATURE_ATOMICS', true],
@@ -695,13 +698,31 @@  if update_flags

     machine_args = [] # Clear previous machine args

+    candidate_mcpu = ''
+    if part_number_config.has_key('mcpu')
+        mcpu = part_number_config['mcpu']
+        if (cc.has_argument('-mcpu=' + mcpu))
+            candidate_mcpu = mcpu
+        endif
+    endif
+
+    march_features = []
+    if part_number_config.has_key('march_features')
+        march_features += part_number_config['march_features']
+    endif
+    if soc_config.has_key('extra_march_features')
+        march_features += soc_config['extra_march_features']
+    endif
+
     # probe supported archs and their features
     candidate_march = ''
-    if part_number_config.has_key('march')
+    if part_number_config.has_key('march') and candidate_mcpu == ''
         if part_number_config.get('force_march', false)
-            candidate_march = part_number_config['march']
+            if cc.has_argument('-march=' +  part_number_config['march'])
+                candidate_march = part_number_config['march']
+            endif
         else
-            supported_marchs = ['armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-a',
+            supported_marchs = ['armv9-a', 'armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-a',
                                 'armv8.2-a', 'armv8.1-a', 'armv8-a']
             check_compiler_support = false
             foreach supported_march: supported_marchs
@@ -717,32 +738,44 @@  if update_flags
                 endif
             endforeach
         endif
-        if candidate_march == ''
-            error('No suitable armv8 march version found.')
-        endif
+
         if candidate_march != part_number_config['march']
-            warning('Configuration march version is ' +
-                    '@0@, but the compiler supports only @1@.'
-                    .format(part_number_config['march'], candidate_march))
+            warning('Configuration march version is @0@, not supported.'
+                    .format(part_number_config['march']))
+            if candidate_march != ''
+                warning('Using march version @0@.'.format(candidate_march))
+            endif
         endif
-        candidate_march = '-march=' + candidate_march

-        march_features = []
-        if part_number_config.has_key('march_features')
-            march_features += part_number_config['march_features']
+        if candidate_march == '' and candidate_mcpu == ''
+            error('No suitable ARM march/mcpu version found.')
         endif
-        if soc_config.has_key('extra_march_features')
-            march_features += soc_config['extra_march_features']
+
+        if candidate_march != ''
+            candidate_march = '-march=' + candidate_march
+            foreach feature: march_features
+                if cc.has_argument('+'.join([candidate_march, feature]))
+                    candidate_march = '+'.join([candidate_march, feature])
+                else
+                    warning('The compiler does not support feature @0@'
+                        .format(feature))
+                endif
+            endforeach
+            machine_args += candidate_march
         endif
+    endif
+
+    if candidate_mcpu != ''
+        candidate_mcpu = '-mcpu=' + candidate_mcpu
         foreach feature: march_features
-            if cc.has_argument('+'.join([candidate_march, feature]))
-                candidate_march = '+'.join([candidate_march, feature])
+            if cc.has_argument('+'.join([candidate_mcpu, feature]))
+                candidate_mcpu = '+'.join([candidate_mcpu, feature])
             else
                 warning('The compiler does not support feature @0@'
                     .format(feature))
             endif
         endforeach
-        machine_args += candidate_march
+        machine_args += candidate_mcpu
     endif

     # apply supported compiler options