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: 1389111 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2CC243FDF5 for ; Thu, 30 Aug 2012 18:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754900Ab2H3S1C (ORCPT ); Thu, 30 Aug 2012 14:27:02 -0400 Received: from na3sys009aog105.obsmtp.com ([74.125.149.75]:56915 "EHLO na3sys009aog105.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754811Ab2H3S0k (ORCPT ); Thu, 30 Aug 2012 14:26:40 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]) (using TLSv1) by na3sys009aob105.postini.com ([74.125.148.12]) with SMTP ID DSNKUD+wXgvSpHQsLlrGrkGNoZtNzj0xeIjP@postini.com; Thu, 30 Aug 2012 11:26:39 PDT Received: by obbuo13 with SMTP id uo13so3911242obb.19 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=ETWd5UlQX7+dgXVJXYl2VXujJ1nnUKBTS2o7GQe5989fn2PYHJERIjXEKI3TzOw6Rn g7qibbCljqH1hp9BJrp15piAtQ5jDI0lSDN6J7hlkkA7L5xX1Ec31xXqcmVF1S5cdf3A YW74+b4w6ISais9+W9JKmt7BFECDSgTingtzMDrQlvCXERDBayHZ2pY85MwrNsEqoyGz Le3AsvAAFWWjRPmbqRrnfpP0tEZu3Xq/01vfiNNaCKnPKqjqXkoD5LzchMf7j+1+WY6j Vh1ACm6UzaPJzj9uMimklXfTNJVx+8Q2QzOf5IrRe88P9EVDZA8PxUTq9vZHyUJMyZ2A H0nQ== 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: , , , Cc: Fernando Guzman Lugo 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: ALoCoQmS+iWzNzEabJRb6WhHJzULKo5D6ErUNYkblySSJQd354M9kURj0CQggOmwqKHVsFhJc/HH Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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 */