We derive the spin-wave dynamics in crystals from the time-dependent v
ariational principle, which involves Berry phase terms as well as the
energy of frozen spin waves. The general formulation is based on the a
diabatic and harmonic approximations. Formulas for ferromagnets and an
tiferromagnets are derived in terms of Kohn-Sham wave functions, which
are particularly suitable for practical ab initio calculations.