common 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env bash
  2. common_abspath() (
  3. echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
  4. )
  5. common_bench_cmd() (
  6. # Benchmark a command.
  7. #
  8. # $1: command to benchmark
  9. # $2: where to append write results to. Default: /dev/null.
  10. #
  11. # Result format:
  12. #
  13. # cmd <command run>
  14. # time <time in seconds to finish>
  15. # exit_status <exit status>
  16. cmd="$1"
  17. results_file="${2:-/dev/null}"
  18. printf 'cmd ' >> "$results_file"
  19. env time --append -f 'time %e' --output="$results_file" "${root_dir}/eeval" -a "$cmd" "$results_file"
  20. printf "exit_status $?\n" >> "$results_file"
  21. )
  22. set_common_vars() {
  23. arch="$1"
  24. gem5="${2:-false}"
  25. case "$arch" in
  26. a|arm)
  27. arch=arm
  28. ;;
  29. A|aarch64)
  30. arch=aarch64
  31. ;;
  32. m|mips64)
  33. arch=mips64
  34. ;;
  35. x|x86_64)
  36. arch=x86_64
  37. ;;
  38. *)
  39. printf "unknown arch: ${arch}\n" 1>&2
  40. exit 2
  41. ;;
  42. esac
  43. common_suffix="${3:-}"
  44. buildroot_dir="${root_dir}/buildroot"
  45. arch_dir="$arch"
  46. if [ -n "$common_suffix" ]; then
  47. arch_dir="${arch_dir}-${common_suffix}"
  48. fi
  49. out_arch_dir="${out_dir}/${arch_dir}"
  50. buildroot_out_dir="${out_arch_dir}/buildroot"
  51. build_dir="${buildroot_out_dir}/build"
  52. images_dir="${buildroot_out_dir}/images"
  53. host_dir="${buildroot_out_dir}/host"
  54. qemu_out_dir="${out_arch_dir}/qemu"
  55. gem5_run_out_dir="${out_arch_dir}/gem5"
  56. m5out_dir="${gem5_run_out_dir}/m5out"
  57. if "$gem5"; then
  58. common_out_run_dir="$gem5_run_out_dir"
  59. common_trace_txt_file="${m5out_dir}/trace.txt"
  60. else
  61. common_out_run_dir="$qemu_out_dir"
  62. common_trace_txt_file="${common_out_run_dir}/trace.txt"
  63. fi
  64. }
  65. common_mkdir() (
  66. mkdir -p \
  67. "$build_dir" \
  68. "$gem5_out_dir" \
  69. "$qemu_out_dir" \
  70. "$p9_dir" \
  71. ;
  72. )
  73. root_dir="$(pwd)"
  74. out_dir="${root_dir}/out"
  75. common_bench_boot="${out_dir}/bench-boot.txt"
  76. data_dir="${root_dir}/data"
  77. p9_dir="${data_dir}/9p"
  78. readfile_file="${data_dir}/readfile"
  79. common_dir="${out_dir}/common"
  80. gem5_out_dir="${common_dir}/gem5"
  81. f="${data_dir}/cli"
  82. if [ -f "$f" ]; then
  83. . "$f"
  84. fi
  85. # Default arch.
  86. arch=x86_64
  87. gem5=false