Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Teach module infrastructure to attach any static ev...



details:   https://anonhg.NetBSD.org/src/rev/d2eb28663476
branches:  trunk
changeset: 745092:d2eb28663476
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Feb 22 19:51:57 2020 +0000

description:
Teach module infrastructure to attach any static evcnts that might be
defined in a module, similar to the automatic invocation of sysctl(9)
setup functions.  As requested by riastradh@

diffstat:

 sys/kern/kern_module.c |  76 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 72 insertions(+), 4 deletions(-)

diffs (122 lines):

diff -r a878b7687497 -r d2eb28663476 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Sat Feb 22 19:49:11 2020 +0000
+++ b/sys/kern/kern_module.c    Sat Feb 22 19:51:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_module.c,v 1.146 2020/01/22 22:39:27 pgoyette Exp $       */
+/*     $NetBSD: kern_module.c,v 1.147 2020/02/22 19:51:57 pgoyette Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.146 2020/01/22 22:39:27 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.147 2020/02/22 19:51:57 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -56,6 +56,7 @@
 #include <sys/kthread.h>
 #include <sys/sysctl.h>
 #include <sys/lock.h>
+#include <sys/evcnt.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -983,8 +984,72 @@
                        ls_funcp++;
                }
        }
-       else
-               error = 0;      /* no setup funcs registered */
+}
+
+/*
+ * module_load_evcnt
+ *
+ * Check to see if a non-builtin module has any static evcnt's defined;
+ * if so, attach them.
+ */
+
+static void
+module_load_evcnt(module_t *mod)
+{
+       struct evcnt * const *ls_evp;
+       void *ls_start;
+       size_t ls_size, count;
+       int error;
+
+       /*
+        * Built-in modules' static evcnt stuff will be handled
+        * automatically as part of general kernel initialization
+        */
+       if (mod->mod_source == MODULE_SOURCE_KERNEL)
+               return;
+
+       error = kobj_find_section(mod->mod_kobj, "link_set_evcnts",
+           &ls_start, &ls_size);
+       if (error == 0) {
+               count = ls_size / sizeof(*ls_evp);
+               ls_evp = ls_start;
+               while (count--) {
+                       evcnt_attach_static(*ls_evp++);
+               }
+       }
+}
+
+/*
+ * module_unload_evcnt
+ *
+ * Check to see if a non-builtin module has any static evcnt's defined;
+ * if so, detach them.
+ */
+
+static void
+module_unload_evcnt(module_t *mod)
+{
+       struct evcnt * const *ls_evp;
+       void *ls_start;
+       size_t ls_size, count;
+       int error;
+
+       /*
+        * Built-in modules' static evcnt stuff will be handled
+        * automatically as part of general kernel initialization
+        */
+       if (mod->mod_source == MODULE_SOURCE_KERNEL)
+               return;
+
+       error = kobj_find_section(mod->mod_kobj, "link_set_evcnts",
+           &ls_start, &ls_size);
+       if (error == 0) {
+               count = ls_size / sizeof(*ls_evp);
+               ls_evp = (void *)((char *)ls_start + ls_size);
+               while (count--) {
+                       evcnt_detach(*--ls_evp);
+               }
+       }
 }
 
 /*
@@ -1307,6 +1372,7 @@
        }
 
        module_load_sysctl(mod);        /* Set-up module's sysctl if any */
+       module_load_evcnt(mod);         /* Attach any static evcnt needed */
 
        /*
         * Good, the module loaded successfully.  Put it onto the
@@ -1395,10 +1461,12 @@
        if (mod->mod_sysctllog) {
                sysctl_teardown(&mod->mod_sysctllog);
        }
+       module_unload_evcnt(mod);
        error = (*mod->mod_info->mi_modcmd)(MODULE_CMD_FINI, NULL);
        module_active = prev_active;
        if (error != 0) {
                module_load_sysctl(mod);        /* re-enable sysctl stuff */
+               module_load_evcnt(mod);         /* and reenable evcnts */
                module_print("cannot unload module `%s' error=%d", name,
                    error);
                return error;



Home | Main Index | Thread Index | Old Index