From nobody Wed Dec 29 23:06:27 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1F6C3191FE1B; Wed, 29 Dec 2021 23:06:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JPRq817Fhz3kFV; Wed, 29 Dec 2021 23:06:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B24F859A6; Wed, 29 Dec 2021 23:06:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BTN6Rp6090313; Wed, 29 Dec 2021 23:06:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BTN6R6v090312; Wed, 29 Dec 2021 23:06:27 GMT (envelope-from git) Date: Wed, 29 Dec 2021 23:06:27 GMT Message-Id: <202112292306.1BTN6R6v090312@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: b80a1b584f26 - stable/13 - MFC: Add TSLOG to loader sprintf List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b80a1b584f2676d4a75aa669f34a8982578408bf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640819188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SdTLBG4xsIolp1GTC/JbdPKvNN28FAGyVFBO1My0RZo=; b=tH+q396sLAGMe3kLD08OxP1OqmnAjnpTaavzz5yVDoNYlfQ4RF9JVZxbTLqMr7ywuluprG 69ONlkosJB2WwgxzFdTKJ6MzyIqD59s75xkFytGxhCc56PxalseOR4w8a/kO3X9YhrSuom ZPEGQlU3wmX/33bqeXmpdnGI8ajxiP+76O9BvXmQ6DBOLm1Lf2uRhbjvwKkK7JCBUH5ZJm DnxqrmYH1lDrHw8zAVeqGaM0BdVkqM4Gb7AVFz8jksoWfzhzS+qHNG488RsEyOSSFxTkXF HFeWN6J6ci0+ErBEaXp4X8PqG3HDH13NNoxpRifJx27gqA54AZXvuv7px2ji/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640819188; a=rsa-sha256; cv=none; b=h7aGVV6eH5zPlb5sgZ4RHfLqnsZL0vsKgPI5hPNMcO6xmNQa4WS9Zph/FujfThb11TZGQS Mr8Fixmg8K+HdYM91IpFXIEO/8G/FLX16We3mhZrfli8u36bQlZrEWzyHEbcWWrgy7J6ZW 8DN04B4Ce7u4oX2A5VBVtgKa+HVb8EyPt4F2/ge82IIdqwgDefRb8qdNs9+qgJDqsEqbJt xoyewwMiRMBxwZFmleVrC9FzYr17NlaBh53gPOJ0RbzfPTfepSgQaMOQ+inLZn3YXB1oLW 8WTaK0jE3fUFtNQ9fKNbZ1xqQLuTggh7H76ys0U/Sc+YDX/A67XE0cPVj8pRJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=b80a1b584f2676d4a75aa669f34a8982578408bf commit b80a1b584f2676d4a75aa669f34a8982578408bf Author: Colin Percival AuthorDate: 2021-09-25 03:19:38 +0000 Commit: Colin Percival CommitDate: 2021-12-29 22:53:19 +0000 MFC: Add TSLOG to loader sprintf loader tslog: Don't use sprintf loader printf: Profile with TSLOG Sponsored by: https://www.patreon.com/cperciva (cherry picked from commit 242923eb848a94d657344c2ff45c4f15433cdf3c) (cherry picked from commit 0a35c4b3cab563e3ab1bf5b7b49bf26e0bb7cb04) --- stand/libsa/printf.c | 5 ++++- stand/libsa/tslog.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/stand/libsa/printf.c b/stand/libsa/printf.c index 1602a2dc519d..4de547b644dd 100644 --- a/stand/libsa/printf.c +++ b/stand/libsa/printf.c @@ -271,6 +271,7 @@ kvprintf(char const *fmt, kvprintf_fn_t *func, void *arg, int radix, va_list ap) char padc; int stop = 0, retval = 0; + TSENTER(); num = 0; if (!func) d = (char *) arg; @@ -287,8 +288,10 @@ kvprintf(char const *fmt, kvprintf_fn_t *func, void *arg, int radix, va_list ap) padc = ' '; width = 0; while ((ch = (u_char)*fmt++) != '%' || stop) { - if (ch == '\0') + if (ch == '\0') { + TSEXIT(); return (retval); + } PCHAR(ch); } percent = fmt - 1; diff --git a/stand/libsa/tslog.c b/stand/libsa/tslog.c index c6164aab02a9..a2791f9dc9c4 100644 --- a/stand/libsa/tslog.c +++ b/stand/libsa/tslog.c @@ -42,6 +42,24 @@ static char * tslog_buf = NULL; static size_t tslog_buflen = 0; static size_t tslog_bufpos = 0; +static size_t +tsccat(char * buf, uint64_t tsc) +{ + size_t len; + + /* Handle upper digits. */ + if (tsc >= 10) + len = tsccat(buf, tsc / 10); + else + len = 0; + + /* Write the last digit. */ + buf[len] = "0123456789"[tsc % 10]; + + /* Return the length written. */ + return (len + 1); +} + void tslog_setbuf(void * buf, size_t len) { @@ -69,16 +87,34 @@ tslog(const char * type, const char * f, const char * s) #else uint64_t tsc = 0; #endif - int len; /* If we have no buffer, do nothing. */ if (tslog_buf == NULL) return; - /* Append to existing buffer, if we have enough space. */ - len = snprintf(&tslog_buf[tslog_bufpos], - tslog_buflen - tslog_bufpos, "0x0 %llu %s %s%s%s\n", - (unsigned long long)tsc, type, f, s ? " " : "", s ? s : ""); - if ((len > 0) && (tslog_bufpos + len <= tslog_buflen)) - tslog_bufpos += len; + /* Check that we have enough space. */ + if (tslog_buflen - tslog_bufpos < 32 + strlen(type) + strlen(f) + + (s ? strlen(s) : 0)) + return; + + /* Append to existing buffer. */ + strcpy(&tslog_buf[tslog_bufpos], "0x0 "); + tslog_bufpos += 4; + tslog_bufpos += tsccat(&tslog_buf[tslog_bufpos], tsc); + strcpy(&tslog_buf[tslog_bufpos], " "); + tslog_bufpos += 1; + strcpy(&tslog_buf[tslog_bufpos], type); + tslog_bufpos += strlen(type); + strcpy(&tslog_buf[tslog_bufpos], " "); + tslog_bufpos += 1; + strcpy(&tslog_buf[tslog_bufpos], f); + tslog_bufpos += strlen(f); + if (s != NULL) { + strcpy(&tslog_buf[tslog_bufpos], " "); + tslog_bufpos += 1; + strcpy(&tslog_buf[tslog_bufpos], s); + tslog_bufpos += strlen(s); + } + strcpy(&tslog_buf[tslog_bufpos], "\n"); + tslog_bufpos += 1; }