NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.38k stars 13.6k forks source link

DPDK building fails on arm64 #154492

Open xin3liang opened 2 years ago

xin3liang commented 2 years ago

Describe the bug

DPDK building fails on arm64.

Steps To Reproduce

Steps to reproduce the behavior:

  1. $ nix-build -A dpdk

Expected behavior

Build success

Additional context

$ nix-build -A dpdk
...
Compiler for C supports arguments -Wno-missing-field-initializers: YES
Program /build/dpdk-21.02/config/arm/armv8_machine.py found: YES (/build/dpdk-21.02/config/arm/armv8_machine.py)

config/arm/meson.build:445:4: ERROR: Problem encountered: Error when getting Arm Implementer ID and part number.

A full log can be found at /build/dpdk-21.02/build/meson-logs/meson-log.txt
error: builder for '/nix/store/mincq33z7w6dhvilqmv0h1nhf59qg9na-dpdk-21.02.drv' failed with exit code 1

config/arm/meson.build reelate code

437             detect_vendor = find_program(join_paths(meson.current_source_dir(),
438                                                     'armv8_machine.py'))
439             cmd = run_command(detect_vendor.path())
440             if cmd.returncode() == 0
441                 cmd_output = cmd.stdout().to_lower().strip().split(' ')
442                 implementer_id = cmd_output[0]
443                 part_number = cmd_output[3]
444             else
445                 error('Error when getting Arm Implementer ID and part number.')
446             endif

File armv8_machine.py

 1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: BSD-3-Clause
  3 # Copyright(c) 2017 Cavium, Inc
  4
  5 ident = []
  6 fname = '/sys/devices/system/cpu/cpu0/regs/identification/midr_el1'
  7 with open(fname) as f:
  8     content = f.read()
  9
 10 midr_el1 = (int(content.rstrip('\n'), 16))
 11
 12 ident.append(hex((midr_el1 >> 24) & 0xFF))  # Implementer
 13 ident.append(hex((midr_el1 >> 20) & 0xF))   # Variant
 14 ident.append(hex((midr_el1 >> 16) & 0XF))   # Architecture
 15 ident.append(hex((midr_el1 >> 4) & 0xFFF))  # Primary Part number
 16 ident.append(hex(midr_el1 & 0xF))           # Revision
 17
 18 print(' '.join(ident))
$ /nix/store/9akqxpvd20pc527zx8r0p2zy42kaj33m-source/dpdk/config/arm/armv8_machine.py
0x43 0x1 0xf 0xaf 0x1
$ echo $?
0

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
...
 - system: `"aarch64-linux"`
 - host os: `Linux 5.4.0-90-generic, Ubuntu, 20.04.2 LTS (Focal Fossa)`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.5.1`
 - channels(ubuntu): `"nixpkgs-22.05pre345162.81f05d871fa"`
 - nixpkgs: `/home/ubuntu/.nix-defexpr/channels/nixpkgs`
xin3liang commented 2 years ago

Maybe it needs to add path access into NixOS for '/sys/devices/system/cpu/cpu0/regs/identification/midr_el1'. How?

samueldr commented 2 years ago

These are the kind of things that should not be detected from the machine it's running on. Otherwise the build is different depending on what machine runs it!

So adding access to the path in the sandbox is not the solution.

Though I don't have a solution for this.

It looks like this would be mainly used to optimize the binaries for a specific microarchitecture:

Packages in Nixpkgs must be generic for the platform.

I am not adept at meson, but it looks like there's a way to select a generic "soc":

I suspect it would be by adding -Dplatform=generic:

zhaofengli commented 2 years ago

This was already fixed in https://github.com/NixOS/nixpkgs/commit/5ff289f39e7e3a30298ea7920337480d00988510. Try updating your channels?

xin3liang commented 2 years ago

This was already fixed in 5ff289f. Try updating your channels?

Thanks for your reply. Yeah, I just see it from the source code. I am newbie to NixOS, how to update the channel?

zhaofengli commented 2 years ago

Try nix-channel --update. I just tested that the patch fixes aarch64-linux build on the stable 21.11 channel as well, so let's also backport it.

xin3liang commented 2 years ago

Try nix-channel --update. I just tested that the patch fixes aarch64-linux build on the stable 21.11 channel as well, so let's also backport it.

Thanks for doing this. Really appreciated. 👍