Date: Mon, 23 Mar 2026 20:22:16 +0000 From: Mitchell Horne <mhorne@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Paulo Fragoso <paulo@nlink.com.br> Subject: git: b3a18736ec2f - main - hwpmc: improve diagnostic messages for invalid tunables Message-ID: <69c1a0f8.47d70.6a6a8fe5@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=b3a18736ec2fc2bd097995dedd8d09e79bcb2056 commit b3a18736ec2fc2bd097995dedd8d09e79bcb2056 Author: Paulo Fragoso <paulo@nlink.com.br> AuthorDate: 2026-03-23 14:54:18 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2026-03-23 20:21:28 +0000 hwpmc: improve diagnostic messages for invalid tunables Replace printf() with log(LOG_WARNING, ...) in pmclog_initialize() so that tunable validation failures are visible in dmesg and /var/log/messages rather than only on the early console. Also improve the messages to report both the invalid value and the default it resets to, making it easier for users to understand why their tunable was ignored. While here, adjust some whitespacing/style. Reviewed by: Ali Mashtizadeh <ali@mashtizadeh.com>, mhorne MFC after: 1 week Sponsored by: NLINK (nlink.com.br) Differential Revision: https://reviews.freebsd.org/D56029 --- sys/dev/hwpmc/hwpmc_logging.c | 35 ++++++++++++++++++++++++++--------- sys/sys/pmc.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_logging.c b/sys/dev/hwpmc/hwpmc_logging.c index 8fd7ef06a977..4f507523b6ab 100644 --- a/sys/dev/hwpmc/hwpmc_logging.c +++ b/sys/dev/hwpmc/hwpmc_logging.c @@ -58,6 +58,7 @@ #include <sys/uio.h> #include <sys/unistd.h> #include <sys/vnode.h> +#include <sys/syslog.h> #if defined(__i386__) || defined(__amd64__) #include <machine/clock.h> @@ -1236,24 +1237,39 @@ pmclog_initialize(void) struct pmclog_buffer *plb; int domain, ncpus, total; - if (pmclog_buffer_size <= 0 || pmclog_buffer_size > 16*1024) { - (void) printf("hwpmc: tunable logbuffersize=%d must be " - "greater than zero and less than or equal to 16MB.\n", - pmclog_buffer_size); + if (pmclog_buffer_size <= 0 || + pmclog_buffer_size > PMC_LOG_BUFFER_SIZE_MAX) { + log(LOG_WARNING, + "hwpmc: logbuffersize=%d must be greater than zero " + "and less than or equal to %d, resetting to %d\n", + pmclog_buffer_size, PMC_LOG_BUFFER_SIZE_MAX, + PMC_LOG_BUFFER_SIZE); + pmclog_buffer_size = PMC_LOG_BUFFER_SIZE; } if (pmc_nlogbuffers_pcpu <= 0) { - (void) printf("hwpmc: tunable nlogbuffers=%d must be greater " - "than zero.\n", pmc_nlogbuffers_pcpu); + log(LOG_WARNING, + "hwpmc: nbuffers_pcpu=%d must be greater than zero, " + "resetting to %d\n", + pmc_nlogbuffers_pcpu, PMC_NLOGBUFFERS_PCPU); + pmc_nlogbuffers_pcpu = PMC_NLOGBUFFERS_PCPU; } - if (pmc_nlogbuffers_pcpu*pmclog_buffer_size > 32*1024) { - (void) printf("hwpmc: memory allocated pcpu must be less than 32MB (is %dK).\n", - pmc_nlogbuffers_pcpu*pmclog_buffer_size); + + if (pmc_nlogbuffers_pcpu * pmclog_buffer_size > + PMC_NLOGBUFFERS_PCPU_MEM_MAX) { + log(LOG_WARNING, + "hwpmc: nbuffers_pcpu=%d * logbuffersize=%d exceeds " + "%dMB per CPU limit, resetting to defaults (%d * %d)\n", + pmc_nlogbuffers_pcpu, pmclog_buffer_size, + PMC_NLOGBUFFERS_PCPU_MEM_MAX / 1024, + PMC_NLOGBUFFERS_PCPU, PMC_LOG_BUFFER_SIZE); + pmc_nlogbuffers_pcpu = PMC_NLOGBUFFERS_PCPU; pmclog_buffer_size = PMC_LOG_BUFFER_SIZE; } + for (domain = 0; domain < vm_ndomains; domain++) { ncpus = pmc_dom_hdrs[domain]->pdbh_ncpus; total = ncpus * pmc_nlogbuffers_pcpu; @@ -1270,6 +1286,7 @@ pmclog_initialize(void) pmc_plb_rele_unlocked(plb); } } + mtx_init(&pmc_kthread_mtx, "pmc-kthread", "pmc-sleep", MTX_DEF); } diff --git a/sys/sys/pmc.h b/sys/sys/pmc.h index 4c160c000dab..b9242aafb19c 100644 --- a/sys/sys/pmc.h +++ b/sys/sys/pmc.h @@ -661,7 +661,9 @@ struct pmc_op_caps { #define PMC_HASH_SIZE 1024 #define PMC_MTXPOOL_SIZE 2048 #define PMC_LOG_BUFFER_SIZE 256 +#define PMC_LOG_BUFFER_SIZE_MAX (16 * 1024) #define PMC_NLOGBUFFERS_PCPU 32 +#define PMC_NLOGBUFFERS_PCPU_MEM_MAX (32 * 1024) #define PMC_NSAMPLES 256 #define PMC_CALLCHAIN_DEPTH 128 #define PMC_THREADLIST_MAX 128home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69c1a0f8.47d70.6a6a8fe5>
