/contrib/ntp/html/build/hints/solaris.xtra.patchfreq

https://bitbucket.org/freebsd/freebsd-head/ · Korn Shell · 85 lines · 51 code · 12 blank · 22 comment · 9 complexity · 3089adb9303fe59b00bbe8562ac173d5 MD5 · raw file

  1. #!/bin/ksh
  2. #
  3. # File: patchfreq
  4. # Author: Bryan Cantrill (bmc@eng.sun.com), Solaris Performance
  5. # Modified: Sat Apr 26 04:00:59 PDT 1997
  6. #
  7. # This is a little script to patch a 5.5 or 5.5.1 kernel to get around
  8. # the cpu_tick_freq inaccuracy. Before running this script, one must
  9. # know the true frequency of one's CPU; this can be derived by NTP,
  10. # or by observing the clock relative to the time-of-day chip over a
  11. # long period of time (the TOD will pull system time when it drifts
  12. # by more than two seconds).
  13. #
  14. # Patching a kernel can render a machine unbootable; do not run this
  15. # script unless you are prepared to accept that possibility. It
  16. # is advisable to have a backout path (e.g. net booting, an alternate
  17. # boot disk, an installation CD) should your machine fail to boot.
  18. #
  19. # This is not a product of Sun Microsystems, and is provided "as is",
  20. # without warranty of any kind expressed or implied including, but not
  21. # limited to, the suitability of this script for any purpose.
  22. #
  23. if [ $# -eq 0 ]; then
  24. echo "Usage: $0 cpu_tick_freq [ alternate_kernel ]"
  25. exit 1
  26. fi
  27. cpu_tick_freq=$1
  28. kernel=/platform/sun4u/kernel/unix
  29. if [ $# -eq 2 ]; then
  30. kernel=$2
  31. fi
  32. if [ ! -w $kernel ]; then
  33. echo "$0: Cannot open $kernel for writing."
  34. exit 1
  35. fi
  36. arch=`echo utsname+404?s | adb $kernel | cut -d: -f2`
  37. if [ ! $arch = "sun4u" ]; then
  38. echo "Patch only applies to sun4u"
  39. exit 1
  40. fi
  41. rel=`echo utsname+202?s | adb $kernel | cut -d: -f2`
  42. if [ ! $rel = "5.5" ] && [ ! $rel = "5.5.1" ]; then
  43. echo "Patch only applies to 5.5 or 5.5.1..."
  44. exit 1
  45. fi
  46. nop="1000000" # nop
  47. store_mask="ffffe000" # mask out low 13 bits
  48. store="da256000" # st %o5, [%l5 + offset]
  49. instr=`echo setcpudelay+34?X | adb $kernel | cut -d: -f 2 | nawk '{ print $1 }'`
  50. if [ $instr = $nop ]; then
  51. echo "Instruction already patched..."
  52. else
  53. let masked="(16#$store_mask & 16#$instr) - 16#$store"
  54. if [ $masked -ne 0 ]; then
  55. echo "Couldn't find instruction to patch; aborting."
  56. exit 1
  57. fi
  58. if ! echo setcpudelay+34?W $nop | adb -w $kernel 1> /dev/null
  59. then
  60. echo "adb returned an unexpected error; aborting."
  61. fi
  62. fi
  63. echo "Patching cpu_tick_freq to $cpu_tick_freq..."
  64. if ! echo cpu_tick_freq?W 0t$cpu_tick_freq | adb -w $kernel 1> /dev/null; then
  65. echo "adb returned an unexpected error; aborting."
  66. exit 1
  67. fi
  68. echo "$kernel successfully patched."
  69. exit 0