From patchwork Fri Jun 9 15:03:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 105697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp1064061rwl; Fri, 9 Jun 2023 08:09:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WAxPgnwQPlyAzIMTNYTK6h3t8eVO08iBp/Ghivqt9+3spwOvV1HyOTakvEneO/2j8FSGa X-Received: by 2002:a17:90a:1983:b0:259:3e17:7e15 with SMTP id 3-20020a17090a198300b002593e177e15mr1621672pji.7.1686323381508; Fri, 09 Jun 2023 08:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686323381; cv=none; d=google.com; s=arc-20160816; b=KiDTVD3BX60qfDyZv+JELhi7TfXpJOyXlhSO+Vt1OKc842MdxBx52JnQuXFjjiBViS GqCcSnjoZdUM1jJVJSsSJA5R5RhcETvaqxSfZQwS4EN53kEaCFBuDJGiIiqqXtXmYFFR EvwiJv1AciKQevG7kH+6u/VjHtsXgT+9u97F2DUzND+EGABPuheJhyBNuDOfbGz3AkVs M9KZH5nTZbmxxNA5Q5a7+pDutgc6wajaW/GDSw44aUHlQX51qy3kClnIv92VdcfJ+Ble 0/d1hRFZlZyLuUWYyq7QhTUycM/u2VNDkTDMJDjoOThDFomnkSOgv++blIaw7J2fQ4R9 +lUA== 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=cr2h91iK1BhRzl41+qr9b8AIAdoW4uuXRZNrsLrfkns=; b=CN+gJtIBObC0xAs54u43ganBHvg0bLqA05wm65MZimBneBYkfoANHJNr373cOE6AtD 3fSF9mGfu4QPADtfW9oX9Bild4rV+OUWxtaKoG6lORR87FdMx9taOxNjLkvpA32JGb0R 9mVcdvyzPXanbrvVEyUrLyhO/YD5vap1kip3gSY+r+e/uczyypQXO6tx7D7H8sh+Rtha Sstp70E3vUAYAmj5rBzMTKtUFL2dN+G+s4J0qluoGiJl/vyI1BmTwPDiEY0/9A+qtBMM UsPp82jcz7l2B04x2RLs6mccL3+V8dPJhqWe3bGi53KXzbmuyBhtIltByfUccuw40RfH 0oSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ICYBnhio; 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 e2-20020a63aa02000000b00502d825633asi2714177pgf.639.2023.06.09.08.09.26; Fri, 09 Jun 2023 08:09:41 -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=ICYBnhio; 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 S241730AbjFIPFI (ORCPT + 99 others); Fri, 9 Jun 2023 11:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241759AbjFIPFA (ORCPT ); Fri, 9 Jun 2023 11:05:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6326F1FEB for ; Fri, 9 Jun 2023 08:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686323053; 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=cr2h91iK1BhRzl41+qr9b8AIAdoW4uuXRZNrsLrfkns=; b=ICYBnhioeXHnyPClAAkGvviy0RpKUagiYu5nqERcWZnKgiHgg8Wb6tIQgwm9qPw+Ys37Tb UdlmUH9Lq4wNRwFvQ2L8fOjJKt7qfaF049LeID0P7c0mexBCc9/TUurXrybxQswe0BD6qC DqTNDP70KEgHL6UrOpYt+Oi12x5L7mo= 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-319-PF1whd6VPRizwjCit04jiA-1; Fri, 09 Jun 2023 11:04:12 -0400 X-MC-Unique: PF1whd6VPRizwjCit04jiA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B5BF101A53B; Fri, 9 Jun 2023 15:04:11 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B3DD4087C62; Fri, 9 Jun 2023 15:04:06 +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: [RFC PATCH 1/5] tracing/filters: Dynamically allocate filter_pred.regex Date: Fri, 9 Jun 2023 16:03:20 +0100 Message-Id: <20230609150324.143538-2-vschneid@redhat.com> In-Reply-To: <20230609150324.143538-1-vschneid@redhat.com> References: <20230609150324.143538-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1768238226256481764?= X-GMAIL-MSGID: =?utf-8?q?1768238226256481764?= Every predicate allocation includes a MAX_FILTER_STR_VAL (256) char array in the regex field, even if the predicate function does not use the field. A later commit will introduce a dynamically allocated cpumask to struct filter_pred, which will require a dedicated freeing function. Bite the bullet and make filter_pred.regex dynamically allocated. While at it, reorder the fields of filter_pred to fill in the byte holes. The struct now fits on a single cacheline. No change in behaviour intended. The kfree()'s were patched via Coccinelle: @@ struct filter_pred *pred; @@ -kfree(pred); +free_predicate(pred); Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 62 ++++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 1dad64267878c..d999a218fe833 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -70,15 +70,15 @@ enum filter_pred_fn { }; struct filter_pred { - enum filter_pred_fn fn_num; - u64 val; - u64 val2; - struct regex regex; + struct regex *regex; unsigned short *ops; struct ftrace_event_field *field; - int offset; + u64 val; + u64 val2; + enum filter_pred_fn fn_num; + int offset; int not; - int op; + int op; }; /* @@ -186,6 +186,12 @@ enum { PROCESS_OR = 4, }; +static void free_predicate(struct filter_pred *pred) +{ + kfree(pred->regex); + kfree(pred); +} + /* * Without going into a formal proof, this explains the method that is used in * parsing the logical expressions. @@ -623,7 +629,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, kfree(inverts); if (prog_stack) { for (i = 0; prog_stack[i].pred; i++) - kfree(prog_stack[i].pred); + free_predicate(prog_stack[i].pred); kfree(prog_stack); } return ERR_PTR(ret); @@ -750,7 +756,7 @@ static int filter_pred_string(struct filter_pred *pred, void *event) char *addr = (char *)(event + pred->offset); int cmp, match; - cmp = pred->regex.match(addr, &pred->regex, pred->regex.field_len); + cmp = pred->regex->match(addr, pred->regex, pred->regex->field_len); match = cmp ^ pred->not; @@ -763,7 +769,7 @@ static __always_inline int filter_pchar(struct filter_pred *pred, char *str) int len; len = strlen(str) + 1; /* including tailing '\0' */ - cmp = pred->regex.match(str, &pred->regex, len); + cmp = pred->regex->match(str, pred->regex, len); match = cmp ^ pred->not; @@ -813,7 +819,7 @@ static int filter_pred_strloc(struct filter_pred *pred, void *event) char *addr = (char *)(event + str_loc); int cmp, match; - cmp = pred->regex.match(addr, &pred->regex, str_len); + cmp = pred->regex->match(addr, pred->regex, str_len); match = cmp ^ pred->not; @@ -836,7 +842,7 @@ static int filter_pred_strrelloc(struct filter_pred *pred, void *event) char *addr = (char *)(&item[1]) + str_loc; int cmp, match; - cmp = pred->regex.match(addr, &pred->regex, str_len); + cmp = pred->regex->match(addr, pred->regex, str_len); match = cmp ^ pred->not; @@ -874,7 +880,7 @@ static int filter_pred_comm(struct filter_pred *pred, void *event) { int cmp; - cmp = pred->regex.match(current->comm, &pred->regex, + cmp = pred->regex->match(current->comm, pred->regex, TASK_COMM_LEN); return cmp ^ pred->not; } @@ -1004,7 +1010,7 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not) static void filter_build_regex(struct filter_pred *pred) { - struct regex *r = &pred->regex; + struct regex *r = pred->regex; char *search; enum regex_type type = MATCH_FULL; @@ -1169,7 +1175,7 @@ static void free_prog(struct event_filter *filter) return; for (i = 0; prog[i].pred; i++) - kfree(prog[i].pred); + free_predicate(prog[i].pred); kfree(prog); } @@ -1553,9 +1559,12 @@ static int parse_pred(const char *str, void *data, goto err_free; } - pred->regex.len = len; - strncpy(pred->regex.pattern, str + s, len); - pred->regex.pattern[len] = 0; + pred->regex = kzalloc(sizeof(*pred->regex), GFP_KERNEL); + if (!pred->regex) + goto err_mem; + pred->regex->len = len; + strncpy(pred->regex->pattern, str + s, len); + pred->regex->pattern[len] = 0; /* This is either a string, or an integer */ } else if (str[i] == '\'' || str[i] == '"') { @@ -1597,9 +1606,12 @@ static int parse_pred(const char *str, void *data, goto err_free; } - pred->regex.len = len; - strncpy(pred->regex.pattern, str + s, len); - pred->regex.pattern[len] = 0; + pred->regex = kzalloc(sizeof(*pred->regex), GFP_KERNEL); + if (!pred->regex) + goto err_mem; + pred->regex->len = len; + strncpy(pred->regex->pattern, str + s, len); + pred->regex->pattern[len] = 0; filter_build_regex(pred); @@ -1608,7 +1620,7 @@ static int parse_pred(const char *str, void *data, } else if (field->filter_type == FILTER_STATIC_STRING) { pred->fn_num = FILTER_PRED_FN_STRING; - pred->regex.field_len = field->size; + pred->regex->field_len = field->size; } else if (field->filter_type == FILTER_DYN_STRING) { pred->fn_num = FILTER_PRED_FN_STRLOC; @@ -1691,10 +1703,10 @@ static int parse_pred(const char *str, void *data, return i; err_free: - kfree(pred); + free_predicate(pred); return -EINVAL; err_mem: - kfree(pred); + free_predicate(pred); return -ENOMEM; } @@ -2287,8 +2299,8 @@ static int ftrace_function_set_filter_pred(struct filter_pred *pred, return ret; return __ftrace_function_set_filter(pred->op == OP_EQ, - pred->regex.pattern, - pred->regex.len, + pred->regex->pattern, + pred->regex->len, data); } From patchwork Fri Jun 9 15:03:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 105702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp1075863rwl; Fri, 9 Jun 2023 08:26:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ645OnV1430nu7x9ez6fP7eKgJiDswxgefxwQNFMshqj+hGEgNZgc2Fxuztii1pGNfXTA+B X-Received: by 2002:a05:6a20:8e0a:b0:10e:2fd5:5106 with SMTP id y10-20020a056a208e0a00b0010e2fd55106mr1516444pzj.35.1686324364860; Fri, 09 Jun 2023 08:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686324364; cv=none; d=google.com; s=arc-20160816; b=zeQSNO5F+dwFuihzzHLOJFflCNReSy6nRXs+hLR1RVeLpDssj52uYumm3tbWP54uNp t29Nr1lsQ6jFxkdid9kxHKxvYB7gGBgKqQ0wcL4N1YdjMnnlObJKqsZrFlL6pcMo3NJ1 Ugp/NqCIhTTRnY50FVIgZF24h4ZAx7adlry9vP7XW+zTnnp6uX6yvorsW4veyevmy37O 0H2xyi8EqBbS0N/YqDwiLHCXw1Z8+g8z5nFr54NahO2ZC+AbbLxB0uwbu+bhL1BuakfP ZPMM4OaFUmvGKjNd/HJiKmpZeFRpkfzqLYWOGESG+v57hvrQBEZ8AGT7PVI75xIf3xqo L5gw== 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=EWVIdw42kvaUEVB9fypVLDqQXfw7FfQjjY+1yjJwfjg=; b=WTSbHiy1ouyYxRRueut861B1DcUNorAzCHxTMy7zZMBxPDqrjmLtLp9Ddr6kKi6CVd JtApFRmNlS9DswY6RoBi8KlH4PpcsvOvwzzsnwPCIiQfUtI6M0LpYh4SPXS7e8ltp0B0 ZYaC5h/SUiFXv14ThucnId+J1XvQb66MTffuoVJmowAOoWB4spYEmbvv3eiHF2gxb2Ky NNGsFW+e5yNtc3clozBSFEDlgMOIrg+CsuNcDw55KCBEvGFjXaFMpQMo1VDl6ldt/6Im amvv1APAki6zOboPuF98mcvNGVbyel3xDhX41yXn42hkFqW9aW66ozQ6Z4VOlqQ4eFeX rKiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VaCpMck9; 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 q10-20020aa7842a000000b006619d87a951si2656711pfn.66.2023.06.09.08.25.31; Fri, 09 Jun 2023 08:26:04 -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=VaCpMck9; 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 S241781AbjFIPFP (ORCPT + 99 others); Fri, 9 Jun 2023 11:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241307AbjFIPFG (ORCPT ); Fri, 9 Jun 2023 11:05:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608DC2D6B for ; Fri, 9 Jun 2023 08:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686323057; 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=EWVIdw42kvaUEVB9fypVLDqQXfw7FfQjjY+1yjJwfjg=; b=VaCpMck9wnDWLIjD5vkqBOGr62oD8vhCqLbqs8hDxD7UN2M4lix2aYRM8M+vWLaSDQREMG HhFAyZIdQq/nKy+geAoBg66LaG594N5ZQ+MKZEVNmHMxJDFbXoGWjXp8o4Bs/94uHVI9gC hojH9BrtT/xj0t1hYTxMdfb6D/0wPoI= 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-453-VQM2C7eiOsWVLUt4-WUDNw-1; Fri, 09 Jun 2023 11:04:14 -0400 X-MC-Unique: VQM2C7eiOsWVLUt4-WUDNw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE9A8185A78B; Fri, 9 Jun 2023 15:04:13 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0D3D4087C62; Fri, 9 Jun 2023 15:04:11 +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: [RFC PATCH 2/5] tracing/filters: Enable filtering a cpumask field by another cpumask Date: Fri, 9 Jun 2023 16:03:21 +0100 Message-Id: <20230609150324.143538-3-vschneid@redhat.com> In-Reply-To: <20230609150324.143538-1-vschneid@redhat.com> References: <20230609150324.143538-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1768239257614586576?= X-GMAIL-MSGID: =?utf-8?q?1768239257614586576?= The recently introduced ipi_send_cpumask trace event contains a cpumask field, but it currently cannot be used in filter expressions. Make event filtering aware of cpumask fields, and allow these to be filtered by a user-provided cpumask. The user-provided cpumask is to be given in cpulist format and wrapped as: "MASK{$cpulist}". The use of curly braces instead of parentheses is to prevent predicate_parse() from parsing the contents of MASK{...} as a full-fledged predicate subexpression. This enables e.g.: $ trace-cmd record -e 'ipi_send_cpumask' -f 'cpu & MASK{2,4,6,8-32}' Signed-off-by: Valentin Schneider --- include/linux/trace_events.h | 1 + kernel/trace/trace_events_filter.c | 85 +++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 7c4a0b72334eb..974ef37a06c83 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -804,6 +804,7 @@ enum { FILTER_RDYN_STRING, FILTER_PTR_STRING, FILTER_TRACE_FN, + FILTER_CPUMASK, FILTER_COMM, FILTER_CPU, FILTER_STACKTRACE, diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index d999a218fe833..8af00caa363f7 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -64,6 +64,7 @@ enum filter_pred_fn { FILTER_PRED_FN_PCHAR_USER, FILTER_PRED_FN_PCHAR, FILTER_PRED_FN_CPU, + FILTER_PRED_FN_CPUMASK, FILTER_PRED_FN_FUNCTION, FILTER_PRED_FN_, FILTER_PRED_TEST_VISITED, @@ -71,6 +72,7 @@ enum filter_pred_fn { struct filter_pred { struct regex *regex; + struct cpumask *mask; unsigned short *ops; struct ftrace_event_field *field; u64 val; @@ -94,6 +96,8 @@ struct filter_pred { C(TOO_MANY_OPEN, "Too many '('"), \ C(TOO_MANY_CLOSE, "Too few '('"), \ C(MISSING_QUOTE, "Missing matching quote"), \ + C(MISSING_BRACE_OPEN, "Missing '{'"), \ + C(MISSING_BRACE_CLOSE, "Missing '}'"), \ C(OPERAND_TOO_LONG, "Operand too long"), \ C(EXPECT_STRING, "Expecting string field"), \ C(EXPECT_DIGIT, "Expecting numeric field"), \ @@ -103,6 +107,7 @@ struct filter_pred { C(BAD_SUBSYS_FILTER, "Couldn't find or set field in one of a subsystem's events"), \ C(TOO_MANY_PREDS, "Too many terms in predicate expression"), \ C(INVALID_FILTER, "Meaningless filter expression"), \ + C(INVALID_CPULIST, "Invalid cpulist"), \ C(IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \ C(INVALID_VALUE, "Invalid value (did you forget quotes)?"), \ C(NO_FUNCTION, "Function not found"), \ @@ -189,6 +194,7 @@ enum { static void free_predicate(struct filter_pred *pred) { kfree(pred->regex); + kfree(pred->mask); kfree(pred); } @@ -875,6 +881,26 @@ static int filter_pred_cpu(struct filter_pred *pred, void *event) } } +/* Filter predicate for cpumasks. */ +static int filter_pred_cpumask(struct filter_pred *pred, void *event) +{ + u32 item = *(u32 *)(event + pred->offset); + int loc = item & 0xffff; + const struct cpumask *mask = (event + loc); + const struct cpumask *cmp = pred->mask; + + switch (pred->op) { + case OP_EQ: + return cpumask_equal(mask, cmp); + case OP_NE: + return !cpumask_equal(mask, cmp); + case OP_BAND: + return cpumask_intersects(mask, cmp); + default: + return 0; + } +} + /* Filter predicate for COMM. */ static int filter_pred_comm(struct filter_pred *pred, void *event) { @@ -1242,8 +1268,12 @@ static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir, int filter_assign_type(const char *type) { - if (strstr(type, "__data_loc") && strstr(type, "char")) - return FILTER_DYN_STRING; + if (strstr(type, "__data_loc")) { + if (strstr(type, "char")) + return FILTER_DYN_STRING; + if (strstr(type, "cpumask_t")) + return FILTER_CPUMASK; + } if (strstr(type, "__rel_loc") && strstr(type, "char")) return FILTER_RDYN_STRING; @@ -1355,6 +1385,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_CPUMASK: + return filter_pred_cpumask(pred, event); case FILTER_PRED_FN_FUNCTION: return filter_pred_function(pred, event); case FILTER_PRED_TEST_VISITED: @@ -1566,6 +1598,55 @@ static int parse_pred(const char *str, void *data, strncpy(pred->regex->pattern, str + s, len); pred->regex->pattern[len] = 0; + } else if (!strncmp(str + i, "MASK", 4)) { + unsigned int maskstart; + char *tmp; + + if (field->filter_type != FILTER_CPUMASK) { + parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i); + goto err_free; + } + + /* Skip MASK */ + i += 4; + if (str[i++] != '{') { + parse_error(pe, FILT_ERR_MISSING_BRACE_OPEN, pos + i); + goto err_free; + } + maskstart = i; + + /* Walk the cpulist until closing } */ + for (; str[i] && str[i] != '}'; i++); + if (str[i] != '}') { + parse_error(pe, FILT_ERR_MISSING_BRACE_CLOSE, pos + i); + goto err_free; + } + + if (maskstart == i) { + parse_error(pe, FILT_ERR_INVALID_CPULIST, pos + i); + goto err_free; + } + + /* Copy the cpulist between { and } */ + tmp = kmalloc(i - maskstart + 1, GFP_KERNEL); + strncpy(tmp, str + maskstart, i - maskstart); + tmp[i - maskstart] = '\0'; + + pred->mask = kzalloc(cpumask_size(), GFP_KERNEL); + if (!pred->mask) + goto err_mem; + + /* Now parse it */ + if (cpulist_parse(tmp, pred->mask)) { + parse_error(pe, FILT_ERR_INVALID_CPULIST, pos + i); + goto err_free; + } + + /* Move along */ + i++; + if (field->filter_type == FILTER_CPUMASK) + pred->fn_num = FILTER_PRED_FN_CPUMASK; + /* This is either a string, or an integer */ } else if (str[i] == '\'' || str[i] == '"') { char q = str[i]; From patchwork Fri Jun 9 15:03:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 105698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp1064462rwl; Fri, 9 Jun 2023 08:10:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wOrOkuFYwbppxP8uDrb0CWPd94Kr+j0kFGqqcLGB9iq0SzQHH+GaHFp191fWkaptY7loQ X-Received: by 2002:a17:90a:bd90:b0:256:b190:2733 with SMTP id z16-20020a17090abd9000b00256b1902733mr1146050pjr.33.1686323412337; Fri, 09 Jun 2023 08:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686323412; cv=none; d=google.com; s=arc-20160816; b=nALvF305w/AjIvXgWsoQgpeRyviWeuj19xJ5u7DOg/Gxf5b3iSEVfHGGvT7b85u9WQ Rr2hoEb8AwfPcaT5itoxpRGJn1jk+nwqSooI7C2Ha4dHB9fV4WBKWiABI7+WskdU/zfE PDTa7T/bZskh9aPL8Sgun/i3GgFMB50AhIB0VdrG1QcJObNmviMzO4FEUHPf6wOM2sfu SY+vfJqMfbAQaGa/L9BkB2Tm4J3RekUYXqtBiKaMe96wm/cB7r676L1dbaKXp7JHaUsy RYCfkxZ3aPaRh2hgCyqnY+P3zm+hrxeGPoTQOSd0uepVryN0fvrxJkTgpdosqu9akbDN I4nw== 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=BTFUs8gxr9moRkZBUGlN4k/3c1CssODo/4E7AM+Boo0=; b=skMceilbK/SE5E6LfIg3npIDTZEeL9ep6War3b97inCqZcxCtZhDgfvYj3mrGPH2bY Fweo3Hy/JF6BA3d03oYzolOYLe5EdyuXLkoHcp6EussCOsRyPnMF7vtdpBfIVsxMUxEP +x/u6LaTdBCJNXf8ZU3iu3CQX9RleVXwXsvftsh2saS9X18bpB+Sxld0ipFwDCW1tU9+ Cb2rmM8KZCdRVdeHjfHd/GOJGdkrXNhT/mgnQ7jozpihEnq1X3noso2wFNj4F7huPqqJ KcEcMIXn/MY0FDY5zmU1H5xpfqt+RChsyvQTTfM7o7TAc0esEF5JKBJyZfGn+BqrMAG2 WYmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SjyG5SK5; 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 a21-20020a170902b59500b001ac83d19265si2740647pls.291.2023.06.09.08.09.58; Fri, 09 Jun 2023 08:10:12 -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=SjyG5SK5; 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 S241822AbjFIPF0 (ORCPT + 99 others); Fri, 9 Jun 2023 11:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241737AbjFIPFI (ORCPT ); Fri, 9 Jun 2023 11:05:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D80130E4 for ; Fri, 9 Jun 2023 08:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686323058; 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=BTFUs8gxr9moRkZBUGlN4k/3c1CssODo/4E7AM+Boo0=; b=SjyG5SK5fCa1O9gr1DsjMuwVuiXGPn109aVpGxNjqFCKHDSra/m2Nihbs/lc1F/qJ831LV aYeJWl5XpTxYdmrxHq9W9Y9KQo+FbtgzUJ4ghRbifL5Dy/xmGEChfbZ8rNXso9APvVqtcD DOUC1FyCr0GHJSzPmbzdCPkQ0AXVX5I= 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-157-vuAZu9-eP4-7JP3ypZOA8g-1; Fri, 09 Jun 2023 11:04:17 -0400 X-MC-Unique: vuAZu9-eP4-7JP3ypZOA8g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83AEB101A53B; Fri, 9 Jun 2023 15:04:16 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17BEE4087C67; Fri, 9 Jun 2023 15:04:14 +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: [RFC PATCH 3/5] tracing/filters: Enable filtering a scalar field by a cpumask Date: Fri, 9 Jun 2023 16:03:22 +0100 Message-Id: <20230609150324.143538-4-vschneid@redhat.com> In-Reply-To: <20230609150324.143538-1-vschneid@redhat.com> References: <20230609150324.143538-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1768238258174316243?= X-GMAIL-MSGID: =?utf-8?q?1768238258174316243?= Several events use a scalar field to denote a CPU: o sched_wakeup.target_cpu o sched_migrate_task.orig_cpu,dest_cpu o sched_move_numa.src_cpu,dst_cpu o ipi_send_cpu.cpu o ... Filtering these currently requires using arithmetic comparison functions, which can be tedious when dealing with interleaved SMT or NUMA CPU ids. Allow these to be filtered by a user-provided cpumask, which enables e.g.: $ trace-cmd record -e 'sched_wakeup' -f 'target_cpu & MASK{2,4,6,8-32}' Signed-off-by: Valentin Schneider --- NOTE: I went with an implicit cpumask conversion of the event field, as AFAICT predicate_parse() does not support parsing the application of a function to a field (e.g. 'MASK(target_cpu) & MASK{2,4,6,8-32}') --- kernel/trace/trace_events_filter.c | 92 ++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 8af00caa363f7..99e111c237a93 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -46,15 +46,19 @@ static const char * ops[] = { OPS }; enum filter_pred_fn { FILTER_PRED_FN_NOP, FILTER_PRED_FN_64, + FILTER_PRED_FN_64_CPUMASK, FILTER_PRED_FN_S64, FILTER_PRED_FN_U64, FILTER_PRED_FN_32, + FILTER_PRED_FN_32_CPUMASK, FILTER_PRED_FN_S32, FILTER_PRED_FN_U32, FILTER_PRED_FN_16, + FILTER_PRED_FN_16_CPUMASK, FILTER_PRED_FN_S16, FILTER_PRED_FN_U16, FILTER_PRED_FN_8, + FILTER_PRED_FN_8_CPUMASK, FILTER_PRED_FN_S8, FILTER_PRED_FN_U8, FILTER_PRED_FN_COMM, @@ -641,6 +645,37 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, return ERR_PTR(ret); } +static inline int +do_filter_cpumask(int op, const struct cpumask *mask, const struct cpumask *cmp) +{ + switch (op) { + case OP_EQ: + return cpumask_equal(mask, cmp); + case OP_NE: + return !cpumask_equal(mask, cmp); + case OP_BAND: + return cpumask_intersects(mask, cmp); + default: + return 0; + } +} + +/* Optimisation of do_filter_cpumask() for scalar values */ +static inline int +do_filter_cpumask_scalar(int op, unsigned int cpu, const struct cpumask *mask) +{ + switch (op) { + case OP_EQ: + return cpumask_equal(mask, cpumask_of(cpu)); + case OP_NE: + return !cpumask_equal(mask, cpumask_of(cpu)); + case OP_BAND: + return cpumask_test_cpu(cpu, mask); + default: + return 0; + } +} + enum pred_cmp_types { PRED_CMP_TYPE_NOP, PRED_CMP_TYPE_LT, @@ -684,6 +719,18 @@ static int filter_pred_##type(struct filter_pred *pred, void *event) \ } \ } +#define DEFINE_CPUMASK_COMPARISON_PRED(size) \ +static int filter_pred_##size##_cpumask(struct filter_pred *pred, void *event) \ +{ \ + u##size *addr = (u##size *)(event + pred->offset); \ + unsigned int cpu = *addr; \ + \ + if (cpu >= nr_cpu_ids) \ + return 0; \ + \ + return do_filter_cpumask_scalar(pred->op, cpu, pred->mask); \ +} + #define DEFINE_EQUALITY_PRED(size) \ static int filter_pred_##size(struct filter_pred *pred, void *event) \ { \ @@ -705,6 +752,11 @@ DEFINE_COMPARISON_PRED(u16); DEFINE_COMPARISON_PRED(s8); DEFINE_COMPARISON_PRED(u8); +DEFINE_CPUMASK_COMPARISON_PRED(64); +DEFINE_CPUMASK_COMPARISON_PRED(32); +DEFINE_CPUMASK_COMPARISON_PRED(16); +DEFINE_CPUMASK_COMPARISON_PRED(8); + DEFINE_EQUALITY_PRED(64); DEFINE_EQUALITY_PRED(32); DEFINE_EQUALITY_PRED(16); @@ -889,16 +941,7 @@ static int filter_pred_cpumask(struct filter_pred *pred, void *event) const struct cpumask *mask = (event + loc); const struct cpumask *cmp = pred->mask; - switch (pred->op) { - case OP_EQ: - return cpumask_equal(mask, cmp); - case OP_NE: - return !cpumask_equal(mask, cmp); - case OP_BAND: - return cpumask_intersects(mask, cmp); - default: - return 0; - } + return do_filter_cpumask(pred->op, mask, cmp); } /* Filter predicate for COMM. */ @@ -1349,24 +1392,32 @@ static int filter_pred_fn_call(struct filter_pred *pred, void *event) switch (pred->fn_num) { case FILTER_PRED_FN_64: return filter_pred_64(pred, event); + case FILTER_PRED_FN_64_CPUMASK: + return filter_pred_64_cpumask(pred, event); case FILTER_PRED_FN_S64: return filter_pred_s64(pred, event); case FILTER_PRED_FN_U64: return filter_pred_u64(pred, event); case FILTER_PRED_FN_32: return filter_pred_32(pred, event); + case FILTER_PRED_FN_32_CPUMASK: + return filter_pred_32_cpumask(pred, event); case FILTER_PRED_FN_S32: return filter_pred_s32(pred, event); case FILTER_PRED_FN_U32: return filter_pred_u32(pred, event); case FILTER_PRED_FN_16: return filter_pred_16(pred, event); + case FILTER_PRED_FN_16_CPUMASK: + return filter_pred_16_cpumask(pred, event); case FILTER_PRED_FN_S16: return filter_pred_s16(pred, event); case FILTER_PRED_FN_U16: return filter_pred_u16(pred, event); case FILTER_PRED_FN_8: return filter_pred_8(pred, event); + case FILTER_PRED_FN_8_CPUMASK: + return filter_pred_8_cpumask(pred, event); case FILTER_PRED_FN_S8: return filter_pred_s8(pred, event); case FILTER_PRED_FN_U8: @@ -1602,7 +1653,8 @@ static int parse_pred(const char *str, void *data, unsigned int maskstart; char *tmp; - if (field->filter_type != FILTER_CPUMASK) { + if (field->filter_type != FILTER_CPUMASK && + field->filter_type != FILTER_OTHER) { parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i); goto err_free; } @@ -1644,8 +1696,24 @@ static int parse_pred(const char *str, void *data, /* Move along */ i++; - if (field->filter_type == FILTER_CPUMASK) + if (field->filter_type == FILTER_CPUMASK) { pred->fn_num = FILTER_PRED_FN_CPUMASK; + } else { + switch (field->size) { + case 8: + pred->fn_num = FILTER_PRED_FN_64_CPUMASK; + break; + case 4: + pred->fn_num = FILTER_PRED_FN_32_CPUMASK; + break; + case 2: + pred->fn_num = FILTER_PRED_FN_16_CPUMASK; + break; + case 1: + pred->fn_num = FILTER_PRED_FN_8_CPUMASK; + break; + } + } /* This is either a string, or an integer */ } else if (str[i] == '\'' || str[i] == '"') { From patchwork Fri Jun 9 15:03:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 105699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp1071236rwl; Fri, 9 Jun 2023 08:18:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wg43srd3zoMPZ9aJL7iwZi9yrvncKYmdiB/jnPZCqo2Slprn/AmxYU85GoM2jVgIsZ8S6 X-Received: by 2002:a05:6a21:6811:b0:10f:500b:18a2 with SMTP id wr17-20020a056a21681100b0010f500b18a2mr1291882pzb.48.1686323937428; Fri, 09 Jun 2023 08:18:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686323937; cv=none; d=google.com; s=arc-20160816; b=LhjL3t52hEDvNK2fnmqEZrc5j/oUW51QhCYCzu2sWEIwtG7q/12Mledyi8qOUL/YG4 wzSJ7riouX+/HXzadx+Hb3VWxMe6AZ+xUDjqlkVQskmss9Pl+kh6qPoNWLcXEM4Qvqf2 PNmHrLyvRtCr15Dbr/jkzNkT0elHIRn/OXVg492Oux9ySaZcaBxVq1jLGgidSRi5Jc25 f9P0iM63z4Tv7zrB5zs3G6lyjhfAdwf5tz6TP8tKN04IK/jNsZ3B3MKz6Ft48vrIxF/1 QA+QkHjEmXItaLuUeovlygl2GFdi4Q8gSMLVUoZCR+HEXoB8y9WY9cQHbRcq/+gQQxHy WZcw== 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=HhCGDFDeE6330wjTb7+eVdOM5sDQ6eAc/Pd0Q124xLM=; b=czSzc/JPgAce7G+0XjXlD2APDVuPApFyVxtjaegcQVDFaKpmO9+1149NWRDvEgaAog 3Te3EJTuRBrphTux1Z9pAAXVmSFwRdd3gKJ9eRlX/s5UjcX4SjNfMnqfs3B6Ejvfn+aQ wqHyQ0m5DNFP82a2ZYJkJU0A3mhXUYMkPpdxa5D6hzx1sJcoel6KBBl3nXe3ucdRhTLu QBPxcAdjbaH+A3Op9lpa5eWo1ZNai5l1+0d57e+QKC2FNBMrQA7nFyjoFxejfblyvfZU GgiEUig5Zfisx6bWQUgqkxcZMJCVZnxXNUh0etj/b54UCXPipJlY/+/EbwIsW9Y8RVy8 Dj2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XCOLcq3N; 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 f18-20020a637552000000b0053fb3bdd2fesi2754546pgn.506.2023.06.09.08.18.38; Fri, 09 Jun 2023 08:18:57 -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=XCOLcq3N; 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 S239633AbjFIPH3 (ORCPT + 99 others); Fri, 9 Jun 2023 11:07:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231344AbjFIPH0 (ORCPT ); Fri, 9 Jun 2023 11:07:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57F5635A9 for ; Fri, 9 Jun 2023 08:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686323187; 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=XCOLcq3N0RtxwxyMV5G1epM4iyIsgYU3nh8+nyKNMl/iWE5sY6W5gN/X/AOd630rY8Twk1 1schNugwd2LAlsa0rGpCN0YBoFjdPbCf8NZhjhmRD0bLIjcqiYGdbWHDrxvc+4KOy553Rt sYJY0tWMiv2iWi533SEewGt5I1DdZms= 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-609-Tk9tFEnVO-ePKnVkh1JcRA-1; Fri, 09 Jun 2023 11:04:26 -0400 X-MC-Unique: Tk9tFEnVO-ePKnVkh1JcRA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CDA43C0D1A5; Fri, 9 Jun 2023 15:04:18 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD1BC4087C6A; Fri, 9 Jun 2023 15:04:16 +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: [RFC PATCH 4/5] tracing/filters: Enable filtering the CPU common field by a cpumask Date: Fri, 9 Jun 2023 16:03:23 +0100 Message-Id: <20230609150324.143538-5-vschneid@redhat.com> In-Reply-To: <20230609150324.143538-1-vschneid@redhat.com> References: <20230609150324.143538-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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, 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?1768238809074181090?= X-GMAIL-MSGID: =?utf-8?q?1768238809074181090?= 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: From patchwork Fri Jun 9 15:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 105701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp1075672rwl; Fri, 9 Jun 2023 08:25:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5U8S4Alo29W6vaHn9Z7gpRYOOEqDgiJZeUUdMiv/z1G0Unpi/izg6SKxWIPe7dE/KLeV97 X-Received: by 2002:a05:6a00:b46:b0:64b:f03b:2642 with SMTP id p6-20020a056a000b4600b0064bf03b2642mr2123463pfo.23.1686324346168; Fri, 09 Jun 2023 08:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686324346; cv=none; d=google.com; s=arc-20160816; b=F5NT+9y4vWJ4j4IX1c12JvtETf/jBvIMWuBMqg5UV3fUVSIbROv8g954+ApiAdCAKT 2UzROOoPb06T6FEYuxmwaJU88O7qrQ7SzUgJN9bXBwQvl2LRVTH6W3pSabw4EI4eeuB6 tBZqOweeJrV/kp52cX7wg/JQNklvFq8Y4dRmtwNMYnqV5n3FdYJddU3XLLNtsAV1zE6F T4+2E2v06Bfqz/aViYSML+82k9Wmuwi/LbvDjhm1FzeCb9uLOwq3Ox9ouZT5KJ4qU1aV A9GIwwhhZb7pvg5DgYbIYpeBxswJIz/Me0c+cTSOqVGzvNJNIblqxRogU1Z6EvFOiNL1 jtcQ== 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=snCuxFAiT0B/bnlHGtaiRqsJwVD+zCZujmUlSZJWpwM=; b=D/+m6sIsFSIpU0A7JU2VbDj9kJkDF5LWhOoUr2RwxiExvRgnSqAOm3TwkDjO3PnGl4 39DJpSiIt4nLpA0gW7BaxlvbgcN0SK75o3dav4af+3aqXUbLlCIPcTY47JOXvC8JkYZU koEg7eymNI7I3KKcI/WQS1h0nCNFsiHr4uaBFeSuvFv4d/JFrq2x7TPVooCf0neesA2l j3BH2XuIxOWSVG7UL7riW8nU/YuwbcHSjymdumN3PDrKrrWYjbLw6QmP9ceEq4zLLO3J hoVG1aE5lyk+dMLI+LKbqqSQiEsrS9EwnUii372fNKo8ilW/YV4wKNybzpt5KjSu8V7i 47EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FYvttFH6; 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 s65-20020a637744000000b005406e76606csi2759161pgc.900.2023.06.09.08.25.21; Fri, 09 Jun 2023 08:25:46 -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=FYvttFH6; 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 S231981AbjFIPFu (ORCPT + 99 others); Fri, 9 Jun 2023 11:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241482AbjFIPFh (ORCPT ); Fri, 9 Jun 2023 11:05:37 -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 C1BFC35B7 for ; Fri, 9 Jun 2023 08:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686323069; 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=snCuxFAiT0B/bnlHGtaiRqsJwVD+zCZujmUlSZJWpwM=; b=FYvttFH64LWYJcp7fnajMu/mF/2g4z/EazwGxwTHpP3IytegGxCHK4a9F6d60TIhtdXqCu zGOC/B9qp/EbwCFL4qB4+URujsBlEnzpNCiq0YnkSCzXLqjBV2t069hHsaJSlvtxo1Whzj YooSlBuvlQk8pL08x/+bEGTpz2JLJKE= 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-80-nCse8t6ROPCfh-6T_4NSdQ-1; Fri, 09 Jun 2023 11:04:25 -0400 X-MC-Unique: nCse8t6ROPCfh-6T_4NSdQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 73E2E101A52C; Fri, 9 Jun 2023 15:04:24 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AACC54087C62; Fri, 9 Jun 2023 15:04:18 +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: [RFC PATCH 5/5] tracing/filters: Document cpumask filtering Date: Fri, 9 Jun 2023 16:03:24 +0100 Message-Id: <20230609150324.143538-6-vschneid@redhat.com> In-Reply-To: <20230609150324.143538-1-vschneid@redhat.com> References: <20230609150324.143538-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_H5,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?1768239237466015098?= X-GMAIL-MSGID: =?utf-8?q?1768239237466015098?= Cpumask, scalar and CPU fields can now be filtered by a user-provided cpumask, document the syntax. Signed-off-by: Valentin Schneider --- Documentation/trace/events.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/trace/events.rst b/Documentation/trace/events.rst index f5fcb8e1218f6..e9bc9f23891a0 100644 --- a/Documentation/trace/events.rst +++ b/Documentation/trace/events.rst @@ -219,6 +219,20 @@ the function "security_prepare_creds" and less than the end of that function. The ".function" postfix can only be attached to values of size long, and can only be compared with "==" or "!=". +Cpumask fields or scalar fields that encode a CPU number can be filtered using +a user-provided cpumask in cpulist format. The format is as follows:: + + MASK{$cpulist} + +Operators available to cpumask filtering are: + +& (intersection), ==, != + +For example, this will filter events that have their .target_cpu field present +in the given cpumask:: + + target_cpu & MASK{17-42} + 5.2 Setting filters -------------------