• John Stultz's avatar
    timekeeping: Rework frequency adjustments to work better w/ nohz · dc491596
    John Stultz authored
    The existing timekeeping_adjust logic has always been complicated
    to understand. Further, since it was developed prior to NOHZ becoming
    common, its not surprising it performs poorly when NOHZ is enabled.
    
    Since Miroslav pointed out the problematic nature of the existing code
    in the NOHZ case, I've tried to refactor the code to perform better.
    
    The problem with the previous approach was that it tried to adjust
    for the total cumulative error using a scaled dampening factor. This
    resulted in large errors to be corrected slowly, while small errors
    were corrected quickly. With NOHZ the timekeeping code doesn't know
    how far out the next tick will be, so this results in bad
    over-correction to small errors, and insufficient correction to large
    errors.
    
    Inspired by Miroslav's patch, I've refactored the code to try to
    address the correction in two steps.
    
    1) Check the future freq error for the next tick, and if the frequency
    error is large, try to make sure we correct it so it doesn't cause
    much accumulated error.
    
    2) Then make a small single unit adjustment to correct any cumulative
    error that has collected over time.
    
    This method performs fairly well in the simulator Miroslav created.
    
    Major credit to Miroslav for pointing out the issue, providing the
    original patch to resolve this, a simulator for testing, as well as
    helping debug and resolve issues in my implementation so that it
    performed closer to his original implementation.
    
    Cc: Miroslav Lichvar <mlichvar@redhat.com>
    Cc: Richard Cochran <richardcochran@gmail.com>
    Cc: Prarit Bhargava <prarit@redhat.com>
    Reported-by: default avatarMiroslav Lichvar <mlichvar@redhat.com>
    Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
    dc491596
timekeeping.c 47.8 KB