mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Abel Vesa <abel.vesa@linaro.org>
To: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>
Cc: Caleb Connolly <caleb.connolly@linaro.org>,
	linux-arm-msm@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [RFC 2/2] soc: qcom_stats: Add dynamic debugfs entries for subsystems
Date: Thu, 18 Aug 2022 17:22:15 +0300	[thread overview]
Message-ID: <20220818142215.2282365-2-abel.vesa@linaro.org> (raw)
In-Reply-To: <20220818142215.2282365-1-abel.vesa@linaro.org>

Register per-subsystem notifier using qcom_register_ssr_notifier().
This will allow the order of between the remoteprocs actually starting and
qcom_stats driver probing to become more relaxed.

When the notifier callback gets called, depending on whether the remoteproc is
starting up or shutting down, either create or remove the related debugfs
entry. Also, in order to make sure we're not missing an already started
remoteproc, after the notifier has been set up, we go though the subsystems
list and try to create the entry for it, as it was doing before, but this time
we store the dentry to use it later on for removal, if necessary.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/soc/qcom/qcom_stats.c | 77 ++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c
index fa30540b6583..baaa820c9a77 100644
--- a/drivers/soc/qcom/qcom_stats.c
+++ b/drivers/soc/qcom/qcom_stats.c
@@ -7,8 +7,10 @@
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/remoteproc/qcom_rproc.h>
 #include <linux/seq_file.h>
 
 #include <linux/soc/qcom/smem.h>
@@ -68,11 +70,20 @@ struct appended_stats {
 	u32 reserved[3];
 };
 
+struct subsystem_priv {
+	const struct subsystem_data *subsystem;
+	struct dentry *root;
+	struct dentry *dentry;
+	struct notifier_block nb;
+	void *notifier;
+};
+
 struct qcom_stats_priv {
 	struct device dev;
 	struct stats_data *data;
 	struct dentry *root;
 	const struct stats_config *config;
+	struct subsystem_priv ss_priv[ARRAY_SIZE(subsystems)];
 };
 
 static void qcom_print_stats(struct seq_file *s, const struct sleep_stats *stat)
@@ -177,6 +188,57 @@ static void qcom_create_soc_sleep_stat_files(struct qcom_stats_priv *stats,
 	}
 }
 
+static int qcom_stats_subsys_ssr_notify(struct notifier_block *nb,
+				    unsigned long action,
+				    void *data)
+{
+	struct subsystem_priv *ss_priv = container_of(nb, struct subsystem_priv, nb);
+
+	switch (action) {
+	case QCOM_SSR_AFTER_POWERUP:
+		ss_priv->dentry = debugfs_create_file(ss_priv->subsystem->name, 0400, ss_priv->root,
+							(void *)ss_priv->subsystem,
+							&qcom_subsystem_sleep_stats_fops);
+		break;
+	case QCOM_SSR_BEFORE_SHUTDOWN:
+		debugfs_remove(ss_priv->dentry);
+		break;
+	default:
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+static void qcom_register_subsystem_notifiers(struct qcom_stats_priv *stats)
+{
+	struct device *dev = &stats->dev;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(subsystems); i++) {
+		const struct subsystem_data *subsystem = &subsystems[i];
+		struct subsystem_priv *ss_priv = &stats->ss_priv[i];
+
+		ss_priv->subsystem = subsystem;
+		ss_priv->root = stats->root;
+		ss_priv->nb.notifier_call = qcom_stats_subsys_ssr_notify;
+		ss_priv->notifier = qcom_register_ssr_notifier(subsystem->name, &ss_priv->nb);
+		if (IS_ERR(ss_priv->notifier))
+			dev_err(dev, "failed to register ssr notifier for %s (%ld)",
+				subsystem->name, PTR_ERR(ss_priv->notifier));
+	}
+}
+
+static void qcom_unregister_subsystem_notifiers(struct qcom_stats_priv *stats)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(subsystems); i++)
+		if (stats->ss_priv[i].notifier)
+			qcom_unregister_ssr_notifier(stats->ss_priv[i].notifier,
+							&stats->ss_priv[i].nb);
+}
+
 static void qcom_create_subsystem_stat_files(struct qcom_stats_priv *stats)
 {
 	const struct sleep_stats *stat;
@@ -188,12 +250,20 @@ static void qcom_create_subsystem_stat_files(struct qcom_stats_priv *stats)
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(subsystems); i++) {
+		struct subsystem_priv *ss_priv = &stats->ss_priv[i];
+
 		stat = qcom_smem_get(subsystems[i].pid, subsystems[i].smem_item, NULL);
 		if (IS_ERR(stat))
 			continue;
 
-		debugfs_create_file(subsystems[i].name, 0400, root, (void *)&subsystems[i],
-				    &qcom_subsystem_sleep_stats_fops);
+		/*
+		 * At this point some subsystems have already started
+		 * and so we already missed the startup notification,
+		 * so let's create the entry post-startup.
+		 */
+		ss_priv->dentry = debugfs_create_file(&subsystems[i]->name, 0400, root,
+							(void *)&subsystems[i],
+							&qcom_subsystem_sleep_stats_fops);
 	}
 }
 
@@ -232,6 +302,7 @@ static int qcom_stats_probe(struct platform_device *pdev)
 	stats->data = d;
 	stats->root = root;
 
+	qcom_register_subsystem_notifiers(stats);
 	qcom_create_subsystem_stat_files(stats);
 	qcom_create_soc_sleep_stat_files(stats, reg);
 
@@ -245,6 +316,8 @@ static int qcom_stats_remove(struct platform_device *pdev)
 	struct qcom_stats_priv *stats = platform_get_drvdata(pdev);
 	struct dentry *root = stats->root;
 
+	qcom_unregister_subsystem_notifiers(stats);
+
 	debugfs_remove_recursive(root);
 
 	return 0;
-- 
2.34.1


  reply	other threads:[~2022-08-18 14:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 14:22 [RFC 1/2] soc: qcom_stats: Add state container Abel Vesa
2022-08-18 14:22 ` Abel Vesa [this message]
2022-08-18 18:04   ` [RFC 2/2] soc: qcom_stats: Add dynamic debugfs entries for subsystems Abel Vesa
2022-08-23 11:47   ` Maulik Shah (mkshah)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220818142215.2282365-2-abel.vesa@linaro.org \
    --to=abel.vesa@linaro.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=caleb.connolly@linaro.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®