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>


1289 
1290 void
1291 kstat_delete_byname_zone(const char *ks_module, int ks_instance,
1292     const char *ks_name, zoneid_t ks_zoneid)
1293 {
1294         kstat_t *ksp;
1295 
1296         ksp = kstat_hold_byname(ks_module, ks_instance, ks_name, ks_zoneid);
1297         if (ksp != NULL) {
1298                 kstat_rele(ksp);
1299                 kstat_delete(ksp);
1300         }
1301 }
1302 
1303 void
1304 kstat_delete_byname(const char *ks_module, int ks_instance, const char *ks_name)
1305 {
1306         kstat_delete_byname_zone(ks_module, ks_instance, ks_name, ALL_ZONES);
1307 }
1308 
1309 /*
1310  * The sparc V9 versions of these routines can be much cheaper than
1311  * the poor 32-bit compiler can comprehend, so they're in sparcv9_subr.s.
1312  * For simplicity, however, we always feed the C versions to lint.
1313  */
1314 #if !defined(__sparc) || defined(lint) || defined(__lint)
1315 
1316 void
1317 kstat_waitq_enter(kstat_io_t *kiop)
1318 {
1319         hrtime_t new, delta;
1320         ulong_t wcnt;
1321 
1322         new = gethrtime_unscaled();
1323         delta = new - kiop->wlastupdate;
1324         kiop->wlastupdate = new;
1325         wcnt = kiop->wcnt++;
1326         if (wcnt != 0) {
1327                 kiop->wlentime += delta * wcnt;
1328                 kiop->wtime += delta;
1329         }
1330 }
1331 
1332 void
1333 kstat_waitq_exit(kstat_io_t *kiop)
1334 {
1335         hrtime_t new, delta;
1336         ulong_t wcnt;
1337 
1338         new = gethrtime_unscaled();
1339         delta = new - kiop->wlastupdate;
1340         kiop->wlastupdate = new;
1341         wcnt = kiop->wcnt--;
1342         ASSERT((int)wcnt > 0);
1343         kiop->wlentime += delta * wcnt;
1344         kiop->wtime += delta;
1345 }
1346 
1347 void
1348 kstat_runq_enter(kstat_io_t *kiop)
1349 {
1350         hrtime_t new, delta;
1351         ulong_t rcnt;
1352 
1353         new = gethrtime_unscaled();
1354         delta = new - kiop->rlastupdate;
1355         kiop->rlastupdate = new;
1356         rcnt = kiop->rcnt++;
1357         if (rcnt != 0) {
1358                 kiop->rlentime += delta * rcnt;
1359                 kiop->rtime += delta;
1360         }
1361 }
1362 
1363 void
1364 kstat_runq_exit(kstat_io_t *kiop)
1365 {
1366         hrtime_t new, delta;
1367         ulong_t rcnt;
1368 
1369         new = gethrtime_unscaled();
1370         delta = new - kiop->rlastupdate;
1371         kiop->rlastupdate = new;
1372         rcnt = kiop->rcnt--;
1373         ASSERT((int)rcnt > 0);
1374         kiop->rlentime += delta * rcnt;
1375         kiop->rtime += delta;
1376 }
1377 







