{"id":444,"date":"2022-10-21T14:12:54","date_gmt":"2022-10-21T14:12:54","guid":{"rendered":"https:\/\/www.aixperts.co.uk\/?p=444"},"modified":"2022-10-27T10:39:12","modified_gmt":"2022-10-27T10:39:12","slug":"starting-tactic-script-for-cpu-allocation-calculations-on-power9-10","status":"publish","type":"post","link":"https:\/\/www.aixperts.co.uk\/?p=444","title":{"rendered":"Starting tactic script for CPU allocation calculations on POWER9\/10"},"content":{"rendered":"\n<p>Based on Earl Jew&#8217;s presentation on the 6th of October 2022, &#8220;<em>Simplest starting tactic for Power10 AIX exploitation V1.2&#8243;<\/em>. Excellent IBM POWER VUG materials can be found here:<\/p>\n\n\n\n<p><a href=\"https:\/\/ibm.ent.box.com\/s\/6hn2orvig4r2peu6e39owmp07ewyyf4x\">https:\/\/ibm.ent.box.com\/s\/6hn2orvig4r2peu6e39owmp07ewyyf4x<\/a><\/p>\n\n\n\n<p>And the meeting presentation replay here:<\/p>\n\n\n\n<p><a href=\"https:\/\/ibm.ent.box.com\/s\/5atsp26sxup1ob04c3urbkiovj8epbax\">https:\/\/ibm.ent.box.com\/s\/5atsp26sxup1ob04c3urbkiovj8epbax<\/a><\/p>\n\n\n\n<p>This is an analytic way to calculate the virtual processors (vCPU) and entitlement (eCPU) on IBM POWER LPARs based on actual load during busy periods of the system. It is a starting tactic, so rinse-and-repeat.<\/p>\n\n\n\n<p>The script below crunches the numbers for Earl&#8217;s eCPU\/vCPU calculations. To gather data, as it says at the beginning of the script, setup a cron job to run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uptime | awk '{ print $(NF-2),$(NF-1),$NF }' | tr -d ',' &gt;&gt;\/tmp\/uptime.out<\/code><\/pre>\n\n\n\n<p>every twenty minutes or so, for three weeks (give or take), then run this script.<\/p>\n\n\n\n<p>The script finds the highest 5-minute number, which gives the peak number of threads requesting CPU time, and rounds up to nearest vCPU * SMT# to go above that.<\/p>\n\n\n\n<p>It also does a running calculation of the busiest 5 runs, equaling 1h40m, and calculates the eCPU needed based on the average of all 1-, 5- &amp; 15-minute loads divided by the SMT# for the LPAR.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/ksh93\n\n###############################################\n#\n# eCPU\/vCPU planning script\n#\n# 2022-10-26 Henrik Morsing     1.0     Initial\n#\n\nver=1.0\n\n# Run:\n# uptime | awk '{ print $(NF-2),${NF-1),$NF }' | tr -d ',' &gt;&gt;\/tmp\/uptime.out\n# every twenty minutes for three weeks\n\nsum5=0\nsum5_max=0\nsum5_avg_max=0\nmax5=0\n# DBG=1 # Uncomment for running calculation output\n\n# Find SMT#?\n\nif &#091;&#091; \"$(uname)\" == \"AIX\" ]]\nthen\n   smt=\"$(smtctl | grep \"SMT threads per processor\" | awk '{ print $6 }')\"\nelse\n   smt_temp=\"$(dmesg | grep \"CPU maps initialized for\" | awk '{ print $7 }')\"\n   smt=${smt_temp:-8}\nfi\n\necho\necho \"Running on $(uname -n), ${smt} SMT system. Current load:\"\nuptime\necho\necho \"Analysing $(wc -l \/tmp\/uptime.out) load entries.\"\n\n&#091;&#091; $(wc -l \/tmp\/uptime.out | cut -f 1 -d \" \") -lt 1000 ]] &amp;&amp; echo \"(Is that enough?)\"\necho\n\ntypeset -A last\n\nwhile read m1 m5 m15\ndo\n\n   # Firstly store last five values\n\n   last&#091;5]&#091;5]=${last&#091;5]&#091;4]:-0}\n   last&#091;5]&#091;4]=${last&#091;5]&#091;3]:-0}\n   last&#091;5]&#091;3]=${last&#091;5]&#091;2]:-0}\n   last&#091;5]&#091;2]=${last&#091;5]&#091;1]:-0}\n   last&#091;5]&#091;1]=${m5}\n\n   last&#091;15]&#091;5]=${last&#091;15]&#091;4]:-0}\n   last&#091;15]&#091;4]=${last&#091;15]&#091;3]:-0}\n   last&#091;15]&#091;3]=${last&#091;15]&#091;2]:-0}\n   last&#091;15]&#091;2]=${last&#091;15]&#091;1]:-0}\n   last&#091;15]&#091;1]=${m15}\n\n   last&#091;1]&#091;5]=${last&#091;1]&#091;4]:-0}\n   last&#091;1]&#091;4]=${last&#091;1]&#091;3]:-0}\n   last&#091;1]&#091;3]=${last&#091;1]&#091;2]:-0}\n   last&#091;1]&#091;2]=${last&#091;1]&#091;1]:-0}\n   last&#091;1]&#091;1]=${m1}\n\n\n   ########\n   # vCPU #\n   ########\n\n   # Store max for vCPU calculation and calculate new vCPU when new max is found\n\n   if &#091;&#091; ${m5} -gt ${max5} ]]\n   then\n      max5=${m5}\n\n      # Highest 5 minute load, rounded up as per SMT#, to next number of logical processors. Divide by SMT# gives vCPUs\n      # Sadly, AIX and Linux ksh93 does arithmetic differently, so will have to split this up\n\n      vCPU=$(echo \"scale=0;${max5} \/ ${smt} + 1\" | bc -l)\n\n      &#091;&#091; -n ${DBG} ]] &amp;&amp; echo \"vCPU: \"${vCPU} \"based on max5: \"${max5}\n\n   fi\n\n   ########\n   # eCPU #\n   ########\n\n   # Now, sum up the last five five minute values. This is used to determine the busiest period.\n\n   sum5=$(( ${last&#091;5]&#091;1]}+${last&#091;5]&#091;2]}+${last&#091;5]&#091;3]}+${last&#091;5]&#091;4]}+${last&#091;5]&#091;5]} ))\n\n   # And sum up all values, this is used for the actual calculation.\n\n   sum_all=$(( ${last&#091;1]&#091;1]}+${last&#091;1]&#091;2]}+${last&#091;1]&#091;3]}+${last&#091;1]&#091;4]}+${last&#091;1]&#091;5]}+${last&#091;5]&#091;1]}+${last&#091;5]&#091;2]}+${last&#091;5]&#091;3]}+${last&#091;5]\n&#091;4]}+${last&#091;5]&#091;5]}+${last&#091;15]&#091;1]}+${last&#091;15]&#091;2]}+${last&#091;15]&#091;3]}+${last&#091;15]&#091;4]}+${last&#091;15]&#091;5]} ))\n\n\n   # Keep track of max. When we hit a new max, calculate new eCPU\/vCPU pair\n\n   if &#091;&#091; ${sum5} -gt ${sum5_avg_max} ]]\n   then\n      # Store max value\n      sum5_avg_max=${sum5}\n\n      # Rather than storing all values, just calculate eCPU straight away\n\n      eCPU_temp=$(echo \"scale=2;${sum_all} \/ 15 \/ ${smt}\" | bc -l)\n\n      # We don't want to discard previous higher values of eCPU\n      if &#091;&#091; \"${eCPU_temp}\" -gt \"${eCPU}\" ]]\n      then\n         eCPU=${eCPU_temp}\n      else\n         &#091;&#091; -n ${DBG} ]] &amp;&amp; echo \"eCPU calculation discarded\"\n      fi\n\n      &#091;&#091; -n ${DBG} ]] &amp;&amp; echo \"eCPU: \"${eCPU}\n\n   fi\n\n\ndone &lt;\/tmp\/uptime.out\n\necho \"Final calculation:\"\necho \"eCPU \/ vCPU: \"${eCPU}\" \/ \"${vCPU}\" - Ratio: \"$(( ${vCPU} \/ ${eCPU} ))\n\nexit 0\n\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Based on Earl Jew&#8217;s presentation on the 6th of October 2022, &#8220;Simplest starting tactic for Power10 AIX exploitation V1.2&#8243;. Excellent IBM POWER VUG materials can be found here: https:\/\/ibm.ent.box.com\/s\/6hn2orvig4r2peu6e39owmp07ewyyf4x And the meeting presentation replay here: https:\/\/ibm.ent.box.com\/s\/5atsp26sxup1ob04c3urbkiovj8epbax This is an analytic &hellip; <a href=\"https:\/\/www.aixperts.co.uk\/?p=444\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,147,4,146,148],"tags":[87,101,141,143,144,145,140,142],"class_list":["post-444","post","type-post","status-publish","format-standard","hentry","category-aix","category-ibm-power","category-linux","category-performance-tuning","category-scripting","tag-ibm","tag-lpar","tag-power","tag-processor-entitlement","tag-script","tag-smt","tag-tuning","tag-virtual-cpu"],"_links":{"self":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=444"}],"version-history":[{"count":11,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}