From patchwork Fri Jul 7 17:21:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 117232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3430715vqx; Fri, 7 Jul 2023 10:38:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJo+SUAbGrpokFXZZ5KxcAT1R19FHsI1FT19b4jxf4F7Sg+sGF0WhvJC2esNPoOrS1Wl3R X-Received: by 2002:a17:907:90d5:b0:993:a37a:cb4c with SMTP id gk21-20020a17090790d500b00993a37acb4cmr3870765ejb.9.1688751501077; Fri, 07 Jul 2023 10:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688751501; cv=none; d=google.com; s=arc-20160816; b=ohT/CU2U5sY+V9MrkYEjRxF68B3oZMsHLvQDZw9FjsSS27S1QBUabIZcqBipy2rsd+ tUFR9trN2AMykAUOPNh5y2hotizN5w3Dfl6KmktiYSpFL5TPHbKcmQTnqFT/DbUZ6v6g n67eJ2CSap+/rAvbaE3WoDZuS3YNGsMxMZVIBIPXzeN2nqWGYTqfYMEYNhYO34GM3kJ9 t0TCyu10+G/18YLFgc1SyehEoQZ/eT0A33D7I3Kuo08AQRIDcwNrIfuQjI9PkMuNfNzn MARPv3ZsUcAA48szzXzD9woLF9bGEMu6cNlgHALNm7DnHYFKGGIIxZzDESRYqQVF9gsy VeVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ru1xpHoly8RVJpDGIBIPQWc2v6Ebq5LepRuPaIIUDyE=; fh=P6Lk1G73ziXorgHY2pwMlBudbMoKnFNDjI5Fiv+tnlo=; b=M82EESLzQQ2+Sa9Ohcwv0rqTN8MdoAPJz8Qcy8kmcv4N9zbcBUCZ8WZYuwlrt/hp3T Jqe+XmpUFGWFCj8Kc5eDtKqKFG+98dKvcU7JcrCb2GaKLifC+SLQRsP4Pi+elGVHf3V7 RUakmsmPiNcZUesKuOCckPW4/h5oliQoiHrXJeKDrdxiMe/Fp1Q2RIA/JwlID7CwlB9r j5/hFcnOwZffmcbov4brP9uBkXcIDi6/Xc4PezOuydPbnhVb/SxedM2ewfqK0+tHQROo I4DJdTK125UnUIuEey5aJhhWGBsdgJ+Aw/8aZxhZP5qVY+os5QCN2LshfjcueZTICX66 2RcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="D/GcFg/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a170906860700b009927243e689si2414609ejx.528.2023.07.07.10.37.56; Fri, 07 Jul 2023 10:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="D/GcFg/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232738AbjGGRYD (ORCPT + 99 others); Fri, 7 Jul 2023 13:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232856AbjGGRXt (ORCPT ); Fri, 7 Jul 2023 13:23:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3E3C2686 for ; Fri, 7 Jul 2023 10:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688750546; 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=D/GcFg/kYCyIDD0ZZSaBIi8aab9pYhVcn4F8qTNq65v94KCbgNEv2vtb9vXghFlR292TaW q7yhOKbeQcCFW+mF6DoZAJ2qGyNPzRQLBG60oHABZkEtq3+iLahLCuoWsQNxfvADYIgh8K SGCbbbVLvCMpTn52RRa6SgvxQ2ndX/c= 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-352-MItPMPKePTeia_LL4MNj8g-1; Fri, 07 Jul 2023 13:22:21 -0400 X-MC-Unique: MItPMPKePTeia_LL4MNj8g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C4A8185A794; Fri, 7 Jul 2023 17:22:20 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.164]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D9611454142; Fri, 7 Jul 2023 17:22:19 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Jonathan Corbet , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Leonardo Bras , Frederic Weisbecker Subject: [PATCH v2 4/9] tracing/filters: Enable filtering the CPU common field by a cpumask Date: Fri, 7 Jul 2023 18:21:50 +0100 Message-Id: <20230707172155.70873-5-vschneid@redhat.com> In-Reply-To: <20230707172155.70873-1-vschneid@redhat.com> References: <20230707172155.70873-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770784294051081909?= X-GMAIL-MSGID: =?utf-8?q?1770784294051081909?= 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: