Date: Thu, 16 Apr 2026 15:28:29 +0000 From: Mitchell Horne <mhorne@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Paulo Fragoso <paulo@nlink.com.br> Subject: git: 290a7adfb1df - stable/15 - hwpmc: improve diagnostic messages for invalid tunables Message-ID: <69e1001d.20236.25139544@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=290a7adfb1df0fb0e8ee4161cf002db929a10fc5 commit 290a7adfb1df0fb0e8ee4161cf002db929a10fc5 Author: Paulo Fragoso <paulo@nlink.com.br> AuthorDate: 2026-03-23 14:54:18 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2026-04-16 15:18:25 +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 (cherry picked from commit b3a18736ec2fc2bd097995dedd8d09e79bcb2056) --- 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 12b8ddcb156f..69399ec24743 100644 --- a/sys/sys/pmc.h +++ b/sys/sys/pmc.h @@ -649,7 +649,9 @@ struct pmc_op_getdyneventinfo { #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?69e1001d.20236.25139544>
