Add sysctl_usec_to_sbintime and sysctl_msec_to_sbintime.

These functions are used to present a sbintime_t as either a number of
microseconds or a number of milliseconds respectively.

Sponsored by: Netflix
This commit is contained in:
Warner Losh 2018-11-02 17:50:57 +00:00
parent 14624ab582
commit 003ffd57fe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=340074
2 changed files with 86 additions and 0 deletions

View File

@ -1691,6 +1691,53 @@ sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
return (error);
}
/*
* Based on on sysctl_handle_int() convert microseconds to a sbintime.
*/
int
sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS)
{
int error;
int64_t tt;
sbintime_t sb;
tt = *(int64_t *)arg1;
sb = ustosbt(tt);
error = sysctl_handle_64(oidp, &sb, 0, req);
if (error || !req->newptr)
return (error);
tt = sbttous(sb);
*(int64_t *)arg1 = tt;
return (0);
}
/*
* Based on on sysctl_handle_int() convert milliseconds to a sbintime.
*/
int
sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS)
{
int error;
int64_t tt;
sbintime_t sb;
tt = *(int64_t *)arg1;
sb = mstosbt(tt);
error = sysctl_handle_64(oidp, &sb, 0, req);
if (error || !req->newptr)
return (error);
tt = sbttoms(sb);
*(int64_t *)arg1 = tt;
return (0);
}
/*
* Transfer functions to/from kernel space.
* XXX: rather untested at this point

View File

@ -216,6 +216,9 @@ int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS);
int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
@ -799,6 +802,42 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
NULL); \
})
/* OID expressing a sbintime_t as microseconds */
#define SYSCTL_SBINTIME_USEC(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_usec_to_sbintime, "Q", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
#define SYSCTL_ADD_SBINTIME_USEC(ctx, parent, nbr, name, access, ptr, descr) \
({ \
sbintime_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_usec_to_sbintime, "Q", __DESCR(descr), \
NULL); \
})
/* OID expressing a sbintime_t as milliseconds */
#define SYSCTL_SBINTIME_MSEC(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_msec_to_sbintime, "Q", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
#define SYSCTL_ADD_SBINTIME_MSEC(ctx, parent, nbr, name, access, ptr, descr) \
({ \
sbintime_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_msec_to_sbintime, "Q", __DESCR(descr), \
NULL); \
})
/*
* A macro to generate a read-only sysctl to indicate the presence of optional
* kernel features.