From patchwork Thu Feb 27 17:23:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053209 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A2QhpUm9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVR0HM2z1xrB for ; Fri, 28 Feb 2025 04:23:59 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0BC3341521; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id j9eTcnTN4J1v; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 8B0FA40816 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A2QhpUm9 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8B0FA40816; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6074DC003D; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 868EEC003D for ; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7F5B981E48 for ; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id m9wNdNTH0cOT for ; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org A1CA983A59 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A1CA983A59 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A2QhpUm9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id A1CA983A59 for ; Thu, 27 Feb 2025 17:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fan4gDKXJF92bJPMooNZT5pNVDYcEjSLthf5jTvKv58=; b=A2QhpUm9DZtwS4NnnbBXq5lwjsoMs9+hdRcheEXQpTDhIV3kPuwPzVtLjOB0ATcIEsOXNx gPrjgWczOhgYHZ9gBkGXIv+5upbM7XBiQYmlCLVazBnW4fbi8ZXO1/h07PT7M6A6s+ofb3 cc8SG1h69Z+DVCfOD4xQatZ/dEU8bmE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-Qfd3Bx3mPm-brkTQ0blDig-1; Thu, 27 Feb 2025 12:23:49 -0500 X-MC-Unique: Qfd3Bx3mPm-brkTQ0blDig-1 X-Mimecast-MFC-AGG-ID: Qfd3Bx3mPm-brkTQ0blDig_1740677028 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71606180034A for ; Thu, 27 Feb 2025 17:23:48 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50A0019560AE; Thu, 27 Feb 2025 17:23:46 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:33 +0100 Message-ID: <20250227172340.4120887-2-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: X0yIDSEseinNM1VeOpGzzUBunx2eqDnSVYQCWy1Q5pw_1740677028 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 1/8] utilities: usdt-scripts: Remove sleep in loop. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Without this patch, the chances of events being lost on highly loaded systems increase. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/usdt-scripts/dpif_op_nl_monitor.py | 2 -- utilities/usdt-scripts/upcall_cost.py | 2 -- utilities/usdt-scripts/upcall_monitor.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/utilities/usdt-scripts/dpif_op_nl_monitor.py b/utilities/usdt-scripts/dpif_op_nl_monitor.py index 22d282328..cac14c695 100755 --- a/utilities/usdt-scripts/dpif_op_nl_monitor.py +++ b/utilities/usdt-scripts/dpif_op_nl_monitor.py @@ -92,7 +92,6 @@ import psutil import re import struct import sys -import time # # Actual eBPF source code @@ -784,7 +783,6 @@ def main(): while 1: try: b.ring_buffer_poll() - time.sleep(0.5) except KeyboardInterrupt: break diff --git a/utilities/usdt-scripts/upcall_cost.py b/utilities/usdt-scripts/upcall_cost.py index 765669585..f3fa8afc3 100755 --- a/utilities/usdt-scripts/upcall_cost.py +++ b/utilities/usdt-scripts/upcall_cost.py @@ -65,7 +65,6 @@ import re import struct import subprocess import sys -import time # # Global definitions @@ -1587,7 +1586,6 @@ def main(): b.ring_buffer_poll() if options.stop != 0 and events_received >= options.stop: break - time.sleep(0.5) except KeyboardInterrupt: break diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index d856547f0..3a758b2d2 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -120,7 +120,6 @@ import psutil import re import struct import sys -import time # # Actual eBPF source code @@ -513,7 +512,6 @@ def main(): while 1: try: b.ring_buffer_poll() - time.sleep(0.5) except KeyboardInterrupt: break From patchwork Thu Feb 27 17:23:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053210 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T/SGZUal; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVV0kJLz1xrB for ; Fri, 28 Feb 2025 04:24:02 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 079A9415DF; Thu, 27 Feb 2025 17:24:02 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id FjkcGaq0M6FN; Thu, 27 Feb 2025 17:24:00 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 56F0A4157F Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T/SGZUal Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 56F0A4157F; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D5014C0078; Thu, 27 Feb 2025 17:23:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5458FC0033 for ; Thu, 27 Feb 2025 17:23:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 35F924140E for ; Thu, 27 Feb 2025 17:23:55 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id F6YHxqO8K06v for ; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org C3E1740A86 Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org C3E1740A86 Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T/SGZUal Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id C3E1740A86 for ; Thu, 27 Feb 2025 17:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ZpsalbKiHF7cTPcUQsUkjCmBp04dGvfQL0LJ1kLO2g=; b=T/SGZUalGEDj/iqbdzXKQSgyAJlhAlo9c6QLi9b+l2fX2iJgBjzltNoOYXWTCKze9N8b6b ICQ+4l8+C938qgPTebD9Anloc3e6xs4oBy5ZcD24rhsFYSD8taLOrdovfOp84jiGG5F/1x oNqcIWhSiRg17/1NcYXpiK87Bry9sPs= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-BVY9S0gvPL-gzjHV4n_Fbg-1; Thu, 27 Feb 2025 12:23:51 -0500 X-MC-Unique: BVY9S0gvPL-gzjHV4n_Fbg-1 X-Mimecast-MFC-AGG-ID: BVY9S0gvPL-gzjHV4n_Fbg_1740677030 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5248E1800984 for ; Thu, 27 Feb 2025 17:23:50 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C72D19560AE; Thu, 27 Feb 2025 17:23:48 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:34 +0100 Message-ID: <20250227172340.4120887-3-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2954yWYHWOQxO8BH_M3zAHwUG5-kRAqRrEkziJp_hrg_1740677030 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 2/8] utilities: upcall_monitor: Monitor dropped upcalls. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Generate events for dropped upcalls and add the print the result. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/usdt-scripts/upcall_monitor.py | 136 +++++++++++++++++++---- 1 file changed, 112 insertions(+), 24 deletions(-) diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index 3a758b2d2..0c2518f54 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -25,6 +25,9 @@ # 5952147.003879643 2 handler4 1381158 system@ovs-system 0 70 160 # 5952147.003914924 2 handler4 1381158 system@ovs-system 0 98 152 # +# Also, upcalls dropped by the kernel (e.g: because the netlink buffer is full) +# are reported. This requires the kernel version to be greater or equal to +# 5.14. # In addition, the packet and flow key data can be dumped. This can be done # using the --packet-decode and --flow-key decode options (see below). # @@ -125,12 +128,13 @@ import sys # Actual eBPF source code # ebpf_source = """ -#include +#include #define MAX_PACKET #define MAX_KEY struct event_t { + int result; u32 cpu; u32 pid; u32 upcall_type; @@ -145,23 +149,28 @@ struct event_t { BPF_RINGBUF_OUTPUT(events, ); BPF_TABLE("percpu_array", uint32_t, uint64_t, dropcnt, 1); +static +void report_missed_event() { + uint32_t type = 0; + uint64_t *value = dropcnt.lookup(&type); + if (value) + __sync_fetch_and_add(value, 1); +} + int do_trace(struct pt_regs *ctx) { uint64_t addr; uint64_t size; struct event_t *event = events.ringbuf_reserve(sizeof(struct event_t)); if (!event) { - uint32_t type = 0; - uint64_t *value = dropcnt.lookup(&type); - if (value) - __sync_fetch_and_add(value, 1); - + report_missed_event(); return 1; } event->ts = bpf_ktime_get_ns(); event->cpu = bpf_get_smp_processor_id(); event->pid = bpf_get_current_pid_tgid(); + event->result = 0; bpf_get_current_comm(&event->comm, sizeof(event->comm)); bpf_usdt_readarg(1, ctx, &addr); @@ -189,32 +198,87 @@ int do_trace(struct pt_regs *ctx) { events.ringbuf_submit(event, 0); return 0; }; + +struct inflight_upcall { + u32 cpu; + u32 upcall_type; + u64 ts; + struct sk_buff *skb; + char dpif_name[32]; +}; +BPF_HASH(inflight_upcalls, u64, struct inflight_upcall); + +TRACEPOINT_PROBE(openvswitch, ovs_dp_upcall) +{ + u64 pid = bpf_get_current_pid_tgid(); + struct inflight_upcall upcall = {}; + + upcall.cpu = bpf_get_smp_processor_id(); + upcall.ts = bpf_ktime_get_ns(); + upcall.upcall_type = args->upcall_cmd; + upcall.skb = args->skbaddr; + TP_DATA_LOC_READ_CONST(&upcall.dpif_name, dp_name, + sizeof(upcall.dpif_name)); + + inflight_upcalls.insert(&pid, &upcall); + return 0; +} + +int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) +{ + u64 pid = bpf_get_current_pid_tgid(); + struct inflight_upcall *upcall; + int ret = PT_REGS_RC(ctx); + u64 size; + + upcall = inflight_upcalls.lookup(&pid); + inflight_upcalls.delete(&pid); + if (!upcall) + return 0; + + /* Successfull upcalls are reported in the USDT probe. */ + if (!ret) + return 0; + + struct event_t *event = events.ringbuf_reserve(sizeof(struct event_t)); + if (!event) { + report_missed_event(); + return 1; + } + + event->ts = upcall->ts; + event->cpu = upcall->cpu; + event->pid = pid; + event->result = ret; + __builtin_memcpy(&event->dpif_name, &upcall->dpif_name, 32); + bpf_get_current_comm(&event->comm, sizeof(event->comm)); + event->pkt_size = upcall->skb->len; + event->upcall_type = upcall->upcall_type; + event->key_size = 0; + + size = upcall->skb->len - upcall->skb->data_len; + if (size > MAX_PACKET) + size = MAX_PACKET; + + bpf_probe_read_kernel(event->pkt, size, upcall->skb->data); + events.ringbuf_submit(event, 0); + return 0; +} """ # -# print_event() +# print_key() # -def print_event(ctx, data, size): - event = b['events'].event(data) - print("{:<18.9f} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<10}". - format(event.ts / 1000000000, - event.cpu, - event.comm.decode("utf-8"), - event.pid, - event.dpif_name.decode("utf-8"), - event.upcall_type, - event.pkt_size, - event.key_size)) - - # - # Dump flow key information - # +def print_key(event): if event.key_size < options.flow_key_size: key_len = event.key_size else: key_len = options.flow_key_size + if not key_len: + return + if options.flow_key_decode != 'none': print(" Flow key size {} bytes, size captured {} bytes.". format(event.key_size, key_len)) @@ -237,6 +301,30 @@ def print_event(ctx, data, size): else: port = "Unknown" + return port + + +# +# print_event() +# +def print_event(ctx, data, size): + event = b['events'].event(data) + print("{:<18.9f} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<12} {:<8}". + format(event.ts / 1000000000, + event.cpu, + event.comm.decode("utf-8"), + event.pid, + event.dpif_name.decode("utf-8"), + event.upcall_type, + event.pkt_size, + event.key_size, + event.result)) + + # + # Dump flow key information + # + port = print_key(event) + # # Decode packet only if there is data # @@ -501,9 +589,9 @@ def main(): # # Print header # - print("{:<18} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<10}".format( + print("{:<18} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<12} {:<8}".format( "TIME", "CPU", "COMM", "PID", "DPIF_NAME", "TYPE", "PKT_LEN", - "FLOW_KEY_LEN")) + "FLOW_KEY_LEN", "RESULT")) # # Dump out all events From patchwork Thu Feb 27 17:23:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053211 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Tk+ezsWS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVY3Xf5z1xrB for ; Fri, 28 Feb 2025 04:24:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0A778416B0; Thu, 27 Feb 2025 17:24:05 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id R6bKPei7Qx8d; Thu, 27 Feb 2025 17:24:02 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 021094156E Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Tk+ezsWS Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 021094156E; Thu, 27 Feb 2025 17:24:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6F7E0C0035; Thu, 27 Feb 2025 17:24:01 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 229B1C0033 for ; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 07BD440816 for ; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4TD6S5sOnJOY for ; Thu, 27 Feb 2025 17:23:56 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org CAA1340845 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CAA1340845 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id CAA1340845 for ; Thu, 27 Feb 2025 17:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j5Z9hqstNzUZfXHwh/J1FOgKaqMmgmq+LZndRIeNzo4=; b=Tk+ezsWSGcSwkkqhRBs5FPCWMvrceUXrhkClT+KWBH1zODqawAw9TsK1rd/9sH7zT7+bpJ WbpGBLGOhRa0Y5lrcKigeJa8Wgz6sjtmqJrFG1A8wQuYSZqvCpArJak8YwRrIUoMzM33rM ldx5kbQTyqPk39tD5KsfSdNoOsuWO/M= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-NTWKq7F7MUSmBkpGJ4dCCg-1; Thu, 27 Feb 2025 12:23:53 -0500 X-MC-Unique: NTWKq7F7MUSmBkpGJ4dCCg-1 X-Mimecast-MFC-AGG-ID: NTWKq7F7MUSmBkpGJ4dCCg_1740677032 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 667FB180087D for ; Thu, 27 Feb 2025 17:23:52 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC3C219560AE; Thu, 27 Feb 2025 17:23:50 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:35 +0100 Message-ID: <20250227172340.4120887-4-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: UohFwCS2MHO7y_WhU5wF5eEQLQs8WMa1pdhh94WhUKs_1740677032 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 3/8] utilities: upcall_monitor: Allow filtering on result. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This patch makes it possible to display only succeeded or errored upcalls. Signed-off-by: Adrian Moreno --- utilities/usdt-scripts/upcall_monitor.py | 58 +++++++++++++++++++----- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index 0c2518f54..ca304d7c9 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -62,6 +62,9 @@ # Set maximum packet size to capture, default 64 # -w PCAP_FILE, --pcap PCAP_FILE # Write upcall packets to specified pcap file. +# -r, --result {error,ok,any} +# Display only events with the given result, +# default: any # # The following is an example of how to use the script on the running # ovs-vswitchd process with a packet and flow key dump enabled: @@ -157,6 +160,7 @@ void report_missed_event() { __sync_fetch_and_add(value, 1); } +#if int do_trace(struct pt_regs *ctx) { uint64_t addr; uint64_t size; @@ -198,7 +202,9 @@ int do_trace(struct pt_regs *ctx) { events.ringbuf_submit(event, 0); return 0; }; +#endif +#if struct inflight_upcall { u32 cpu; u32 upcall_type; @@ -264,6 +270,7 @@ int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) events.ringbuf_submit(event, 0); return 0; } +#endif """ @@ -526,9 +533,29 @@ def main(): parser.add_argument("-w", "--pcap", metavar="PCAP_FILE", help="Write upcall packets to specified pcap file.", type=str, default=None) + parser.add_argument("-r", "--result", + help="Display only events with the given result, " + "default: any", + choices=["error", "ok", "any"], default="any") options = parser.parse_args() + # + # Check if current kernel supports error reporting. + # + upcall_tp_path = \ + "/sys/kernel/debug/tracing/events/openvswitch/ovs_dp_upcall" + + if not exists(upcall_tp_path): + if options.result == "error": + print("ERROR: Monitoring error upcalls is not supported by the " + "running kernel.") + sys.exit(-1) + if options.result == "any": + print("WARN: Monitoring error upcalls is not supported by the " + "running kernel. Only successful ones will be monitored.") + options.result = "ok" + # # Find the PID of the ovs-vswitchd daemon if not specified. # @@ -560,20 +587,23 @@ def main(): # # Attach the usdt probe # - u = USDT(pid=int(options.pid)) - try: - u.enable_probe(probe="recv_upcall", fn_name="do_trace") - except USDTException as e: - print("ERROR: {}" - "ovs-vswitchd!".format( - (re.sub('^', ' ' * 7, str(e), flags=re.MULTILINE)).strip(). - replace("--with-dtrace or --enable-dtrace", - "--enable-usdt-probes"))) - sys.exit(-1) + usdt = [] + if options.result in ["ok", "any"]: + u = USDT(pid=int(options.pid)) + try: + u.enable_probe(probe="recv_upcall", fn_name="do_trace") + usdt.append(u) + except USDTException as e: + print("ERROR: {}" + "ovs-vswitchd!".format( + (re.sub('^', ' ' * 7, str(e), flags=re.MULTILINE)). + strip().replace("--with-dtrace or --enable-dtrace", + "--enable-usdt-probes"))) + sys.exit(-1) # # Uncomment to see how arguments are decoded. - # print(u.get_text()) + # print(u.get_text()) # # @@ -583,8 +613,12 @@ def main(): source = source.replace("", str(options.flow_key_size)) source = source.replace("", str(options.buffer_page_count)) + source = source.replace("", "1" + if options.result in ["ok", "any"] else "0") + source = source.replace("", "1" + if options.result in ["error", "any"] else "0") - b = BPF(text=source, usdt_contexts=[u], debug=options.debug) + b = BPF(text=source, usdt_contexts=usdt, debug=options.debug) # # Print header From patchwork Thu Feb 27 17:23:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053212 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OPSJVe2F; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVf1FJ6z1xrB for ; Fri, 28 Feb 2025 04:24:10 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 444EB41511; Thu, 27 Feb 2025 17:24:10 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id y_-jee9QhK3F; Thu, 27 Feb 2025 17:24:05 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org EAAC0414E7 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OPSJVe2F Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id EAAC0414E7; Thu, 27 Feb 2025 17:24:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 97AD0C0078; Thu, 27 Feb 2025 17:24:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 14AB6C0927 for ; Thu, 27 Feb 2025 17:24:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id EA0BA415DB for ; Thu, 27 Feb 2025 17:24:00 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id VMqTy99wimac for ; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org B07F341517 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B07F341517 Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OPSJVe2F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id B07F341517 for ; Thu, 27 Feb 2025 17:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rLWVvxFyNTgOCukjzQBZl7hLhO1ucLQDR+rAa0PoYKA=; b=OPSJVe2F3YYpnWSGJskDiSHKQc14U+ZeAEvKjtIzyVBAT2BUk/oWS4QZzYNw4AIxRkzxMJ SQ5T5QtYs2zLiit2Z3i2xaaRyeJJTF+QLKKnG/p16ihzau+JEfGLVo1zz10gALf3cRIgAe c8u9lZR3rA9DNaYYepFtEzIdS1QokxE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-prBoup8SNIeLfg1aAg4YiQ-1; Thu, 27 Feb 2025 12:23:55 -0500 X-MC-Unique: prBoup8SNIeLfg1aAg4YiQ-1 X-Mimecast-MFC-AGG-ID: prBoup8SNIeLfg1aAg4YiQ_1740677034 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 46B941800874 for ; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF53319560AE; Thu, 27 Feb 2025 17:23:52 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:36 +0100 Message-ID: <20250227172340.4120887-5-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IVBDFPIrX7vjeukiczm2IfU381RCsTFlCCu6o6V9i8Q_1740677034 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 4/8] utilities: upcall_cost: Refactor port mapping cache. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The upcall_cost.py script has a useful port mapping cache that can be very useful for other scripts. Move it into a library file (usdt_lib.py). While we're at it, refactor it into a class since setting attributes to functions and having it return different types depending on input is not very clean. This patch should not introduce any functional change. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/automake.mk | 7 ++- utilities/usdt-scripts/upcall_cost.py | 71 ++++----------------------- utilities/usdt-scripts/usdt_lib.py | 70 ++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 63 deletions(-) create mode 100644 utilities/usdt-scripts/usdt_lib.py diff --git a/utilities/automake.mk b/utilities/automake.mk index 22260b254..fcd353109 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -28,7 +28,8 @@ usdt_SCRIPTS += \ utilities/usdt-scripts/kernel_delay.rst \ utilities/usdt-scripts/reval_monitor.py \ utilities/usdt-scripts/upcall_cost.py \ - utilities/usdt-scripts/upcall_monitor.py + utilities/usdt-scripts/upcall_monitor.py \ + utilities/usdt-scripts/usdt_lib.py completion_SCRIPTS += \ utilities/ovs-appctl-bashcomp.bash \ @@ -78,7 +79,9 @@ EXTRA_DIST += \ utilities/usdt-scripts/kernel_delay.rst \ utilities/usdt-scripts/reval_monitor.py \ utilities/usdt-scripts/upcall_cost.py \ - utilities/usdt-scripts/upcall_monitor.py + utilities/usdt-scripts/upcall_monitor.py \ + utilities/usdt-scripts/usdt_lib.py + MAN_ROOTS += \ utilities/ovs-testcontroller.8.in \ utilities/ovs-dpctl.8.in \ diff --git a/utilities/usdt-scripts/upcall_cost.py b/utilities/usdt-scripts/upcall_cost.py index f3fa8afc3..cc4151266 100755 --- a/utilities/usdt-scripts/upcall_cost.py +++ b/utilities/usdt-scripts/upcall_cost.py @@ -58,12 +58,13 @@ from strenum import StrEnum from text_histogram3 import histogram from time import process_time +from usdt_lib import DpPortMapping + import argparse import ast import psutil import re import struct -import subprocess import sys # @@ -352,7 +353,7 @@ class DpUpcall(Event): pkt_frag_len): super(DpUpcall, self).__init__(ts, pid, comm, cpu, EventType.DP_UPCALL) self.dpif_name = dpif_name - self.dp_port = get_dp_mapping(dpif_name, port) + self.dp_port = dp_map.get(dpif_name, port) if self.dp_port is None: # # As we only identify interfaces at startup, new interfaces could @@ -445,13 +446,7 @@ class RecvUpcall(Event): self.pkt_len) def get_system_dp_port(dpif_name): - dp_map = get_dp_mapping(dpif_name, "ovs-system", return_map=True) - if dpif_name not in dp_map: - return None - try: - return dp_map[dpif_name]["ovs-system"] - except KeyError: - return None + return dp_map.get_map().get(dpif_name, {}).get("ovs-system", None) def decode_nlm(msg, indent=4, dump=True): bytes_left = len(msg) @@ -620,54 +615,6 @@ class OpFlowExecute(Event): return event -# -# get_dp_mapping() -# -def get_dp_mapping(dp, port, return_map=False, dp_map=None): - if options.unit_test: - return port - - if dp_map is not None: - get_dp_mapping.dp_port_map_cache = dp_map - - # - # Build a cache, so we do not have to execue the ovs command each time. - # - if not hasattr(get_dp_mapping, "dp_port_map_cache"): - try: - output = subprocess.check_output(['ovs-appctl', 'dpctl/show'], - encoding='utf8').split("\n") - except subprocess.CalledProcessError: - output = "" - pass - - current_dp = None - get_dp_mapping.dp_port_map_cache = {} - - for line in output: - match = re.match("^system@(.*):$", line) - if match is not None: - current_dp = match.group(1) - - match = re.match("^ port ([0-9]+): ([^ /]*)", line) - if match is not None and current_dp is not None: - try: - get_dp_mapping.dp_port_map_cache[ - current_dp][match.group(2)] = int(match.group(1)) - except KeyError: - get_dp_mapping.dp_port_map_cache[current_dp] = \ - {match.group(2): int(match.group(1))} - - if return_map: - return get_dp_mapping.dp_port_map_cache - - if dp not in get_dp_mapping.dp_port_map_cache or \ - port not in get_dp_mapping.dp_port_map_cache[dp]: - return None - - return get_dp_mapping.dp_port_map_cache[dp][port] - - # # event_to_dict() # @@ -1428,6 +1375,9 @@ def main(): global events_received global event_count global export_file + global dp_map + + dp_map = DpPortMapping() # # Argument parsing @@ -1530,9 +1480,9 @@ def main(): event_count = {'total': {}, 'valid': {}, 'miss': {}} if options.read_events is None: # - # Call get_dp_mapping() to prepare the cache + # Prepare the datapath port mapping cache # - dp_port_map = get_dp_mapping("ovs-system", "eth0", return_map=True) + dp_port_map = dp_map.get_map() if export_file is not None: export_file.write("dp_port_map = {}\n".format(dp_port_map)) @@ -1641,8 +1591,7 @@ def main(): if entry.startswith('dp_port_map = {'): if not dp_port_mapping_valid: dp_port_mapping_valid = True - get_dp_mapping("", "", - dp_map=ast.literal_eval(entry[14:])) + dp_map.set_map(ast.literal_eval(entry[14:])) elif (entry.startswith('event = {') and dp_port_mapping_valid): event = ast.literal_eval(entry[8:]) diff --git a/utilities/usdt-scripts/usdt_lib.py b/utilities/usdt-scripts/usdt_lib.py new file mode 100644 index 000000000..cf6fa576a --- /dev/null +++ b/utilities/usdt-scripts/usdt_lib.py @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re +import subprocess + + +class DpPortMapping: + """Class used to retrieve and cache datapath port numbers to port names.""" + + def __init__(self): + self.cache_map = None + + def get_map(self): + """Get the cache map.""" + if not self.cache_map: + self._get_mapping() + + return self.cache_map + + def set_map(self, cache_map): + """Override the internal cache map.""" + self.cache_map = cache_map + + def get(self, dp, port_no): + """Get the portname from a port number.""" + if self.cache_map is None: + self._get_mapping() + + return self.cache_map.get(dp, {}).get(port_no, None) + + def _get_mapping(self): + """Get the datapath port mapping from the running OVS.""" + try: + output = subprocess.check_output( + ["ovs-appctl", "dpctl/show"], encoding="utf8" + ).split("\n") + except subprocess.CalledProcessError: + output = "" + return + + current_dp = None + self.cache_map = {} + + for line in output: + match = re.match("^system@(.*):$", line) + if match: + current_dp = match.group(1) + + match = re.match("^ port ([0-9]+): ([^ /]*)", line) + if match and current_dp: + try: + self.cache_map[current_dp][match.group(2)] = int( + match.group(1) + ) + except KeyError: + self.cache_map[current_dp] = { + match.group(2): int(match.group(1)) + } From patchwork Thu Feb 27 17:23:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053214 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bYvL7/uJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVm4yKWz1xrB for ; Fri, 28 Feb 2025 04:24:16 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 64C7361B12; Thu, 27 Feb 2025 17:24:15 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 1v-Ozx2G5UM0; Thu, 27 Feb 2025 17:24:12 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4EEA461798 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bYvL7/uJ Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4EEA461798; Thu, 27 Feb 2025 17:24:07 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E08D1C003D; Thu, 27 Feb 2025 17:24:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0EF53C0033 for ; Thu, 27 Feb 2025 17:24:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 860DF83EED for ; Thu, 27 Feb 2025 17:24:00 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6EHp6W_W0ahf for ; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 37AE383EE0 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 37AE383EE0 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bYvL7/uJ Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 37AE383EE0 for ; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3wAxtW6LlEE+ZJBcgEPlv8PM7OvzcR8HoB86X1cHygU=; b=bYvL7/uJmvl8EmZwQm+Bx+L7Ar25kuJY5WdjrbwH8ZfuOTvPHRM0FvULaqGxVVwg6cLpco GBlKzx8kDFAHZiAt913qI95grDHpPycRCwlmWl6HUwbm72rtA64X+LPEORoJa/OL0ML9pr GaNM+85B15EagB+SiZE9AOY9uLCMXLg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-Olz6AfmUPtmUaai42X17gA-1; Thu, 27 Feb 2025 12:23:56 -0500 X-MC-Unique: Olz6AfmUPtmUaai42X17gA-1 X-Mimecast-MFC-AGG-ID: Olz6AfmUPtmUaai42X17gA_1740677036 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E73A91954B1D for ; Thu, 27 Feb 2025 17:23:55 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6B4D19560AE; Thu, 27 Feb 2025 17:23:54 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:37 +0100 Message-ID: <20250227172340.4120887-6-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IWSM8ZuNhzCWN4Usi6ccb8pupN-dLVgFedS5EXQ4f_w_1740677036 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 5/8] utilities: upcall_monitor: Print port names. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Printing just the datapath on each upcall gives little information (most often, there will only be one well-known datapath). Instead, print both the input port name (plus the datapath). In order to do this, refactor decode_nla to always generate the dump that only gets printed if needed. That way it can be called earlier on. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/usdt-scripts/upcall_cost.py | 4 +- utilities/usdt-scripts/upcall_monitor.py | 110 +++++++++++++---------- utilities/usdt-scripts/usdt_lib.py | 20 ++++- 3 files changed, 84 insertions(+), 50 deletions(-) diff --git a/utilities/usdt-scripts/upcall_cost.py b/utilities/usdt-scripts/upcall_cost.py index cc4151266..605728e6f 100755 --- a/utilities/usdt-scripts/upcall_cost.py +++ b/utilities/usdt-scripts/upcall_cost.py @@ -353,7 +353,7 @@ class DpUpcall(Event): pkt_frag_len): super(DpUpcall, self).__init__(ts, pid, comm, cpu, EventType.DP_UPCALL) self.dpif_name = dpif_name - self.dp_port = dp_map.get(dpif_name, port) + self.dp_port = dp_map.get_port_number(dpif_name, port) if self.dp_port is None: # # As we only identify interfaces at startup, new interfaces could @@ -446,7 +446,7 @@ class RecvUpcall(Event): self.pkt_len) def get_system_dp_port(dpif_name): - return dp_map.get_map().get(dpif_name, {}).get("ovs-system", None) + return dp_map.get_port_number(dpif_name, "ovs-system") def decode_nlm(msg, indent=4, dump=True): bytes_left = len(msg) diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index ca304d7c9..9199818f2 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -20,10 +20,10 @@ # packets sent by the kernel to ovs-vswitchd. By default, it will show all # upcall events, which looks something like this: # -# TIME CPU COMM PID DPIF_NAME TYPE PKT_LEN... -# 5952147.003848809 2 handler4 1381158 system@ovs-system 0 98 132 -# 5952147.003879643 2 handler4 1381158 system@ovs-system 0 70 160 -# 5952147.003914924 2 handler4 1381158 system@ovs-system 0 98 152 +# TIME CPU COMM PID PORT_NAME TYPE .. +# 5952147.003848809 2 handler4 1381158 eth0 (system@ovs-system) 0 +# 5952147.003879643 2 handler4 1381158 eth0 (system@ovs-system) 0 +# 5952147.003914924 2 handler4 1381158 eth0 (system@ovs-system) 0 # # Also, upcalls dropped by the kernel (e.g: because the netlink buffer is full) # are reported. This requires the kernel version to be greater or equal to @@ -71,7 +71,7 @@ # # $ ./upcall_monitor.py --packet-decode decode --flow-key-decode nlraw \ # --packet-size 128 --flow-key-size 256 -# TIME CPU COMM PID DPIF_NAME ... +# TIME CPU COMM PID PORT_NAME ... # 5953013.333214231 2 handler4 1381158 system@ovs-system ... # Flow key size 132 bytes, size captured 132 bytes. # nla_len 8, nla_type OVS_KEY_ATTR_RECIRC_ID[20], data: 00 00 00 00 @@ -121,6 +121,8 @@ from os.path import exists from scapy.all import hexdump, wrpcap from scapy.layers.l2 import Ether +from usdt_lib import DpPortMapping + import argparse import psutil import re @@ -277,7 +279,7 @@ int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) # # print_key() # -def print_key(event): +def print_key(event, decode_dump): if event.key_size < options.flow_key_size: key_len = event.key_size else: @@ -298,39 +300,48 @@ def print_key(event): dump=True), flags=re.MULTILINE)) - if options.flow_key_decode == 'nlraw': - nla = decode_nlm(bytes(event.key)[:key_len]) - else: - nla = decode_nlm(bytes(event.key)[:key_len], dump=False) - - if "OVS_KEY_ATTR_IN_PORT" in nla: - port = struct.unpack("=I", nla["OVS_KEY_ATTR_IN_PORT"])[0] - else: - port = "Unknown" - - return port + if options.flow_key_decode == "nlraw": + for line in decode_dump: + print(line) # # print_event() # def print_event(ctx, data, size): - event = b['events'].event(data) - print("{:<18.9f} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<12} {:<8}". - format(event.ts / 1000000000, - event.cpu, - event.comm.decode("utf-8"), - event.pid, - event.dpif_name.decode("utf-8"), - event.upcall_type, - event.pkt_size, - event.key_size, - event.result)) + event = b["events"].event(data) + dp = event.dpif_name.decode("utf-8") + + nla, key_dump = decode_nlm( + bytes(event.key)[: min(event.key_size, options.flow_key_size)] + ) + if "OVS_KEY_ATTR_IN_PORT" in nla: + port_no = struct.unpack("=I", nla["OVS_KEY_ATTR_IN_PORT"])[0] + port = dp_map.get_port_name(dp.partition("@")[-1], port_no) + if not port: + port = str(port_no) + else: + port = "Unknown" + + print( + "{:<18.9f} {:<4} {:<16} {:<10} {:<40} {:<4} {:<10} {:<12} {:<8}". + format( + event.ts / 1000000000, + event.cpu, + event.comm.decode("utf-8"), + event.pid, + "{} ({})".format(port, dp), + event.upcall_type, + event.pkt_size, + event.key_size, + event.result, + ) + ) # # Dump flow key information # - port = print_key(event) + print_key(event, key_dump) # # Decode packet only if there is data @@ -369,23 +380,26 @@ def print_event(ctx, data, size): # # decode_nlm() # -def decode_nlm(msg, indent=4, dump=True): +def decode_nlm(msg, indent=4): bytes_left = len(msg) result = {} + dump = [] while bytes_left: if bytes_left < 4: - if dump: - print("{}WARN: decode truncated; can't read header".format( - ' ' * indent)) + dump.append( + "{}WARN: decode truncated; can't read header".format( + " " * indent + ) + ) break nla_len, nla_type = struct.unpack("=HH", msg[:4]) if nla_len < 4: - if dump: - print("{}WARN: decode truncated; nla_len < 4".format( - ' ' * indent)) + dump.append( + "{}WARN: decode truncated; nla_len < 4".format(" " * indent) + ) break nla_data = msg[4:nla_len] @@ -397,16 +411,19 @@ def decode_nlm(msg, indent=4, dump=True): else: result[get_ovs_key_attr_str(nla_type)] = nla_data - if dump: - print("{}nla_len {}, nla_type {}[{}], data: {}{}".format( + dump.append( + "{}nla_len {}, nla_type {}[{}], data: {}{}".format( ' ' * indent, nla_len, get_ovs_key_attr_str(nla_type), nla_type, - "".join("{:02x} ".format(b) for b in nla_data), trunc)) + "".join("{:02x} ".format(b) for b in nla_data), trunc) + ) if trunc != "": - if dump: - print("{}WARN: decode truncated; nla_len > msg_len[{}] ". - format(' ' * indent, bytes_left)) + dump.append( + "{}WARN: decode truncated; nla_len > msg_len[{}] ".format( + " " * indent, bytes_left + ) + ) break # update next offset, but make sure it's aligned correctly @@ -414,7 +431,7 @@ def decode_nlm(msg, indent=4, dump=True): msg = msg[next_offset:] bytes_left -= next_offset - return result + return result, dump # @@ -499,6 +516,9 @@ def main(): # global b global options + global dp_map + + dp_map = DpPortMapping() # # Argument parsing @@ -623,8 +643,8 @@ def main(): # # Print header # - print("{:<18} {:<4} {:<16} {:<10} {:<32} {:<4} {:<10} {:<12} {:<8}".format( - "TIME", "CPU", "COMM", "PID", "DPIF_NAME", "TYPE", "PKT_LEN", + print("{:<18} {:<4} {:<16} {:<10} {:<40} {:<4} {:<10} {:<12} {:<8}".format( + "TIME", "CPU", "COMM", "PID", "PORT_NAME", "TYPE", "PKT_LEN", "FLOW_KEY_LEN", "RESULT")) # diff --git a/utilities/usdt-scripts/usdt_lib.py b/utilities/usdt-scripts/usdt_lib.py index cf6fa576a..d8659102f 100644 --- a/utilities/usdt-scripts/usdt_lib.py +++ b/utilities/usdt-scripts/usdt_lib.py @@ -33,12 +33,26 @@ class DpPortMapping: """Override the internal cache map.""" self.cache_map = cache_map - def get(self, dp, port_no): - """Get the portname from a port number.""" + def get_port_name(self, dp, port_no): + """Get the port name from a port number.""" if self.cache_map is None: self._get_mapping() - return self.cache_map.get(dp, {}).get(port_no, None) + if not self.cache_map.get(dp): + return None + + for name, num in self.cache_map[dp].items(): + if num == port_no: + return name + + return None + + def get_port_number(self, dp, port): + """Get the port number from a port name.""" + if self.cache_map is None: + self._get_mapping() + + return self.cache_map.get(dp, {}).get(port, None) def _get_mapping(self): """Get the datapath port mapping from the running OVS.""" From patchwork Thu Feb 27 17:23:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053213 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VXrM7Vad; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVh5lP6z1xrB for ; Fri, 28 Feb 2025 04:24:12 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 90E8F41553; Thu, 27 Feb 2025 17:24:12 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id iIcwJCsBlM03; Thu, 27 Feb 2025 17:24:11 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org CE4444152A Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VXrM7Vad Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id CE4444152A; Thu, 27 Feb 2025 17:24:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A6B01C0035; Thu, 27 Feb 2025 17:24:10 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0FE52C0925 for ; Thu, 27 Feb 2025 17:24:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5DC0583ED9 for ; Thu, 27 Feb 2025 17:24:03 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id IJTE4AVwCNjw for ; Thu, 27 Feb 2025 17:24:02 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 6880183EEE Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6880183EEE Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VXrM7Vad Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6880183EEE for ; Thu, 27 Feb 2025 17:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TO5oiwIWz8HdKEEg0YvWOh87hKNf57YXcxZGrcR/4rE=; b=VXrM7VadOWGlp7AqVK5tj3Yu4nYlCzeKg8cwJ3UY/BSo8UC0IvEgNt748MS93TLojpwd18 EBtA24mjEqn/JJPNp9Xh7cU8vyFnktsx5QWc8tOJxl/0jy0VIJUNf5T5LRAJNaSb8GN476 3Dn8faj6hdz6chXcU+Ft0YuadPK0Qfs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-tk3VGj15P3ydBW3AOHZpiA-1; Thu, 27 Feb 2025 12:23:58 -0500 X-MC-Unique: tk3VGj15P3ydBW3AOHZpiA-1 X-Mimecast-MFC-AGG-ID: tk3VGj15P3ydBW3AOHZpiA_1740677037 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CE4011800373 for ; Thu, 27 Feb 2025 17:23:57 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 882A51955F0F; Thu, 27 Feb 2025 17:23:56 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:38 +0100 Message-ID: <20250227172340.4120887-7-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hXr2ejliC8pp678FtHK3qmm0SYSwfjUeNVcKk_nYs7M_1740677037 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 6/8] utilities: monitor_upcalls: Print ports from drops. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Drop events are generated from the kernel, not ovs-vswitchd so instead of relying on nla decoding, copy the skb's device name directly into the event. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/usdt-scripts/upcall_monitor.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index 9199818f2..a1adeee0a 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -133,6 +133,7 @@ import sys # Actual eBPF source code # ebpf_source = """ +#include #include #define MAX_PACKET @@ -148,6 +149,7 @@ struct event_t { u64 key_size; char comm[TASK_COMM_LEN]; char dpif_name[32]; + char dev_name[16]; unsigned char pkt[MAX_PACKET]; unsigned char key[MAX_KEY]; }; @@ -177,6 +179,7 @@ int do_trace(struct pt_regs *ctx) { event->cpu = bpf_get_smp_processor_id(); event->pid = bpf_get_current_pid_tgid(); event->result = 0; + event->dev_name[0] = 0; bpf_get_current_comm(&event->comm, sizeof(event->comm)); bpf_usdt_readarg(1, ctx, &addr); @@ -237,6 +240,7 @@ int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) u64 pid = bpf_get_current_pid_tgid(); struct inflight_upcall *upcall; int ret = PT_REGS_RC(ctx); + struct net_device *dev; u64 size; upcall = inflight_upcalls.lookup(&pid); @@ -263,6 +267,9 @@ int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) event->pkt_size = upcall->skb->len; event->upcall_type = upcall->upcall_type; event->key_size = 0; + bpf_probe_read(&dev, sizeof(upcall->skb->dev), + ((char *)upcall->skb + offsetof(struct sk_buff, dev))); + bpf_probe_read_kernel(&event->dev_name, 16, dev->name); size = upcall->skb->len - upcall->skb->data_len; if (size > MAX_PACKET) @@ -315,7 +322,9 @@ def print_event(ctx, data, size): nla, key_dump = decode_nlm( bytes(event.key)[: min(event.key_size, options.flow_key_size)] ) - if "OVS_KEY_ATTR_IN_PORT" in nla: + if event.dev_name: + port = event.dev_name.decode("utf-8") + elif "OVS_KEY_ATTR_IN_PORT" in nla: port_no = struct.unpack("=I", nla["OVS_KEY_ATTR_IN_PORT"])[0] port = dp_map.get_port_name(dp.partition("@")[-1], port_no) if not port: From patchwork Thu Feb 27 17:23:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053215 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MCEKHml6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVv6Tj9z1xrB for ; Fri, 28 Feb 2025 04:24:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1915A83EDA; Thu, 27 Feb 2025 17:24:24 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id CcpBFOAACu0E; Thu, 27 Feb 2025 17:24:22 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org CFAB483ECB Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MCEKHml6 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id CFAB483ECB; Thu, 27 Feb 2025 17:24:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83219C0033; Thu, 27 Feb 2025 17:24:14 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24540C0924 for ; Thu, 27 Feb 2025 17:24:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id C9B7941622 for ; Thu, 27 Feb 2025 17:24:04 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OHWyLROFXXy9 for ; Thu, 27 Feb 2025 17:24:03 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 2046A41620 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2046A41620 Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MCEKHml6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 2046A41620 for ; Thu, 27 Feb 2025 17:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/CbB5J9qRQI7Oh0lV3ig2RxOMsdwVTkzElquvM2ernQ=; b=MCEKHml61/hyZb0Q4C2/267rIXIh12Rq7mDLvJVhAA4zN/01WDoW49wrHi/Euul821mi34 V63sTxCZQmptpUlozYZs6bsBqVi6gaB/DZeLha7Cekk6HXa6YNJNPzFdta9tGHDUqG11/j lWHyxIDzSD/SxU+JyfOErdaKyXpK6N8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-3Rmt1E-FOPKlO10ADjI3kw-1; Thu, 27 Feb 2025 12:24:00 -0500 X-MC-Unique: 3Rmt1E-FOPKlO10ADjI3kw-1 X-Mimecast-MFC-AGG-ID: 3Rmt1E-FOPKlO10ADjI3kw_1740677039 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 955ED1800873 for ; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6A52719560B9; Thu, 27 Feb 2025 17:23:58 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:39 +0100 Message-ID: <20250227172340.4120887-8-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Q0GKSil4_ZExciqFpp5cYYINP1sumPwCDONUCeaRmkc_1740677039 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 7/8] utilities: upcall_monitor: Add extra info to pcap. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Use pcapng instead of pcap format and store the result, the key (if available) and the input port name so they are visible in wireshark/tshark. Signed-off-by: Adrian Moreno --- utilities/usdt-scripts/upcall_monitor.py | 53 +++++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/utilities/usdt-scripts/upcall_monitor.py b/utilities/usdt-scripts/upcall_monitor.py index a1adeee0a..77378751f 100755 --- a/utilities/usdt-scripts/upcall_monitor.py +++ b/utilities/usdt-scripts/upcall_monitor.py @@ -118,7 +118,12 @@ from bcc import BPF, USDT, USDTException from os.path import exists -from scapy.all import hexdump, wrpcap +try: + # Try using pcapng support from scapy >= 2.4. + from scapy.all import hexdump, PcapNgWriter +except ImportError: + from scapy.all import hexdump, wrpcap + from scapy.layers.l2 import Ether from usdt_lib import DpPortMapping @@ -282,40 +287,48 @@ int kretprobe__ovs_dp_upcall(struct pt_regs *ctx) #endif """ +pcap_writer = None + # # print_key() # def print_key(event, decode_dump): + lines = [] if event.key_size < options.flow_key_size: key_len = event.key_size else: key_len = options.flow_key_size if not key_len: - return + return [] if options.flow_key_decode != 'none': - print(" Flow key size {} bytes, size captured {} bytes.". - format(event.key_size, key_len)) + lines.append(" Flow key size {} bytes, size captured {} bytes.". + format(event.key_size, key_len)) if options.flow_key_decode == 'hex': # # Abuse scapy's hex dump to dump flow key # - print(re.sub('^', ' ' * 4, hexdump(Ether(bytes(event.key)[:key_len]), - dump=True), - flags=re.MULTILINE)) + lines.extend(re.sub('^', ' ' * 4, + hexdump( + Ether(bytes(event.key)[:key_len]), + dump=True), + flags=re.MULTILINE).split("\n")) if options.flow_key_decode == "nlraw": - for line in decode_dump: - print(line) + lines.extend(decode_dump) + + return lines # # print_event() # def print_event(ctx, data, size): + global pcap_writer + event = b["events"].event(data) dp = event.dpif_name.decode("utf-8") @@ -350,7 +363,9 @@ def print_event(ctx, data, size): # # Dump flow key information # - print_key(event, key_dump) + key_lines = print_key(event, key_dump) + for line in key_lines: + print(line) # # Decode packet only if there is data @@ -383,7 +398,23 @@ def print_event(ctx, data, size): print(re.sub('^', ' ' * 4, packet.show(dump=True), flags=re.MULTILINE)) if options.pcap is not None: - wrpcap(options.pcap, packet, append=True, snaplen=options.packet_size) + try: + if pcap_writer is None: + pcap_writer = PcapNgWriter(options.pcap) + + comment = "cpu={} comm={} pid={} upcall_type={} result={}". format( + event.cpu, event.comm.decode("utf-8"), event.pid, + event.upcall_type, event.result) + + if options.flow_key_decode != 'none': + comment = comment + "\n" + "\n".join(key_lines) + + packet.comment = comment + packet.sniffed_on = "{} ({})".format(port, dp) + pcap_writer.write(packet) + except NameError: # PcapNgWriter not found + wrpcap(options.pcap, packet, append=True, + snaplen=options.packet_size) # From patchwork Thu Feb 27 17:23:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 2053216 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d7WuJzd8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Z3dVy5hgHz1xrB for ; Fri, 28 Feb 2025 04:24:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 77C98415B6; Thu, 27 Feb 2025 17:24:26 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id x70Uhs0QPp3Z; Thu, 27 Feb 2025 17:24:21 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B9F03415B4 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d7WuJzd8 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id B9F03415B4; Thu, 27 Feb 2025 17:24:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C270C0925; Thu, 27 Feb 2025 17:24:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7B10EC0035 for ; Thu, 27 Feb 2025 17:24:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2E1A061AB3 for ; Thu, 27 Feb 2025 17:24:10 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id nuv_uEv_AkPC for ; Thu, 27 Feb 2025 17:24:07 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amorenoz@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 36A63617B4 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 36A63617B4 Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d7WuJzd8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 36A63617B4 for ; Thu, 27 Feb 2025 17:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740677044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U9pZ9Cas6aNw+qCxdA6Rhcu6TifjAPkWIkhmHvufkoE=; b=d7WuJzd8nlf46cpZCGWI9OicTN/08FB3NO7IKpnW6TlbGRf7cJ/zpiUIBLAiE7SsM82JUY BsBkFmCQ5CYXhYLHqw4lzUxShJCeQxlVGWrNfYFOhtsd4GFDUAvxD0BipytmlRGiNe7/rP hz/rZ54YSBEihWIFjAKuaa3lhyptRHg= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-7rzE5aI8N42La2Fpa0XDMQ-1; Thu, 27 Feb 2025 12:24:02 -0500 X-MC-Unique: 7rzE5aI8N42La2Fpa0XDMQ-1 X-Mimecast-MFC-AGG-ID: 7rzE5aI8N42La2Fpa0XDMQ_1740677041 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62C031800872 for ; Thu, 27 Feb 2025 17:24:01 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.32.147]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B42E19560AE; Thu, 27 Feb 2025 17:23:59 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Thu, 27 Feb 2025 18:23:40 +0100 Message-ID: <20250227172340.4120887-9-amorenoz@redhat.com> In-Reply-To: <20250227172340.4120887-1-amorenoz@redhat.com> References: <20250227172340.4120887-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: TJh9cuBGXzO36MDBjLouS8DFkKY7kju3RwlYUFNxvwg_1740677041 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 8/8] utilities: usdt-scripts: Retry on dp cache miss. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" If the dp cache request misses, retry but only a couple of times so we don't overload the system and only if we're not running on an externally provided cache. Signed-off-by: Adrian Moreno Acked-by: Eelco Chaudron --- utilities/usdt-scripts/usdt_lib.py | 50 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/utilities/usdt-scripts/usdt_lib.py b/utilities/usdt-scripts/usdt_lib.py index d8659102f..335b586e8 100644 --- a/utilities/usdt-scripts/usdt_lib.py +++ b/utilities/usdt-scripts/usdt_lib.py @@ -19,43 +19,60 @@ import subprocess class DpPortMapping: """Class used to retrieve and cache datapath port numbers to port names.""" + MAX_REQUESTS = 2 + def __init__(self): self.cache_map = None + self.n_requests = 0 def get_map(self): """Get the cache map.""" - if not self.cache_map: - self._get_mapping() + self._get_mapping() return self.cache_map def set_map(self, cache_map): """Override the internal cache map.""" self.cache_map = cache_map + self.n_requests = self.MAX_REQUESTS - def get_port_name(self, dp, port_no): - """Get the port name from a port number.""" - if self.cache_map is None: - self._get_mapping() + def _retry(self, func): + self._get_mapping() - if not self.cache_map.get(dp): - return None + result = func(self.cache_map) - for name, num in self.cache_map[dp].items(): - if num == port_no: - return name + if not result: + self._get_mapping(refresh=True) + return func(self.cache_map) - return None + return result + + def get_port_name(self, dp, port_no): + """Get the port name from a port number.""" + def _get_port_name(cache_map): + if not cache_map.get(dp): + return None + for name, num in cache_map[dp].items(): + if num == port_no: + return name + + return self._retry(_get_port_name) def get_port_number(self, dp, port): """Get the port number from a port name.""" - if self.cache_map is None: - self._get_mapping() + def _get_port_number(cache_map): + return cache_map.get(dp, {}).get(port, None) - return self.cache_map.get(dp, {}).get(port, None) + return self._retry(_get_port_number) - def _get_mapping(self): + def _get_mapping(self, refresh=False): """Get the datapath port mapping from the running OVS.""" + if self.n_requests >= self.MAX_REQUESTS \ + or (self.cache_map and not refresh): + return + + self.n_requests += 1 + try: output = subprocess.check_output( ["ovs-appctl", "dpctl/show"], encoding="utf8" @@ -82,3 +99,4 @@ class DpPortMapping: self.cache_map[current_dp] = { match.group(2): int(match.group(1)) } +