From patchwork Mon Jun 22 14:26:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 191338 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp1092988ile; Mon, 22 Jun 2020 07:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNHSl9E+3uJ6Zpdef7t+Vs3aN4tz3oJN6Y2iUcF1PA2AotRfMmITmfzXMhsyd+FC4XDvUF X-Received: by 2002:aa7:ce93:: with SMTP id y19mr16667636edv.50.1592836078615; Mon, 22 Jun 2020 07:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592836078; cv=none; d=google.com; s=arc-20160816; b=CbEtz38+5PE/rldy2mDa2LGCVdOtU58y2E1gj2tytsYnTLrl86wAOOvrzsOii7b6JK rZQFcASHyLEz8Mk5wGUAq7QWGlEmhMYgGtt8VXod6k9lNHemL5NZ9M66V2pLyr8B/ihY WjQ/L2Lfz9kKo1U3O2YaV+iEsS/hW44ZDm+c6tA0WZ/Cobg7xMVVwPk5djkjNPi6sfsv 1qwUyDgLNKCrNZZwE+veTqDiDZF87P3xzy9ucs3hG3Cn6VTUVxTZaWOY+TNJVw8tPIoq IeIkN6vk3ZXGgv6g1EujLEz+NXqMb/0jmG5Ecy8+UvlDPLVuFMODq7unG3qCdXVpyy/Z ndgg== 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=pc+U0P/AR9qtpkq8zTOWkCnw6ZuVQgOVonwl6k91GoJQjenG9dL0vnM4BJ7WoFmK0t qP5f0uid9sdwuosD5tqIjXwv9uc7fpvBEX8c7QMpSjzIL11ishQxuk1+vkHASAoz+SXv pt4rMPP2B9t/1eFyX6dgQQo6gTmW6mpNurKm65/i4OkSVyeBTR7cMiGN0cfqL9S1cDEd 86pw6IajMAxudVv+rRsVKtt/jlBDIrl6y0LEOygI6ibE3KM9Ql8XR0l5T0MysNmptNw7 BrW4xvk2x0uJzhfNbNih0Oa/MyzQ7PflSeUFhuSmCxgtthetgkkfLTa3O0gEh2mgURFJ KArg== 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-serial-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-serial-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 y16si9037717ejr.344.2020.06.22.07.27.58; Mon, 22 Jun 2020 07:27:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-serial-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-serial-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-serial-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 S1729813AbgFVO15 (ORCPT + 1 other); Mon, 22 Jun 2020 10:27:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729818AbgFVO1z (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 C9313C061795 for ; Mon, 22 Jun 2020 07:27:55 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id b5so8214562pgm.8 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=mqFeGRq9KD5OFA43TjSZA4rI0hYHmolVF6XY575Ue9TaUDP1ZqTSWTyUwMyOSGW1xk 7N7Or+Hti0BYnuP/pVvm40kp3VG+luA28y7HP55CYIGt/R3bK/LcLxxyy1bOJcp72azt XZerlbJ+75tJsQ6jQkbrWujt+aO+3rSAGf0yvcnmBXWZXj8+XuWOJdvy0Cuk3CiUie/f vbcrf0wxk69OrS/dGoSvQ1SB02FBC1d6snAUu8xZ6GSBDsKWIzXOsnqDHjLYcMmJzlxw kB33rT6z131nU28Ji2lWeeYYuEEhSc0KKICqFJGdUBgZpkihjbsQcWvObSLLELTLjAlG b5ZQ== X-Gm-Message-State: AOAM530ad0BXep+I7yHaQUEqX78WqoiKHb5qtoRyoJC1QD38pdU20uNM UUD6aFWaGuFwPqtAQlGNdJRSHg== 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-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@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(-) -- 2.7.4 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;