Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2343587pxa; Mon, 17 Aug 2020 07:26:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfjwCUlxAlT0rhWS8UkqQSBJ1wRKPrcOhMuva9kJtblIqAsmb19E467FTB/jjimOtYjPro X-Received: by 2002:aa7:d8d8:: with SMTP id k24mr15856501eds.32.1597674367766; Mon, 17 Aug 2020 07:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597674367; cv=none; d=google.com; s=arc-20160816; b=FFR4f6jexxgCIulEYUmUUMQ5U8u5Ur4njY/Mu6XnA1roAuSOUHo+vjRsL1czKAyuFo nwK+UMTuvejcM9vCVLENH9QY0ZrYENXs4qt9jdoGyG0gGQDls72fIFVZyamBATJ+Qszp PCWZ7WRPgTqTSVJZS8Kygo7/rE4YpG6RE3Kbi4Ub+OaGz953KJRUE4jv2jLvzHMFkMGZ mgpIupZg8i8pYkCxZ7Z85cG1uXpxJ1eXpocqSsXSTQZP6YWO5xKtSpVbcq7qfrYtVAPr XXTNc6/NFb+INSShj5Wp4s6QMaYUrpDo11aUXqsy0kwXhR6lOTyY3ut+4vv+KSU+SSLi Hk6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oU7e+jIr/cI/ou5kHSSsfha06PmR4hz2KnNYeE0ncyg=; b=kvKSKm7KEOuVxytwv3HW6idtgJ8jkyoWnHhjv697AxZ99VqTDT/XTwJwYTQKTGDc8W zdDfcbGfirRCarQXeDbpSZwzhr0ebdzx63/O0m65o6RlYq65BtkS5yN9Mn27897c2Rxn RDXWBtw0VRnZg4a/GyKbyPEBgWWeD59Qzjut/P6/IAEMFslzPP+8XHClfXtilkBYn8D3 vquvMIRgwd/Mxh1fIKkIldS8mYrp4uiIljmKlwUUhI0Bcxrh3HCek1+fXHWuA32KJruS JpQ2/DlSt05auiMdFVD+oFP1EFiQqTKYvOeE9RE5Ms6BJeA7B0xqaC6P7ZVscgP3ovkA 0EfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EiPVoknU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc15si11042726ejb.374.2020.08.17.07.25.43; Mon, 17 Aug 2020 07:26:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EiPVoknU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728963AbgHQOYM (ORCPT + 99 others); Mon, 17 Aug 2020 10:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbgHQOYJ (ORCPT ); Mon, 17 Aug 2020 10:24:09 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 423D8C061389 for ; Mon, 17 Aug 2020 07:24:08 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w25so17650143ljo.12 for ; Mon, 17 Aug 2020 07:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oU7e+jIr/cI/ou5kHSSsfha06PmR4hz2KnNYeE0ncyg=; b=EiPVoknUJcywffhSmPfzdZX8frrHNh4TAkgBe9sRQg3aMFUAzaAs2xuI7sPHuBYHoB nHj9iUvWbWAxExZAwF+zDwOjmhRgHvPsIGHZEWfKE0QIEXr5q7wH8wsfNinfWGErSQFI I2SaKX/XfpzOgiGFuDP2S+VJixH2ZWk27E5fDzpPZFfMTpP5S5l/WAFdODRP93oiMe7/ fCAk7F5bKrO0MdBpTrTpwRmhCAvdu08zqb9Khk2U+fbXYaWwxo41vQZHzaQLskGEteZv JuP6grRSg6wimPHpZclWJJrhJmO+BjBhUBhzo6s8vu8nw+LGp8/sjVpC/6HuHj7TDfGo habw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oU7e+jIr/cI/ou5kHSSsfha06PmR4hz2KnNYeE0ncyg=; b=I/dQGyuFfbQetrmu+aLR7fgCQ6hOZ+8/YmYYHLCWiS2bHiHMNmJsYBPLpL4Zz/JFs5 EJyH4aaY2aytgAxsk867rzaQcuzZrdH2srsf3IEIEob+DhxOM7jwC2WRXZKigvpOS0nY Gp/KAm3i9utYdmQIFpGtXybnpfay8nU1ERC4fGv/mSuqEq9mxeTmGwSpzGy+83ypYxw8 0Q8LXA+nOOwHdMEaX1OLOjGj7inbgG8Hfk5uM/IlkAl1zTVkaf/jTkF9bAXCUlih2oar gOeyrg7BUpfvzpeut5/K2YHZjXnAoVXzPvLuFMHztcQg+jWbyzljqrFGesucumleAoa+ H2xQ== X-Gm-Message-State: AOAM531p0Vgv97KEqF97h6iMZv+Db2XGTJu5LZcvODJPkfiJo056x8iF DFtd4iP5T0hGi7vz8clal5I9gUZJXf6wmMcSHU8JuQ== X-Received: by 2002:a2e:3202:: with SMTP id y2mr7902509ljy.30.1597674246644; Mon, 17 Aug 2020 07:24:06 -0700 (PDT) MIME-Version: 1.0 References: <1595333413-30052-1-git-send-email-sumit.garg@linaro.org> <1595333413-30052-3-git-send-email-sumit.garg@linaro.org> <20200814141322.lffebtamfjt2qrym@holly.lan> In-Reply-To: From: Sumit Garg Date: Mon, 17 Aug 2020 19:53:55 +0530 Message-ID: Subject: Re: [RFC 2/5] serial: core: Add framework to allow NMI aware serial drivers To: Doug Anderson Cc: Daniel Thompson , Greg Kroah-Hartman , linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Jiri Slaby , Russell King - ARM Linux , Jason Wessel , LKML , Linux ARM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Aug 2020 at 19:27, Doug Anderson wrote: > > Hi, > > On Mon, Aug 17, 2020 at 5:27 AM Sumit Garg wrote: > > > > Thanks for your suggestion, irq_work_schedule() looked even better > > without any overhead, see below: > > > > diff --git a/include/linux/irq_work.h b/include/linux/irq_work.h > > index 3082378..1eade89 100644 > > --- a/include/linux/irq_work.h > > +++ b/include/linux/irq_work.h > > @@ -3,6 +3,7 @@ > > #define _LINUX_IRQ_WORK_H > > > > #include > > +#include > > > > /* > > * An entry can be in one of four states: > > @@ -24,6 +25,11 @@ struct irq_work { > > void (*func)(struct irq_work *); > > }; > > > > +struct irq_work_schedule { > > + struct irq_work work; > > + struct work_struct *sched_work; > > +}; > > + > > static inline > > void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *)) > > { > > { > > @@ -39,6 +45,7 @@ void init_irq_work(struct irq_work *work, void > > (*func)(struct irq_work *)) > > > > bool irq_work_queue(struct irq_work *work); > > bool irq_work_queue_on(struct irq_work *work, int cpu); > > +bool irq_work_schedule(struct work_struct *sched_work); > > > > void irq_work_tick(void); > > void irq_work_sync(struct irq_work *work); > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > > index eca8396..3880316 100644 > > --- a/kernel/irq_work.c > > +++ b/kernel/irq_work.c > > @@ -24,6 +24,8 @@ > > static DEFINE_PER_CPU(struct llist_head, raised_list); > > static DEFINE_PER_CPU(struct llist_head, lazy_list); > > > > +static struct irq_work_schedule irq_work_sched; > > + > > /* > > * Claim the entry so that no one else will poke at it. > > */ > > @@ -79,6 +81,25 @@ bool irq_work_queue(struct irq_work *work) > > } > > EXPORT_SYMBOL_GPL(irq_work_queue); > > > > +static void irq_work_schedule_fn(struct irq_work *work) > > +{ > > + struct irq_work_schedule *irq_work_sched = > > + container_of(work, struct irq_work_schedule, work); > > + > > + if (irq_work_sched->sched_work) > > + schedule_work(irq_work_sched->sched_work); > > +} > > + > > +/* Schedule work via irq work queue */ > > +bool irq_work_schedule(struct work_struct *sched_work) > > +{ > > + init_irq_work(&irq_work_sched.work, irq_work_schedule_fn); > > + irq_work_sched.sched_work = sched_work; > > + > > + return irq_work_queue(&irq_work_sched.work); > > +} > > +EXPORT_SYMBOL_GPL(irq_work_schedule); > > Wait, howzat work? There's a single global variable that you stash > the "sched_work" into with no locking? What if two people schedule > work at the same time? This API is intended to be invoked from NMI context only, so I think there will be a single user at a time. And we can make that explicit as well: +/* Schedule work via irq work queue */ +bool irq_work_schedule(struct work_struct *sched_work) +{ + if (in_nmi()) { + init_irq_work(&irq_work_sched.work, irq_work_schedule_fn); + irq_work_sched.sched_work = sched_work; + + return irq_work_queue(&irq_work_sched.work); + } + + return false; +} +EXPORT_SYMBOL_GPL(irq_work_schedule); -Sumit > > -Doug