#!/bin/bash

# author: allin.han
# date: 2018-05-10

reload_microcode() {
  local kernel_version=`uname -r`
  if [[ ${kernel_version:0:13} = '2.6.32-279.19' ]];then
    local cpu_nums=`cat /proc/cpuinfo | grep -c processor`
    for ((i=0;i<${cpu_nums};i++)); do
        echo 1 > /sys/devices/system/cpu/cpu$i/microcode/reload
    done
  elif [[ ${kernel_version:0:5} = '4.1.0' ]];then
    echo 1 > /sys/devices/system/cpu/microcode/reload
  else
    :
  fi
}

reload_microcode
