Most modern gasoline engines have knock sensors but not so you can run a lower octane (it allows it but wasn't designed for that purpose) Knock sensors allow the ECM to retard timing as much as possible to maintain the power band for the driving at hand to increase fuel economy. When the sensor(s) detect a knock they tell the ECU to increase timing until the knock goes away, thus maintaining the power band etc.......... The vehicle doesn't know what the octane level is for the fuel that's in the tank, it just knows "X" fuel, obtain engine parameters (speed, torque, air density, pedal position and a lot of other inputs) , retard timing and determine if a knock condition exists......... if not, retard timing etc...... once it gets a knock increase timing ............. all of which takes place within one or two firing cycles...... rinse and repeat.