From patchwork Thu Aug 30 18:26:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guzman Lugo, Fernando" X-Patchwork-Id: 1389231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id DE25A3FDF5 for ; Thu, 30 Aug 2012 18:30:36 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T79SP-0004Jt-UA; Thu, 30 Aug 2012 18:27:09 +0000 Received: from na3sys009aog112.obsmtp.com ([74.125.149.207]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1T79Rw-0004Hm-HB for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2012 18:26:43 +0000 Received: from mail-ob0-f177.google.com ([209.85.214.177]) (using TLSv1) by na3sys009aob112.postini.com ([74.125.148.12]) with SMTP ID DSNKUD+wXgvSpHQsLlrGrkGNoZtNzj0xeIjP@postini.com; Thu, 30 Aug 2012 11:26:40 PDT Received: by obbta17 with SMTP id ta17so4159417obb.36 for ; Thu, 30 Aug 2012 11:26:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=VdeKq5EA5BLha5he3R5w5JKEYsbMI5CjxRqe0rdLhRY=; b=If2cv//x/rY8qC6ZPAl+M8xkVzdAa8QRPqEkROg+K2IT0dzW6lipRceIxwGz04I0k4 Pt+mmn8O7qLi4JlTWIi9LbtgioujUOVewwkMMvJwZCl0Nhifn3mPuM7n0Tmi8MiGw27f r19591gjDcY8NbefDeAXvQOJ9zF7Ujzy6WUpKfW2JgSElW0MEWzDB2612cBFoE3sDrFC aaSJddJMa2KWwxnu0HtMXKcI9fBr4Ju1RR6zslw01B6OvaTqCSyA3it9cx2potj1kfYS QOiqX4kVN+feKOun/vVCA1Tfelv+Xb2MpNnz9OLQKCRc8fqaX4cJOhonAZhFt0r7GTry 7ztg== Received: by 10.182.217.38 with SMTP id ov6mr5621234obc.33.1346351198434; Thu, 30 Aug 2012 11:26:38 -0700 (PDT) Received: from localhost.localdomain (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id d6sm1950349obx.15.2012.08.30.11.26.37 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 11:26:37 -0700 (PDT) From: Fernando Guzman Lugo To: , , , Subject: [PATCHv2 3/3] remoteproc: create debugfs entry to disable/enable recovery dynamically Date: Thu, 30 Aug 2012 13:26:14 -0500 Message-Id: <1346351174-28441-4-git-send-email-fernando.lugo@ti.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1346351174-28441-1-git-send-email-fernando.lugo@ti.com> References: <1346351174-28441-1-git-send-email-fernando.lugo@ti.com> X-Gm-Message-State: ALoCoQkN6LPZljWvs7ICOl/Lv9weaoAARwhoufmvODvfs3lXAnkAm+IL+5ZeOJrGpxjI5s8/SklV X-Spam-Note: CRM114 invocation failed X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [74.125.149.207 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Fernando Guzman Lugo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add a debugfs entry (named recovery) so that recovery can be disabled dynamically at runtime. This entry is very useful when you are trying to debug a rproc crash. Without this a recovery will take place making impossible to debug the issue. Original idea from Ohad Ben-Cohen and contributions from Subramaniam Chanderashekarapuram Example: -disabling recovery: $ echo disabled > /remoteproc/remoteproc0/recovery -enabling recovery: $ echo enabled > /remoteproc/remoteproc0/recovery -in case you have disabled recovery and you want to continue debugging you can recover the remoteproc once using recover. This will not change the state of the recovery entry, it will only recovery the rproc if its state is RPROC_CRASHED $ echo recover > /remoteproc/remoteproc0/recovery Signed-off-by: Fernando Guzman Lugo --- drivers/remoteproc/remoteproc_core.c | 3 +- drivers/remoteproc/remoteproc_debugfs.c | 83 +++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 2 + 3 files changed, 87 insertions(+), 1 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 9fbd364..16e20f7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -936,7 +936,8 @@ static void rproc_crash_handler_work(struct work_struct *work) ++rproc->crash_cnt, rproc->name); mutex_unlock(&rproc->lock); - rproc_trigger_recover(rproc); + if (!rproc->recovery_disabled) + rproc_trigger_recover(rproc); } /** diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c index 0383385..aa95cde 100644 --- a/drivers/remoteproc/remoteproc_debugfs.c +++ b/drivers/remoteproc/remoteproc_debugfs.c @@ -28,6 +28,9 @@ #include #include #include +#include + +#include "remoteproc_internal.h" /* remoteproc debugfs parent dir */ static struct dentry *rproc_dbg; @@ -111,6 +114,84 @@ static const struct file_operations rproc_name_ops = { .llseek = generic_file_llseek, }; +/* expose recovery flag via debugfs */ +static ssize_t rproc_recovery_read(struct file *filp, char __user *userbuf, + size_t count, loff_t *ppos) +{ + struct rproc *rproc = filp->private_data; + char *buf = rproc->recovery_disabled ? "disabled\n" : "enabled\n"; + + return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf)); +} + + +/* + * Writing to the recovey debugfs entry we can change the behavior of the + * recovery dynamically. The default value of this entry is "enabled". + * + * There are 3 possible options you can write to the recovery debug entry: + * "enabled", "disabled" and "recover" + * + * enabled: In this case recovery will be enabled, every time there is a + * rproc crashed the rproc will be recovered. If recovery has been + * disabled and it crashed and you enable recovery it will be + * recover as soon as you enable recovery. + * disabled: In this case recovery will be disabled, that means if a rproc + * crashes it will remain in crashed state. Therefore the rproc + * won't be functional any more. But this option is used for + * debugging purposes. Otherwise, debugging a crash would not be + * possible. + * recover: This function will trigger a recovery without taking care of + * the recovery state (enabled/disabled) and without changing it. + * This useful for the cases when you are debugging a crash and + * after enabling recovery you get another crash immediately. As + * the recovery state will be enabled it will recover the rproc + * without let you debug the new crash. So, it is recommended to + * disabled recovery, then starting debugging and use "recovery" + * command while still debugging and when you are done then you + * case use enabled command. + */ +static ssize_t rproc_recovery_write(struct file *filp, + const char __user *user_buf, size_t count, loff_t *ppos) +{ + struct rproc *rproc = filp->private_data; + char buf[10]; + int ret; + + if (count > sizeof(buf)) + return count; + + ret = copy_from_user(buf, user_buf, count); + if (ret) + return ret; + + /* remove end of line */ + if (buf[count - 1] == '\n') + buf[count - 1] = '\0'; + + if (!strncmp(buf, "enabled", count)) { + rproc->recovery_disabled = false; + /* if rproc has crashed trigger recovery */ + if (rproc->state == RPROC_CRASHED) + rproc_trigger_recover(rproc); + } else if (!strncmp(buf, "disabled", count)) { + rproc->recovery_disabled = true; + } else if (!strncmp(buf, "recover", count)) { + /* if rproc has crashed trigger recovery */ + if (rproc->state == RPROC_CRASHED) + rproc_trigger_recover(rproc); + } + + return count; +} + +static const struct file_operations rproc_recovery_ops = { + .read = rproc_recovery_read, + .write = rproc_recovery_write, + .open = simple_open, + .llseek = generic_file_llseek, +}; + void rproc_remove_trace_file(struct dentry *tfile) { debugfs_remove(tfile); @@ -154,6 +235,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_name_ops); debugfs_create_file("state", 0400, rproc->dbg_dir, rproc, &rproc_state_ops); + debugfs_create_file("recovery", 0400, rproc->dbg_dir, + rproc, &rproc_recovery_ops); } void __init rproc_init_debugfs(void) diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 0c1a2f9..2ccc3fe 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -399,6 +399,7 @@ enum rproc_crash_type { * @crash_handler: workqueue for handling a crash * @crash_cnt: crash counter * @crash_comp: completion used to sync crash handler and the rproc reload + * @recovery_disabled: flag that state if recovery was disabled */ struct rproc { struct klist_node node; @@ -425,6 +426,7 @@ struct rproc { struct work_struct crash_handler; unsigned crash_cnt; struct completion crash_comp; + bool recovery_disabled; }; /* we currently support only two vrings per rvdev */