RitchieSolo

omx-afdo-profile.sh

Oct 7th, 2026 (edited)
69
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.01 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2. # omx-afdo-profile.sh
  3. #
  4. # Collect and convert AutoFDO / Propeller profiles for a Clang-built
  5. # Linux kernel.
  6. #
  7. # Workflow:
  8. #
  9. # STAGE 1 — AutoFDO
  10. #
  11. # Build:
  12. # OMX-Kernel-Build-Script.sh ... --autofdo
  13. #
  14. # Boot that kernel, then:
  15. # sudo omx-afdo-profile.sh record VMLINUX run1.afdo 3600
  16. #
  17. # Or run a specific workload:
  18. # sudo omx-afdo-profile.sh record VMLINUX run1.afdo -- COMMAND...
  19. #
  20. # Repeat for additional workloads if desired.
  21. #
  22. # Merge:
  23. # omx-afdo-profile.sh merge final.afdo run1.afdo run2.afdo
  24. #
  25. #
  26. # STAGE 2 — AutoFDO + Propeller profiling kernel
  27. #
  28. # Build with:
  29. # ... --afdo-profile final.afdo --propeller
  30. #
  31. # Boot that kernel, then:
  32. # sudo omx-afdo-profile.sh record-propeller VMLINUX PREFIX 3600
  33. #
  34. # This produces:
  35. # PREFIX.perf.data
  36. # PREFIX_cc_profile.txt
  37. # PREFIX_ld_profile.txt
  38. #
  39. #
  40. # STAGE 3 — Final optimized kernel
  41. #
  42. # Build with:
  43. # ... --afdo-profile final.afdo --propeller-profile PREFIX
  44. #
  45. #
  46. # Rescue / conversion:
  47. #
  48. # AutoFDO:
  49. # omx-afdo-profile.sh convert VMLINUX PERF.data OUT.afdo
  50. #
  51. # Propeller:
  52. # omx-afdo-profile.sh convert-propeller VMLINUX PREFIX PERF.data
  53. #
  54. #
  55. # Requirements:
  56. # - perf
  57. # - llvm-profgen + llvm-profdata (LLVM >= 19)
  58. # - generate_propeller_profiles from google/llvm-propeller
  59. # (found via PROPELLER_TOOL, PATH, then /opt/llvm-propeller*/bin)
  60. # OR create_llvm_prof from a compatible AutoFDO/Propeller build
  61. # - Intel LBR or AMD branch-sampling hardware
  62. #
  63. # The kernel vmlinux must correspond EXACTLY to the kernel being profiled.
  64. #
  65. # Reference:
  66. # Linux Documentation/dev-tools/autofdo.rst
  67. # Linux Documentation/dev-tools/propeller.rst
  68.  
  69. set -Eeuo pipefail
  70.  
  71.  
  72. # ---------------------------------------------------------------------------
  73. # Basic helpers
  74. # ---------------------------------------------------------------------------
  75.  
  76. die() {
  77. printf 'ERROR: %s\n' "$*" >&2
  78. exit 1
  79. }
  80.  
  81. warn() {
  82. printf 'WARNING: %s\n' "$*" >&2
  83. }
  84.  
  85. need() {
  86. command -v "$1" >/dev/null 2>&1 ||
  87. die "missing required tool: $1"
  88. }
  89.  
  90.  
  91. give_back() {
  92. # Files written under sudo are root-owned; give them to the invoking user.
  93. [[ -n "${SUDO_UID:-}" ]] || return 0
  94.  
  95. chown "${SUDO_UID}:${SUDO_GID:-$SUDO_UID}" "$@" 2>/dev/null || true
  96. }
  97.  
  98.  
  99. # ---------------------------------------------------------------------------
  100. # Usage
  101. # ---------------------------------------------------------------------------
  102.  
  103. usage() {
  104. cat <<'USAGE'
  105.  
  106. Usage:
  107.  
  108. AutoFDO recording:
  109. omx-afdo-profile.sh record VMLINUX OUT.afdo [SECONDS]
  110. omx-afdo-profile.sh record VMLINUX OUT.afdo -- COMMAND...
  111.  
  112. Convert existing AutoFDO perf data:
  113. omx-afdo-profile.sh convert VMLINUX PERF.data OUT.afdo
  114.  
  115. Merge AutoFDO profiles:
  116. omx-afdo-profile.sh merge OUT.afdo IN1.afdo [IN2.afdo ...]
  117.  
  118. Propeller recording:
  119. omx-afdo-profile.sh record-propeller VMLINUX PREFIX [SECONDS]
  120. omx-afdo-profile.sh record-propeller VMLINUX PREFIX -- COMMAND...
  121.  
  122. Convert existing Propeller perf data:
  123. omx-afdo-profile.sh convert-propeller VMLINUX PREFIX PERF.data
  124. omx-afdo-profile.sh convert-propeller VMLINUX PREFIX PERF1.data PERF2.data ...
  125.  
  126. Examples:
  127.  
  128. sudo omx-afdo-profile.sh record \
  129. /usr/src/kernels/$(uname -r)/vmlinux \
  130. ~/afdo/xanmod.afdo \
  131. 3600
  132.  
  133. sudo omx-afdo-profile.sh record-propeller \
  134. /usr/src/kernels/$(uname -r)/vmlinux \
  135. ~/afdo/xanmod-propeller \
  136. 3600
  137.  
  138. omx-afdo-profile.sh merge \
  139. ~/afdo/final.afdo \
  140. ~/afdo/workload1.afdo \
  141. ~/afdo/workload2.afdo
  142.  
  143. Environment:
  144.  
  145. AFDO_PERIOD=500009
  146. Hardware branch sample period. Default: 500009.
  147.  
  148. AFDO_ALLOW_VM=1
  149. Permit operation inside a VM. Hardware branch sampling normally
  150. requires bare-metal PMU/LBR support.
  151.  
  152. PROPELLER_TOOL=/path/to/generate_propeller_profiles
  153. Use this converter instead of searching PATH and /opt/llvm-propeller*.
  154.  
  155. PROPELLER_ARGS='--flag {BIN} {PROF} {CC} {LD} ...'
  156. Custom converter flags if the installed tool's interface differs from
  157. the kernel's propeller.rst. Placeholders: {BIN} vmlinux, {PROF} perf
  158. data, {CC} cc profile, {LD} ld profile.
  159.  
  160. USAGE
  161. }
  162.  
  163.  
  164. # ---------------------------------------------------------------------------
  165. # LLVM version checking
  166. # ---------------------------------------------------------------------------
  167.  
  168. llvm_major() {
  169. "$1" --version 2>/dev/null |
  170. sed -n 's/.*version \([0-9][0-9]*\).*/\1/p' |
  171. head -n1
  172. }
  173.  
  174. need_llvm19() {
  175. local tool version
  176.  
  177. for tool in "$@"; do
  178. need "$tool"
  179.  
  180. version="$(llvm_major "$tool")"
  181.  
  182. [[ "${version:-0}" -ge 19 ]] ||
  183. die "$tool must come from LLVM >= 19 (found ${version:-unknown})"
  184. done
  185. }
  186.  
  187.  
  188. # ---------------------------------------------------------------------------
  189. # VMLINUX validation
  190. # ---------------------------------------------------------------------------
  191.  
  192. check_vmlinux_file() {
  193. local vmlinux="$1"
  194.  
  195. [[ -e "$vmlinux" ]] ||
  196. die "no such file: $vmlinux"
  197.  
  198. [[ ! -d "$vmlinux" ]] ||
  199. die "VMLINUX must be the vmlinux FILE, not a directory: $vmlinux"
  200.  
  201. need readelf
  202.  
  203. readelf -h "$vmlinux" >/dev/null 2>&1 ||
  204. die "not a valid ELF file: $vmlinux"
  205. }
  206.  
  207.  
  208. # ---------------------------------------------------------------------------
  209. # Verify VMLINUX matches the currently running kernel
  210. # ---------------------------------------------------------------------------
  211.  
  212. running_build_id() {
  213. local id="" out
  214.  
  215. # Test hook / manual override.
  216. if [[ -n "${AFDO_RUNNING_BUILDID:-}" ]]; then
  217. printf '%s\n' "$AFDO_RUNNING_BUILDID"
  218. return 0
  219. fi
  220.  
  221. out="$(perf buildid-list -k 2>/dev/null || true)"
  222. id="$(awk 'NR == 1 { print $1 }' <<<"$out")"
  223.  
  224. # Fallback: parse the GNU build-id note exposed by the running kernel.
  225. if [[ -z "$id" && -r /sys/kernel/notes ]] && command -v python3 >/dev/null 2>&1; then
  226. id="$(python3 - <<'NOTES_PY' 2>/dev/null || true
  227. import struct
  228. b = open('/sys/kernel/notes', 'rb').read(); i = 0
  229. while i + 12 <= len(b):
  230. n, d, t = struct.unpack_from('<III', b, i); i += 12
  231. name = b[i:i+n]; i += (n + 3) & ~3
  232. desc = b[i:i+d]; i += (d + 3) & ~3
  233. if t == 3 and name.startswith(b'GNU'):
  234. print(desc.hex()); break
  235. NOTES_PY
  236. )"
  237. fi
  238.  
  239. printf '%s\n' "$id"
  240. }
  241.  
  242. vmlinux_build_id() {
  243. local out
  244.  
  245. out="$(readelf -n "$1" 2>/dev/null || true)"
  246. awk '/Build ID/ { print $3 }' <<<"$out" | sed -n '1p'
  247. }
  248.  
  249. check_vmlinux_matches_running() {
  250. local running_id vmlinux_id
  251.  
  252. running_id="$(running_build_id)"
  253. vmlinux_id="$(vmlinux_build_id "$1")"
  254.  
  255. if [[ -n "$running_id" && -n "$vmlinux_id" ]]; then
  256. if [[ "$running_id" != "$vmlinux_id" ]]; then
  257. die \
  258. "VMLINUX build-id ($vmlinux_id) differs from the running kernel ($running_id). " \
  259. "You are using the wrong vmlinux for this boot."
  260. fi
  261.  
  262. printf 'OK: vmlinux matches running kernel %s\n' "$(uname -r)" >&2
  263. printf ' Build-ID: %s\n' "$vmlinux_id" >&2
  264. else
  265. warn \
  266. "could not compare build-IDs automatically. " \
  267. "Make absolutely sure VMLINUX belongs to running kernel $(uname -r)."
  268. fi
  269. }
  270.  
  271.  
  272. # ---------------------------------------------------------------------------
  273. # Detect CPU and configure branch sampling
  274. #
  275. # Linux kernel Propeller documentation specifies:
  276. #
  277. # Intel:
  278. # BR_INST_RETIRED.NEAR_TAKEN:k
  279. #
  280. # AMD:
  281. # RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k
  282. #
  283. # Both require:
  284. # -a -N -b -c <period>
  285. # ---------------------------------------------------------------------------
  286.  
  287. setup_sampling() {
  288. [[ $EUID -eq 0 ]] ||
  289. die "run as root (system-wide branch sampling requires root permissions)"
  290.  
  291. need perf
  292.  
  293. if grep -qw hypervisor /proc/cpuinfo &&
  294. [[ "${AFDO_ALLOW_VM:-0}" != 1 ]]; then
  295.  
  296. die \
  297. "running inside a VM: hardware branch sampling is normally unavailable. " \
  298. "Set AFDO_ALLOW_VM=1 only if your VM exposes the required PMU/LBR facility."
  299. fi
  300.  
  301. period="${AFDO_PERIOD:-500009}"
  302.  
  303. [[ "$period" =~ ^[0-9]+$ ]] ||
  304. die "AFDO_PERIOD must be a positive integer"
  305.  
  306. # Determine CPU vendor explicitly.
  307. if grep -q 'GenuineIntel' /proc/cpuinfo; then
  308.  
  309. cpu_vendor="Intel"
  310.  
  311. event_args=(
  312. -e
  313. BR_INST_RETIRED.NEAR_TAKEN:k
  314. )
  315.  
  316. elif grep -q 'AuthenticAMD' /proc/cpuinfo; then
  317.  
  318. cpu_vendor="AMD"
  319.  
  320. event_args=(
  321. --pfm-events
  322. RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k
  323. )
  324.  
  325. else
  326.  
  327. die \
  328. "unsupported CPU vendor. " \
  329. "This script currently supports Intel LBR and AMD branch sampling."
  330. fi
  331.  
  332. printf 'CPU vendor: %s\n' "$cpu_vendor" >&2
  333. printf 'Branch event: %s\n' "${event_args[*]}" >&2
  334. printf 'Sample period: %s\n' "$period" >&2
  335.  
  336. # Verify that perf can actually open the branch event before doing
  337. # a potentially long recording.
  338. local tmp rc=0
  339.  
  340. tmp="$(mktemp)"
  341.  
  342. # NOTE: "if ! cmd; then rc=$?" would always record 0 (the negated status),
  343. # which silently disabled this check. Capture the real status instead.
  344. perf record \
  345. "${event_args[@]}" \
  346. -a \
  347. -N \
  348. -b \
  349. -c "$period" \
  350. -o "$tmp" \
  351. -- sleep 1 >/dev/null 2>&1 || rc=$?
  352.  
  353. rm -f "$tmp"
  354.  
  355. if [[ $rc -ne 0 ]]; then
  356.  
  357. cat >&2 <<EOF
  358.  
  359. ERROR: perf could not initialize hardware branch sampling.
  360.  
  361. CPU vendor: $cpu_vendor
  362. Event: ${event_args[*]}
  363. Period: $period
  364.  
  365. The kernel Propeller documentation expects this event:
  366.  
  367. Intel:
  368. BR_INST_RETIRED.NEAR_TAKEN:k
  369.  
  370. AMD:
  371. RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k
  372.  
  373. Check the PMU exposed by your system with:
  374.  
  375. perf list | grep -E 'BR_INST_RETIRED|RETIRED_TAKEN_BRANCH|branch|LBR'
  376.  
  377. EOF
  378.  
  379. die "hardware branch sampling is unavailable or restricted on this system"
  380. fi
  381.  
  382. printf 'OK: hardware branch sampling is available.\n' >&2
  383. }
  384.  
  385.  
  386. # ---------------------------------------------------------------------------
  387. # Record perf branch samples
  388. # ---------------------------------------------------------------------------
  389.  
  390. run_sampling() {
  391. local perfdata="$1"
  392. shift
  393.  
  394. local load
  395.  
  396. if [[ "${1:-}" == "--" ]]; then
  397. shift
  398.  
  399. [[ $# -gt 0 ]] ||
  400. die "-- requires a command"
  401.  
  402. load=("$@")
  403.  
  404. else
  405. local seconds="${1:-120}"
  406.  
  407. [[ "$seconds" =~ ^[0-9]+$ ]] ||
  408. die "SECONDS must be a non-negative integer"
  409.  
  410. load=(sleep "$seconds")
  411. fi
  412.  
  413. mkdir -p "$(dirname "$perfdata")"
  414.  
  415. printf '\n' >&2
  416. printf 'Sampling branch execution...\n' >&2
  417. printf ' Period: %s\n' "$period" >&2
  418. printf ' Event: %s\n' "${event_args[*]}" >&2
  419. printf ' Load: %s\n' "${load[*]}" >&2
  420. printf ' Output: %s\n' "$perfdata" >&2
  421. printf '\n' >&2
  422.  
  423. perf record \
  424. "${event_args[@]}" \
  425. -a \
  426. -N \
  427. -b \
  428. -c "$period" \
  429. -o "$perfdata" \
  430. -- "${load[@]}"
  431. }
  432.  
  433.  
  434. # ---------------------------------------------------------------------------
  435. # Convert AutoFDO profile
  436. # ---------------------------------------------------------------------------
  437.  
  438. convert_afdo() {
  439. local vmlinux="$1"
  440. local perfdata="$2"
  441. local output="$3"
  442.  
  443. need_llvm19 llvm-profgen
  444.  
  445. [[ -r "$vmlinux" ]] ||
  446. die "cannot read vmlinux: $vmlinux"
  447.  
  448. [[ -r "$perfdata" ]] ||
  449. die "cannot read perf data: $perfdata"
  450.  
  451. mkdir -p "$(dirname "$output")"
  452.  
  453. printf 'Converting AutoFDO profile with llvm-profgen...\n' >&2
  454.  
  455. llvm-profgen \
  456. --kernel \
  457. --binary="$vmlinux" \
  458. --perfdata="$perfdata" \
  459. -o "$output"
  460.  
  461. give_back "$perfdata" "$output"
  462.  
  463. printf 'Profile written: %s\n' "$output" >&2
  464. }
  465.  
  466.  
  467. # ---------------------------------------------------------------------------
  468. # Locate Propeller conversion tool
  469. # ---------------------------------------------------------------------------
  470.  
  471. find_propeller_tool() {
  472. local f best=""
  473.  
  474. # 1. Explicit override.
  475. if [[ -n "${PROPELLER_TOOL:-}" ]]; then
  476. if [[ -x "$PROPELLER_TOOL" ]] || command -v "$PROPELLER_TOOL" >/dev/null 2>&1; then
  477. printf '%s\n' "$PROPELLER_TOOL"
  478. return 0
  479. fi
  480. return 1
  481. fi
  482.  
  483. # 2. PATH.
  484. if command -v generate_propeller_profiles >/dev/null 2>&1; then
  485. printf '%s\n' generate_propeller_profiles
  486. return 0
  487. fi
  488.  
  489. # 3. /opt installs (e.g. /opt/llvm-propeller-23/bin). sudo resets PATH, so
  490. # these are searched explicitly; the newest match wins.
  491. shopt -s nullglob
  492. # shellcheck disable=SC2231
  493. for f in ${PROPELLER_SEARCH_GLOB:-/opt/llvm-propeller*/bin/generate_propeller_profiles}; do
  494. [[ -x "$f" ]] && best="$f"
  495. done
  496. shopt -u nullglob
  497.  
  498. if [[ -n "$best" ]]; then
  499. printf '%s\n' "$best"
  500. return 0
  501. fi
  502.  
  503. # 4. AutoFDO's converter (older Propeller workflow).
  504. if command -v create_llvm_prof >/dev/null 2>&1; then
  505. printf '%s\n' create_llvm_prof
  506. return 0
  507. fi
  508.  
  509. return 1
  510. }
  511.  
  512.  
  513. # ---------------------------------------------------------------------------
  514. # Convert Propeller profile
  515. # ---------------------------------------------------------------------------
  516.  
  517. convert_propeller() {
  518. local vmlinux="$1"
  519. local prefix="$2"
  520.  
  521. shift 2
  522.  
  523. [[ $# -gt 0 ]] ||
  524. die "at least one perf.data file is required"
  525.  
  526. local tool
  527. local profile
  528. local list=""
  529.  
  530. tool="$(find_propeller_tool)" ||
  531. die \
  532. "no Propeller conversion tool found (searched PROPELLER_TOOL, PATH, " \
  533. "/opt/llvm-propeller*/bin, create_llvm_prof). " \
  534. "Set PROPELLER_TOOL=/path/to/generate_propeller_profiles."
  535.  
  536. [[ -r "$vmlinux" ]] ||
  537. die "cannot read vmlinux: $vmlinux"
  538.  
  539. local perfdata
  540.  
  541. for perfdata in "$@"; do
  542. [[ -r "$perfdata" ]] ||
  543. die "cannot read perf data: $perfdata"
  544. done
  545.  
  546. mkdir -p "$(dirname "$prefix")"
  547.  
  548. # One perf.data:
  549. #
  550. # --profile=file
  551. #
  552. # Multiple perf.data files:
  553. #
  554. # --profile=@filelist
  555. #
  556. # This is the interface documented by Linux's propeller.rst.
  557. if [[ $# -eq 1 ]]; then
  558.  
  559. profile="$1"
  560.  
  561. else
  562.  
  563. list="$(mktemp)"
  564.  
  565. # Always remove the temporary list on exit.
  566. trap 'rm -f "$list"' RETURN
  567.  
  568. printf '%s\n' "$@" > "$list"
  569.  
  570. profile="@${list}"
  571. fi
  572.  
  573. printf '\n' >&2
  574. printf 'Converting Propeller profile...\n' >&2
  575. printf ' Tool: %s\n' "$tool" >&2
  576. printf ' Binary: %s\n' "$vmlinux" >&2
  577. printf ' Profile: %s\n' "$profile" >&2
  578. printf '\n' >&2
  579.  
  580. if [[ -n "${PROPELLER_ARGS:-}" ]]; then
  581. # Custom flags for tools whose interface differs from propeller.rst.
  582. # Placeholders: {BIN} vmlinux, {PROF} perf data (or @list),
  583. # {CC} cc profile, {LD} ld profile.
  584. local args="$PROPELLER_ARGS"
  585.  
  586. args="${args//\{BIN\}/$vmlinux}"
  587. args="${args//\{PROF\}/$profile}"
  588. args="${args//\{CC\}/${prefix}_cc_profile.txt}"
  589. args="${args//\{LD\}/${prefix}_ld_profile.txt}"
  590.  
  591. printf ' Custom flags: %s\n\n' "$args" >&2
  592.  
  593. # shellcheck disable=SC2086
  594. "$tool" $args
  595. else
  596. "$tool" \
  597. --binary="$vmlinux" \
  598. --profile="$profile" \
  599. --format=propeller \
  600. --propeller_output_module_name \
  601. --out="${prefix}_cc_profile.txt" \
  602. --propeller_symorder="${prefix}_ld_profile.txt"
  603. fi
  604.  
  605. [[ -s "${prefix}_cc_profile.txt" ]] ||
  606. die "Propeller CC profile was not generated"
  607.  
  608. [[ -s "${prefix}_ld_profile.txt" ]] ||
  609. die "Propeller linker/symbol-order profile was not generated"
  610.  
  611. give_back "${prefix}_cc_profile.txt" "${prefix}_ld_profile.txt" "$@"
  612.  
  613. printf '\n' >&2
  614. printf 'Propeller profiles written:\n' >&2
  615. printf ' CC / basic-block profile: %s_cc_profile.txt\n' "$prefix" >&2
  616. printf ' LD / symbol-order profile: %s_ld_profile.txt\n' "$prefix" >&2
  617. }
  618.  
  619.  
  620. # ---------------------------------------------------------------------------
  621. # Main command
  622. # ---------------------------------------------------------------------------
  623.  
  624. cmd="${1:-}"
  625.  
  626. [[ -n "$cmd" ]] ||
  627. {
  628. usage
  629. exit 1
  630. }
  631.  
  632. shift || true
  633.  
  634.  
  635. case "$cmd" in
  636.  
  637. # -----------------------------------------------------------------------
  638. # AutoFDO recording
  639. # -----------------------------------------------------------------------
  640.  
  641. record)
  642.  
  643. [[ $# -ge 2 ]] ||
  644. {
  645. usage
  646. exit 1
  647. }
  648.  
  649. vmlinux="$1"
  650. out="$2"
  651.  
  652. shift 2
  653.  
  654. check_vmlinux_file "$vmlinux"
  655.  
  656. need_llvm19 llvm-profgen
  657.  
  658. setup_sampling
  659.  
  660. check_vmlinux_matches_running "$vmlinux"
  661.  
  662. perfdata="${out%.afdo}.perf.data"
  663.  
  664. run_sampling "$perfdata" "$@"
  665.  
  666. give_back "$perfdata"
  667.  
  668. printf '\nRaw AutoFDO samples kept in:\n %s\n\n' \
  669. "$perfdata" >&2
  670.  
  671. convert_afdo \
  672. "$vmlinux" \
  673. "$perfdata" \
  674. "$out"
  675.  
  676. ;;
  677.  
  678.  
  679. # -----------------------------------------------------------------------
  680. # Convert existing AutoFDO perf data
  681. # -----------------------------------------------------------------------
  682.  
  683. convert)
  684.  
  685. [[ $# -eq 3 ]] ||
  686. {
  687. usage
  688. exit 1
  689. }
  690.  
  691. check_vmlinux_file "$1"
  692.  
  693. [[ -r "$2" ]] ||
  694. die "cannot read $2"
  695.  
  696. convert_afdo "$1" "$2" "$3"
  697.  
  698. ;;
  699.  
  700.  
  701. # -----------------------------------------------------------------------
  702. # Merge AutoFDO profiles
  703. # -----------------------------------------------------------------------
  704.  
  705. merge)
  706.  
  707. [[ $# -ge 2 ]] ||
  708. die "merge requires OUT.afdo plus at least one input profile"
  709.  
  710. out="$1"
  711.  
  712. shift
  713.  
  714. need_llvm19 llvm-profdata
  715.  
  716. printf 'Merging AutoFDO profiles...\n' >&2
  717.  
  718. llvm-profdata merge \
  719. -o "$out" \
  720. "$@"
  721.  
  722. give_back "$out"
  723.  
  724. printf 'Merged profile written: %s\n' "$out" >&2
  725.  
  726. ;;
  727.  
  728.  
  729. # -----------------------------------------------------------------------
  730. # Propeller recording
  731. # -----------------------------------------------------------------------
  732.  
  733. record-propeller)
  734.  
  735. [[ $# -ge 2 ]] ||
  736. {
  737. usage
  738. exit 1
  739. }
  740.  
  741. vmlinux="$1"
  742. prefix="$2"
  743.  
  744. shift 2
  745.  
  746. check_vmlinux_file "$vmlinux"
  747.  
  748. # Fail now, not after an hour of recording.
  749. tool_check="$(find_propeller_tool)" ||
  750. die "no Propeller converter found; set PROPELLER_TOOL=/path/to/generate_propeller_profiles"
  751.  
  752. printf 'Propeller converter: %s\n' "$tool_check" >&2
  753.  
  754. setup_sampling
  755.  
  756. check_vmlinux_matches_running "$vmlinux"
  757.  
  758. perfdata="${prefix}.perf.data"
  759.  
  760. run_sampling "$perfdata" "$@"
  761.  
  762. give_back "$perfdata"
  763.  
  764. printf '\nRaw Propeller samples kept in:\n %s\n\n' \
  765. "$perfdata" >&2
  766.  
  767. convert_propeller \
  768. "$vmlinux" \
  769. "$prefix" \
  770. "$perfdata"
  771.  
  772. ;;
  773.  
  774.  
  775. # -----------------------------------------------------------------------
  776. # Convert existing Propeller perf data
  777. # -----------------------------------------------------------------------
  778.  
  779. convert-propeller)
  780.  
  781. [[ $# -ge 3 ]] ||
  782. {
  783. usage
  784. exit 1
  785. }
  786.  
  787. check_vmlinux_file "$1"
  788.  
  789. convert_propeller "$@"
  790.  
  791. ;;
  792.  
  793.  
  794. *)
  795.  
  796. usage
  797. exit 1
  798.  
  799. ;;
  800.  
  801. esac
Advertisement
Comments
  • RitchieSolo
    17 days
    # text 0.47 KB | 0 0
    1. This script was created to Collect data and convert AutoFDO / Propeller profiles for a Xanmod Clang / LLVM built custom kernel in OpenMandriva. Use this script to generate your AutoFDO profile. You may also need to cd into the kernel's tools folder and make the perf utility as this utility must be compiled first in order to use this script. The associated kernel build script should assist with installing any necessary dependencies from the OpenMandriva repo where applicable.
  • RitchieSolo
    17 days
    # text 0.85 KB | 0 0
    1. Here is a link to llvm-propeller-23.0.0-1-omv6000.x86_64.rpm https://mega.nz/file/O15hgTbA#BcdIRJEl2K69zrH-bhjow9ZtuKEyRR8ddquMDR5QZgU This is a prepackaged version of llvm-propeller-git downloaded from google's repo and built in OpenMandriva Lx 6.0 Rock. This archive installs in /opt and does not conflict with native shipped clang / llvm but does include propeller and provides : clang clang++ clang-23 clang-cl clang-cpp generate_propeller_profiles llvm-profgen
    2. the generate_propeller_profiles is needed for generation of profiles to configure propeller when using this flat in your kernel build. You will also need to go into the source tree of the Xanmod source into the tools folder which will be created from the kernel build script at ~//omx-tmp/omx-kernel-work-noncitizen-national/linux/tools/perf/ and build the perf utility for usage with the afdo script.
Add Comment
Please, Sign In to add comment