[RESEND] EDAC/device: Add sysfs notification for UE,CE count change

Message ID 20230912212508.4691-1-quic_djaggi@quicinc.com
State New
Headers
Series [RESEND] EDAC/device: Add sysfs notification for UE,CE count change |

Commit Message

Deepti Jaggi Sept. 12, 2023, 9:25 p.m. UTC
  A daemon running in user space collects information on correctable
and uncorrectable errors from EDAC driver by reading corresponding
sysfs entries and takes appropriate action.
This patch adds support for user space daemon to wait on poll() until
the sysfs entries for UE count and CE count change and then read updated
counts instead of continuously monitoring the sysfs entries for
any changes.

Signed-off-by: Deepti Jaggi <quic_djaggi@quicinc.com>
---
 drivers/edac/edac_device.c       | 16 ++++++++++++++++
 drivers/edac/edac_device.h       |  8 ++++++++
 drivers/edac/edac_device_sysfs.c | 20 ++++++++++++++++++++
 3 files changed, 44 insertions(+)
  

Comments

Trilok Soni Sept. 13, 2023, 1:42 a.m. UTC | #1
On 9/12/2023 2:25 PM, Deepti Jaggi wrote:
> A daemon running in user space collects information on correctable
> and uncorrectable errors from EDAC driver by reading corresponding
> sysfs entries and takes appropriate action.
> This patch adds support for user space daemon to wait on poll() until
> the sysfs entries for UE count and CE count change and then read updated
> counts instead of continuously monitoring the sysfs entries for
> any changes.
> 
> Signed-off-by: Deepti Jaggi <quic_djaggi@quicinc.com>

Can we please continue the discussion on the original thread? I don't see need of doing RESEND.
  

Patch

diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index 0689e1510721..d93c45b4beaa 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -555,12 +555,20 @@  void edac_device_handle_ce_count(struct edac_device_ctl_info *edac_dev,
 	if (instance->nr_blocks > 0) {
 		block = instance->blocks + block_nr;
 		block->counters.ce_count += count;
+
+		/* Notify block sysfs attribute change */
+		if (block->kn_ce)
+			sysfs_notify_dirent(block->kn_ce);
 	}
 
 	/* Propagate the count up the 'totals' tree */
 	instance->counters.ce_count += count;
 	edac_dev->counters.ce_count += count;
 
+	/* Notify instance sysfs attribute change */
+	if (instance->kn_ce)
+		sysfs_notify_dirent(instance->kn_ce);
+
 	if (edac_device_get_log_ce(edac_dev))
 		edac_device_printk(edac_dev, KERN_WARNING,
 				   "CE: %s instance: %s block: %s count: %d '%s'\n",
@@ -601,12 +609,20 @@  void edac_device_handle_ue_count(struct edac_device_ctl_info *edac_dev,
 	if (instance->nr_blocks > 0) {
 		block = instance->blocks + block_nr;
 		block->counters.ue_count += count;
+
+		/* Notify block sysfs attribute change */
+		if (block->kn_ue)
+			sysfs_notify_dirent(block->kn_ue);
 	}
 
 	/* Propagate the count up the 'totals' tree */
 	instance->counters.ue_count += count;
 	edac_dev->counters.ue_count += count;
 
+	/* Notify instance sysfs attribute change */
+	if (instance->kn_ue)
+		sysfs_notify_dirent(instance->kn_ue);
+
 	if (edac_device_get_log_ue(edac_dev))
 		edac_device_printk(edac_dev, KERN_EMERG,
 				   "UE: %s instance: %s block: %s count: %d '%s'\n",
diff --git a/drivers/edac/edac_device.h b/drivers/edac/edac_device.h
index 3f44e6b9d387..ae6ed6559c1c 100644
--- a/drivers/edac/edac_device.h
+++ b/drivers/edac/edac_device.h
@@ -127,6 +127,10 @@  struct edac_device_block {
 
 	/* edac sysfs device control */
 	struct kobject kobj;
+
+	/* kern fs node for block ue_count and ce count attributes*/
+	struct kernfs_node *kn_ue;
+	struct kernfs_node *kn_ce;
 };
 
 /* device instance control structure */
@@ -141,6 +145,10 @@  struct edac_device_instance {
 
 	/* edac sysfs device control */
 	struct kobject kobj;
+
+	/* kern fs node for block ue_count and ce count attributes*/
+	struct kernfs_node *kn_ue;
+	struct kernfs_node *kn_ce;
 };
 
 
diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 010c26be5846..51a93a8a0712 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -564,6 +564,13 @@  static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
 	}
 	kobject_uevent(&block->kobj, KOBJ_ADD);
 
+	/*
+	 * Save kernfs pointer for ue count and ce count
+	 * to notify from any context when attributes change
+	 */
+	block->kn_ue = sysfs_get_dirent(block->kobj.sd, "ue_count");
+	block->kn_ce = sysfs_get_dirent(block->kobj.sd, "ce_count");
+
 	return 0;
 
 	/* Error unwind stack */
@@ -596,6 +603,9 @@  static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,
 		}
 	}
 
+	block->kn_ue = NULL;
+	block->kn_ce = NULL;
+
 	/* unregister this block's kobject, SEE:
 	 *	edac_device_ctrl_block_release() callback operation
 	 */
@@ -662,6 +672,13 @@  static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
 	edac_dbg(4, "Registered instance %d '%s' kobject\n",
 		 idx, instance->name);
 
+	/*
+	 * Save kernfs pointer for ue count and ce count
+	 * to notify from any context when attributes change
+	 */
+	instance->kn_ue = sysfs_get_dirent(instance->kobj.sd, "ue_count");
+	instance->kn_ce = sysfs_get_dirent(instance->kobj.sd, "ce_count");
+
 	return 0;
 
 	/* error unwind stack */
@@ -684,6 +701,9 @@  static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,
 
 	instance = &edac_dev->instances[idx];
 
+	instance->kn_ue = NULL;
+	instance->kn_ce = NULL;
+
 	/* unregister all blocks in this instance */
 	for (i = 0; i < instance->nr_blocks; i++)
 		edac_device_delete_block(edac_dev, &instance->blocks[i]);