• Petr Mladek's avatar
    ring_buffer: Fix more races when terminating the producer in the benchmark · f47cb66d
    Petr Mladek authored
    The commit b44754d8 ("ring_buffer: Allow to exit the ring
    buffer benchmark immediately") added a hack into ring_buffer_producer()
    that set @kill_test when kthread_should_stop() returned true. It improved
    the situation a lot. It stopped the kthread in most cases because
    the producer spent most of the time in the patched while cycle.
    
    But there are still few possible races when kthread_should_stop()
    is set outside of the cycle. Then we do not set @kill_test and
    some other checks pass.
    
    This patch adds a better fix. It renames @test_kill/TEST_KILL() into
    a better descriptive @test_error/TEST_ERROR(). Also it introduces
    break_test() function that checks for both @test_error and
    kthread_should_stop().
    
    The new function is used in the producer when the check for @test_error
    is not enough. It is not used in the consumer because its state
    is manipulated by the producer via the "reader_finish" variable.
    
    Also we add a missing check into ring_buffer_producer_thread()
    between setting TASK_INTERRUPTIBLE and calling schedule_timeout().
    Otherwise, we might miss a wakeup from kthread_stop().
    
    Link: http://lkml.kernel.org/r/1441629518-32712-3-git-send-email-pmladek@suse.comSigned-off-by: default avatarPetr Mladek <pmladek@suse.com>
    Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
    f47cb66d
ring_buffer_benchmark.c 10.8 KB