From patchwork Wed Jul 5 18:12:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13302570 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 723B5C001DD for ; Wed, 5 Jul 2023 18:16:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 101B98D0003; Wed, 5 Jul 2023 14:16:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08B2D8D0001; Wed, 5 Jul 2023 14:16:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E47358D0003; Wed, 5 Jul 2023 14:16:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D0ABA8D0001 for ; Wed, 5 Jul 2023 14:16:34 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 77CD2120441 for ; Wed, 5 Jul 2023 18:16:34 +0000 (UTC) X-FDA: 80978363508.10.9940A29 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 9EF7514001A for ; Wed, 5 Jul 2023 18:16:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OM4s+tMN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1688580992; 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=HhCGDFDeE6330wjTb7+eVdOM5sDQ6eAc/Pd0Q124xLM=; b=vMIrEzCDa75diBzw0WngwgobnpxuFlHFKA9uv/MwS0XoG6pcjGanxknASXSEiLbJuMHz9Q pCD9ivXCcc4qJNu62KhVoFHxRykWBQucuo+RO6gxPi4+JucbPNVVUW60ynbNj/PbshKQQ8 ceY6dSLBOTauHNOrMrRm7sTcUBwfc3Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OM4s+tMN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1688580992; a=rsa-sha256; cv=none; b=H+zQXCRDYsD4uWXW8en8CJaZ6fmgiq0IPucUtJDPzr6VUngjpTd62uwlL6CJjtHTjUTyuN KWdGmJBneTn4UdyZSxadgzhrY9/FZr/kPV6wVwqj7jzbv3gRchbQWF2dpPminwrJEGJcID skHEF6XyFn7KZIFQmqdeAZMKOcV6VOY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688580991; 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=HhCGDFDeE6330wjTb7+eVdOM5sDQ6eAc/Pd0Q124xLM=; b=OM4s+tMNhZpUJoSFCwxhRgVsfO2+z5RrMOsvgeVozQXajPZuBmMjllPIB0u6x/ThvFAhsF pi/SPRJgB5M9N1S2631asrkcR8/eBlIc+VRh+76wTjPeIIsTlcjkfwI/Zv3ipR+jXTn0Py tNXOHzXlgcAE0smgqb4USzLypXmydxw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-9fom_J9fNdKBOQiCT3xrlw-1; Wed, 05 Jul 2023 14:16:26 -0400 X-MC-Unique: 9fom_J9fNdKBOQiCT3xrlw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 930C32808E6D; Wed, 5 Jul 2023 18:16:24 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.164]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E602BF5CFB; Wed, 5 Jul 2023 18:15:54 +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 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" , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Josh Poimboeuf , 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 04/14] tracing/filters: Enable filtering the CPU common field by a cpumask Date: Wed, 5 Jul 2023 19:12:46 +0100 Message-Id: <20230705181256.3539027-5-vschneid@redhat.com> In-Reply-To: <20230705181256.3539027-1-vschneid@redhat.com> References: <20230705181256.3539027-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Stat-Signature: 9y5f9p1m86mtq8yinooknhgwfo9h3rim X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9EF7514001A X-HE-Tag: 1688580992-119639 X-HE-Meta: U2FsdGVkX18OotV+TYFGvX/RIFMrxlfLJZpN8FyLzDBAHG61xpARSYjZr1SmLQxUi96qgBFmqwhNFEAQX2vmOVVDPFFxy8d9No/OUMPx+XNZ3wzU4ElfutZOt98nb8rcNBUVaTEBc+kynMQVbkSRQxeSB3HOLnbYcYpYqBH8ZjMscc4oxfwr8uLIaL7pmnFyOIfkinBcYjGQS1zc8HCWCniHa7x2LTqIgCszd2DMamRiMzeksT0ljrIfxhS3p8BXkJY03OLAvC5U+dWPO4scHSxNW+eKu6h4QqBQ8W5ZRWYqym1bObdMr95X+3ZjDDikWowgiOC8Qs4B+cji3gs2m0+2VevQHCbK4CNx+JeZ5vPTPfuxOTYFNsVgYdq3ICZN/pOZy8INL/p5VUT+O8byxqDY0B/kZMiBLxFBqlDXecQHHbhrhy0JHD0lON3lqbktDfw7bO2dH9nrTknUPKnT1m9miaFM3tudJA91tVDrMLMEEWJ4s8aswPY1iCI2nptabDzvLvj+YwmOk8Sz+ZROU1fsyx/x3PNIj6dXQhdHbwd4s49oq0d3RvAiyeMQ9cfdm3/KOh+mmZ7eydgYfDJrUTijaPfw0+iT0ptGXY5bglDsMGkenl7mdzmn8D89PUzmq3+dOGm/ZQ+YE16E/O3Wu3CqGnF7DAHq4YzeBzXfj7aBDUdTuvM2b48zQ2LSuJVWnQUIeE+WvPlQk8kxcrB1RSLHVXBhgBAa+rjUYC8dfmpDEzExVCCMRhVxYToBJBu9fCtPjVbPddActp03LaxMU8OzBhvJfBvFqQM6l1u8ZI7laqwqQBmFJlr/4JADWd4evPekMywe+rSxGZk/ItoQJ4e4PCvvahuGdhEgdVn5ea4RLCnHes8PyE5NAgVcSO8OeCDJFZigN78aNWMI6E50nfiD0PrhJ6PwaBQEWpVN02Wz+35YiGUJqSZA9cZcDO5+x39LpY/UpHE57mcJJ87 Rln+Yo76 cE24zmuYlFh/pvL/3RXSpk0uNDhxeoCH4ABsL6SubXkg6fD4CCcXr6/n5ov2HzEaeH85yEE055QNVxSKt0uLmob/AGjXjsvWC3kD5zv0coyRIUyu/XjqQgqZqOZLfHSwqdnw4C+stJPNLk8O9gqbj/b527R8uVXl1q9yh3DgeEcSgqGQ= 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 & MASK{12-52}' \ -e 'sched_wakeup' -f 'target_cpu & MASK{12-52}' Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 99e111c237a93..b3d2612d4670a 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_, @@ -933,6 +934,13 @@ static int filter_pred_cpu(struct filter_pred *pred, void *event) } } +static int filter_pred_cpu_cpumask(struct filter_pred *pred, void *event) +{ + int cpu = raw_smp_processor_id(); + + return do_filter_cpumask_scalar(pred->op, cpu, pred->mask); +} + /* Filter predicate for cpumasks. */ static int filter_pred_cpumask(struct filter_pred *pred, void *event) { @@ -1436,6 +1444,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: @@ -1654,6 +1664,7 @@ static int parse_pred(const char *str, void *data, char *tmp; if (field->filter_type != FILTER_CPUMASK && + field->filter_type != FILTER_CPU && field->filter_type != FILTER_OTHER) { parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i); goto err_free; @@ -1698,6 +1709,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: