From patchwork Sun Oct 26 14:20:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4527 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:2995:b0:72f:f16c:e055 with SMTP id f21csp895889max; Sun, 26 Oct 2025 07:21:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMMKXpd3L8A2j4SyBTR8gJ4V6fVcYuJgHoiDh3O6JPmCd1PYGJJKpkhJwbrT7N6paNRC8KbSA3lzQ=@openvpn.net X-Google-Smtp-Source: AGHT+IEYfCe1SpZKZ3YF68oFlSn2snFUuwH2X3BQeHduMKvkSaykpv/h8+4/HB4zZ3MlaBg+eZ7C X-Received: by 2002:a05:6830:63cd:b0:745:9272:4a26 with SMTP id 46e09a7af769-7c27ca3133bmr24190281a34.12.1761488505534; Sun, 26 Oct 2025 07:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1761488505; cv=none; d=google.com; s=arc-20240605; b=O3hIhCVPb1j0XF9IQ3Be9XsJjSlfcDoIVGSc6EGWSq3GBZ7peQKpbmk3VBxMod/Tz0 RQ+f7Zntn7fgKwoKmjZawV2zuo+4q0GXDjmR63u72EdhzL/e+P6XNz0VZTV8BDdLgkHJ EE3mukEMr/hBfeB3RSOjEr7r7ef7mBGPW/pKfnaQwozuSgGrHiwuQEHN+LuWRNlhMtPO oI9yOFHLN/Bvarz7tfts04MLQB1npgNXXETpUtyYQW9xz8bw8kJuriLqNUOCoThU0Ifp 13kxx+RBw0yMVlZMAHUFzOvNLN34k8HVMrpRyNbfVreWmUYvv1PjNhb46fjIbs67RNWy OTKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=lg7fUVRXdP/XcdlDe4KRP4C4suOEUxavKPi4hBPMlEM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=HCTwPlpzF9mXiuvqLq3zN3TraNf6sUwLOZcM8EpmiS+aAaqhpIAOI4KhjEhmKXt4iT CoAtf1TEn10SS2HZopi1TMiQ28SptrPi+O0GfkimJu1/3hf7mBGuzqpQKVkwwtJz08ta 62Q16oEppy9jWveviK3yWRz2EBF+zs+txI/ki2k9mF1gZRBe9oJ2YObPOVeTxKNLqLNW zwNEgrjX0GiOracm8pHWjwPcYiF6Bxr1SOjH64eZPSBsNRfGBwE/1jTxMRqnLQQIEWMF VkXpGPIWBAF3SqBV7+Iu4ih5gTWjcLtpmkiyjuKSo3akQ4OR6RJaYgAV+9cFcfBoLGmc LTSQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=CZlP0J0J; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=f+tYj5S9; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gVl8SLVn; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-7c530c9a1fbsi1345802a34.368.2025.10.26.07.21.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Oct 2025 07:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=CZlP0J0J; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=f+tYj5S9; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gVl8SLVn; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lg7fUVRXdP/XcdlDe4KRP4C4suOEUxavKPi4hBPMlEM=; b=CZlP0J0JobJYc7pOZ7UGjSbESS IMLKn/RvMWrgwZvLe/8VRH3769c512BErG+pLOeMVc7xztLCUq1jXan4NTKYWiqG3T55N/JVmLYpZ o3bBbnRQLQSyC+13Mb14i92GQINAyEZMQSjdcpEv1E5EeW/y931kHvdxp9tiEHb5PxRM=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vD1cq-0007tC-3d; Sun, 26 Oct 2025 14:21:40 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vD1co-0007sm-F5 for openvpn-devel@lists.sourceforge.net; Sun, 26 Oct 2025 14:21:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1A0VXPojZRc2j+LJojx4eW6HSFswMBMuBK6lylvFfg0=; b=f+tYj5S9eNsG81wyPQYvy79Dpk 0HcK1m45pnNUXNTLwd8TYUK2b/0shk9i+DlGBiG924U6zUuhEb/Dt+KUWW6pPd74ztkUAs8CYLJKb v39u7KAN6SKDKHa3/mn/RkfJ1giplV55kjQBDY3ye/GnGmi+b/Znk7UhX9Aff3tzRk7c=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1A0VXPojZRc2j+LJojx4eW6HSFswMBMuBK6lylvFfg0=; b=gVl8SLVnh6t72OvcaVM+niKEyf Kqk1KzrtgNamKdwqCri2Xp7mIZWCMtR9INpMGY0sC+mFH8P/1p98vZfQWYMQUGKnn3/E2w0gv2KGZ 6u5k75G++HnDEgSD1WTqksEjygZcytetecQM6snd0oE8Jqg2HE5JIWtIyy0DqYkTCPTs=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1vD1cP-0002E7-5n for openvpn-devel@lists.sourceforge.net; Sun, 26 Oct 2025 14:21:15 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 59QEL1YS012162 for ; Sun, 26 Oct 2025 15:21:01 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59QEL1On012161 for openvpn-devel@lists.sourceforge.net; Sun, 26 Oct 2025 15:21:01 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 26 Oct 2025 15:20:52 +0100 Message-ID: <20251026142100.12147-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Steffan Karger This code was always disabled by ENABLE_PERFORMANCE_METRICS being commented out in perf.h. There was no configure flag. None of the active developers remembers using it, the git log shows no actual co [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1vD1cP-0002E7-5n Subject: [Openvpn-devel] [PATCH v1] Remove perf.c/perf.h X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1847054571369741213?= X-GMAIL-MSGID: =?utf-8?q?1847054571369741213?= From: Steffan Karger This code was always disabled by ENABLE_PERFORMANCE_METRICS being commented out in perf.h. There was no configure flag. None of the active developers remembers using it, the git log shows no actual code changes since at least the project structure overhaul of 2012, and tools like gprof are nowadays the go-to tool for performance profiling. So, out with our custom implementation. This was triggered by a bug report submitted by Joshua Rogers, who used ZeroPath to discover we missed a perf_pop() call in one of the error paths of ssl_mbedtls.c. This commit resolves that using git rm. Change-Id: I5bb666a73b4381066e86f53d957e1987fa07303b Signed-off-by: Steffan Karger Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1303 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1303 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/CMakeLists.txt b/CMakeLists.txt index 23fb4a5..5954a6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -519,8 +519,6 @@ src/openvpn/ovpn_dco_win.h src/openvpn/packet_id.c src/openvpn/packet_id.h - src/openvpn/perf.c - src/openvpn/perf.h src/openvpn/ping.c src/openvpn/ping.h src/openvpn/pkcs11.c diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index e44fb2b..dc58cd1 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -112,7 +112,6 @@ options_parse.c \ otime.c otime.h \ packet_id.c packet_id.h \ - perf.c perf.h \ ping.c ping.h \ plugin.c plugin.h \ pool.c pool.h \ diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 58c2fd1..735d259 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -34,7 +34,6 @@ #include "socket.h" #include "tun.h" #include "otime.h" -#include "perf.h" #include "status.h" #include "integer.h" #include "ps.h" @@ -734,11 +733,6 @@ abort(); } #endif - - if (status == OPENVPN_EXIT_STATUS_GOOD) - { - perf_output_results(); - } } exit(status); diff --git a/src/openvpn/event.h b/src/openvpn/event.h index 8a89a25..f6aa9c4 100644 --- a/src/openvpn/event.h +++ b/src/openvpn/event.h @@ -25,7 +25,6 @@ #include "win32.h" #include "sig.h" -#include "perf.h" /* * rwflags passed to event_ctl and returned by @@ -189,9 +188,7 @@ event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen) { int ret; - perf_push(PERF_IO_WAIT); ret = (*es->func.wait)(es, tv, out, outlen); - perf_pop(); return ret; } diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 79a6fc7..7f72000 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -932,8 +932,6 @@ /*ASSERT (!c->c2.to_tun.len);*/ - perf_push(PERF_READ_IN_LINK); - c->c2.buf = c->c2.buffers->read_link_buf; ASSERT(buf_init(&c->c2.buf, c->c2.frame.buf.headroom)); @@ -966,7 +964,6 @@ msg(D_STREAM_ERRORS, "Connection reset, restarting [%d]", status); } } - perf_pop(); return; } @@ -983,8 +980,6 @@ /* Remove socks header if applicable */ socks_postprocess_incoming_link(c, sock); - - perf_pop(); } bool @@ -1212,15 +1207,11 @@ static void process_incoming_link(struct context *c, struct link_socket *sock) { - perf_push(PERF_PROC_IN_LINK); - struct link_socket_info *lsi = &sock->info; const uint8_t *orig_buf = c->c2.buf.data; process_incoming_link_part1(c, lsi, false); process_incoming_link_part2(c, lsi, orig_buf); - - perf_pop(); } void @@ -1326,8 +1317,6 @@ */ /*ASSERT (!c->c2.to_link.len);*/ - perf_push(PERF_READ_IN_TUN); - c->c2.buf = c->c2.buffers->read_tun_buf; #ifdef _WIN32 @@ -1360,7 +1349,6 @@ { register_signal(c->sig, SIGTERM, "tun-stop"); msg(M_INFO, "TUN/TAP interface has been stopped, exiting"); - perf_pop(); return; } @@ -1370,14 +1358,11 @@ register_signal(c->sig, SIGHUP, "tun-abort"); c->persist.restart_sleep_seconds = 10; msg(M_INFO, "TUN/TAP I/O operation aborted, restarting"); - perf_pop(); return; } /* Check the status return from read() */ check_status(c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap); - - perf_pop(); } /** @@ -1497,8 +1482,6 @@ { struct gc_arena gc = gc_new(); - perf_push(PERF_PROC_IN_TUN); - if (c->c2.buf.len > 0) { c->c2.tun_read_bytes += c->c2.buf.len; @@ -1542,7 +1525,6 @@ { buf_reset(&c->c2.to_link); } - perf_pop(); gc_free(&gc); } @@ -1770,8 +1752,6 @@ struct gc_arena gc = gc_new(); int error_code = 0; - perf_push(PERF_PROC_OUT_LINK); - if (c->c2.to_link.len > 0 && c->c2.to_link.len <= c->c2.frame.buf.payload_size) { /* @@ -1899,7 +1879,6 @@ buf_reset(&c->c2.to_link); - perf_pop(); gc_free(&gc); } @@ -1919,8 +1898,6 @@ return; } - perf_push(PERF_PROC_OUT_TUN); - /* * The --mssfix option requires * us to examine the IP header (IPv4 or IPv6). @@ -1993,8 +1970,6 @@ } buf_reset(&c->c2.to_tun); - - perf_pop(); } #if defined(__GNUC__) || defined(__clang__) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index fa9c654..f60944d 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -580,8 +580,6 @@ void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown) { - perf_push(PERF_MULTI_CLOSE_INSTANCE); - ASSERT(!mi->halt); mi->halt = true; bool is_dgram = proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto); @@ -672,8 +670,6 @@ * vhash reaper deal with it. */ multi_instance_dec_refcount(mi); - - perf_pop(); } /* @@ -734,8 +730,6 @@ struct gc_arena gc = gc_new(); struct multi_instance *mi; - perf_push(PERF_MULTI_CREATE_INSTANCE); - msg(D_MULTI_MEDIUM, "MULTI: multi_create_instance called"); ALLOC_OBJ_CLEAR(mi, struct multi_instance); @@ -807,13 +801,11 @@ mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE; mi->ev_arg.u.mi = mi; - perf_pop(); gc_free(&gc); return mi; err: multi_close_instance(m, mi, false); - perf_pop(); gc_free(&gc); return NULL; } @@ -2907,7 +2899,6 @@ if (BLEN(buf) > 0) { - perf_push(PERF_MULTI_BCAST); #ifdef MULTI_DEBUG_EVENT_LOOP printf("BCAST len=%d\n", BLEN(buf)); #endif @@ -2929,7 +2920,6 @@ hash_iterator_free(&hi); mbuf_free_buf(mb); - perf_pop(); } } @@ -3399,7 +3389,6 @@ /* decrypt in instance context */ - perf_push(PERF_PROC_IN_LINK); lsi = &sock->info; orig_buf = c->c2.buf.data; if (process_incoming_link_part1(c, lsi, floated)) @@ -3412,7 +3401,6 @@ process_incoming_link_part2(c, lsi, orig_buf); } - perf_pop(); if (TUNNEL_TYPE(m->top.c1.tuntap) == DEV_TYPE_TUN) { @@ -4180,8 +4168,6 @@ while (true) { - perf_push(PERF_EVENT_LOOP); - /* wait on tun/socket list */ multi_get_timeout(multi, &multi->top.c2.timeval); status = multi_io_wait(multi); @@ -4202,7 +4188,6 @@ } MULTI_CHECK_SIG(multi); - perf_pop(); } } diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 97bbc4a..594ea3a 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -38,7 +38,6 @@ #include "mudp.h" #include "mtcp.h" #include "multi_io.h" -#include "perf.h" #include "vlan.h" #include "reflect_filter.h" diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c index 0bfbb63..6e31687 100644 --- a/src/openvpn/multi_io.c +++ b/src/openvpn/multi_io.c @@ -242,9 +242,7 @@ tun_input_pending = NULL; /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */ c->c2.timeval.tv_sec = 1; - perf_push(PERF_PROC_OUT_TUN_MTCP); io_wait(c, IOW_TO_TUN); - perf_pop(); break; case TA_SOCKET_WRITE: diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c index 64b4f8c..eaaa59b 100644 --- a/src/openvpn/openvpn.c +++ b/src/openvpn/openvpn.c @@ -72,8 +72,6 @@ /* main event loop */ while (true) { - perf_push(PERF_EVENT_LOOP); - /* process timers, TLS, etc. */ pre_select(c); P2P_CHECK_SIG(); @@ -85,15 +83,12 @@ /* timeout? */ if (c->c2.event_set_status == ES_TIMEOUT) { - perf_pop(); continue; } /* process the I/O which triggered select */ process_io(c, c->c2.link_sockets[0]); P2P_CHECK_SIG(); - - perf_pop(); } persist_client_stats(c); diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index cd99cd4..a198fcf 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -524,7 +524,6 @@ if (IS_SIG(c)) \ { \ const int brk = func(arg); \ - perf_pop(); \ if (brk) \ { \ break; \ diff --git a/src/openvpn/perf.c b/src/openvpn/perf.c deleted file mode 100644 index 51c1a97..0000000 --- a/src/openvpn/perf.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * OpenVPN -- An application to securely tunnel IP networks - * over a single TCP/UDP port, with support for SSL/TLS-based - * session authentication and key exchange, - * packet encryption, packet authentication, and - * packet compression. - * - * Copyright (C) 2002-2025 OpenVPN Inc - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, see . - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "syshead.h" - -#include "perf.h" - -#ifdef ENABLE_PERFORMANCE_METRICS - -#include "error.h" -#include "otime.h" - -#include "memdbg.h" - -static const char *metric_names[] = { "PERF_BIO_READ_PLAINTEXT", - "PERF_BIO_WRITE_PLAINTEXT", - "PERF_BIO_READ_CIPHERTEXT", - "PERF_BIO_WRITE_CIPHERTEXT", - "PERF_TLS_MULTI_PROCESS", - "PERF_IO_WAIT", - "PERF_EVENT_LOOP", - "PERF_MULTI_CREATE_INSTANCE", - "PERF_MULTI_CLOSE_INSTANCE", - "PERF_MULTI_SHOW_STATS", - "PERF_MULTI_BCAST", - "PERF_MULTI_MCAST", - "PERF_SCRIPT", - "PERF_READ_IN_LINK", - "PERF_PROC_IN_LINK", - "PERF_READ_IN_TUN", - "PERF_PROC_IN_TUN", - "PERF_PROC_OUT_LINK", - "PERF_PROC_OUT_TUN", - "PERF_PROC_OUT_TUN_MTCP" }; - -struct perf -{ -#define PS_INITIAL 0 -#define PS_METER_RUNNING 1 -#define PS_METER_INTERRUPTED 2 - int state; - - struct timeval start; - double sofar; - double sum; - double max; - double count; -}; - -struct perf_set -{ - int stack_len; - int stack[STACK_N]; - struct perf perf[PERF_N]; -}; - -static struct perf_set perf_set; - -static void perf_print_state(int lev); - -static inline int -get_stack_index(int sdelta) -{ - const int sindex = perf_set.stack_len + sdelta; - if (sindex >= 0 && sindex < STACK_N) - { - return sindex; - } - else - { - return -1; - } -} - -static int -get_perf_index(int sdelta) -{ - const int sindex = get_stack_index(sdelta); - if (sindex >= 0) - { - const int pindex = perf_set.stack[sindex]; - if (pindex >= 0 && pindex < PERF_N) - { - return pindex; - } - else - { - return -1; - } - } - else - { - return -1; - } -} - -static struct perf * -get_perf(int sdelta) -{ - const int pindex = get_perf_index(sdelta); - if (pindex >= 0) - { - return &perf_set.perf[pindex]; - } - else - { - return NULL; - } -} - -static void -push_perf_index(int pindex) -{ - const int sindex = get_stack_index(0); - const int newlen = get_stack_index(1); - if (sindex >= 0 && newlen >= 0 && pindex >= 0 && pindex < PERF_N) - { - int i; - for (i = 0; i < sindex; ++i) - { - if (perf_set.stack[i] == pindex) - { - perf_print_state(M_INFO); - msg(M_FATAL, "PERF: push_perf_index %s failed", metric_names[pindex]); - } - } - - perf_set.stack[sindex] = pindex; - perf_set.stack_len = newlen; - } - else - { - msg(M_FATAL, "PERF: push_perf_index: stack push error"); - } -} - -static void -pop_perf_index(void) -{ - const int newlen = get_stack_index(-1); - if (newlen >= 0) - { - perf_set.stack_len = newlen; - } - else - { - msg(M_FATAL, "PERF: pop_perf_index: stack pop error"); - } -} - -static void -state_must_be(const struct perf *p, const int wanted) -{ - if (p->state != wanted) - { - msg(M_FATAL, "PERF: bad state actual=%d wanted=%d", p->state, wanted); - } -} - -static void -update_sofar(struct perf *p) -{ - struct timeval current; - ASSERT(!gettimeofday(¤t, NULL)); - p->sofar += (double)tv_subtract(¤t, &p->start, 600) / 1000000.0; - tv_clear(&p->start); -} - -static void -perf_start(struct perf *p) -{ - state_must_be(p, PS_INITIAL); - ASSERT(!gettimeofday(&p->start, NULL)); - p->sofar = 0.0; - p->state = PS_METER_RUNNING; -} - -static void -perf_stop(struct perf *p) -{ - state_must_be(p, PS_METER_RUNNING); - update_sofar(p); - p->sum += p->sofar; - if (p->sofar > p->max) - { - p->max = p->sofar; - } - p->count += 1.0; - p->sofar = 0.0; - p->state = PS_INITIAL; -} - -static void -perf_interrupt(struct perf *p) -{ - state_must_be(p, PS_METER_RUNNING); - update_sofar(p); - p->state = PS_METER_INTERRUPTED; -} - -static void -perf_resume(struct perf *p) -{ - state_must_be(p, PS_METER_INTERRUPTED); - ASSERT(!gettimeofday(&p->start, NULL)); - p->state = PS_METER_RUNNING; -} - -void -perf_push(int type) -{ - struct perf *prev; - struct perf *cur; - - ASSERT(SIZE(metric_names) == PERF_N); - push_perf_index(type); - - prev = get_perf(-2); - cur = get_perf(-1); - - ASSERT(cur); - - if (prev) - { - perf_interrupt(prev); - } - perf_start(cur); -} - -void -perf_pop(void) -{ - struct perf *prev; - struct perf *cur; - - prev = get_perf(-2); - cur = get_perf(-1); - - ASSERT(cur); - perf_stop(cur); - - if (prev) - { - perf_resume(prev); - } - - pop_perf_index(); -} - -void -perf_output_results(void) -{ - int i; - msg(M_INFO, "LATENCY PROFILE (mean and max are in milliseconds)"); - for (i = 0; i < PERF_N; ++i) - { - struct perf *p = &perf_set.perf[i]; - if (p->count > 0.0) - { - const double mean = p->sum / p->count; - msg(M_INFO, "%s n=%.0f mean=%.3f max=%.3f", metric_names[i], p->count, mean * 1000.0, - p->max * 1000.0); - } - } -} - -static void -perf_print_state(int lev) -{ - struct gc_arena gc = gc_new(); - int i; - msg(lev, "PERF STATE"); - msg(lev, "Stack:"); - for (i = 0; i < perf_set.stack_len; ++i) - { - const int j = perf_set.stack[i]; - const struct perf *p = &perf_set.perf[j]; - msg(lev, "[%d] %s state=%d start=%s sofar=%f sum=%f max=%f count=%f", i, metric_names[j], - p->state, tv_string(&p->start, &gc), p->sofar, p->sum, p->max, p->count); - } - gc_free(&gc); -} -#endif /* ifdef ENABLE_PERFORMANCE_METRICS */ diff --git a/src/openvpn/perf.h b/src/openvpn/perf.h deleted file mode 100644 index 2a178a1..0000000 --- a/src/openvpn/perf.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * OpenVPN -- An application to securely tunnel IP networks - * over a single TCP/UDP port, with support for SSL/TLS-based - * session authentication and key exchange, - * packet encryption, packet authentication, and - * packet compression. - * - * Copyright (C) 2002-2025 OpenVPN Inc - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, see . - */ - -/* - * The interval_ routines are designed to optimize the calling of a routine - * (normally tls_multi_process()) which can be called less frequently - * between triggers. - */ - -#ifndef PERF_H -#define PERF_H - -/*#define ENABLE_PERFORMANCE_METRICS*/ - -/* - * Metrics - */ -#define PERF_BIO_READ_PLAINTEXT 0 -#define PERF_BIO_WRITE_PLAINTEXT 1 -#define PERF_BIO_READ_CIPHERTEXT 2 -#define PERF_BIO_WRITE_CIPHERTEXT 3 -#define PERF_TLS_MULTI_PROCESS 4 -#define PERF_IO_WAIT 5 -#define PERF_EVENT_LOOP 6 -#define PERF_MULTI_CREATE_INSTANCE 7 -#define PERF_MULTI_CLOSE_INSTANCE 8 -#define PERF_MULTI_SHOW_STATS 9 -#define PERF_MULTI_BCAST 10 -#define PERF_MULTI_MCAST 11 -#define PERF_SCRIPT 12 -#define PERF_READ_IN_LINK 13 -#define PERF_PROC_IN_LINK 14 -#define PERF_READ_IN_TUN 15 -#define PERF_PROC_IN_TUN 16 -#define PERF_PROC_OUT_LINK 17 -#define PERF_PROC_OUT_TUN 18 -#define PERF_PROC_OUT_TUN_MTCP 19 -#define PERF_N 20 - -#ifdef ENABLE_PERFORMANCE_METRICS - -#include "basic.h" - -/* - * Stack size - */ -#define STACK_N 64 - -void perf_push(int type); - -void perf_pop(void); - -void perf_output_results(void); - -#else /* ifdef ENABLE_PERFORMANCE_METRICS */ - -static inline void -perf_push(int type) -{ -} -static inline void -perf_pop(void) -{ -} -static inline void -perf_output_results(void) -{ -} - -#endif /* ifdef ENABLE_PERFORMANCE_METRICS */ - -#endif /* ifndef PERF_H */ diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 567560f..908854a 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -47,7 +47,6 @@ #include "misc.h" #include "fdmisc.h" #include "interval.h" -#include "perf.h" #include "status.h" #include "gremlin.h" #include "pkcs11.h" @@ -3220,8 +3219,6 @@ int active = TLSMP_INACTIVE; bool error = false; - perf_push(PERF_TLS_MULTI_PROCESS); - tls_clear_error(); /* @@ -3413,7 +3410,6 @@ } #endif - perf_pop(); gc_free(&gc); return (tas == TLS_AUTHENTICATION_FAILED) ? TLSMP_KILL : active; diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 80eb51b..488f9b9 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -1286,14 +1286,12 @@ key_state_write_plaintext_const(struct key_state_ssl *ks, const uint8_t *data, int len) { int retval = 0; - perf_push(PERF_BIO_WRITE_PLAINTEXT); ASSERT(NULL != ks); ASSERT(len >= 0); if (0 == len) { - perf_pop(); return 0; } @@ -1303,7 +1301,6 @@ if (retval < 0) { - perf_pop(); if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval) { return 0; @@ -1316,14 +1313,12 @@ { msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_plaintext_const incomplete %d/%d", retval, len); - perf_pop(); return -1; } /* successful write */ dmsg(D_HANDSHAKE_VERBOSE, "write tls_write_plaintext_const %d bytes", retval); - perf_pop(); return 1; } @@ -1333,15 +1328,12 @@ int retval = 0; int len = 0; - perf_push(PERF_BIO_READ_CIPHERTEXT); - ASSERT(NULL != ks); ASSERT(buf); ASSERT(buf->len >= 0); if (buf->len) { - perf_pop(); return 0; } @@ -1352,7 +1344,6 @@ /* Error during read, check for retry error */ if (retval < 0) { - perf_pop(); if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval) { return 0; @@ -1365,14 +1356,12 @@ if (0 == retval) { buf->len = 0; - perf_pop(); return 0; } /* successful read */ dmsg(D_HANDSHAKE_VERBOSE, "read tls_read_ciphertext %d bytes", retval); buf->len = retval; - perf_pop(); return 1; } @@ -1380,7 +1369,6 @@ key_state_write_ciphertext(struct key_state_ssl *ks, struct buffer *buf) { int retval = 0; - perf_push(PERF_BIO_WRITE_CIPHERTEXT); ASSERT(NULL != ks); ASSERT(buf); @@ -1388,7 +1376,6 @@ if (0 == buf->len) { - perf_pop(); return 0; } @@ -1396,8 +1383,6 @@ if (retval < 0) { - perf_pop(); - if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval) { return 0; @@ -1410,7 +1395,6 @@ { msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_ciphertext incomplete %d/%d", retval, buf->len); - perf_pop(); return -1; } @@ -1420,7 +1404,6 @@ memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ buf->len = 0; - perf_pop(); return 1; } @@ -1430,15 +1413,12 @@ int retval = 0; int len = 0; - perf_push(PERF_BIO_READ_PLAINTEXT); - ASSERT(NULL != ks); ASSERT(buf); ASSERT(buf->len >= 0); if (buf->len) { - perf_pop(); return 0; } @@ -1455,14 +1435,12 @@ } mbed_log_err(D_TLS_ERRORS, retval, "TLS_ERROR: read tls_read_plaintext error"); buf->len = 0; - perf_pop(); return -1; } /* Nothing read, try again */ if (0 == retval) { buf->len = 0; - perf_pop(); return 0; } @@ -1470,7 +1448,6 @@ dmsg(D_HANDSHAKE_VERBOSE, "read tls_read_plaintext %d bytes", retval); buf->len = retval; - perf_pop(); return 1; } diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 434df7d..d997141 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -2208,14 +2208,12 @@ key_state_write_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf) { int ret = 0; - perf_push(PERF_BIO_WRITE_PLAINTEXT); ASSERT(NULL != ks_ssl); ret = bio_write(ks_ssl->ssl_bio, BPTR(buf), BLEN(buf), "tls_write_plaintext"); bio_write_post(ret, buf); - perf_pop(); return ret; } @@ -2223,13 +2221,11 @@ key_state_write_plaintext_const(struct key_state_ssl *ks_ssl, const uint8_t *data, int len) { int ret = 0; - perf_push(PERF_BIO_WRITE_PLAINTEXT); ASSERT(NULL != ks_ssl); ret = bio_write(ks_ssl->ssl_bio, data, len, "tls_write_plaintext_const"); - perf_pop(); return ret; } @@ -2237,13 +2233,11 @@ key_state_read_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf) { int ret = 0; - perf_push(PERF_BIO_READ_CIPHERTEXT); ASSERT(NULL != ks_ssl); ret = bio_read(ks_ssl->ct_out, buf, "tls_read_ciphertext"); - perf_pop(); return ret; } @@ -2251,14 +2245,12 @@ key_state_write_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf) { int ret = 0; - perf_push(PERF_BIO_WRITE_CIPHERTEXT); ASSERT(NULL != ks_ssl); ret = bio_write(ks_ssl->ct_in, BPTR(buf), BLEN(buf), "tls_write_ciphertext"); bio_write_post(ret, buf); - perf_pop(); return ret; } @@ -2266,13 +2258,11 @@ key_state_read_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf) { int ret = 0; - perf_push(PERF_BIO_READ_PLAINTEXT); ASSERT(NULL != ks_ssl); ret = bio_read(ks_ssl->ssl_bio, buf, "tls_read_plaintext"); - perf_pop(); return ret; } diff --git a/src/openvpn/status.c b/src/openvpn/status.c index 1e1e3fb..5ca33cb 100644 --- a/src/openvpn/status.c +++ b/src/openvpn/status.c @@ -27,7 +27,6 @@ #include "syshead.h" #include "status.h" -#include "perf.h" #include "misc.h" #include "fdmisc.h"