Print this page
codereview and testing fixes.
6558 kstat: desire type for timestamps


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.

  26  */
  27 
  28 #ifndef _SYS_KSTAT_H
  29 #define _SYS_KSTAT_H
  30 
  31 /*
  32  * Definition of general kernel statistics structures and /dev/kstat ioctls
  33  */
  34 
  35 #include <sys/types.h>
  36 #include <sys/time.h>
  37 
  38 #ifdef  __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 typedef int     kid_t;          /* unique kstat id */
  43 
  44 /*
  45  * Kernel statistics driver (/dev/kstat) ioctls


 465                         } addr;
 466                         uint32_t        len;    /* # bytes for strlen + '\0' */
 467                 } str;
 468 /*
 469  * The int64_t and uint64_t types are not valid for a maximally conformant
 470  * 32-bit compilation environment (cc -Xc) using compilers prior to the
 471  * introduction of C99 conforming compiler (reference ISO/IEC 9899:1990).
 472  * In these cases, the visibility of i64 and ui64 is only permitted for
 473  * 64-bit compilation environments or 32-bit non-maximally conformant
 474  * C89 or C90 ANSI C compilation environments (cc -Xt and cc -Xa). In the
 475  * C99 ANSI C compilation environment, the long long type is supported.
 476  * The _INT64_TYPE is defined by the implementation (see sys/int_types.h).
 477  */
 478 #if defined(_INT64_TYPE)
 479                 int64_t         i64;
 480                 uint64_t        ui64;
 481 #endif
 482                 long            l;
 483                 ulong_t         ul;
 484 


 485                 /* These structure members are obsolete */
 486 
 487                 longlong_t      ll;
 488                 u_longlong_t    ull;
 489                 float           f;
 490                 double          d;
 491         } value;                        /* value of counter */
 492 } kstat_named_t;
 493 
 494 #define KSTAT_DATA_CHAR         0
 495 #define KSTAT_DATA_INT32        1
 496 #define KSTAT_DATA_UINT32       2
 497 #define KSTAT_DATA_INT64        3
 498 #define KSTAT_DATA_UINT64       4
 499 
 500 #if !defined(_LP64)
 501 #define KSTAT_DATA_LONG         KSTAT_DATA_INT32
 502 #define KSTAT_DATA_ULONG        KSTAT_DATA_UINT32
 503 #else
 504 #if !defined(_KERNEL)


 511 #endif  /* !_LP64 */
 512 
 513 /*
 514  * Statistics exporting named kstats with long strings (KSTAT_DATA_STRING)
 515  * may not make the assumption that ks_data_size is equal to (ks_ndata * sizeof
 516  * (kstat_named_t)).  ks_data_size in these cases is equal to the sum of the
 517  * amount of space required to store the strings (ie, the sum of
 518  * KSTAT_NAMED_STR_BUFLEN() for all KSTAT_DATA_STRING statistics) plus the
 519  * space required to store the kstat_named_t's.
 520  *
 521  * The default update routine will update ks_data_size automatically for
 522  * variable-length kstats containing long strings (using the default update
 523  * routine only makes sense if the string is the only thing that is changing
 524  * in size, and ks_ndata is constant).  Fixed-length kstats containing long
 525  * strings must explicitly change ks_data_size (after creation but before
 526  * initialization) to reflect the correct amount of space required for the
 527  * long strings and the kstat_named_t's.
 528  */
 529 #define KSTAT_DATA_STRING       9
 530 





 531 /* These types are obsolete */
 532 
 533 #define KSTAT_DATA_LONGLONG     KSTAT_DATA_INT64
 534 #define KSTAT_DATA_ULONGLONG    KSTAT_DATA_UINT64
 535 #define KSTAT_DATA_FLOAT        5
 536 #define KSTAT_DATA_DOUBLE       6
 537 
 538 #define KSTAT_NAMED_PTR(kptr)   ((kstat_named_t *)(kptr)->ks_data)
 539 
 540 /*
 541  * Retrieve the pointer of the string contained in the given named kstat.
 542  */
 543 #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.str.addr.ptr)
 544 
 545 /*
 546  * Retrieve the length of the buffer required to store the string in the given
 547  * named kstat.
 548  */
 549 #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.str.len)
 550 




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  26  * Copyright 2016 Garrett D'Amore
  27  */
  28 
  29 #ifndef _SYS_KSTAT_H
  30 #define _SYS_KSTAT_H
  31 
  32 /*
  33  * Definition of general kernel statistics structures and /dev/kstat ioctls
  34  */
  35 
  36 #include <sys/types.h>
  37 #include <sys/time.h>
  38 
  39 #ifdef  __cplusplus
  40 extern "C" {
  41 #endif
  42 
  43 typedef int     kid_t;          /* unique kstat id */
  44 
  45 /*
  46  * Kernel statistics driver (/dev/kstat) ioctls


 466                         } addr;
 467                         uint32_t        len;    /* # bytes for strlen + '\0' */
 468                 } str;
 469 /*
 470  * The int64_t and uint64_t types are not valid for a maximally conformant
 471  * 32-bit compilation environment (cc -Xc) using compilers prior to the
 472  * introduction of C99 conforming compiler (reference ISO/IEC 9899:1990).
 473  * In these cases, the visibility of i64 and ui64 is only permitted for
 474  * 64-bit compilation environments or 32-bit non-maximally conformant
 475  * C89 or C90 ANSI C compilation environments (cc -Xt and cc -Xa). In the
 476  * C99 ANSI C compilation environment, the long long type is supported.
 477  * The _INT64_TYPE is defined by the implementation (see sys/int_types.h).
 478  */
 479 #if defined(_INT64_TYPE)
 480                 int64_t         i64;
 481                 uint64_t        ui64;
 482 #endif
 483                 long            l;
 484                 ulong_t         ul;
 485 
 486                 hrtime_t        t;
 487 
 488                 /* These structure members are obsolete */
 489 
 490                 longlong_t      ll;
 491                 u_longlong_t    ull;
 492                 float           f;
 493                 double          d;
 494         } value;                        /* value of counter */
 495 } kstat_named_t;
 496 
 497 #define KSTAT_DATA_CHAR         0
 498 #define KSTAT_DATA_INT32        1
 499 #define KSTAT_DATA_UINT32       2
 500 #define KSTAT_DATA_INT64        3
 501 #define KSTAT_DATA_UINT64       4
 502 
 503 #if !defined(_LP64)
 504 #define KSTAT_DATA_LONG         KSTAT_DATA_INT32
 505 #define KSTAT_DATA_ULONG        KSTAT_DATA_UINT32
 506 #else
 507 #if !defined(_KERNEL)


 514 #endif  /* !_LP64 */
 515 
 516 /*
 517  * Statistics exporting named kstats with long strings (KSTAT_DATA_STRING)
 518  * may not make the assumption that ks_data_size is equal to (ks_ndata * sizeof
 519  * (kstat_named_t)).  ks_data_size in these cases is equal to the sum of the
 520  * amount of space required to store the strings (ie, the sum of
 521  * KSTAT_NAMED_STR_BUFLEN() for all KSTAT_DATA_STRING statistics) plus the
 522  * space required to store the kstat_named_t's.
 523  *
 524  * The default update routine will update ks_data_size automatically for
 525  * variable-length kstats containing long strings (using the default update
 526  * routine only makes sense if the string is the only thing that is changing
 527  * in size, and ks_ndata is constant).  Fixed-length kstats containing long
 528  * strings must explicitly change ks_data_size (after creation but before
 529  * initialization) to reflect the correct amount of space required for the
 530  * long strings and the kstat_named_t's.
 531  */
 532 #define KSTAT_DATA_STRING       9
 533 
 534 /*
 535  * Value is an hrtime_t, in seconds since system boot.
 536  */
 537 #define KSTAT_DATA_TIME         10
 538 
 539 /* These types are obsolete */
 540 
 541 #define KSTAT_DATA_LONGLONG     KSTAT_DATA_INT64
 542 #define KSTAT_DATA_ULONGLONG    KSTAT_DATA_UINT64
 543 #define KSTAT_DATA_FLOAT        5
 544 #define KSTAT_DATA_DOUBLE       6
 545 
 546 #define KSTAT_NAMED_PTR(kptr)   ((kstat_named_t *)(kptr)->ks_data)
 547 
 548 /*
 549  * Retrieve the pointer of the string contained in the given named kstat.
 550  */
 551 #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.str.addr.ptr)
 552 
 553 /*
 554  * Retrieve the length of the buffer required to store the string in the given
 555  * named kstat.
 556  */
 557 #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.str.len)
 558