From patchwork Thu Aug 18 14:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 598583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AD80C00140 for ; Thu, 18 Aug 2022 14:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245064AbiHROW3 (ORCPT ); Thu, 18 Aug 2022 10:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243887AbiHROW3 (ORCPT ); Thu, 18 Aug 2022 10:22:29 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D30F9AFAF7 for ; Thu, 18 Aug 2022 07:22:27 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id s11-20020a1cf20b000000b003a52a0945e8so1018613wmc.1 for ; Thu, 18 Aug 2022 07:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=aIyech5h/+UXGvGLsMrbDOfgSWvv8J2d6bGJqyRKLIs=; b=O9v21FbbSfqHPvVquF/flI5r+QPmlmjFivxMpnAQKTKf/tlVK4A8HkVHCo76oD0Du6 +nzZhpGwvPhccFE1y3N4NVu0heVFDjMRNWA/H03f+zJtu8Wd4b2DI9D1Jbeuwgs+6Akh 1Cvva9kQlwjAgQFTyk74mpaddNLHNbSUnFQ4z/xfgRr+uP7iXZy5EckH7p2W6Rw2JGjL uaAsUDDxsA0tloBc+Cip81Yl4qczuIQgXrh5V/E5wRyHuhKtKhLRts4kO8SbjFaFVJUt Q6gEP6FXEvIH0VUwv72sHRzK5JDpiQa4c9hZwSNjIj3vAYZZvnBgkbIMeZat59kfNdIV DDMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=aIyech5h/+UXGvGLsMrbDOfgSWvv8J2d6bGJqyRKLIs=; b=SbvyJ7f46Huz2HDh2wsANk0SZQ0u5d2m+btt5D8O1k+WY9MwyDhtkymdyIk82WjT8Q gUFzIdjOGQzAcxvXkl9+i+E4I+cs4VTxy3qm2zWEwTD34HYYHew4NvYIjXcBYGcJHkJ4 /7WCM0aEm3TJ52NIQ0ZkiX8bxvHBySGEoVcmUmNeOQYJo65yNRrK7LNlJAZXpgcmFtud mbrMbeHMArQPwR1cZJj3D6eLbUsTZqjFdylpzroBuJprzKV95WpARo+NLwUZDi8ELDha rIT3wvEDSLyrquSVJHV1ST2tsqpeGiHSYJQm/w25XzsMvthLpd3uL9Xs0mc1VSuqJr1J 1kRg== X-Gm-Message-State: ACgBeo1W75T0yJeA53pQmNS/5o/Zr/lxsn5kGRDRC3NxcE8C8YG95lqz lhtJ8Cq2heTOSx8eOR+06s24IHFUW3m/45lb X-Google-Smtp-Source: AA6agR67lNyCP6PU22sf32+TiEHnPS75sfs2dClSXmIvi0DyXi1vN8TTIy5FUefyOu3N8LHeF1OOnw== X-Received: by 2002:a05:600c:4d15:b0:3a5:b3fe:75dd with SMTP id u21-20020a05600c4d1500b003a5b3fe75ddmr5384209wmp.116.1660832546392; Thu, 18 Aug 2022 07:22:26 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id l23-20020a05600c1d1700b003a61306d79dsm2767184wms.41.2022.08.18.07.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 07:22:25 -0700 (PDT) From: Abel Vesa To: Andy Gross , Bjorn Andersson , Konrad Dybcio Cc: Caleb Connolly , linux-arm-msm@vger.kernel.org, Linux Kernel Mailing List Subject: [RFC 1/2] soc: qcom_stats: Add state container Date: Thu, 18 Aug 2022 17:22:14 +0300 Message-Id: <20220818142215.2282365-1-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In order to allow the dynamic creation of debugfs subsystem entries, the notifier and the notifier_block need to be stored in a per-subsystem fashion. For that we need some kind of state container, so add it and group everything related to the probing device into it. Signed-off-by: Abel Vesa --- drivers/soc/qcom/qcom_stats.c | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c index d6bfd1bbdc2a..fa30540b6583 100644 --- a/drivers/soc/qcom/qcom_stats.c +++ b/drivers/soc/qcom/qcom_stats.c @@ -68,6 +68,13 @@ struct appended_stats { u32 reserved[3]; }; +struct qcom_stats_priv { + struct device dev; + struct stats_data *data; + struct dentry *root; + const struct stats_config *config; +}; + static void qcom_print_stats(struct seq_file *s, const struct sleep_stats *stat) { u64 accumulated = stat->accumulated; @@ -121,10 +128,13 @@ static int qcom_soc_sleep_stats_show(struct seq_file *s, void *unused) DEFINE_SHOW_ATTRIBUTE(qcom_soc_sleep_stats); DEFINE_SHOW_ATTRIBUTE(qcom_subsystem_sleep_stats); -static void qcom_create_soc_sleep_stat_files(struct dentry *root, void __iomem *reg, - struct stats_data *d, - const struct stats_config *config) +static void qcom_create_soc_sleep_stat_files(struct qcom_stats_priv *stats, + void __iomem *reg) { + struct dentry *root = stats->root; + struct stats_data *d = stats->data; + const struct stats_config *config = stats->config; + char stat_type[sizeof(u32) + 1] = {0}; size_t stats_offset = config->stats_offset; u32 offset = 0, type; @@ -167,10 +177,11 @@ static void qcom_create_soc_sleep_stat_files(struct dentry *root, void __iomem * } } -static void qcom_create_subsystem_stat_files(struct dentry *root, - const struct stats_config *config) +static void qcom_create_subsystem_stat_files(struct qcom_stats_priv *stats) { const struct sleep_stats *stat; + const struct stats_config *config = stats->config; + struct dentry *root = stats->root; int i; if (!config->subsystem_stats_in_smem) @@ -188,12 +199,17 @@ static void qcom_create_subsystem_stat_files(struct dentry *root, static int qcom_stats_probe(struct platform_device *pdev) { + struct qcom_stats_priv *stats = NULL; void __iomem *reg; struct dentry *root; const struct stats_config *config; struct stats_data *d; int i; + stats = devm_kzalloc(&pdev->dev, sizeof(*stats), GFP_KERNEL); + if (!stats) + return -ENOMEM; + config = device_get_match_data(&pdev->dev); if (!config) return -ENODEV; @@ -212,17 +228,22 @@ static int qcom_stats_probe(struct platform_device *pdev) root = debugfs_create_dir("qcom_stats", NULL); - qcom_create_subsystem_stat_files(root, config); - qcom_create_soc_sleep_stat_files(root, reg, d, config); + stats->config = config; + stats->data = d; + stats->root = root; + + qcom_create_subsystem_stat_files(stats); + qcom_create_soc_sleep_stat_files(stats, reg); - platform_set_drvdata(pdev, root); + platform_set_drvdata(pdev, stats); return 0; } static int qcom_stats_remove(struct platform_device *pdev) { - struct dentry *root = platform_get_drvdata(pdev); + struct qcom_stats_priv *stats = platform_get_drvdata(pdev); + struct dentry *root = stats->root; debugfs_remove_recursive(root); From patchwork Thu Aug 18 14:22:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 598157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C908BC25B0E for ; Thu, 18 Aug 2022 14:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245726AbiHROWb (ORCPT ); Thu, 18 Aug 2022 10:22:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245708AbiHROWa (ORCPT ); Thu, 18 Aug 2022 10:22:30 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A1AFB07FA for ; Thu, 18 Aug 2022 07:22:29 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so2674744wme.1 for ; Thu, 18 Aug 2022 07:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0C4aHcXgWxy6PpVtW7d+ycoPUGyQqm944VNk/U4/NEU=; b=PsXnrzMhLsWDUil+KFa5V4r3P1L/3E4kZ0cSF50jUartlrp/clGytZsubYHebiRMe1 91d4VpZ5GJpPHS+QJPjgNfHXpDtBKEvp7q7/+EdVGK8blNPjCaX1MI8rBokTQn/kfc0i /wGf6lIYlaev2k+xgLi8m7pt5pRz60fstTfUIvZ6Q32mQnVzMJDf6KoM28BTgUMrkL6w R8IDTMA48lnVrtppWC7EcoJyiRw/kHK4bFJ7ttng9Zi0rcnsi3/djv3n6nC4WPC+aVWw G/Uxz+YsncMQsaXUsCvouJnw7UX8lbfV5G8nG1armO5wlo+t/JJMdeYKjey4ySk/WXnn kcZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0C4aHcXgWxy6PpVtW7d+ycoPUGyQqm944VNk/U4/NEU=; b=0t3Mablqbmf716rdHc+b/hyH9odCvrcVWidkwy1QE2kNQb1MtgiHfSJ1OpryVI3N9J oQwlf6glF8rrgNpcK8LR9+ByxsftMQkHuj77efVYLy+utnXFDmZxHBEQYzm8u7MS/LPd WMjsO99zBLLIbf5te7mx4erCGwIzxT0gUnLtP11aRDnIEXogKYqSIxlNNiOleqnhQPyo TTLNUiYJupfSDMj60InRo0CqK4Hy8TJFJVv3cghphUNf2MhrWvW/78JGq62GJPyBkYC2 ijhe4s7lkmdoR4nixJLbnhbVb/iBLGf1jyjHeM39P2boL9wZQft1hX7PcbOxTgElYFoM SGQA== X-Gm-Message-State: ACgBeo1QHjFFI5M5Ji0B9rXdp/1lDbVP31cw8bo/PSNNWGc5WnOfJMeq qYWHVrAP/clbw/KxlGe8+lNgkg== X-Google-Smtp-Source: AA6agR44P7ilTfUquQEX1o5MpBOZ1OuPn3FU8J3+aJ/By+VOYXtcqgjwm8k+Jy6ZDhRPTwoDaZvPEg== X-Received: by 2002:a7b:cb55:0:b0:3a5:41a:829c with SMTP id v21-20020a7bcb55000000b003a5041a829cmr5362465wmj.153.1660832547859; Thu, 18 Aug 2022 07:22:27 -0700 (PDT) Received: from hackbox.lan ([94.52.112.99]) by smtp.gmail.com with ESMTPSA id l23-20020a05600c1d1700b003a61306d79dsm2767184wms.41.2022.08.18.07.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 07:22:27 -0700 (PDT) From: Abel Vesa To: Andy Gross , Bjorn Andersson , Konrad Dybcio Cc: Caleb Connolly , linux-arm-msm@vger.kernel.org, Linux Kernel Mailing List Subject: [RFC 2/2] soc: qcom_stats: Add dynamic debugfs entries for subsystems Date: Thu, 18 Aug 2022 17:22:15 +0300 Message-Id: <20220818142215.2282365-2-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220818142215.2282365-1-abel.vesa@linaro.org> References: <20220818142215.2282365-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 --- 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 #include #include +#include #include #include +#include #include #include @@ -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;