Re: [PATCH v6 11/14] misc: bcm-vk: add BCM_VK_QSTATS

2020-11-17 Thread Scott Branden
Hi Florian,

On 2020-10-02 6:39 p.m., Florian Fainelli wrote:
>
>
> On 10/2/2020 2:23 PM, Scott Branden wrote:
>> Add BCM_VK_QSTATS Kconfig option to allow for enabling debug VK
>> queue statistics.
>>
>> These statistics keep track of max, abs_max, and average for the
>> messages queues.
>>
>> Co-developed-by: Desmond Yan 
>> Signed-off-by: Desmond Yan 
>> Signed-off-by: Scott Branden 
>
> would not it make more sense to have those debug prints be trace printks 
> instead? Given what you explained in the previous patch version and the 
> desire to correlate with other system wide activity, that might make more 
> sense. Looking at the kernel's log for debugging performance or utilization 
> or just to get a glimpse of what is going on is not quite suited past probe.
The debug prints have served our purpose up to this point.
But, in the interest of getting the other driver patches accepted I will drop 
this patch from the series and we will investigate further.

Thanks,
 Scott


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [PATCH v6 11/14] misc: bcm-vk: add BCM_VK_QSTATS

2020-10-02 Thread Florian Fainelli




On 10/2/2020 2:23 PM, Scott Branden wrote:

Add BCM_VK_QSTATS Kconfig option to allow for enabling debug VK
queue statistics.

These statistics keep track of max, abs_max, and average for the
messages queues.

Co-developed-by: Desmond Yan 
Signed-off-by: Desmond Yan 
Signed-off-by: Scott Branden 


would not it make more sense to have those debug prints be trace printks 
instead? Given what you explained in the previous patch version and the 
desire to correlate with other system wide activity, that might make 
more sense. Looking at the kernel's log for debugging performance or 
utilization or just to get a glimpse of what is going on is not quite 
suited past probe.

--
Florian


[PATCH v6 11/14] misc: bcm-vk: add BCM_VK_QSTATS

2020-10-02 Thread Scott Branden
Add BCM_VK_QSTATS Kconfig option to allow for enabling debug VK
queue statistics.

These statistics keep track of max, abs_max, and average for the
messages queues.

Co-developed-by: Desmond Yan 
Signed-off-by: Desmond Yan 
Signed-off-by: Scott Branden 
---
 drivers/misc/bcm-vk/Kconfig  | 14 +
 drivers/misc/bcm-vk/bcm_vk_dev.c |  9 ++
 drivers/misc/bcm-vk/bcm_vk_msg.c | 52 +++-
 drivers/misc/bcm-vk/bcm_vk_msg.h | 12 
 4 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/bcm-vk/Kconfig b/drivers/misc/bcm-vk/Kconfig
index 2272e47655ed..a3a020b19e3b 100644
--- a/drivers/misc/bcm-vk/Kconfig
+++ b/drivers/misc/bcm-vk/Kconfig
@@ -13,3 +13,17 @@ config BCM_VK
  accelerators via /dev/bcm-vk.N devices.
 
  If unsure, say N.
+
+if BCM_VK
+
+config BCM_VK_QSTATS
+   bool "VK Queue Statistics"
+   help
+ Turn on to enable Queue Statistics.
+ These are useful for debugging purposes.
+ Some performance loss by enabling this debug config.
+ For properly operating PCIe hardware no need to enable this.
+
+ If unsure, say N.
+
+endif
diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c
index 718badb53100..6c2370723e0a 100644
--- a/drivers/misc/bcm-vk/bcm_vk_dev.c
+++ b/drivers/misc/bcm-vk/bcm_vk_dev.c
@@ -1097,6 +1097,15 @@ static int bcm_vk_trigger_reset(struct bcm_vk *vk)
vkwrite32(vk, 0, BAR_0, BAR_INTF_VER);
memset(>host_alert, 0, sizeof(vk->host_alert));
memset(>peer_alert, 0, sizeof(vk->peer_alert));
+#if defined(CONFIG_BCM_VK_QSTATS)
+   /* clear qstats */
+   for (i = 0; i < VK_MSGQ_MAX_NR; i++) {
+   memset(>to_v_msg_chan.qstats[i].qcnts, 0,
+  sizeof(vk->to_v_msg_chan.qstats[i].qcnts));
+   memset(>to_h_msg_chan.qstats[i].qcnts, 0,
+  sizeof(vk->to_h_msg_chan.qstats[i].qcnts));
+   }
+#endif
/* clear 4096 bits of bitmap */
bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);
 
diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c
index e31d41400199..6ba0a7a94dcc 100644
--- a/drivers/misc/bcm-vk/bcm_vk_msg.c
+++ b/drivers/misc/bcm-vk/bcm_vk_msg.c
@@ -91,6 +91,44 @@ u32 msgq_avail_space(const struct bcm_vk_msgq __iomem *msgq,
return (qinfo->q_size - msgq_occupied(msgq, qinfo) - 1);
 }
 
+#if defined(CONFIG_BCM_VK_QSTATS)
+
+/* Use default value of 2 rd/wr per update */
+#if !defined(BCM_VK_QSTATS_ACC_CNT)
+#define BCM_VK_QSTATS_ACC_CNT 2
+#endif
+
+static void bcm_vk_update_qstats(struct bcm_vk *vk,
+const char *tag,
+struct bcm_vk_qstats *qstats,
+u32 occupancy)
+{
+   struct bcm_vk_qs_cnts *qcnts = >qcnts;
+
+   if (occupancy > qcnts->max_occ) {
+   qcnts->max_occ = occupancy;
+   if (occupancy > qcnts->max_abs)
+   qcnts->max_abs = occupancy;
+   }
+
+   qcnts->acc_sum += occupancy;
+   if (++qcnts->cnt >= BCM_VK_QSTATS_ACC_CNT) {
+   /* log average and clear counters */
+   dev_dbg(>pdev->dev,
+   "%s[%d]: Max: [%3d/%3d] Acc %d num %d, Aver %d\n",
+   tag, qstats->q_num,
+   qcnts->max_occ, qcnts->max_abs,
+   qcnts->acc_sum,
+   qcnts->cnt,
+   qcnts->acc_sum / qcnts->cnt);
+
+   qcnts->cnt = 0;
+   qcnts->max_occ = 0;
+   qcnts->acc_sum = 0;
+   }
+}
+#endif
+
 /* number of retries when enqueue message fails before returning EAGAIN */
 #define BCM_VK_H2VK_ENQ_RETRY 10
 #define BCM_VK_H2VK_ENQ_RETRY_DELAY_MS 50
@@ -495,8 +533,12 @@ static int bcm_vk_msg_chan_init(struct bcm_vk_msg_chan 
*chan)
 
mutex_init(>msgq_mutex);
spin_lock_init(>pendq_lock);
-   for (i = 0; i < VK_MSGQ_MAX_NR; i++)
+   for (i = 0; i < VK_MSGQ_MAX_NR; i++) {
INIT_LIST_HEAD(>pendq[i]);
+#if defined(CONFIG_BCM_VK_QSTATS)
+   chan->qstats[i].q_num = i;
+#endif
+   }
 
return 0;
 }
@@ -605,6 +647,10 @@ static int bcm_to_v_msg_enqueue(struct bcm_vk *vk, struct 
bcm_vk_wkent *entry)
 
avail = msgq_avail_space(msgq, qinfo);
 
+#if defined(CONFIG_BCM_VK_QSTATS)
+   bcm_vk_update_qstats(vk, "to_v", >qstats[q_num],
+qinfo->q_size - avail);
+#endif
/* if not enough space, return EAGAIN and let app handles it */
retry = 0;
while ((avail < entry->to_v_blks) &&
@@ -818,6 +864,10 @@ s32 bcm_to_h_msg_dequeue(struct bcm_vk *vk)
goto idx_err;
}
 
+#if defined(CONFIG_BCM_VK_QSTATS)
+   bcm_vk_update_qstats(vk, "to_h", >qstats[q_num],
+msgq_occupied(msgq,