Date: Sat, 12 Jun 2021 14:01:05 GMT From: Andrew Turner <andrew@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: a0dd2317e8f5 - stable/13 - Use if ... else when printing memory attributes Message-ID: <202106121401.15CE15Ts022208@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=a0dd2317e8f5daf2e1e3b9cfdd4640a6996487fc commit a0dd2317e8f5daf2e1e3b9cfdd4640a6996487fc Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2021-04-11 09:00:00 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2021-06-12 01:21:12 +0000 Use if ... else when printing memory attributes In vmstat there is a switch statement that converts these attributes to a string. As some values can be duplicate we have to hide these from userspace. Replace this switch statement with an if ... else macro that lets us repeat values without a compiler error. Reviewed by: kib MFC after: 2 weeks Sponsored by: ABT Systems Ltd Differential Revision: https://reviews.freebsd.org/D29703 (cherry picked from commit 15221c552b3cabcbf26613246e855010b176805a) --- usr.bin/vmstat/vmstat.c | 54 +++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index aae3af8aeef8..403dc6e2a054 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1538,66 +1538,48 @@ display_object(struct kinfo_vmobject *kvo) xo_emit("{:inactive/%5ju} ", (uintmax_t)kvo->kvo_inactive); xo_emit("{:refcount/%3d} ", kvo->kvo_ref_count); xo_emit("{:shadowcount/%3d} ", kvo->kvo_shadow_count); - switch (kvo->kvo_memattr) { + +#define MEMATTR_STR(type, val) \ + if (kvo->kvo_memattr == (type)) { \ + str = (val); \ + } else #ifdef VM_MEMATTR_UNCACHEABLE - case VM_MEMATTR_UNCACHEABLE: - str = "UC"; - break; + MEMATTR_STR(VM_MEMATTR_UNCACHEABLE, "UC") #endif #ifdef VM_MEMATTR_WRITE_COMBINING - case VM_MEMATTR_WRITE_COMBINING: - str = "WC"; - break; + MEMATTR_STR(VM_MEMATTR_WRITE_COMBINING, "WC") #endif #ifdef VM_MEMATTR_WRITE_THROUGH - case VM_MEMATTR_WRITE_THROUGH: - str = "WT"; - break; + MEMATTR_STR(VM_MEMATTR_WRITE_THROUGH, "WT") #endif #ifdef VM_MEMATTR_WRITE_PROTECTED - case VM_MEMATTR_WRITE_PROTECTED: - str = "WP"; - break; + MEMATTR_STR(VM_MEMATTR_WRITE_PROTECTED, "WP") #endif #ifdef VM_MEMATTR_WRITE_BACK - case VM_MEMATTR_WRITE_BACK: - str = "WB"; - break; + MEMATTR_STR(VM_MEMATTR_WRITE_BACK, "WB") #endif #ifdef VM_MEMATTR_WEAK_UNCACHEABLE - case VM_MEMATTR_WEAK_UNCACHEABLE: - str = "UC-"; - break; + MEMATTR_STR(VM_MEMATTR_WEAK_UNCACHEABLE, "UC-") #endif #ifdef VM_MEMATTR_WB_WA - case VM_MEMATTR_WB_WA: - str = "WB"; - break; + MEMATTR_STR(VM_MEMATTR_WB_WA, "WB") #endif #ifdef VM_MEMATTR_NOCACHE - case VM_MEMATTR_NOCACHE: - str = "NC"; - break; + MEMATTR_STR(VM_MEMATTR_NOCACHE, "NC") #endif #ifdef VM_MEMATTR_DEVICE - case VM_MEMATTR_DEVICE: - str = "DEV"; - break; + MEMATTR_STR(VM_MEMATTR_DEVICE, "DEV") #endif #ifdef VM_MEMATTR_CACHEABLE - case VM_MEMATTR_CACHEABLE: - str = "C"; - break; + MEMATTR_STR(VM_MEMATTR_CACHEABLE, "C") #endif #ifdef VM_MEMATTR_PREFETCHABLE - case VM_MEMATTR_PREFETCHABLE: - str = "PRE"; - break; + MEMATTR_STR(VM_MEMATTR_PREFETCHABLE, "PRE") #endif - default: + { str = "??"; - break; } +#undef MEMATTR_STR xo_emit("{:attribute/%-3s} ", str); switch (kvo->kvo_type) { case KVME_TYPE_NONE:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106121401.15CE15Ts022208>