Changeset View
Standalone View
sys/kern/subr_param.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
#define NPROC (20 + 16 * maxusers) | #define NPROC (20 + 16 * maxusers) | ||||
#ifndef NBUF | #ifndef NBUF | ||||
#define NBUF 0 | #define NBUF 0 | ||||
#endif | #endif | ||||
#ifndef MAXFILES | #ifndef MAXFILES | ||||
#define MAXFILES (40 + 32 * maxusers) | #define MAXFILES (40 + 32 * maxusers) | ||||
#endif | #endif | ||||
static int sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS); | struct sysctl_enum_params { | ||||
int *const value; | |||||
int first; | |||||
u_int count; | |||||
kib: This might be nitems(names). Also I am not sure that you need 'first', by using array… | |||||
Done Inline Actionsnitems(vm_guest_sysctl_params.names) => 0 (downside of a flexible array) first is for the case of an enum where the least element is negative or large positive number. A negative number would cause misbehavior. A large positive number would consume memory for unused elements. ehem_freebsd_m5p.com: `nitems(vm_guest_sysctl_params.names)` => `0` (downside of a flexible array)
first is for the… | |||||
char *const names[]; | |||||
}; | |||||
static int sysctl_enum_proc(SYSCTL_HANDLER_ARGS); | |||||
int hz; /* system clock's frequency */ | int hz; /* system clock's frequency */ | ||||
int tick; /* usec per tick (1000000 / hz) */ | int tick; /* usec per tick (1000000 / hz) */ | ||||
struct bintime tick_bt; /* bintime per tick (1s / hz) */ | struct bintime tick_bt; /* bintime per tick (1s / hz) */ | ||||
sbintime_t tick_sbt; | sbintime_t tick_sbt; | ||||
int maxusers; /* base tunable */ | int maxusers; /* base tunable */ | ||||
int maxproc; /* maximum # of processes */ | int maxproc; /* maximum # of processes */ | ||||
int maxprocperuid; /* max # of procs per user */ | int maxprocperuid; /* max # of procs per user */ | ||||
int maxfiles; /* sys. wide open files limit */ | int maxfiles; /* sys. wide open files limit */ | ||||
Show All 38 Lines | |||||
SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxdsiz, 0, | SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxdsiz, 0, | ||||
"Maximum data size"); | "Maximum data size"); | ||||
SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &dflssiz, 0, | SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &dflssiz, 0, | ||||
"Initial stack size limit"); | "Initial stack size limit"); | ||||
SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxssiz, 0, | SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxssiz, 0, | ||||
"Maximum stack size"); | "Maximum stack size"); | ||||
SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &sgrowsiz, 0, | SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &sgrowsiz, 0, | ||||
"Amount to grow stack on a stack fault"); | "Amount to grow stack on a stack fault"); | ||||
SYSCTL_PROC(_kern, OID_AUTO, vm_guest, | |||||
CTLFLAG_RD | CTLTYPE_STRING | CTLFLAG_MPSAFE, NULL, 0, | |||||
sysctl_kern_vm_guest, "A", | |||||
"Virtual machine guest detected?"); | |||||
/* | /* | ||||
* The elements of this array are ordered based upon the values of the | * Parameters for the vm_guest enum | ||||
* corresponding enum VM_GUEST members. | |||||
*/ | */ | ||||
static const char *const vm_guest_sysctl_names[] = { | static const struct sysctl_enum_params vm_guest_sysctl_params = { | ||||
[VM_GUEST_NO] = "none", | &vm_guest, | ||||
[VM_GUEST_VM] = "generic", | VM_GUEST_NO, | ||||
[VM_GUEST_XEN] = "xen", | VM_LAST - VM_GUEST_NO, /* VM_LAST is an invalid value */ | ||||
[VM_GUEST_HV] = "hv", | { | ||||
[VM_GUEST_VMWARE] = "vmware", | [VM_GUEST_BHYVE - VM_GUEST_NO] = "bhyve", | ||||
[VM_GUEST_KVM] = "kvm", | [VM_GUEST_HV - VM_GUEST_NO] = "hv", | ||||
[VM_GUEST_BHYVE] = "bhyve", | [VM_GUEST_KVM - VM_GUEST_NO] = "kvm", | ||||
[VM_GUEST_VBOX] = "vbox", | [VM_GUEST_NO - VM_GUEST_NO] = "none", | ||||
[VM_GUEST_PARALLELS] = "parallels", | [VM_GUEST_PARALLELS - VM_GUEST_NO] = "parallels", | ||||
[VM_LAST] = NULL | [VM_GUEST_VBOX - VM_GUEST_NO] = "vbox", | ||||
[VM_GUEST_VM - VM_GUEST_NO] = "generic", | |||||
[VM_GUEST_VMWARE - VM_GUEST_NO] = "vmware", | |||||
[VM_GUEST_XEN - VM_GUEST_NO] = "xen", | |||||
[VM_LAST - VM_GUEST_NO] = NULL | |||||
} | |||||
}; | }; | ||||
CTASSERT(nitems(vm_guest_sysctl_names) - 1 == VM_LAST); | |||||
SYSCTL_PROC(_kern, OID_AUTO, vm_guest, | |||||
CTLFLAG_RD | CTLTYPE_STRING | CTLFLAG_MPSAFE, | |||||
__DECONST(void *, &vm_guest_sysctl_params), 0, sysctl_enum_proc, "A", | |||||
"Virtual machine guest detected?"); | |||||
/* | /* | ||||
* Boot time overrides that are not scaled against main memory | * Boot time overrides that are not scaled against main memory | ||||
*/ | */ | ||||
void | void | ||||
init_param1(void) | init_param1(void) | ||||
{ | { | ||||
#if !defined(__mips__) && !defined(__arm64__) | #if !defined(__mips__) && !defined(__arm64__) | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | #endif | ||||
if (maxpipekva < 512 * 1024) | if (maxpipekva < 512 * 1024) | ||||
maxpipekva = 512 * 1024; | maxpipekva = 512 * 1024; | ||||
if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64) | if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64) | ||||
maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / | maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / | ||||
64; | 64; | ||||
} | } | ||||
/* | /* | ||||
* Sysctl stringifying handler for kern.vm_guest. | * Generalized sysctl stringifying handler for enums | ||||
*/ | */ | ||||
static int | static int | ||||
sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS) | sysctl_enum_proc(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
return (SYSCTL_OUT_STR(req, vm_guest_sysctl_names[vm_guest])); | const struct sysctl_enum_params *const params = arg1; | ||||
u_int index = *params->value - params->first; | |||||
if (index >= params->count) | |||||
return (ENXIO); | |||||
Done Inline ActionsThis blank line is not needed kib: This blank line is not needed | |||||
if (params->names[index] == NULL) | |||||
return (0); | |||||
return (SYSCTL_OUT_STR(req, params->names[index])); | |||||
Not Done Inline ActionsName this local differently than 'params' and then you can use SYSCTL_HANDLER_ARGS? I would call it eparams. kib: Name this local differently than 'params' and then you can use SYSCTL_HANDLER_ARGS?
I would… | |||||
Done Inline ActionsAll depends on how far SYSCTL_HANDLER_ARGS is pushed and why. I was thinking it was simply meant as a handy macro and didn't think the arguments got changed that often, but I could believe my guess was wrong. One issue I see are "arg1" and "arg2" really should be "argptr" and "argnum". The other issue is here the pointer really should be marked as pointing to a constant, similar to SYSINIT() versus C_SYSINIT(). If use of SYSCTL_HANDLER_ARGS is that strongly preferred, I would tend towards "pparams". ehem_freebsd_m5p.com: All depends on how far SYSCTL_HANDLER_ARGS is pushed and why. I was thinking it was simply… | |||||
Done Inline ActionsAnd this kib: And this | |||||
} | } |
This might be nitems(names). Also I am not sure that you need 'first', by using array designated initializer you instantiate all possible indexes anyway, and they you check for NULL.