The trick is that grid frequency is proportional to the integral WRT time of the net power (Power input - power used), to raise the frequency you just turn up the throttles at one or more prime movers and the whole thing slowly winds up to a higher frequency, same thing if you are generating more power then is being used, the frequency ramps up until the excursion causes units to throttle back reducing the power input until the frequency is back where it should be.
It is the setup of the governors on the prime movers that determines which units load up when.
For example (In a 50Hz system), if you have some massive hydro or nuke or something plant that is very economical as a base load plant, you maybe set the governor to 50.1Hz with little droop so that as long as the frequency is below that the thing will be running flat out. On the other hand if your plant is a open cycle gas turbine or a Tesla battery or something (Expensive to run under load, or of limited duration, but fast to bring up), you set the governor to 49.9Hz with full output occurring at say 49.8Hz, that way your plant stays at idle until the grid frequency drops to well below normal at which point the throttles start opening to apply torque to the rotating machine, and you start feeding power into the grid.
Interestingly all the machines on the grid are turning at the same speed (number of poles dependent), what varies based on the governor settings is the torque produced by the prime movers.
When considering three phase machines, you can consider the system as a phasor between the rotating field in the stator (due to the grid connection) and the rotor, with the difference being an angle either positive or negative depending on whither the machine is generating or motoring, steady state this angle can be seen as a torque on the rotor.
An interesting case is a power station with a transmission line to the grid protected by a recloser at each end, if the recloser trips there is then a very finite time for the recloser to close again before the rotor has gotten so far ahead of the (now missing) stator field that the phase error will cause damage, activation of such reclosers is by all accounts something everyone at the power plant tends to notice.
Regards, Dan.