From patchwork Thu Jul 20 16:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13320788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97B1BEB64DA for ; Thu, 20 Jul 2023 16:32:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ED8F280132; Thu, 20 Jul 2023 12:32:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 275C628004C; Thu, 20 Jul 2023 12:32:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C882280132; Thu, 20 Jul 2023 12:32:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EEDA428004C for ; Thu, 20 Jul 2023 12:32:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AB58F1201DC for ; Thu, 20 Jul 2023 16:32:40 +0000 (UTC) X-FDA: 81032533680.29.2F77E9A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 34D7F1C0031 for ; Thu, 20 Jul 2023 16:32:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nd8+fnSy; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689870758; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ru1xpHoly8RVJpDGIBIPQWc2v6Ebq5LepRuPaIIUDyE=; b=GMdh7jPgGDdPpoqx5FIr4QS/HwQ3UTsi/pNSgoSdsP2e3fPrPwkuW4TW1L6FaB1k8Pl4LT 8KMYulJJ83I1gG59vX1aO0Xlw6TpVxO+PpyBtAdD/NcZrLaRLYzUztnH0wJ+qqPd0BDXVw pOPnjivBKfeTpisMwCGPFAGYRTiTW0k= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nd8+fnSy; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689870758; a=rsa-sha256; cv=none; b=zyFrlIAqBkeET2nKpHa0t1IshjX34KJX+DWpcg7oL7HUsXjiJjkJDrWze0a9eJQgFpUUQo vAtqwRcYJyBDuk+t/X5f0+VMMG+0L44FI54EUlgf2qkQX/M3X/QbHLruZ9ieavV5WqKlVC HVeToCJ34yNoGnukpFklTq3qCOx0UzM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689870757; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ru1xpHoly8RVJpDGIBIPQWc2v6Ebq5LepRuPaIIUDyE=; b=Nd8+fnSyrqK5jkh5DSLtui61/xLP/CZtRAon3lWFGAhfQHQN6Ztp8cECi4f118o/u7BXE/ qrrW71K3/S0RNkB67KJA9CN/lUD36gOIDKacJAZG0ftzxu37rl2tdqpKdoYFUttcWW5ecg aSvbJi0peh3Q+VY5AUuljloJlZzcMPg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-468-L0PDvKruOe6zKXZsgB5siQ-1; Thu, 20 Jul 2023 12:32:33 -0400 X-MC-Unique: L0PDvKruOe6zKXZsgB5siQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B209B1044590; Thu, 20 Jul 2023 16:32:30 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4F2E40C206F; Thu, 20 Jul 2023 16:32:16 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, x86@kernel.org, rcu@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Andy Lutomirski , Peter Zijlstra , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Josh Poimboeuf , Jason Baron , Kees Cook , Sami Tolvanen , Ard Biesheuvel , Nicholas Piggin , Juerg Haefliger , Nicolas Saenz Julienne , "Kirill A. Shutemov" , Nadav Amit , Dan Carpenter , Chuang Wang , Yang Jihong , Petr Mladek , "Jason A. Donenfeld" , Song Liu , Julian Pidancet , Tom Lendacky , Dionna Glaze , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Yair Podemsky Subject: [RFC PATCH v2 04/20] tracing/filters: Enable filtering the CPU common field by a cpumask Date: Thu, 20 Jul 2023 17:30:40 +0100 Message-Id: <20230720163056.2564824-5-vschneid@redhat.com> In-Reply-To: <20230720163056.2564824-1-vschneid@redhat.com> References: <20230720163056.2564824-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 34D7F1C0031 X-Stat-Signature: idntrwze3ugah5jp19cz4uuib7j1qx6n X-Rspam-User: X-HE-Tag: 1689870757-456753 X-HE-Meta: U2FsdGVkX1+a+tdgQOYwePmgVV7qtWMbGEF4i2alo7VDVrQptqxQr4MpsRE021k0Ey6q7EmNI6xucY9wCNsAQcOkybF8e1iIQ7ASdbfBPe8g0OYQSTHWBPZcbZjI0PURJX+V18QJ5KbqWO3tKw/7sta26ZhNLEK2UnwLIkbhCcPZiFGQxYxqmlzteCIHjNBurKPEmjac5k5mkpSyFQOwOs68nw1ybtF5WotmVlWGZdspLNasyVpPEBPz96AVJ95myQqXdhUPCPUSWPimlodj7asDZg+FuYDnONk11ub9XpiY2Zh0LEFwtsCIujwHnaBtkLOBepsHhi8YehTfk2ce/FwHz2AA+UNzaVoTQ7FOque+DuJoVXMWL70WgK7wwE1fRlnrFjvybMu/S3UjBaX30nG88MD4ad5Puuj+EYpw+0OnACEfruPkgniQmhqIVotdxoOPvRjS9KdwlHpPb9/rZe7f/GLdT5/9xf+VFmkHPUIM9tPtzqRE4v9o5egIw8wulBxjBWCLO99SfsG7EnY8/8sTNnKl8ji3rbNIGc1t6HWokJpQv4jyz1W832/WAjfBTmhK5Mv/Lu7UTtno8sIjPXz8gcusuYEYZDtRDR0X4tsiFO8Xd3hKeNl5MVXQPBakLW6sZLAAsQLjYXyCnswzp97Xz+ErPKW+jBar/WoWeufkMcXBXF48OukyOSVy9STNstIJdYuZlaH5EPxVA+wk+9xxqVYQstoPn/0XbRWBHC6uZ8O2jeVaTAF4MYgl0X7ycgB+/llDxpGWoFVfqwibaZlmF62zfK1FMY3GqnrHaOjz/3X+1iqyCo6W5fhpvXH5WdSr9ESy9VMQygEJyf1GgtGbqW9FktII0DGeCGUdDV0HSjRhuBRVbjfPmfxrh/zKYtO6WJXC5BAJNbKlb7v4N4yhHKbybxDGOAtawdf7j6TtzzT9Z4ZhslWhR9zHw7yqojqxb3RqKebAS7Bi3nP O5vbAKMB /lp4tqvmpVZq8NBxknUbLABLcGCYRQ30uhPg4u8d+O/eqhVfX1d5uoLxjd8SGbQqCiHbPQMcE9Uxo5WWF4MNnqXVlCmIFC3mOIuGbIzPrgXC7VX3i8WTXf87eV2bRzCVB+j/2ddoq5nR04urXX8yBVhd8mgW4JqWsiMifXU8L4GwcFLaMRvq8Jju+Ksh4Gr8TE9GggjUFr80kwQZnIxh51gVK2lJkkZPXwPGXBYwBn3xGXCQWBrwhvn9F4g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The tracing_cpumask lets us specify which CPUs are traced in a buffer instance, but doesn't let us do this on a per-event basis (unless one creates an instance per event). A previous commit added filtering scalar fields by a user-given cpumask, make this work with the CPU common field as well. This enables doing things like $ trace-cmd record -e 'sched_switch' -f 'CPU & CPUS{12-52}' \ -e 'sched_wakeup' -f 'target_cpu & CPUS{12-52}' Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 1e14f801685a8..3009d0c61b532 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -68,6 +68,7 @@ enum filter_pred_fn { FILTER_PRED_FN_PCHAR_USER, FILTER_PRED_FN_PCHAR, FILTER_PRED_FN_CPU, + FILTER_PRED_FN_CPU_CPUMASK, FILTER_PRED_FN_CPUMASK, FILTER_PRED_FN_FUNCTION, FILTER_PRED_FN_, @@ -937,6 +938,14 @@ static int filter_pred_cpu(struct filter_pred *pred, void *event) } } +/* Filter predicate for current CPU vs user-provided cpumask */ +static int filter_pred_cpu_cpumask(struct filter_pred *pred, void *event) +{ + int cpu = raw_smp_processor_id(); + + return do_filter_scalar_cpumask(pred->op, cpu, pred->mask); +} + /* Filter predicate for cpumask field vs user-provided cpumask */ static int filter_pred_cpumask(struct filter_pred *pred, void *event) { @@ -1440,6 +1449,8 @@ static int filter_pred_fn_call(struct filter_pred *pred, void *event) return filter_pred_pchar(pred, event); case FILTER_PRED_FN_CPU: return filter_pred_cpu(pred, event); + case FILTER_PRED_FN_CPU_CPUMASK: + return filter_pred_cpu_cpumask(pred, event); case FILTER_PRED_FN_CPUMASK: return filter_pred_cpumask(pred, event); case FILTER_PRED_FN_FUNCTION: @@ -1659,6 +1670,7 @@ static int parse_pred(const char *str, void *data, switch (field->filter_type) { case FILTER_CPUMASK: + case FILTER_CPU: case FILTER_OTHER: break; default: @@ -1714,6 +1726,8 @@ static int parse_pred(const char *str, void *data, i++; if (field->filter_type == FILTER_CPUMASK) { pred->fn_num = FILTER_PRED_FN_CPUMASK; + } else if (field->filter_type == FILTER_CPU) { + pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; } else { switch (field->size) { case 8: