This study introduces a real-time optimization framework for eco-driving of heavy-duty vehicles over long-distance routes. A longitudinal dynamic model incorporating powertrain performance and fuel consumption is formulated, and the eco-driving scenario is expressed as a quadratic programming (QP) problem. To improve computational efficiency, a novel variable-step spatial segmentation method is introduced, which ensures a balance between modeling accuracy and computational cost. Simulations involving mixed-terrain scenarios verify the effectiveness of the proposed approach. The results show that the QP-based method achieves fuel savings comparable to those offered by dynamic programming while significantly reducing computation time to sub-second levels; thus, the proposed strategy offers real-time applicability. These findings demonstrate the feasibility of global optimal velocity profile generation in practical eco-driving scenarios.