Print this page
NEX-13937 Improve kstat performance
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-4425 support KSTAT_DATA_STRING in non-virtual named kstats
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
        
@@ -1304,24 +1304,17 @@
 kstat_delete_byname(const char *ks_module, int ks_instance, const char *ks_name)
 {
         kstat_delete_byname_zone(ks_module, ks_instance, ks_name, ALL_ZONES);
 }
 
-/*
- * The sparc V9 versions of these routines can be much cheaper than
- * the poor 32-bit compiler can comprehend, so they're in sparcv9_subr.s.
- * For simplicity, however, we always feed the C versions to lint.
- */
-#if !defined(__sparc) || defined(lint) || defined(__lint)
-
 void
-kstat_waitq_enter(kstat_io_t *kiop)
+kstat_waitq_enter_time(kstat_io_t *kiop, const hrtime_t new)
 {
-        hrtime_t new, delta;
+        hrtime_t delta;
         ulong_t wcnt;
 
-        new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
         delta = new - kiop->wlastupdate;
         kiop->wlastupdate = new;
         wcnt = kiop->wcnt++;
         if (wcnt != 0) {
                 kiop->wlentime += delta * wcnt;
@@ -1328,31 +1321,31 @@
                 kiop->wtime += delta;
         }
 }
 
 void
-kstat_waitq_exit(kstat_io_t *kiop)
+kstat_waitq_exit_time(kstat_io_t *kiop, const hrtime_t new)
 {
-        hrtime_t new, delta;
+        hrtime_t delta;
         ulong_t wcnt;
 
-        new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
         delta = new - kiop->wlastupdate;
         kiop->wlastupdate = new;
         wcnt = kiop->wcnt--;
         ASSERT((int)wcnt > 0);
         kiop->wlentime += delta * wcnt;
         kiop->wtime += delta;
 }
 
 void
-kstat_runq_enter(kstat_io_t *kiop)
+kstat_runq_enter_time(kstat_io_t *kiop, const hrtime_t new)
 {
-        hrtime_t new, delta;
+        hrtime_t delta;
         ulong_t rcnt;
 
-        new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
         delta = new - kiop->rlastupdate;
         kiop->rlastupdate = new;
         rcnt = kiop->rcnt++;
         if (rcnt != 0) {
                 kiop->rlentime += delta * rcnt;
@@ -1359,70 +1352,71 @@
                 kiop->rtime += delta;
         }
 }
 
 void
-kstat_runq_exit(kstat_io_t *kiop)
+kstat_runq_exit_time(kstat_io_t *kiop, const hrtime_t new)
 {
-        hrtime_t new, delta;
+        hrtime_t delta;
         ulong_t rcnt;
 
-        new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
         delta = new - kiop->rlastupdate;
         kiop->rlastupdate = new;
         rcnt = kiop->rcnt--;
         ASSERT((int)rcnt > 0);
         kiop->rlentime += delta * rcnt;
         kiop->rtime += delta;
 }
 
+/*
+ * The sparc V9 versions of these routines can be much cheaper than
+ * the poor 32-bit compiler can comprehend, so they're in sparcv9_subr.s.
+ * For simplicity, however, we always feed the C versions to lint.
+ */
+#if !defined(__sparc) || defined(lint) || defined(__lint)
+
 void
-kstat_waitq_to_runq(kstat_io_t *kiop)
+kstat_waitq_enter(kstat_io_t *kiop)
 {
-        hrtime_t new, delta;
-        ulong_t wcnt, rcnt;
+        kstat_waitq_enter_time(kiop, gethrtime_unscaled());
+}
 
-        new = gethrtime_unscaled();
+void
+kstat_waitq_exit(kstat_io_t *kiop)
+{
+        kstat_waitq_exit_time(kiop, gethrtime_unscaled());
+}
 
-        delta = new - kiop->wlastupdate;
-        kiop->wlastupdate = new;
-        wcnt = kiop->wcnt--;
-        ASSERT((int)wcnt > 0);
-        kiop->wlentime += delta * wcnt;
-        kiop->wtime += delta;
+void
+kstat_runq_enter(kstat_io_t *kiop)
+{
+        kstat_runq_enter_time(kiop, gethrtime_unscaled());
+}
 
-        delta = new - kiop->rlastupdate;
-        kiop->rlastupdate = new;
-        rcnt = kiop->rcnt++;
-        if (rcnt != 0) {
-                kiop->rlentime += delta * rcnt;
-                kiop->rtime += delta;
-        }
+void
+kstat_runq_exit(kstat_io_t *kiop)
+{
+        kstat_runq_exit_time(kiop, gethrtime_unscaled());
 }
 
 void
-kstat_runq_back_to_waitq(kstat_io_t *kiop)
+kstat_waitq_to_runq(kstat_io_t *kiop)
 {
-        hrtime_t new, delta;
-        ulong_t wcnt, rcnt;
+        hrtime_t new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
+        kstat_waitq_exit_time(kiop, new);
+        kstat_runq_enter_time(kiop, new);
+}
 
-        new = gethrtime_unscaled();
-
-        delta = new - kiop->rlastupdate;
-        kiop->rlastupdate = new;
-        rcnt = kiop->rcnt--;
-        ASSERT((int)rcnt > 0);
-        kiop->rlentime += delta * rcnt;
-        kiop->rtime += delta;
-
-        delta = new - kiop->wlastupdate;
-        kiop->wlastupdate = new;
-        wcnt = kiop->wcnt++;
-        if (wcnt != 0) {
-                kiop->wlentime += delta * wcnt;
-                kiop->wtime += delta;
-        }
+void
+kstat_runq_back_to_waitq(kstat_io_t *kiop)
+{
+        hrtime_t new = gethrtime_unscaled();
+        ASSERT(kiop != NULL);
+        kstat_runq_exit_time(kiop, new);
+        kstat_waitq_enter_time(kiop, new);
 }
 
 #endif
 
 void