[PATCH v2] lib: sbi: protect dprintf output with spinlock

Anup Patel Anup.Patel at wdc.com
Sun Aug 29 20:56:27 PDT 2021



On 30/08/21, 8:20 AM, "opensbi on behalf of Xiang W" <opensbi-bounces at lists.infradead.org on behalf of wxjstz at 126.com> wrote:

    在 2021-08-28星期六的 14:45 +0800,Dong Du写道:
    > Avoid getting messages from multiple harts (using dprintf and printf)
    > concurrently with a spinlock serializaing calls to sbi_dprintf(),
    > sbi_printf() and sbi_puts()
    > 
    > Signed-off-by: Dong Du <Dd_nirvana at sjtu.edu.cn>

    look good to me.
    Reviewed-by: Xiang W <wxjstz at 126.com>

Looks good to me.

Reviewed-by: Anup Patel <anup.patel at wdc.com>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

    > ---
    >  lib/sbi/sbi_console.c | 5 ++++-
    >  1 file changed, 4 insertions(+), 1 deletion(-)
    > 
    > diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
    > index b54f7a2..29eede3 100644
    > --- a/lib/sbi/sbi_console.c
    > +++ b/lib/sbi/sbi_console.c
    > @@ -387,8 +387,11 @@ int sbi_dprintf(const char *format, ...)
    >         struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
    >  
    >         va_start(args, format);
    > -       if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS)
    > +       if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS) {
    > +               spin_lock(&console_out_lock);
    >                 retval = print(NULL, NULL, format, args);
    > +               spin_unlock(&console_out_lock);
    > +       }
    >         va_end(args);
    >  
    >         return retval;
    > -- 
    > 2.31.1
    > 
    > 



    -- 
    opensbi mailing list
    opensbi at lists.infradead.org
    http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list