Re: [PATCH] Reduce case duplication in kern_sysctl
On Sat, 09 Jan 2021 14:39:53 -0800 Greg Steuck wrote: > Thanks for the reviews! > > Marcus Glocker writes: > > > On Sat, 9 Jan 2021 22:09:06 +0100 > > Marcus Glocker wrote: > > If you could fix the switch() indentation in a separate commit (as > > you already mentioned in one of your previous e-mails), that would > > be nice. > > How's this instead? OK? I saw you already committed, but yes, improves the readability. OK mglocker@ > Tested with the usual diff of before/after sysctl outputs and a random > sysctl -w poke. > > Subject: [PATCH] Split hierarchical calls into kern_sysctl_dirs > > Removed a rash of +/-1 and made both functions shorter and more > focused. --- > sys/kern/kern_sysctl.c | 86 > ++ 1 file changed, 45 > insertions(+), 41 deletions(-) > > diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c > index 7b164d3d32a..383b2a7c074 100644 > --- sys/kern/kern_sysctl.c > +++ sys/kern/kern_sysctl.c > @@ -352,106 +352,110 @@ const struct sysctl_bounded_args kern_vars[] > = { #endif > }; > > -/* > - * kernel related system variables. > - */ > int > -kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, > void *newp, > -size_t newlen, struct proc *p) > +kern_sysctl_dirs(int top_name, int *name, u_int namelen, > +void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct > proc *p) { > - int error, level, inthostid, stackgap; > - dev_t dev; > - extern int pool_debug; > - > - /* dispatch the non-terminal nodes first */ > - if (namelen != 1) { > - switch (name[0]) { > + switch (top_name) { > #ifndef SMALL_KERNEL > case KERN_PROC: > - return (sysctl_doproc(name + 1, namelen - 1, oldp, > oldlenp)); > + return (sysctl_doproc(name, namelen, oldp, oldlenp)); > case KERN_PROC_ARGS: > - return (sysctl_proc_args(name + 1, namelen - 1, > oldp, oldlenp, > - p)); > + return (sysctl_proc_args(name, namelen, oldp, > oldlenp, p)); case KERN_PROC_CWD: > - return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, > oldlenp, > - p)); > + return (sysctl_proc_cwd(name, namelen, oldp, > oldlenp, p)); case KERN_PROC_NOBROADCASTKILL: > - return (sysctl_proc_nobroadcastkill(name + 1, > namelen - 1, > + return (sysctl_proc_nobroadcastkill(name, namelen, >newp, newlen, oldp, oldlenp, p)); > case KERN_PROC_VMMAP: > - return (sysctl_proc_vmmap(name + 1, namelen - 1, > oldp, oldlenp, > - p)); > + return (sysctl_proc_vmmap(name, namelen, oldp, > oldlenp, p)); case KERN_FILE: > - return (sysctl_file(name + 1, namelen - 1, oldp, > oldlenp, p)); > + return (sysctl_file(name, namelen, oldp, oldlenp, > p)); #endif > #if defined(GPROF) || defined(DDBPROF) > case KERN_PROF: > - return (sysctl_doprof(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_doprof(name, namelen, oldp, oldlenp, > newp, newlen)); > #endif > case KERN_MALLOCSTATS: > - return (sysctl_malloc(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_malloc(name, namelen, oldp, oldlenp, > newp, newlen, p)); > case KERN_TTY: > - return (sysctl_tty(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_tty(name, namelen, oldp, oldlenp, > newp, newlen)); > case KERN_POOL: > - return (sysctl_dopool(name + 1, namelen - 1, oldp, > oldlenp)); > + return (sysctl_dopool(name, namelen, oldp, oldlenp)); > #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) > case KERN_SYSVIPC_INFO: > - return (sysctl_sysvipc(name + 1, namelen - 1, oldp, > oldlenp)); > + return (sysctl_sysvipc(name, namelen, oldp, > oldlenp)); #endif > #ifdef SYSVSEM > case KERN_SEMINFO: > - return (sysctl_sysvsem(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_sysvsem(name, namelen, oldp, oldlenp, > newp, newlen)); > #endif > #ifdef SYSVSHM > case KERN_SHMINFO: > - return (sysctl_sysvshm(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_sysvshm(name, namelen, oldp, oldlenp, > newp, newlen)); > #endif > #ifndef SMALL_KERNEL > case KERN_INTRCNT: > - return (sysctl_intrcnt(name + 1, namelen - 1, oldp, > oldlenp)); > + return (sysctl_intrcnt(name, namelen, oldp, > oldlenp)); case KERN_WATCHDOG: > - return (sysctl_wdog(name + 1, namelen - 1, oldp, > oldlenp, > + return (sysctl_wdog(name, namelen, oldp, oldlenp, > newp, newlen)); > #endif > #ifndef SMALL_KERNEL > case KERN_EVCOUNT: > - return (evcount_sysctl(name + 1, namelen - 1, oldp, >
Re: [PATCH] Reduce case duplication in kern_sysctl
On Sat, 09 Jan 2021 14:39:53 -0800, Greg Steuck wrote: > How's this instead? OK? > > Tested with the usual diff of before/after sysctl outputs and a random > sysctl -w poke. > > Subject: [PATCH] Split hierarchical calls into kern_sysctl_dirs > > Removed a rash of +/-1 and made both functions shorter and more focused. OK millert@ - todd
Re: [PATCH] Reduce case duplication in kern_sysctl
Thanks for the reviews! Marcus Glocker writes: > On Sat, 9 Jan 2021 22:09:06 +0100 > Marcus Glocker wrote: > If you could fix the switch() indentation in a separate commit (as you > already mentioned in one of your previous e-mails), that would be nice. How's this instead? OK? Tested with the usual diff of before/after sysctl outputs and a random sysctl -w poke. Subject: [PATCH] Split hierarchical calls into kern_sysctl_dirs Removed a rash of +/-1 and made both functions shorter and more focused. --- sys/kern/kern_sysctl.c | 86 ++ 1 file changed, 45 insertions(+), 41 deletions(-) diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c index 7b164d3d32a..383b2a7c074 100644 --- sys/kern/kern_sysctl.c +++ sys/kern/kern_sysctl.c @@ -352,106 +352,110 @@ const struct sysctl_bounded_args kern_vars[] = { #endif }; -/* - * kernel related system variables. - */ int -kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, -size_t newlen, struct proc *p) +kern_sysctl_dirs(int top_name, int *name, u_int namelen, +void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct proc *p) { - int error, level, inthostid, stackgap; - dev_t dev; - extern int pool_debug; - - /* dispatch the non-terminal nodes first */ - if (namelen != 1) { - switch (name[0]) { + switch (top_name) { #ifndef SMALL_KERNEL case KERN_PROC: - return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); + return (sysctl_doproc(name, namelen, oldp, oldlenp)); case KERN_PROC_ARGS: - return (sysctl_proc_args(name + 1, namelen - 1, oldp, oldlenp, -p)); + return (sysctl_proc_args(name, namelen, oldp, oldlenp, p)); case KERN_PROC_CWD: - return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp, -p)); + return (sysctl_proc_cwd(name, namelen, oldp, oldlenp, p)); case KERN_PROC_NOBROADCASTKILL: - return (sysctl_proc_nobroadcastkill(name + 1, namelen - 1, + return (sysctl_proc_nobroadcastkill(name, namelen, newp, newlen, oldp, oldlenp, p)); case KERN_PROC_VMMAP: - return (sysctl_proc_vmmap(name + 1, namelen - 1, oldp, oldlenp, -p)); + return (sysctl_proc_vmmap(name, namelen, oldp, oldlenp, p)); case KERN_FILE: - return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p)); + return (sysctl_file(name, namelen, oldp, oldlenp, p)); #endif #if defined(GPROF) || defined(DDBPROF) case KERN_PROF: - return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_doprof(name, namelen, oldp, oldlenp, newp, newlen)); #endif case KERN_MALLOCSTATS: - return (sysctl_malloc(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_malloc(name, namelen, oldp, oldlenp, newp, newlen, p)); case KERN_TTY: - return (sysctl_tty(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_tty(name, namelen, oldp, oldlenp, newp, newlen)); case KERN_POOL: - return (sysctl_dopool(name + 1, namelen - 1, oldp, oldlenp)); + return (sysctl_dopool(name, namelen, oldp, oldlenp)); #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) case KERN_SYSVIPC_INFO: - return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp)); + return (sysctl_sysvipc(name, namelen, oldp, oldlenp)); #endif #ifdef SYSVSEM case KERN_SEMINFO: - return (sysctl_sysvsem(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_sysvsem(name, namelen, oldp, oldlenp, newp, newlen)); #endif #ifdef SYSVSHM case KERN_SHMINFO: - return (sysctl_sysvshm(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_sysvshm(name, namelen, oldp, oldlenp, newp, newlen)); #endif #ifndef SMALL_KERNEL case KERN_INTRCNT: - return (sysctl_intrcnt(name + 1, namelen - 1, oldp, oldlenp)); + return (sysctl_intrcnt(name, namelen, oldp, oldlenp)); case KERN_WATCHDOG: - return (sysctl_wdog(name + 1, namelen - 1, oldp, oldlenp, + return (sysctl_wdog(name, namelen, oldp, oldlenp, newp, newlen)); #endif #ifndef SMALL_KERNEL case KERN_EVCOUNT: - return (evcount_sysctl(name + 1, namelen - 1, oldp, oldlenp, + return (evcount_sysctl(name, namelen, oldp, oldlenp, newp, newlen)); #endif case KERN_TIMECOUNTER: - return (sysctl_tc(name + 1, namelen - 1, oldp, oldlenp, - newp,
Re: [PATCH] Reduce case duplication in kern_sysctl
On Sat, 9 Jan 2021 22:09:06 +0100 Marcus Glocker wrote: > On Sat, 09 Jan 2021 13:06:36 -0800 > Greg Steuck wrote: > > > Thanks Todd for reviewing these boring patches! > > > > Todd C. Miller writes: > > > > > Updated diff looks good to me. OK millert@ but it would be good > > > to get feedback from Marcus too. > > > > Sure thing, I'll wait till tomorrow then? > > > > Thanks > > Greg > > Sorry, I totally missed that. > I'm just checking it now, give me a bit. If you could fix the switch() indentation in a separate commit (as you already mentioned in one of your previous e-mails), that would be nice. Otherwise the diff is fine for me as well. OK mglocker@
Re: [PATCH] Reduce case duplication in kern_sysctl
On Sat, 09 Jan 2021 13:06:36 -0800 Greg Steuck wrote: > Thanks Todd for reviewing these boring patches! > > Todd C. Miller writes: > > > Updated diff looks good to me. OK millert@ but it would be good > > to get feedback from Marcus too. > > Sure thing, I'll wait till tomorrow then? > > Thanks > Greg Sorry, I totally missed that. I'm just checking it now, give me a bit.
Re: [PATCH] Reduce case duplication in kern_sysctl
Thanks Todd for reviewing these boring patches! Todd C. Miller writes: > Updated diff looks good to me. OK millert@ but it would be good > to get feedback from Marcus too. Sure thing, I'll wait till tomorrow then? Thanks Greg
Re: [PATCH] Reduce case duplication in kern_sysctl
On Mon, 28 Dec 2020 22:00:55 -0800, Greg Steuck wrote: > Here's an updated version to account from an intervening change since I > posted this first. Updated diff looks good to me. OK millert@ but it would be good to get feedback from Marcus too. - todd
Re: [PATCH] Reduce case duplication in kern_sysctl
On Sun, 20 Dec 2020 15:52:07 -0800, Greg Steuck wrote: > I tested this by diff'ing sysctl output before/after on amd64. Since > there's a bunch of ifdef'ness I verified RAMDISK still builds. > > I deliberately didn't fix the indentation to keep this diff a pure line > motion (would run over 80 chars otherwise). I can either fix that it in > a separate commit or in this one before submitting. Can you re-send a version of this that applies on top of -current? - todd
Re: [PATCH] Reduce case duplication in kern_sysctl
> I tested this by diff'ing sysctl output before/after on amd64. Since > there's a bunch of ifdef'ness I verified RAMDISK still builds. > > I deliberately didn't fix the indentation to keep this diff a pure line > motion (would run over 80 chars otherwise). I can either fix that it in > a separate commit or in this one before submitting. > > OK? Here's an updated version to account from an intervening change since I posted this first. Marcus, since my change conflicted with yours, maybe you could review? Thanks Greg Subject: [PATCH] Reduce case duplication in kern_sysctl This changes amd64 GENERIC.MP .text size of kern_sysctl.o from 6440 to 6400. Surprisingly, RAMDISK grows from 1645 to 1678. --- sys/kern/kern_sysctl.c | 191 ++--- 1 file changed, 84 insertions(+), 107 deletions(-) diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c index d462926fea2..7b164d3d32a 100644 --- sys/kern/kern_sysctl.c +++ sys/kern/kern_sysctl.c @@ -363,32 +363,92 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, dev_t dev; extern int pool_debug; - /* all sysctl names at this level are terminal except a ton of them */ + /* dispatch the non-terminal nodes first */ if (namelen != 1) { switch (name[0]) { - case KERN_PROC: - case KERN_PROF: - case KERN_MALLOCSTATS: - case KERN_TTY: - case KERN_POOL: - case KERN_PROC_ARGS: - case KERN_PROC_CWD: - case KERN_PROC_NOBROADCASTKILL: - case KERN_PROC_VMMAP: - case KERN_SYSVIPC_INFO: - case KERN_SEMINFO: - case KERN_SHMINFO: - case KERN_INTRCNT: - case KERN_WATCHDOG: - case KERN_EVCOUNT: - case KERN_TIMECOUNTER: - case KERN_CPTIME2: - case KERN_FILE: - case KERN_WITNESS: - case KERN_AUDIO: - case KERN_VIDEO: - case KERN_CPUSTATS: - break; +#ifndef SMALL_KERNEL + case KERN_PROC: + return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); + case KERN_PROC_ARGS: + return (sysctl_proc_args(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_PROC_CWD: + return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_PROC_NOBROADCASTKILL: + return (sysctl_proc_nobroadcastkill(name + 1, namelen - 1, +newp, newlen, oldp, oldlenp, p)); + case KERN_PROC_VMMAP: + return (sysctl_proc_vmmap(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_FILE: + return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p)); +#endif +#if defined(GPROF) || defined(DDBPROF) + case KERN_PROF: + return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif + case KERN_MALLOCSTATS: + return (sysctl_malloc(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen, p)); + case KERN_TTY: + return (sysctl_tty(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); + case KERN_POOL: + return (sysctl_dopool(name + 1, namelen - 1, oldp, oldlenp)); +#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) + case KERN_SYSVIPC_INFO: + return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp)); +#endif +#ifdef SYSVSEM + case KERN_SEMINFO: + return (sysctl_sysvsem(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifdef SYSVSHM + case KERN_SHMINFO: + return (sysctl_sysvshm(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifndef SMALL_KERNEL + case KERN_INTRCNT: + return (sysctl_intrcnt(name + 1, namelen - 1, oldp, oldlenp)); + case KERN_WATCHDOG: + return (sysctl_wdog(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifndef SMALL_KERNEL + case KERN_EVCOUNT: + return (evcount_sysctl(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif + case KERN_TIMECOUNTER: + return (sysctl_tc(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); + case KERN_CPTIME2: + return (sysctl_cptime2(name + 1, namelen -1, oldp, oldlenp, + newp, newlen)); +#ifdef WITNESS + case KERN_WITNESSWATCH: + return witness_sysctl_watch(oldp, oldlenp, newp, newlen); + case KERN_WITNESS: + return witness_sysctl(name + 1, na
[PATCH] Reduce case duplication in kern_sysctl
I tested this by diff'ing sysctl output before/after on amd64. Since there's a bunch of ifdef'ness I verified RAMDISK still builds. I deliberately didn't fix the indentation to keep this diff a pure line motion (would run over 80 chars otherwise). I can either fix that it in a separate commit or in this one before submitting. OK? Subject: [PATCH] Reduce case duplication in kern_sysctl This changes amd64 GENERIC.MP .text size of kern_sysctl.o from 6440 to 6400. Surprisingly, RAMDISK grows from 1645 to 1678. --- sys/kern/kern_sysctl.c | 180 ++--- 1 file changed, 79 insertions(+), 101 deletions(-) diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c index 82010e3ee1c..72686560b5d 100644 --- sys/kern/kern_sysctl.c +++ sys/kern/kern_sysctl.c @@ -356,31 +356,87 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, dev_t dev; extern int pool_debug; - /* all sysctl names at this level are terminal except a ton of them */ + /* dispatch the non-terminal nodes first */ if (namelen != 1) { switch (name[0]) { - case KERN_PROC: - case KERN_PROF: - case KERN_MALLOCSTATS: - case KERN_TTY: - case KERN_POOL: - case KERN_PROC_ARGS: - case KERN_PROC_CWD: - case KERN_PROC_NOBROADCASTKILL: - case KERN_PROC_VMMAP: - case KERN_SYSVIPC_INFO: - case KERN_SEMINFO: - case KERN_SHMINFO: - case KERN_INTRCNT: - case KERN_WATCHDOG: - case KERN_EVCOUNT: - case KERN_TIMECOUNTER: - case KERN_CPTIME2: - case KERN_FILE: - case KERN_WITNESS: - case KERN_AUDIO: - case KERN_CPUSTATS: - break; +#ifndef SMALL_KERNEL + case KERN_PROC: + return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); + case KERN_PROC_ARGS: + return (sysctl_proc_args(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_PROC_CWD: + return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_PROC_NOBROADCASTKILL: + return (sysctl_proc_nobroadcastkill(name + 1, namelen - 1, +newp, newlen, oldp, oldlenp, p)); + case KERN_PROC_VMMAP: + return (sysctl_proc_vmmap(name + 1, namelen - 1, oldp, oldlenp, +p)); + case KERN_FILE: + return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p)); +#endif +#if defined(GPROF) || defined(DDBPROF) + case KERN_PROF: + return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif + case KERN_MALLOCSTATS: + return (sysctl_malloc(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen, p)); + case KERN_TTY: + return (sysctl_tty(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); + case KERN_POOL: + return (sysctl_dopool(name + 1, namelen - 1, oldp, oldlenp)); +#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) + case KERN_SYSVIPC_INFO: + return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp)); +#endif +#ifdef SYSVSEM + case KERN_SEMINFO: + return (sysctl_sysvsem(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifdef SYSVSHM + case KERN_SHMINFO: + return (sysctl_sysvshm(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifndef SMALL_KERNEL + case KERN_INTRCNT: + return (sysctl_intrcnt(name + 1, namelen - 1, oldp, oldlenp)); + case KERN_WATCHDOG: + return (sysctl_wdog(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif +#ifndef SMALL_KERNEL + case KERN_EVCOUNT: + return (evcount_sysctl(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif + case KERN_TIMECOUNTER: + return (sysctl_tc(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); + case KERN_CPTIME2: + return (sysctl_cptime2(name + 1, namelen -1, oldp, oldlenp, + newp, newlen)); +#ifdef WITNESS + case KERN_WITNESSWATCH: + return witness_sysctl_watch(oldp, oldlenp, newp, newlen); + case KERN_WITNESS: + return witness_sysctl(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen); +#endif +#if NAUDIO > 0 + case KERN_AUDIO: + return (sysctl_audio(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); +#endif + case KERN_CPUST