1378 void
1379 kstat_waitq_to_runq(kstat_io_t *kiop)
1380 {
1381         hrtime_t new, delta;
1382         ulong_t wcnt, rcnt;
1383 
1384         new = gethrtime_unscaled();




1385 
1386         delta = new - kiop->wlastupdate;
1387         kiop->wlastupdate = new;
1388         wcnt = kiop->wcnt--;
1389         ASSERT((int)wcnt > 0);
1390         kiop->wlentime += delta * wcnt;
1391         kiop->wtime += delta;
1392 
1393         delta = new - kiop->rlastupdate;
1394         kiop->rlastupdate = new;
1395         rcnt = kiop->rcnt++;
1396         if (rcnt != 0) {
1397                 kiop->rlentime += delta * rcnt;
1398                 kiop->rtime += delta;
1399         }
1400 }
1401 
1402 void
1403 kstat_runq_back_to_waitq(kstat_io_t *kiop)
1404 {
1405         hrtime_t new, delta;
1406         ulong_t wcnt, rcnt;



1407 
1408         new = gethrtime_unscaled();
1409 
1410         delta = new - kiop->rlastupdate;
1411         kiop->rlastupdate = new;
1412         rcnt = kiop->rcnt--;
1413         ASSERT((int)rcnt > 0);
1414         kiop->rlentime += delta * rcnt;
1415         kiop->rtime += delta;
1416 
1417         delta = new - kiop->wlastupdate;
1418         kiop->wlastupdate = new;
1419         wcnt = kiop->wcnt++;
1420         if (wcnt != 0) {
1421                 kiop->wlentime += delta * wcnt;
1422                 kiop->wtime += delta;
1423         }
1424 }
1425 
1426 #endif
1427 
1428 void
1429 kstat_timer_start(kstat_timer_t *ktp)
1430 {
1431         ktp->start_time = gethrtime();
1432 }
1433 
1434 void
1435 kstat_timer_stop(kstat_timer_t *ktp)
1436 {
1437         hrtime_t        etime;
1438         u_longlong_t    num_events;
1439 
1440         ktp->stop_time = etime = gethrtime();
1441         etime -= ktp->start_time;
1442         num_events = ktp->num_events;
1443         if (etime < ktp->min_time || num_events == 0)


1289 
1290 void
1291 kstat_delete_byname_zone(const char *ks_module, int ks_instance,
1292     const char *ks_name, zoneid_t ks_zoneid)
1293 {
1294         kstat_t *ksp;
1295 
1296         ksp = kstat_hold_byname(ks_module, ks_instance, ks_name, ks_zoneid);
1297         if (ksp != NULL) {
1298                 kstat_rele(ksp);
1299                 kstat_delete(ksp);
1300         }
1301 }
1302 
1303 void
1304 kstat_delete_byname(const char *ks_module, int ks_instance, const char *ks_name)
1305 {
1306         kstat_delete_byname_zone(ks_module, ks_instance, ks_name, ALL_ZONES);
1307 }
1308 







1309 void
1310 kstat_waitq_enter_time(kstat_io_t *kiop, const hrtime_t new)
1311 {
1312         hrtime_t delta;
1313         ulong_t wcnt;
1314 
1315         ASSERT(kiop != NULL);
1316         delta = new - kiop->wlastupdate;
1317         kiop->wlastupdate = new;
1318         wcnt = kiop->wcnt++;
1319         if (wcnt != 0) {
1320                 kiop->wlentime += delta * wcnt;
1321                 kiop->wtime += delta;
1322         }
1323 }
1324 
1325 void
1326 kstat_waitq_exit_time(kstat_io_t *kiop, const hrtime_t new)
1327 {
1328         hrtime_t delta;
1329         ulong_t wcnt;
1330 
1331         ASSERT(kiop != NULL);
1332         delta = new - kiop->wlastupdate;
1333         kiop->wlastupdate = new;
1334         wcnt = kiop->wcnt--;
1335         ASSERT((int)wcnt > 0);
1336         kiop->wlentime += delta * wcnt;
1337         kiop->wtime += delta;
1338 }
1339 
1340 void
1341 kstat_runq_enter_time(kstat_io_t *kiop, const hrtime_t new)
1342 {
1343         hrtime_t delta;
1344         ulong_t rcnt;
1345 
1346         ASSERT(kiop != NULL);
1347         delta = new - kiop->rlastupdate;
1348         kiop->rlastupdate = new;
1349         rcnt = kiop->rcnt++;
1350         if (rcnt != 0) {
1351                 kiop->rlentime += delta * rcnt;
1352                 kiop->rtime += delta;
1353         }
1354 }
1355 
1356 void
1357 kstat_runq_exit_time(kstat_io_t *kiop, const hrtime_t new)
1358 {
1359         hrtime_t delta;
1360         ulong_t rcnt;
1361 
1362         ASSERT(kiop != NULL);
1363         delta = new - kiop->rlastupdate;
1364         kiop->rlastupdate = new;
1365         rcnt = kiop->rcnt--;
1366         ASSERT((int)rcnt > 0);
1367         kiop->rlentime += delta * rcnt;
1368         kiop->rtime += delta;
1369 }
1370 
1371 /*
1372  * The sparc V9 versions of these routines can be much cheaper than
1373  * the poor 32-bit compiler can comprehend, so they're in sparcv9_subr.s.
1374  * For simplicity, however, we always feed the C versions to lint.
1375  */
1376 #if !defined(__sparc) || defined(lint) || defined(__lint)
1377 
1378 void
1379 kstat_waitq_enter(kstat_io_t *kiop)
1380 {
1381         kstat_waitq_enter_time(kiop, gethrtime_unscaled());
1382 }
1383 
1384 void
1385 kstat_waitq_exit(kstat_io_t *kiop)
1386 {
1387         kstat_waitq_exit_time(kiop, gethrtime_unscaled());
1388 }
1389 
1390 void
1391 kstat_runq_enter(kstat_io_t *kiop)
1392 {
1393         kstat_runq_enter_time(kiop, gethrtime_unscaled());
1394 }

1395 
1396 void
1397 kstat_runq_exit(kstat_io_t *kiop)
1398 {
1399         kstat_runq_exit_time(kiop, gethrtime_unscaled());



1400 }
1401 
1402 void
1403 kstat_waitq_to_runq(kstat_io_t *kiop)
1404 {
1405         hrtime_t new = gethrtime_unscaled();
1406         ASSERT(kiop != NULL);
1407         kstat_waitq_exit_time(kiop, new);
1408         kstat_runq_enter_time(kiop, new);
1409 }
1410 
1411 void
1412 kstat_runq_back_to_waitq(kstat_io_t *kiop)
1413 {
1414         hrtime_t new = gethrtime_unscaled();
1415         ASSERT(kiop != NULL);
1416         kstat_runq_exit_time(kiop, new);
1417         kstat_waitq_enter_time(kiop, new);









1418 }
1419 
1420 #endif
1421 
1422 void
1423 kstat_timer_start(kstat_timer_t *ktp)
1424 {
1425         ktp->start_time = gethrtime();
1426 }
1427 
1428 void
1429 kstat_timer_stop(kstat_timer_t *ktp)
1430 {
1431         hrtime_t        etime;
1432         u_longlong_t    num_events;
1433 
1434         ktp->stop_time = etime = gethrtime();
1435         etime -= ktp->start_time;
1436         num_events = ktp->num_events;
1437         if (etime < ktp->min_time || num_events == 0)