mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v2 3/4] ipmi: msghandler: Get the number of users and messages through sysfs
Date: Wed, 30 Mar 2022 00:12:41 +0800	[thread overview]
Message-ID: <tencent_18DFCE075E9FCD148D18C7676CE0C4836306@qq.com> (raw)
In-Reply-To: <20220329161242.76457-1-chen.chenchacha@foxmail.com>

The administrator reads the user_count and msg_count file
corresponding the ipmi device, ipmi traverse all intf, and count
the number of users and messages.

Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
 drivers/char/ipmi/ipmi_msghandler.c | 71 +++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 80ab88702c5f..a188dc7e7135 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -922,6 +922,19 @@ unsigned int ipmi_addr_length(int addr_type)
 }
 EXPORT_SYMBOL(ipmi_addr_length);

+static unsigned int intf_user_count(struct ipmi_smi *intf)
+{
+	struct ipmi_user *user;
+	int index, count = 0;
+
+	index = srcu_read_lock(&intf->users_srcu);
+	list_for_each_entry_rcu(user, &intf->users, link)
+		count++;
+	srcu_read_unlock(&intf->users_srcu, index);
+
+	return count;
+}
+
 static void intf_msg_count(struct ipmi_smi *intf,
 			   unsigned int *hp_count, unsigned int *count)
 {
@@ -2760,6 +2773,42 @@ static int bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
 	return __bmc_get_device_id(intf, bmc, id, guid_set, guid, -1);
 }

+static unsigned int get_user_count(void)
+{
+	struct ipmi_smi *intf;
+	int index;
+	unsigned int count = 0;
+
+	index = srcu_read_lock(&ipmi_interfaces_srcu);
+	list_for_each_entry_rcu(intf, &ipmi_interfaces, link)
+		count += intf_user_count(intf);
+	srcu_read_unlock(&ipmi_interfaces_srcu, index);
+
+	return count;
+}
+
+static void get_msg_count(unsigned int *hp_count, unsigned int *count)
+{
+	struct ipmi_smi *intf;
+	int index;
+
+	*hp_count = 0;
+	*count = 0;
+
+	index = srcu_read_lock(&ipmi_interfaces_srcu);
+	list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+		int hp_msg_count = 0, msg_count = 0;
+
+		rcu_read_lock();
+		intf_msg_count(intf, &hp_msg_count, &msg_count);
+		rcu_read_unlock();
+
+		*hp_count += hp_msg_count;
+		*count += msg_count;
+	}
+	srcu_read_unlock(&ipmi_interfaces_srcu, index);
+}
+
 static ssize_t device_id_show(struct device *dev,
 			      struct device_attribute *attr,
 			      char *buf)
@@ -2929,6 +2978,26 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(guid);

+static ssize_t user_count_show(struct device *dev, struct device_attribute *attr,
+			       char *buf)
+{
+	unsigned int user_count = get_user_count();
+
+	return snprintf(buf, 20, "%u\n", user_count);
+}
+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,
@@ -2940,6 +3009,8 @@ static struct attribute *bmc_dev_attrs[] = {
 	&dev_attr_product_id.attr,
 	&dev_attr_aux_firmware_revision.attr,
 	&dev_attr_guid.attr,
+	&dev_attr_user_count.attr,
+	&dev_attr_msg_count.attr,
 	NULL
 };

--
2.25.1


  parent reply	other threads:[~2022-03-29 16:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220329161242.76457-1-chen.chenchacha@foxmail.com>
2022-03-29 16:12 ` [PATCH v2 1/4] ipmi: msghandler: Add a limit for the number of users Chen Guanqiao
2022-03-29 16:12 ` [PATCH v2 2/4] ipmi: msghandler: Add a limit for the number of messages Chen Guanqiao
2022-03-29 16:12 ` Chen Guanqiao [this message]
2022-03-29 16:12 ` [PATCH v2 4/4] 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_18DFCE075E9FCD148D18C7676CE0C4836306@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®