Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2806438ybt; Mon, 22 Jun 2020 07:30:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTaB43kzZfqDJYVCdxojgM8wUyyUgPBM+cw2phWNHYKF4LucS887pDAzQp7zo/zYkq3uHg X-Received: by 2002:aa7:da4f:: with SMTP id w15mr16698344eds.384.1592836245711; Mon, 22 Jun 2020 07:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592836245; cv=none; d=google.com; s=arc-20160816; b=h/XpM6yikLp2TROiyULw/p9wn9RpVSBbrVJZJBfRtf9vm/K6ZM1Ko/s1sx/4PloVyt ItGo0zN2t5H22kZ7ij8/n21mmS/H9sWaIzX3EnCjlPGGdj7pRJ9eeCy9nglo0YnTi5qy bs6P/K9Q2jP+9a3c+/AdCdGt7HM4hggfHpxIhNo1tWUrPY8P7dyrHH52Y7AXUibshwOe 7KlyEJV68Do32rsqRJevVyQeV2XKMoBVrV7WU24Z9ABz3FebiyaZqyopxiLcWOhG1QPj rTLuBceVCYXX8vg9wy2pF/4F+hw6uAeZdwpVokMj2xOA8p9z5Amel561vT4afzyczY5G PqEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=JRSHvl6U+IZL0NsvNZuwTx0bEAhR9MBQN7axB8epcUs=; b=YHd6Vyv9ajxCQ7kg1wrDP/PMmPGceeuIfXaxeK9heACeypyzQpyOHXGQLqdy7vP4nm pMVnp9NcIpGXZVfAJLFzGQVnDHL3AcivDmuwX5asJO0u96TRamJKWzW+sXMQScj4fwee z7cXuv99QhcFNNA5e8HUfb3xmkUo9hdF3XpjaQaN2Tq4io6DEs51yUkg+0Vjhur1UN72 0HsaactcfiK9zZSHxXg95q3i8ebKw65u02ctITguWUTZe4/CxTaVfqmvxgAPATwUqGpx mo/p1K5zkzKH4/ExIm3nDp6/SWniLGqkiMko8Mec7sCF+wyYPSdEvGwtLtXwHMwcL25a 8apA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S8TezEvu; 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 dk19si8761053edb.446.2020.06.22.07.30.23; Mon, 22 Jun 2020 07:30:45 -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=S8TezEvu; 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 S1729821AbgFVO16 (ORCPT + 99 others); Mon, 22 Jun 2020 10:27:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729816AbgFVO1z (ORCPT ); Mon, 22 Jun 2020 10:27:55 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8DE0C061573 for ; Mon, 22 Jun 2020 07:27:55 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id p3so5532953pgh.3 for ; Mon, 22 Jun 2020 07:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JRSHvl6U+IZL0NsvNZuwTx0bEAhR9MBQN7axB8epcUs=; b=S8TezEvuiSh9r4tBiJ8Y0oZfklqL3bPKvd/7r3OyPqXHHov7Otay0asDWDli0VDaTF KFKyvZN2KacrOaS0MVEXkb9jRAT3dQ4+Cf6+zAfEvJedm3lyOYDDTqLOfN/36anHjr9r KsqPKjJzOfSAwUn3oO5oleQ5ofNvOhbgSz8gIHtWYPg+o2u7HtyH8K3QJE5pq3xfJxCf 709Ko3xFJDv3Pq4cJf9abD0OkIiy+mcEygCEca/dxQTzzLvArfOFqQzOToCln2rtZ7F3 ckoSN05a+EOUNIWgO9ziPfaAC+soDU1jlx1wKcwKemwABOOuuzqjb6b6ae8iByzjA2HG bZ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JRSHvl6U+IZL0NsvNZuwTx0bEAhR9MBQN7axB8epcUs=; b=SZzEvk+kIh7Vyj0sVKisXoY6Oglp+iCejEwEUgH5/TTPjEYUeeQ7WDv3sGXK/EvWV0 tDwbuT/RFgCzuj3A0MNXV+JVM9chsKme0Ffo0VUYc0ymfyLYHJQ5J1KmcpxQKJfbl16g I7RzcLRweOWbJ4dH+VDJmHWEv6AreiLI9jaE67OOpAVi9IFOhvZvlb8//R68l/6+B7P1 avFv8lTnZ8VdalYrdCMuuot3CBJ0O3P3g62zTx6DLb61vvuGGyZT9cuOhzlddbAswo7E U9YEg5/4owQ1lEEnVZHs4t646AXSvrmdhfS2vw8uTY1mKlC3UGBZZ5MMyzowC46cSjhT vVcQ== X-Gm-Message-State: AOAM532cY1KFXHZSHwoaDJS8cHxNjONZ4Csw8+oCbeyw0wdnkAVoullM uzBD93fTJIUMr5K+BG1hU83jxQ== X-Received: by 2002:a63:d652:: with SMTP id d18mr13372987pgj.164.1592836075366; Mon, 22 Jun 2020 07:27:55 -0700 (PDT) Received: from localhost.localdomain ([117.252.67.186]) by smtp.gmail.com with ESMTPSA id d6sm14547939pjh.5.2020.06.22.07.27.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2020 07:27:54 -0700 (PDT) From: Sumit Garg To: kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Cc: gregkh@linuxfoundation.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, dianders@chromium.org, jslaby@suse.com, linux@armlinux.org.uk, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH 7/7] serial: kgdb_nmi: Replace hrtimer with irq_work ping Date: Mon, 22 Jun 2020 19:56:24 +0530 Message-Id: <1592835984-28613-8-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> References: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Thompson Currently kgdb_nmi relies on a 100Hz timer to "defer" work from an NMI handler. This is essentially doing the job that irq_work is designed to do but in an odd and inefficient manner. Remove the timer code and replace it with more appropriate irq_work related APIs. Signed-off-by: Daniel Thompson Signed-off-by: Sumit Garg --- drivers/tty/serial/kgdb_nmi.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c index 2580f39..ad84eef 100644 --- a/drivers/tty/serial/kgdb_nmi.c +++ b/drivers/tty/serial/kgdb_nmi.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -127,7 +127,7 @@ static struct console kgdb_nmi_console = { struct kgdb_nmi_tty_priv { struct tty_port port; - struct timer_list timer; + struct irq_work work; STRUCT_KFIFO(char, KGDB_NMI_FIFO_SIZE) fifo; }; @@ -141,13 +141,12 @@ static void kgdb_tty_recv(int ch) if (!kgdb_nmi_port || ch < 0) return; /* - * Can't use port->tty->driver_data as tty might be not there. Timer - * will check for tty and will get the ref, but here we don't have to - * do that, and actually, we can't: we're in NMI context, no locks are - * possible. + * Can't use port->tty->driver_data as tty might be not there. Also, we + * can't even do that as we're in NMI context, no locks are possible. */ priv = container_of(kgdb_nmi_port, struct kgdb_nmi_tty_priv, port); kfifo_in(&priv->fifo, &c, 1); + irq_work_queue(&priv->work); } static int kgdb_nmi_poll_one_knock(void) @@ -222,18 +221,12 @@ bool kgdb_nmi_poll_knock(void) return true; } -/* - * The tasklet is cheap, it does not cause wakeups when reschedules itself, - * instead it waits for the next tick. - */ -static void kgdb_nmi_tty_receiver(struct timer_list *t) +static void kgdb_nmi_tty_receiver(struct irq_work *work) { - struct kgdb_nmi_tty_priv *priv = from_timer(priv, t, timer); + struct kgdb_nmi_tty_priv *priv = + container_of(work, struct kgdb_nmi_tty_priv, work); char ch; - priv->timer.expires = jiffies + (HZ/100); - add_timer(&priv->timer); - if (likely(!atomic_read(&kgdb_nmi_num_readers) || !kfifo_len(&priv->fifo))) return; @@ -245,22 +238,13 @@ static void kgdb_nmi_tty_receiver(struct timer_list *t) static int kgdb_nmi_tty_activate(struct tty_port *port, struct tty_struct *tty) { - struct kgdb_nmi_tty_priv *priv = - container_of(port, struct kgdb_nmi_tty_priv, port); - kgdb_nmi_port = port; - priv->timer.expires = jiffies + (HZ/100); - add_timer(&priv->timer); return 0; } static void kgdb_nmi_tty_shutdown(struct tty_port *port) { - struct kgdb_nmi_tty_priv *priv = - container_of(port, struct kgdb_nmi_tty_priv, port); - - del_timer(&priv->timer); kgdb_nmi_port = NULL; } @@ -279,7 +263,8 @@ static int kgdb_nmi_tty_install(struct tty_driver *drv, struct tty_struct *tty) return -ENOMEM; INIT_KFIFO(priv->fifo); - timer_setup(&priv->timer, kgdb_nmi_tty_receiver, 0); + init_irq_work(&priv->work, kgdb_nmi_tty_receiver); + atomic_set(&priv->work.flags, IRQ_WORK_LAZY); tty_port_init(&priv->port); priv->port.ops = &kgdb_nmi_tty_port_ops; tty->driver_data = priv; -- 2.7.4