[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tencent_15F1836A9FD7475D1FCED49818CC6778A006@qq.com>
Date: Mon, 28 Mar 2022 00:47:43 +0800
From: Chen Guanqiao <chen.chenchacha@...mail.com>
To: minyard@....org, openipmi-developer@...ts.sourceforge.net,
linux-kernel@...r.kernel.org
Cc: Chen Guanqiao <chen.chenchacha@...mail.com>
Subject: [PATCH 2/3] ipmi: msghandler: Get the number of message through sysfs
Reads the message_count file corresponding the ipmi device, ipmi traverse all
intf, and count the number of message and high priority message.
Signed-off-by: Chen Guanqiao <chen.chenchacha@...mail.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 44 +++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e14beb51cae4..0238be81c435 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2729,6 +2729,38 @@ static unsigned int get_user_count(void)
return total_count;
}
+static void get_msg_count(unsigned int *hp_count, unsigned int *count)
+{
+ struct ipmi_smi *intf;
+ int index;
+ int hp_msg_count = 0, msg_count = 0;
+
+ index = srcu_read_lock(&ipmi_interfaces_srcu);
+ list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+ struct ipmi_smi_msg *msg;
+ unsigned long flags;
+ int run_to_completion = intf->run_to_completion;
+
+ rcu_read_lock();
+ if (!run_to_completion)
+ spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
+ if (!intf->in_shutdown) {
+ list_for_each_entry(msg, &intf->hp_xmit_msgs, link)
+ hp_msg_count++;
+
+ list_for_each_entry(msg, &intf->xmit_msgs, link)
+ msg_count++;
+ }
+ if (!run_to_completion)
+ spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
+ rcu_read_unlock();
+ }
+ srcu_read_unlock(&ipmi_interfaces_srcu, index);
+
+ *hp_count = msg_count;
+ *count = hp_msg_count;
+}
+
static ssize_t device_id_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -2907,6 +2939,17 @@ static ssize_t user_count_show(struct device *dev,
}
static DEVICE_ATTR_ADMIN_RO(user_count);
+static ssize_t msg_count_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ unsigned int hp_count, count;
+
+ get_msg_count(&hp_count, &count);
+
+ return snprintf(buf, 40, "hp msg:%u, msg:%u\n", hp_count, count);
+}
+static DEVICE_ATTR_ADMIN_RO(msg_count);
+
static struct attribute *bmc_dev_attrs[] = {
&dev_attr_device_id.attr,
&dev_attr_provides_device_sdrs.attr,
@@ -2919,6 +2962,7 @@ static struct attribute *bmc_dev_attrs[] = {
&dev_attr_aux_firmware_revision.attr,
&dev_attr_guid.attr,
&dev_attr_user_count.attr,
+ &dev_attr_msg_count.attr,
NULL
};
--
2.25.1
Powered by blists - more mailing lists