all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Soo <jsoo1@asu.edu>
To: Mathieu Othacehe <othacehe@gnu.org>
Cc: Help Guix <help-guix@gnu.org>
Subject: Re: BPF in linux-libre
Date: Tue, 30 Jun 2020 22:40:11 -0700	[thread overview]
Message-ID: <87h7ur3i9w.fsf@asu.edu> (raw)
In-Reply-To: <87wo3uxfrq.fsf@gnu.org> (Mathieu Othacehe's message of "Fri, 26 Jun 2020 12:50:17 +0200")

[-- Attachment #1: Type: text/plain, Size: 272 bytes --]

Hi Mathieu and Guix,

I forgot to mention that I do have an updated patchset where libbpf is
found. I've attached my work. This is I think closer to the desired
effect but now there is a compile error I do not understand. I hope you
can get further than I did.

- John




[-- Attachment #2: 0001-gnu-Add-libbpf.patch --]
[-- Type: text/x-patch, Size: 2814 bytes --]

From 6560dc2a5eedb3040bdd5fba8d8b6950b7a2b6d1 Mon Sep 17 00:00:00 2001
From: John Soo <jsoo1@asu.edu>
Date: Sat, 13 Jun 2020 14:53:50 -0700
Subject: [PATCH 1/5] gnu: Add libbpf.

* gnu/packages/linux.scm (libbpf): New variable.
---
 gnu/packages/linux.scm | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index cadfd186a1..c0ac8f24bc 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -45,6 +45,7 @@
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
 ;;; Copyright © 2020 Morgan Smith <Morgan.J.Smith@outlook.com>
+;;; Copyright © 2020 John Soo <jsoo1@asu.edu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -7139,3 +7140,48 @@ cache data store that is used by network file systems such as @code{AFS} and
 @code{NFS} to cache data locally on disk.  The content of the cache is
 persistent over reboots.")
     (license license:gpl2+)))
+
+(define-public libbpf
+  (let* ((commit "6a1615c263b679c17ecb292fa897f159e826dc10"))
+    (package
+      (name "libbpf")
+      (version "0.0.8")
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/libbpf/libbpf")
+               (commit commit)))
+         (sha256
+          (base32
+           "02vbpg9v5sjcw7ihximy63cjmz82q5izkp91i44m1qp6qj5qn4sr"))))
+      (build-system gnu-build-system)
+      (inputs
+       `(("libelf" ,libelf)
+         ("pkg-config" ,pkg-config)
+         ("zlib" ,zlib)))
+      (arguments
+       `(#:tests? #f ; No tests
+         #:make-flags
+         (list
+          (string-append "PREFIX=''")
+          (string-append "DESTDIR=" (assoc-ref %outputs "out"))
+          (string-append
+           "CC=" (assoc-ref %build-inputs "gcc") "/bin/gcc"))
+         #:phases
+         (modify-phases %standard-phases
+           (delete 'configure)
+           (add-before 'build 'pre-build
+             (lambda* (#:key inputs #:allow-other-keys)
+               (substitute* "scripts/check-reallocarray.sh"
+                 (("/bin/rm" rm)
+                  (string-append (assoc-ref inputs "coreutils") rm)))
+               (chdir "src")
+               #t)))))
+      (home-page "https://github.com/libbpf/libbpf")
+      (synopsis "BPF CO-RE (Compile Once – Run Everywhere)")
+      (description
+       "Libbpf supports building BPF CO-RE-enabled applications, which, in
+contrast to BCC, do not require Clang/LLVM runtime being deployed to target
+servers and does not rely on kernel-devel headers being available.")
+      (license `(,license:lgpl2.1 ,license:bsd-2)))))
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-gnu-Add-bpf-extra-linux-options.patch --]
[-- Type: text/x-patch, Size: 1339 bytes --]

From 124267a629c30d0acb5e5c931772cc8d0f3c43ac Mon Sep 17 00:00:00 2001
From: John Soo <jsoo1@asu.edu>
Date: Sat, 13 Jun 2020 22:52:55 -0700
Subject: [PATCH 2/5] gnu: Add %bpf-extra-linux-options.

* gnu/packages/linux (%bpf-extra-linux-options): New variable.
---
 gnu/packages/linux.scm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index c0ac8f24bc..4daa371c6b 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -619,6 +619,22 @@ for ARCH and optionally VARIANT, or #f if there is no such configuration."
     ("CONFIG_CIFS" . m)
     ("CONFIG_9P_FS" . m)))
 
+;; See https://github.com/iovisor/bcc/blob/master/INSTALL.md#kernel-configuration
+(define %bpf-extra-linux-options
+  `(("CONFIG_BPF" . #t)
+    ("CONFIG_BPF_SYSCALL" . #t)
+    ;; optional, for tc filters
+    ("CONFIG_NET_CLS_BPF" . m)
+    ;; optional, for tc actions
+    ("CONFIG_NET_ACT_BPF" . m)
+    ("CONFIG_BPF_JIT" . #t)
+    ;; for Linux kernel versions 4.1 through 4.6
+    ;; ("CONFIG_HAVE_BPF_JIT" . y)
+    ;; for Linux kernel versions 4.7 and later
+    ("CONFIG_HAVE_EBPF_JIT" . #t)
+    ;; optional, for kprobes
+    ("CONFIG_BPF_EVENTS" . #t)))
+
 (define (config->string options)
   (string-join (map (match-lambda
                       ((option . 'm)
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-gnu-Add-linux-libre-with-bpf.patch --]
[-- Type: text/x-patch, Size: 1248 bytes --]

From 88c88d787a399069f0554c8635f1f3496a9fd1e2 Mon Sep 17 00:00:00 2001
From: John Soo <jsoo1@asu.edu>
Date: Sat, 13 Jun 2020 22:54:24 -0700
Subject: [PATCH 3/5] gnu: Add linux-libre-with-bpf.

* gnu/packages/linux.scm (linux-libre-with-bpf): New variable.
---
 gnu/packages/linux.scm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 4daa371c6b..f3eec978ec 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -7157,6 +7157,16 @@ cache data store that is used by network file systems such as @code{AFS} and
 persistent over reboots.")
     (license license:gpl2+)))
 
+(define-public linux-libre-with-bpf
+  (make-linux-libre* linux-libre-5.4-version
+                     linux-libre-5.4-source
+                     '("x86_64-linux" "i686-linux" "armhf-linux" "aarch64-linux" "riscv64-linux")
+                     #:extra-version "bpf"
+                     #:configuration-file kernel-config
+                     #:extra-options
+                     (append %bpf-extra-linux-options
+                             %default-extra-linux-options)))
+
 (define-public libbpf
   (let* ((commit "6a1615c263b679c17ecb292fa897f159e826dc10"))
     (package
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-gnu-Add-bcc.patch --]
[-- Type: text/x-patch, Size: 3924 bytes --]

From 0358dccc866a392512ddb15f9fee0e24e6bc837c Mon Sep 17 00:00:00 2001
From: John Soo <jsoo1@asu.edu>
Date: Sat, 13 Jun 2020 23:16:11 -0700
Subject: [PATCH 4/5] gnu: Add bcc.

* gnu/packages/linux.scm (bcc): New variable.
---
 gnu/packages/linux.scm | 65 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index f3eec978ec..0b8b08883a 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -97,6 +97,8 @@
   #:use-module (gnu packages haskell-xyz)
   #:use-module (gnu packages libunwind)
   #:use-module (gnu packages libusb)
+  #:use-module (gnu packages llvm)
+  #:use-module (gnu packages lua)
   #:use-module (gnu packages man)
   #:use-module (gnu packages maths)
   #:use-module (gnu packages multiprecision)
@@ -131,6 +133,7 @@
   #:use-module (gnu packages rsync)
   #:use-module (gnu packages selinux)
   #:use-module (gnu packages swig)
+  #:use-module (gnu packages version-control)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system go)
@@ -7211,3 +7214,65 @@ persistent over reboots.")
 contrast to BCC, do not require Clang/LLVM runtime being deployed to target
 servers and does not rely on kernel-devel headers being available.")
       (license `(,license:lgpl2.1 ,license:bsd-2)))))
+
+(define-public bcc
+  (let* ((ver "0.14.0")
+         (commit (string-append "v" ver))
+         (revision "1"))
+    (package
+      (name "bcc")
+      (version (git-version ver revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/iovisor/bcc")
+               (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32
+           "08m21avzamr48qwshd4r5hlcckk1kvgrb1i6qw373b7la89jf5an"))))
+      (build-system cmake-build-system)
+      (inputs
+       `(;; TODO: package optional integrations
+         ;; ("arping" ,argping)
+         ;; ("netperf" ,netperf)
+         ;; ("iperf" ,iperf) or ("iperf3" ,iperf3)
+         ("bison" ,bison)
+         ("clang-toolchain" ,clang-toolchain)
+         ("flex" ,flex)
+         ;; FIXME: Timestamp some other way.
+         ("git" ,git)
+         ("libbpf" ,(package-source libbpf))
+         ;; LibElf required but libelf does not contain
+         ;; archives, only object files.
+         ;; https://github.com/iovisor/bcc/issues/504
+         ("elfutils" ,elfutils)
+         ("linux-libre-headers" ,linux-libre-headers)
+         ("luajit" ,luajit)
+         ("python-wrapper" ,python-wrapper)))
+      (arguments
+       `(;; Tests all require sudo and a "standard" file heirarchy
+         #:tests? #f
+         ;; LIBBPF_INCLUDE_DIR should work with the output of libbpf -
+         ;; i.e. ,libbpf instead of ,(package-source libbpf) in inputs
+         ;; but it seems there could be a bug
+         ;; #:configure-flags
+         ;; (list
+         ;;  (string-append
+         ;;   "-DLIBBPF_INCLUDE_DIR=" (assoc-ref %build-inputs "libbpf") "/include"))
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'unpack 'copy-libbpf
+             (lambda* (#:key inputs #:allow-other-keys)
+               (delete-file-recursively "src/cc/libbpf")
+               (copy-recursively (assoc-ref inputs "libbpf") "src/cc/libbpf"))))))
+      (home-page "https://github.com/iovisor/bcc")
+      (synopsis "Tools for BPF on Linux")
+      (description
+       "BCC is a toolkit for creating efficient kernel tracing and
+manipulation programs, and includes several useful tools and examples.  It
+makes use of extended BPF (Berkeley Packet Filters), formally known as eBPF, a
+new feature that was first added to Linux 3.15.  Much of what BCC uses requires
+Linux 4.1 and above.")
+      (license license:asl2.0))))
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-WIP-gnu-Add-bpftrace.patch --]
[-- Type: text/x-patch, Size: 3405 bytes --]

From 3176597e20946e7b3564479f655ac51b65109b5f Mon Sep 17 00:00:00 2001
From: John Soo <jsoo1@asu.edu>
Date: Sat, 13 Jun 2020 23:16:56 -0700
Subject: [PATCH 5/5] [WIP] gnu: Add bpftrace.

* gnu/packages/linux.scm (bpftrace): New variable.
---
 gnu/packages/linux.scm | 60 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 0b8b08883a..00c4c41c82 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -7276,3 +7276,63 @@ makes use of extended BPF (Berkeley Packet Filters), formally known as eBPF, a
 new feature that was first added to Linux 3.15.  Much of what BCC uses requires
 Linux 4.1 and above.")
       (license license:asl2.0))))
+
+(define-public bpftrace
+  (let* ((ver "0.10.0")
+         (commit (string-append "v" ver))
+         (revision "1"))
+    (package
+      (name "bpftrace")
+      (version (git-version ver revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/iovisor/bpftrace")
+               (commit commit)))
+         (file-name (git-file-name name ver))
+         (sha256
+          (base32
+           "023ardywbw5w8815j2ny9rrp2xlpxndqaa7v2njjm8109p7ilsdn"))))
+      (build-system cmake-build-system)
+      (inputs
+       `(("bcc" ,bcc)
+         ("binutils" ,binutils)
+         ("bison" ,bison)
+         ("clang-toolchain" ,clang-toolchain)
+         ("elfutils" ,elfutils)
+         ("flex" ,flex)
+         ;; FIXME: Tests require googletest but not from system
+         ;; ("googletest" ,googletest)
+         ("libbpf" ,libbpf)
+         ("libiberty" ,libiberty)
+         ("linux-libre-headers" ,linux-libre-headers)
+         ("zlib" ,zlib)))
+      (arguments
+       `(#:configure-flags
+         (let ((libbpf (assoc-ref %build-inputs "libbpf"))
+               (zlib (assoc-ref %build-inputs "zlib"))
+               (binutils (assoc-ref %build-inputs "binutils")))
+           `(;; FIXME: Make tests not clone the googletest repository
+             "-DBUILD_TESTING=OFF"
+             "-DSTATIC_LINKING=ON"
+             ;; ,(string-append "-DLIBBFD_LIBRARY=" binutils)
+             ;; ,(string-append "-DLIBBFD_INCLUDE_DIRS=" binutils "/include")
+             ,(string-append "-DLIBZ_LIBRARIES=" zlib "/lib")
+             ;; ,(string-append "-DLIBBPF_LIBRARY=" libbpf)
+             ;; ,(string-append "-DLIBBPF_LIBRARIES=" libbpf "/lib")
+             ;; ,(string-append "-DLIBBPF_INCLUDE_DIRS=" libbpf "/include")
+             ;; "-DLIBBFD_DISASM_FOUR_ARGS_SIGNATURE=ON"
+             ))))
+      (home-page "https://github.com/iovisor/bpftrace")
+      (synopsis "High-level tracing language for Linux eBPF")
+      (description
+       "bpftrace is a high-level tracing language for Linux enhanced Berkeley
+Packet Filter (eBPF) available in recent Linux kernels (4.x).  bpftrace uses
+LLVM as a backend to compile scripts to BPF-bytecode and makes use of BCC for
+interacting with the Linux BPF system, as well as existing Linux tracing
+capabilities: kernel dynamic tracing (kprobes), user-level dynamic
+tracing (uprobes), and tracepoints.  The bpftrace language is inspired by awk
+and C, and predecessor tracers such as DTrace and SystemTap.  bpftrace was
+created by Alastair Robertson.")
+      (license license:asl2.0))))
-- 
2.26.2


  parent reply	other threads:[~2020-07-01  5:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14  3:21 BPF in linux-libre John Soo
2020-06-14  9:23 ` Mathieu Othacehe
2020-06-14 15:11   ` John Soo
2020-06-17 10:16     ` Mathieu Othacehe
2020-06-17 13:42       ` John Soo
2020-06-21 15:32       ` John Soo
2020-06-26 10:50         ` Mathieu Othacehe
2020-06-28 20:24           ` John Soo
2020-07-01  5:40           ` John Soo [this message]
2020-07-03 16:01           ` John Soo
2020-07-05  8:18             ` Mathieu Othacehe
2020-07-05  8:20             ` Mathieu Othacehe
2020-07-06  0:44               ` John Soo
2020-07-06 13:26                 ` [bug#42227] " Mathieu Othacehe
2020-07-11 16:28                   ` John Soo
2020-07-30 18:48                     ` Mathieu Othacehe
2020-07-31  2:20                       ` John Soo
2020-07-31 11:04                         ` bug#42227: " Mathieu Othacehe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7ur3i9w.fsf@asu.edu \
    --to=jsoo1@asu.edu \
    --cc=help-guix@gnu.org \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.