This paper proposed a novel hard real-time dynamic voltage scheduling (RT-DVS) algorithm for periodically hard real-time task set. Based on a mathematical system model which meets the real situation, the proposed RT-DVS algorithm fully exploited all the slack times, gave an optimal solution for the hard real-time task on CPUs with two adjustable frequencies and voltages. Finally, the optimality of RT-DVS algorithm is proven. The RT-DVS algorithm can be extended to used on CPUs with more adjustable frequencies, and is useful in multitask environments.