Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect cpu.sleeper accounting #3

Merged
merged 1 commit into from
Jun 15, 2020

Commits on Jun 11, 2020

  1. Fix incorrect cpu.sleeper accounting

    Under contention for the CPU lock, you could end up in a scenario where
    waiters on the cpu.sem would be awoken earlier than they should have been.
    
    The problem crosses two functions. lkl_cpu_get and lkl_cpu_put:
    
    https://github.com/lsds/lkl/blob/master/arch/lkl/kernel/cpu.c#L95
    https://github.com/lsds/lkl/blob/master/arch/lkl/kernel/cpu.c#L113
    
    The handling of "cpu.sleepers" is incorrect. "cpu.sleepers" should be
    incremented when a thread is waiting to get the cpu.sem so that in lkl_cpu_put,
    it can call sem_up to wake a sleeper if any exists.
    
    However what it is currently doing is in lkl_cpu_get is incrementing the
    sleepers thread count every time it can't get the cpu lock.
    
    https://github.com/lsds/lkl/blob/master/arch/lkl/kernel/cpu.c#L102
    
    So, if a thread fails to get the lock more than once it will increment the
    count of sleeping threads more than once. This means as it stands, in lkl_cpu_put,
    that one thread trying to get the lock several times can account for multiple calls
    to sem_up. Given that it is awoken each time in lkl_cpu_get, that is wrong.
    
    The correct logic is to decrement the sleepers count after the sem_down returns in
    lkl_cpu_get and not in lkl_cpu_put. That will correctly match up cpu.sleepers with
    the number of threads waiting on cpu.sem.
    SeanTAllen committed Jun 11, 2020
    Configuration menu
    Copy the full SHA
    52964a5 View commit details
    Browse the repository at this point in the history