You can make an udev rule to automate the change of governor based on battery or on charger:
Make the following file:
sudo nano /etc/udev/rules.d/99-ac-battery.rules
With the content:
## ACTION TO DO WHEN ON BATTERY
SUBSYSTEM=="power_supply", ACTION=="change", ENV{POWER_SUPPLY_ONLINE}=="0", ENV{POWER}="off", RUN+="/usr/bin/cpupower frequency-set --governor ondemand"
## ACTION TO DO WHEN ON CHARGER
SUBSYSTEM=="power_supply", ACTION=="change", ENV{POWER_SUPPLY_ONLINE}=="1", ENV{POWER}="on", RUN+="/usr/bin/cpupower frequency-set --governor performance"
Then execute sudo udevadm control --reload-rules