pass: resmon: Add support of multiple uevent subsystem type by one resource monitor 66/262366/2
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 9 Aug 2021 04:18:51 +0000 (13:18 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 11 Aug 2021 06:03:02 +0000 (15:03 +0900)
The an 'struct resmon_ops' instance has supported only one uevent subsystem type.
But, even if subsystems in linux kernel are different, sometimes treats
the same raw data like thermal. For example, both thermal and power_supply
subsystems provides the current temperature to user-space via uevent and sysfs
node. So that Add support of multiple uevent subsystem type by one resource monitor
instance.

Change-Id: I2ad7f25f1a894539ea1e460c4faeb5334acc50b5
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-resmon-internal.h
src/pass/pass-resmon-source.c
src/pass/pass-resmon.c

index 0b3563f..80a4e79 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <libudev.h>
 
+#include "pass.h"
+
 /**
  * @brief      Represents the type of resource-monitor.
  */
@@ -59,15 +61,21 @@ struct resmon_ops {
        int (*uevent_handler)(struct resmon *monitor, void *result,
                                struct udev_device *dev);
        /**
-        * Instance of uevent subsystem. It will be used for only uevent-based
+        * List of uevent subsystem name. It will be used for only uevent-based
         * resource monitor.
         */
-       const char *uevent_subsystem;
+       const char *uevent_subsystem[BUFF_MAX];
+       /**
+        * List of uevent device type name. It will be used for only uevent-based
+        * resource monitor.
+        */
+       const char *uevent_devtype[BUFF_MAX];
+
        /**
-        * Instance of uevent device type. It will be used for only uevent-based
+        * Number of uevent type. It will be used for only uevent-based
         * resource monitor.
         */
-       const char *uevent_devtype;
+       const int number_of_uevent;
 };
 
 /**
index 0248fb8..0cd45b4 100644 (file)
@@ -314,8 +314,13 @@ struct resmon_ops thermal_src_ops = {
        .exit = resmon_thermal_exit,
        .timer_handler = resmon_thermal_timer_handler,
        .uevent_handler = resmon_thermal_uevent_handler,
-       .uevent_subsystem = "thermal",
-       .uevent_devtype = NULL,
+       .uevent_subsystem =  {
+               "thermal",
+       },
+       .uevent_devtype =  {
+               NULL,
+       },
+       .number_of_uevent = 1,
 };
 
 /**
@@ -327,8 +332,13 @@ struct resmon_ops cpuhp_src_ops = {
        .exit = resmon_cpuhp_exit,
        .timer_handler = resmon_cpuhp_timer_handler,
        .uevent_handler = NULL,
-       .uevent_subsystem = NULL,
-       .uevent_devtype = NULL,
+       .uevent_subsystem =  {
+               NULL,
+       },
+       .uevent_devtype =  {
+               NULL,
+       },
+       .number_of_uevent = 0,
 };
 
 /**
index aa4852e..570248a 100644 (file)
@@ -512,6 +512,7 @@ static int resmon_uevent_add(struct resmon *monitor)
        guint gfd;
        int ret;
        int fd;
+       int i;
 
        /* Initialize the udev-monitor instance and set buffer size */
        udev_monitor = udev_monitor_new_from_netlink(g_udev, "kernel");
@@ -523,9 +524,9 @@ static int resmon_uevent_add(struct resmon *monitor)
        }
 
        /*
-        * At least, either uevent_subsystem or uevent_devtype should be not NULL
+        * Number of uevent subsystem must be more than 0 at least.
         */
-       if (!monitor->ops->uevent_subsystem && !monitor->ops->uevent_devtype) {
+       if (monitor->ops->number_of_uevent <= 0) {
                _E("failed to add filter due to subsystem/devtype are NULL " \
                                "(res_name:%s, src_type: 0x%x)\n",
                                res->config_data.res_name, monitor->src_type);
@@ -534,24 +535,30 @@ static int resmon_uevent_add(struct resmon *monitor)
        }
 
        /* Update the kernel's subsystem and devtype for filtering */
-       ret = udev_monitor_filter_add_match_subsystem_devtype(
-                                       udev_monitor,
-                                       monitor->ops->uevent_subsystem,
-                                       monitor->ops->uevent_devtype);
-       if (ret < 0) {
-               _E("failed to add filter with subsystem and devtype " \
-                               "(res_name:%s, src_type: 0x%x)\n",
-                               res->config_data.res_name, monitor->src_type);
-               goto err_udev_monitor;
+       for (i = 0; i < monitor->ops->number_of_uevent; i++) {
+               ret = udev_monitor_filter_add_match_subsystem_devtype(
+                                               udev_monitor,
+                                               monitor->ops->uevent_subsystem[i],
+                                               monitor->ops->uevent_devtype[i]);
+               if (ret < 0) {
+                       _E("failed to add filter with subsystem(%s)/devtype(%s) " \
+                                       "(res_name:%s, src_type: 0x%x)\n",
+                                       monitor->ops->uevent_subsystem[i],
+                                       monitor->ops->uevent_devtype[i],
+                                       res->config_data.res_name, monitor->src_type);
+                       goto err_udev_monitor;
+               }
        }
 
        ret = udev_monitor_filter_update(udev_monitor);
        if (ret < 0) {
-               _E("failed to update filter with subsystem(%s) & devtype(%s) " \
+               for (i = 0; i < monitor->ops->number_of_uevent; i++) {
+                       _E("failed to update filter with subsystem(%s)/devtype(%s) " \
                                "(res_name:%s, src_type: 0x%x)\n",
-                               monitor->ops->uevent_subsystem,
-                               monitor->ops->uevent_devtype,
+                               monitor->ops->uevent_subsystem[i],
+                               monitor->ops->uevent_devtype[i],
                                res->config_data.res_name, monitor->src_type);
+               }
                goto err_udev_monitor;
        }