A knock sensor assures that you're getting as much power and fuel economy as is possible from your engine.
A knock sensor allows the engine to run with the ignition timing as far advanced as possible. The computer will continue to advance the timing until the knock sensor detects pinging. At that point the computer retards the ignition timing just enough for the pinging to stop.
The knock sensor responds to spark knock caused by Pre-detonation of the Air/Fuel mixture. As the flame front moves out from the spark plug ignition point, pressure waves in the chamber crash into the piston or cylinder walls resulting in a sound known as a knock or ping. This is caused by using a fuel with a low octane rating, overheating, or over advanced timing. Sometimes it can be caused by hot carbon deposits on the piston or cylinder head that raise compression. A knock sensor is comprised of Piezoelectric materials; Crystals that when impacted, generate a voltage (same idea as a BBQ ignitor). This voltage is monitored by the computer, and when an irregularity is detected, the computer corrects timing in VVT (variable valve timing) engines, or triggers a DTC Diagnostic Trouble Code) in older vehicles.