From: Chen Guanqiao <chen.chenchacha@foxmail.com>
To: minyard@acm.org, openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Cc: Chen Guanqiao <chen.chenchacha@foxmail.com>
Subject: [PATCH 2/3] ipmi: msghandler: Get the number of message through sysfs
Date: Mon, 28 Mar 2022 00:47:43 +0800 [thread overview]
Message-ID: <tencent_15F1836A9FD7475D1FCED49818CC6778A006@qq.com> (raw)
In-Reply-To: <cover.1648397283.git.chen.chenchacha@foxmail.com>
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@foxmail.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
next prev parent reply other threads:[~2022-03-27 16:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1648397283.git.chen.chenchacha@foxmail.com>
2022-03-27 16:47 ` [PATCH 1/3] ipmi: msghandler: Get the number of user " Chen Guanqiao
2022-03-27 16:47 ` Chen Guanqiao [this message]
2022-03-27 16:47 ` [PATCH 3/3] ipmi: msghandler: add a interface to clean message queue in sysfs Chen Guanqiao
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=tencent_15F1836A9FD7475D1FCED49818CC6778A006@qq.com \
--to=chen.chenchacha@foxmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
/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®