[RFC,v2,06/20] tracing/filters: Optimise scalar vs cpumask filtering when the user mask is a single CPU
Message ID | 20230720163056.2564824-7-vschneid@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3244840vqt; Thu, 20 Jul 2023 09:39:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFo85hbX/CTb9hr5Tu4aI69nqpVEH8SdmD1cR8E0Ty9gcs9Qdd6vLWysyhbLWqClZrCfg/w X-Received: by 2002:a05:6512:39d3:b0:4fb:94c6:fd63 with SMTP id k19-20020a05651239d300b004fb94c6fd63mr2412469lfu.17.1689871173776; Thu, 20 Jul 2023 09:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689871173; cv=none; d=google.com; s=arc-20160816; b=lfn/7wBzv7adFYOO8n4ha7bC0d5hDJ9Ps6k+Or7fBCqiywBVSazAguDgfaXOK1Zg4o ijY0C2ZjX4qBfNSc7fTzRY6BLe4tON5c3B0ThJIjEAEpeIkRxXqu0KuEFMMaQaOifkP1 RoJdkSEbKeI7B5HAriQmskejUqOcvpdNLfaSuJHxQHouezTAlCP4za/cmEhr4dIC5ZLx qTpfB21xaSk93ZUG33Ppwlgd9RmXm6qQEq8lsI8bftkRVenjebfR68WNf7vyUrXTnZ9T rNpu969ZxwkWMqa0ayCn3bK0GynQAbfTk5eSK3uy6D3qMhpPtuN8yoZtSlqAbb0nIlMI tnow== 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=Aip5VpUJA7qveL6maeQFBeNCXZHRxiQ1qBeFLUBOMzY=; fh=PtaPM/evcxdC1AWAoNYkNA7d0RyqsevCG9x/XhoE/I4=; b=igAa1+MehImPEeJV6ycNuX07SRC9WtZX/nGCn1l6Kw7VBfFbSTJOv6gHMvNFETv6nW AjEh0lmwBKvIMv68jf+VPCYz/qiepGxT6xWK4hvhvjqHY38GbTnRXNUcJ64kmHGu2LWd KMIW8gy2h60BYVTmB0/ZoVXcQYG9FegZLdyZzUwqJBWlYdEiKaFwX2E/9bxGPAN8mzxt hXUH2KYaMrFj3UppERQjCRRs9JyXZTUUEydhe/oRBCWLaspfQL07ZGlMnsH5bpYI/CRd ZBSEGN3tNH/G9xs1KD6shklDhANllx24B5fiQ0PhkaCrx4L6NHrNtfpXYJt12o3mSUDT UY4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XWfFkNjF; 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 z19-20020a1709063a1300b00991e6951c1bsi849138eje.423.2023.07.20.09.39.09; Thu, 20 Jul 2023 09:39:33 -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=XWfFkNjF; 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 S231396AbjGTQd6 (ORCPT <rfc822;assdfgzxcv4@gmail.com> + 99 others); Thu, 20 Jul 2023 12:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbjGTQds (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Jul 2023 12:33:48 -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 CA43A19B5 for <linux-kernel@vger.kernel.org>; Thu, 20 Jul 2023 09:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689870773; 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=Aip5VpUJA7qveL6maeQFBeNCXZHRxiQ1qBeFLUBOMzY=; b=XWfFkNjFh9W1M2PllnU/1UWFnlbphgIrFBv3NEVA8Qtk8yvikWDNsuJXcBpnt9j+VMtuBp YPSEMbBp5U+Kkkkh5INe2ZlaUFU6sCBBsxZakCwSYGX/r0zkVm1nJPdJzdlC+mVVmQ/iOK Yf0ltBHhj1XC7ll+JrfET0QrpyesGuc= 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-660-hS_t_EPEMJWOi3NXCeMnHQ-1; Thu, 20 Jul 2023 12:32:51 -0400 X-MC-Unique: hS_t_EPEMJWOi3NXCeMnHQ-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 91B94901848; Thu, 20 Jul 2023 16:32:46 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8DB640C206F; Thu, 20 Jul 2023 16:32:38 +0000 (UTC) From: Valentin Schneider <vschneid@redhat.com> 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 <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org>, Jonathan Corbet <corbet@lwn.net>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com>, Paolo Bonzini <pbonzini@redhat.com>, Wanpeng Li <wanpengli@tencent.com>, Vitaly Kuznetsov <vkuznets@redhat.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Frederic Weisbecker <frederic@kernel.org>, "Paul E. McKenney" <paulmck@kernel.org>, Neeraj Upadhyay <quic_neeraju@quicinc.com>, Joel Fernandes <joel@joelfernandes.org>, Josh Triplett <josh@joshtriplett.org>, Boqun Feng <boqun.feng@gmail.com>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Lai Jiangshan <jiangshanlai@gmail.com>, Zqiang <qiang.zhang1211@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, Uladzislau Rezki <urezki@gmail.com>, Christoph Hellwig <hch@infradead.org>, Lorenzo Stoakes <lstoakes@gmail.com>, Josh Poimboeuf <jpoimboe@kernel.org>, Jason Baron <jbaron@akamai.com>, Kees Cook <keescook@chromium.org>, Sami Tolvanen <samitolvanen@google.com>, Ard Biesheuvel <ardb@kernel.org>, Nicholas Piggin <npiggin@gmail.com>, Juerg Haefliger <juerg.haefliger@canonical.com>, Nicolas Saenz Julienne <nsaenz@kernel.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Nadav Amit <namit@vmware.com>, Dan Carpenter <error27@gmail.com>, Chuang Wang <nashuiliang@gmail.com>, Yang Jihong <yangjihong1@huawei.com>, Petr Mladek <pmladek@suse.com>, "Jason A. Donenfeld" <Jason@zx2c4.com>, Song Liu <song@kernel.org>, Julian Pidancet <julian.pidancet@oracle.com>, Tom Lendacky <thomas.lendacky@amd.com>, Dionna Glaze <dionnaglaze@google.com>, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>, Juri Lelli <juri.lelli@redhat.com>, Daniel Bristot de Oliveira <bristot@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>, Yair Podemsky <ypodemsk@redhat.com> Subject: [RFC PATCH v2 06/20] tracing/filters: Optimise scalar vs cpumask filtering when the user mask is a single CPU Date: Thu, 20 Jul 2023 17:30:42 +0100 Message-Id: <20230720163056.2564824-7-vschneid@redhat.com> In-Reply-To: <20230720163056.2564824-1-vschneid@redhat.com> References: <20230720163056.2564824-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771958356136391453 X-GMAIL-MSGID: 1771958356136391453 |
Series |
context_tracking,x86: Defer some IPIs until a user->kernel transition
|
|
Commit Message
Valentin Schneider
July 20, 2023, 4:30 p.m. UTC
Steven noted that when the user-provided cpumask contains a single CPU,
then the filtering function can use a scalar as input instead of a
full-fledged cpumask.
When the mask contains a single CPU, directly re-use the unsigned field
predicate functions. Transform '&' into '==' beforehand.
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
kernel/trace/trace_events_filter.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On Thu, 20 Jul 2023 17:30:42 +0100 Valentin Schneider <vschneid@redhat.com> wrote: > Steven noted that when the user-provided cpumask contains a single CPU, > then the filtering function can use a scalar as input instead of a > full-fledged cpumask. > > When the mask contains a single CPU, directly re-use the unsigned field > predicate functions. Transform '&' into '==' beforehand. > > Suggested-by: Steven Rostedt <rostedt@goodmis.org> > Signed-off-by: Valentin Schneider <vschneid@redhat.com> > --- > kernel/trace/trace_events_filter.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c > index 2fe65ddeb34ef..54d642fabb7f1 100644 > --- a/kernel/trace/trace_events_filter.c > +++ b/kernel/trace/trace_events_filter.c > @@ -1750,7 +1750,7 @@ static int parse_pred(const char *str, void *data, > * then we can treat it as a scalar input. > */ > single = cpumask_weight(pred->mask) == 1; > - if (single && field->filter_type == FILTER_CPUMASK) { > + if (single && field->filter_type != FILTER_CPU) { > pred->val = cpumask_first(pred->mask); > kfree(pred->mask); > } > @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, > FILTER_PRED_FN_CPUMASK; > } else if (field->filter_type == FILTER_CPU) { > pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; > + } else if (single) { > + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; Nit, the above can be written as: pred->op = pret->op != OP_BAND ? : OP_EQ; -- Steve > + pred->fn_num = select_comparison_fn(pred->op, field->size, false); > + if (pred->op == OP_NE) > + pred->not = 1; > } else { > switch (field->size) { > case 8:
On 29/07/23 15:55, Steven Rostedt wrote: > On Thu, 20 Jul 2023 17:30:42 +0100 > Valentin Schneider <vschneid@redhat.com> wrote: > >> Steven noted that when the user-provided cpumask contains a single CPU, >> then the filtering function can use a scalar as input instead of a >> full-fledged cpumask. >> >> When the mask contains a single CPU, directly re-use the unsigned field >> predicate functions. Transform '&' into '==' beforehand. >> >> Suggested-by: Steven Rostedt <rostedt@goodmis.org> >> Signed-off-by: Valentin Schneider <vschneid@redhat.com> >> --- >> kernel/trace/trace_events_filter.c | 7 ++++++- >> 1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c >> index 2fe65ddeb34ef..54d642fabb7f1 100644 >> --- a/kernel/trace/trace_events_filter.c >> +++ b/kernel/trace/trace_events_filter.c >> @@ -1750,7 +1750,7 @@ static int parse_pred(const char *str, void *data, >> * then we can treat it as a scalar input. >> */ >> single = cpumask_weight(pred->mask) == 1; >> - if (single && field->filter_type == FILTER_CPUMASK) { >> + if (single && field->filter_type != FILTER_CPU) { >> pred->val = cpumask_first(pred->mask); >> kfree(pred->mask); >> } >> @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, >> FILTER_PRED_FN_CPUMASK; >> } else if (field->filter_type == FILTER_CPU) { >> pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; >> + } else if (single) { >> + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; > > Nit, the above can be written as: > > pred->op = pret->op != OP_BAND ? : OP_EQ; > That's neater, thanks! > -- Steve > > >> + pred->fn_num = select_comparison_fn(pred->op, field->size, false); >> + if (pred->op == OP_NE) >> + pred->not = 1; >> } else { >> switch (field->size) { >> case 8:
On Sat, Jul 29, 2023 at 03:55:47PM -0400, Steven Rostedt wrote: > > @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, > > FILTER_PRED_FN_CPUMASK; > > } else if (field->filter_type == FILTER_CPU) { > > pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; > > + } else if (single) { > > + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; > > Nit, the above can be written as: > > pred->op = pret->op != OP_BAND ? : OP_EQ; > Heh. Those are not equivalent. The right way to write this is: if (pred->op == OP_BAND) pred->op = OP_EQ; regards, dan carpenter
On Mon, 31 Jul 2023 15:07:52 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > On Sat, Jul 29, 2023 at 03:55:47PM -0400, Steven Rostedt wrote: > > > @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, > > > FILTER_PRED_FN_CPUMASK; > > > } else if (field->filter_type == FILTER_CPU) { > > > pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; > > > + } else if (single) { > > > + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; > > > > Nit, the above can be written as: > > > > pred->op = pret->op != OP_BAND ? : OP_EQ; > > > > Heh. Those are not equivalent. The right way to write this is: You mean because of my typo? > > if (pred->op == OP_BAND) > pred->op = OP_EQ; But sure, I'm fine with that, and it's probably more readable too. -- Steve
On Mon, Jul 31, 2023 at 11:54:53AM -0400, Steven Rostedt wrote: > On Mon, 31 Jul 2023 15:07:52 +0300 > Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > On Sat, Jul 29, 2023 at 03:55:47PM -0400, Steven Rostedt wrote: > > > > @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, > > > > FILTER_PRED_FN_CPUMASK; > > > > } else if (field->filter_type == FILTER_CPU) { > > > > pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; > > > > + } else if (single) { > > > > + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; > > > > > > Nit, the above can be written as: > > > > > > pred->op = pret->op != OP_BAND ? : OP_EQ; > > > > > > > Heh. Those are not equivalent. The right way to write this is: > > You mean because of my typo? No, I hadn't seen the s/pred/pret/ typo. Your code does: if (pred->op != OP_BAND) pred->op = true; else pred->op OP_EQ; Realy we should probably trigger a static checker warning any time someone does a compare operations as part of a "x = comparison ?: bar; Years ago, someone asked me to do that with regards to error codes like: return ret < 0 ?: -EINVAL; but I don't remember the results. regards, dan carpenter
On 31/07/23 19:03, Dan Carpenter wrote: > On Mon, Jul 31, 2023 at 11:54:53AM -0400, Steven Rostedt wrote: >> On Mon, 31 Jul 2023 15:07:52 +0300 >> Dan Carpenter <dan.carpenter@linaro.org> wrote: >> >> > On Sat, Jul 29, 2023 at 03:55:47PM -0400, Steven Rostedt wrote: >> > > > @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, >> > > > FILTER_PRED_FN_CPUMASK; >> > > > } else if (field->filter_type == FILTER_CPU) { >> > > > pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; >> > > > + } else if (single) { >> > > > + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; >> > > >> > > Nit, the above can be written as: >> > > >> > > pred->op = pret->op != OP_BAND ? : OP_EQ; >> > > >> > >> > Heh. Those are not equivalent. The right way to write this is: >> >> You mean because of my typo? > > No, I hadn't seen the s/pred/pret/ typo. Your code does: > > if (pred->op != OP_BAND) > pred->op = true; > else > pred->op OP_EQ; > > Realy we should probably trigger a static checker warning any time > someone does a compare operations as part of a "x = comparison ?: bar; > Years ago, someone asked me to do that with regards to error codes like: > > return ret < 0 ?: -EINVAL; > > but I don't remember the results. > FWIW this is caught by GCC: error: the omitted middle operand in ?: will always be ‘true’, suggest explicit middle operand [-Werror=parentheses] pred->op = pred->op != OP_BAND ? : OP_EQ; > regards, > dan carpenter
On Mon, 31 Jul 2023 19:03:04 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > Nit, the above can be written as: > > > > > > > > pred->op = pret->op != OP_BAND ? : OP_EQ; > > > > > > > > > > Heh. Those are not equivalent. The right way to write this is: > > > > You mean because of my typo? > > No, I hadn't seen the s/pred/pret/ typo. Your code does: > > if (pred->op != OP_BAND) > pred->op = true; > else > pred->op OP_EQ; Ah, for some reason I was thinking the ? : just was just a nop, but I guess it is to assign the cond value :-/ But of course every place I've done that, it was the condition value I wanted, which was the same as the value being assigned. Thanks, -- Steve
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 2fe65ddeb34ef..54d642fabb7f1 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1750,7 +1750,7 @@ static int parse_pred(const char *str, void *data, * then we can treat it as a scalar input. */ single = cpumask_weight(pred->mask) == 1; - if (single && field->filter_type == FILTER_CPUMASK) { + if (single && field->filter_type != FILTER_CPU) { pred->val = cpumask_first(pred->mask); kfree(pred->mask); } @@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data, FILTER_PRED_FN_CPUMASK; } else if (field->filter_type == FILTER_CPU) { pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; + } else if (single) { + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; + pred->fn_num = select_comparison_fn(pred->op, field->size, false); + if (pred->op == OP_NE) + pred->not = 1; } else { switch (field->size) { case 8: