From patchwork Thu Jul 20 16:30:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13320791 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 C148FEB64DA for ; Thu, 20 Jul 2023 16:33:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64791280135; Thu, 20 Jul 2023 12:33:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0A828004C; Thu, 20 Jul 2023 12:33:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4237C280135; Thu, 20 Jul 2023 12:33:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2D1A928004C for ; Thu, 20 Jul 2023 12:33:06 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C9E87160210 for ; Thu, 20 Jul 2023 16:33:05 +0000 (UTC) X-FDA: 81032534730.03.708B7E1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id E6F70A0025 for ; Thu, 20 Jul 2023 16:33:03 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HydDn72C; spf=pass (imf15.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689870783; 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=eoYdZ3j5mn2MTw1iUVYlPJSnwNWgHj3M8L9iz2kPLwU=; b=eI8c9v4AXJmUnxSKzphLh4heUXZvZKotRHiRq4sbioLO510RKbqycovZCI8MnnITDhB7Ex S80Z2sBVGzSJHnkexsqcWsnyN1SURafJ7ql48X6KqcL38qdxF0kuq0rTtUU6/K12BbyIta EG5DdqYJfULIJZ6qPuToh29JjIjn/2k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689870784; a=rsa-sha256; cv=none; b=M3/4igfOIo68isEM7HN1dq0PJszeX1EGYyZbYfy48txd2k3V0wrz5KJoATYno/eDjCUh18 EYBcicmZC56VsOeM/9j+KdJM0rKyM1RAieVGU2PdfpAXe5E/haYr4m/9OLrYFr2VxT+AT3 Mqi5VHIjQ5+29s6qHckWu+ILivxDIn4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HydDn72C; spf=pass (imf15.hostedemail.com: domain of vschneid@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689870783; 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=eoYdZ3j5mn2MTw1iUVYlPJSnwNWgHj3M8L9iz2kPLwU=; b=HydDn72CehzrZvIyJPDBlvtdLiM6MpixhN2qMqtTinigwG/7HU4e0olqgpIn9cuSSQLoGb C5MmBi5fFL+l/9EY0pJ/fkQA5rt04R8VqJnFuIe/daNQRYTS1LLMjJblGUPa7xwlvT4lR0 JpOWIcbZIvhcQu2fXLAfo6Du0t/UFCc= 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-646-xF48V0OiM2SJcrNgAEdCkA-1; Thu, 20 Jul 2023 12:32:57 -0400 X-MC-Unique: xF48V0OiM2SJcrNgAEdCkA-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 C1AF3936D28; Thu, 20 Jul 2023 16:32:54 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1F9740C206F; Thu, 20 Jul 2023 16:32:46 +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 07/20] tracing/filters: Optimise CPU vs cpumask filtering when the user mask is a single CPU Date: Thu, 20 Jul 2023 17:30:43 +0100 Message-Id: <20230720163056.2564824-8-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-Queue-Id: E6F70A0025 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mpachqug9ekfua3cphjfiarctpqfnwo6 X-HE-Tag: 1689870783-436012 X-HE-Meta: U2FsdGVkX19cadC6isKIWs3o5YN3inuyOmqb2uF4Pv1MMssgrVTV+8BStRAjaAgqoEsPHul81d2IbM0+Fb5ktoViuYRcIlnwbF/Y8ma+qnW97Piqe9CcBUhsnGsba6KMyY5kJo5E83jnsVhOXacWu7d/NmPiEV6/xcFpOQgfFeVWBPghcM1hBU0MFSlocnVKJxfk5L1tGW2UqP+5BbM8FZMax/YHBuJ2QwcCmXZVTY6jIXLMxPYhXfOnNeDIoueM/rZukXMsafhunPe3bViHQWSLLBRBhQs2EBc/GXLqVFTeatB0wH7mSSSuxNxOs7KJN56cnbh77sR7WgCcK2W6Sg/Rg9JirE+D8sc3+RBgr4IS58yJIqb385O12czoUm76jBUxLmU2qZ6psQoy81AfK0IghjNePZTh62EFKMa9cN54086ocpe9E7fFubsC7gahO1xYRv5VpDifIxL8h7QjIo+RU033LW0zFg+OMxbgj06mc8GUaVAjgzbz64zssGglYAEzKP+ikp5ZAWVzb2nmwTBuXY2SXLAOdLkOlcVHutPxPKHP6KbWLl0KRuk3uUaNKscMV0daluE4/Er6/cF0rldzHEHxUysmSURpTHTU7XrYKI0uOSZVGi24xmPfXfDP9G6IwIH6fOfMBmqXaJPQWI52dIVETYI+zbOBndeBCm9tuxdpyL322fNdgkFLkBlaNcsZYzcvwJMWvcmxmhy4hGRSTLbiM+WbCQDp9KfdHKMD7EtyWz8GZv4yhhZ+ZLqp3VT57sPooP6fDR6G1QWjNTLyY9JYfdYUZINuecYN0J6ejneSC5rzYqbXMVbOy+cnIoJbw+qaP+NBYi7ukzW8Y3GeQWICRuW5KfFZnp6MUSE/1PLlQBdmo//zy+DGdjozbVHub+Zd37a/IQSAHajRtpmC9cpCSz2nH+CZbnFN64gKR1HwNleMENgL5fW5jX9xaq8j/TOX5QUH7uUkr7T ZABqgMJF Z7upb5zpPiPGPon8JkfOfEGskPDGIOtlR6Ffile/hksT4MI0unJc9dluK3oQR4DWJHc99aDTECmNCM2mMsvS5xtZnUo0tPlkDu00Z5Ts6+m84EBgfIpF08uEkfH8F7ENzJjqtaMDTJfyqED6B0u2M0PDobSrfOvis9P/6d9541Vu+SqqQHCenFkv3gayXOcXJrq9R/7DflRTb5DlCD9WV+vNmlJPeCrr5YVioDlCGSNNqljma4JEWWGLLhNZ9b+kydyYkUl5M+YmDNyiuLLW3kmARkk4YynBqmQ6OTOGMWn/LtBeGXvxOTLIWQ+okppGLxLb6Np9DYBrU41FdpeX4iFS562fcJ2LpI2pZ5EnQtA0vd77BYaYD8BwBOg== 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: 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. In this case we can directly re-use filter_pred_cpu(), we just need to transform '&' into '==' before executing it. Suggested-by: Steven Rostedt Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 54d642fabb7f1..fd72dacc5d1b8 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_CPU) { + if (single) { pred->val = cpumask_first(pred->mask); kfree(pred->mask); } @@ -1760,7 +1760,12 @@ static int parse_pred(const char *str, void *data, FILTER_PRED_FN_CPUMASK_CPU : FILTER_PRED_FN_CPUMASK; } else if (field->filter_type == FILTER_CPU) { - pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; + if (single) { + pred->op = pred->op == OP_BAND ? OP_EQ : pred->op; + pred->fn_num = FILTER_PRED_FN_CPU; + } else { + 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);