From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id B7D1F5A0272; Fri, 2 Feb 2024 00:32:57 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] log: setlogmask(0) can actually result in a system call, don't use it Date: Fri, 2 Feb 2024 00:32:57 +0100 Message-Id: <20240201233257.2287025-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: TGARS2KVX3MDNDLDLKMLMIMXDDVOEWXH X-Message-ID-Hash: TGARS2KVX3MDNDLDLKMLMIMXDDVOEWXH X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Before commit 32d07f5e59f2 ("passt, pasta: Completely avoid dynamic memory allocation"), we didn't store the current log mask in a variable, and we fetched it using setlogmask(0) wherever needed. But after that commit, we can just use our log_mask copy instead. And we should: with recent glibc versions, setlogmask(0) actually results in a system call, which causes a substantial overhead with high transfer rates: we use setlogmask(0) even to decide we don't want to print debug messages. Signed-off-by: Stefano Brivio --- log.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/log.c b/log.c index 4a70e29..a66ecb7 100644 --- a/log.c +++ b/log.c @@ -45,33 +45,33 @@ static time_t log_start; /* Start timestamp */ int log_trace; /* --trace mode enabled */ int log_to_stdout; /* Print to stdout instead of stderr */ -#define BEFORE_DAEMON (setlogmask(0) == LOG_MASK(LOG_EMERG)) +#define BEFORE_DAEMON (log_mask == LOG_MASK(LOG_EMERG)) void vlogmsg(int pri, const char *format, va_list ap) { FILE *out = log_to_stdout ? stdout : stderr; struct timespec tp; - if (setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) { + if (log_mask & LOG_MASK(LOG_DEBUG) && log_file == -1) { clock_gettime(CLOCK_REALTIME, &tp); fprintf(out, "%lli.%04lli: ", (long long int)tp.tv_sec - log_start, (long long int)tp.tv_nsec / (100L * 1000)); } - if ((LOG_MASK(LOG_PRI(pri)) & log_mask) || BEFORE_DAEMON) { + if ((log_mask & LOG_MASK(LOG_PRI(pri))) || BEFORE_DAEMON) { va_list ap2; va_copy(ap2, ap); /* Don't clobber ap, we need it again */ if (log_file != -1) logfile_write(pri, format, ap2); - else if (!(setlogmask(0) & LOG_MASK(LOG_DEBUG))) + else if (!(log_mask & LOG_MASK(LOG_DEBUG))) passt_vsyslog(pri, format, ap2); va_end(ap2); } - if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) || + if ((log_mask & LOG_MASK(LOG_DEBUG) && log_file == -1) || (BEFORE_DAEMON && !(log_opt & LOG_PERROR))) { (void)vfprintf(out, format, ap); if (format[strlen(format)] != '\n') -- 2.39.2