From patchwork Thu Jul 20 16:30:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13320789 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 326D5EB64DD for ; Thu, 20 Jul 2023 16:32:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B50A6280133; Thu, 20 Jul 2023 12:32:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADA4E28004C; Thu, 20 Jul 2023 12:32:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95475280133; Thu, 20 Jul 2023 12:32:48 -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 8463E28004C for ; Thu, 20 Jul 2023 12:32:48 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5598D8020D for ; Thu, 20 Jul 2023 16:32:48 +0000 (UTC) X-FDA: 81032534016.06.FB63F10 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 408CD8001B for ; Thu, 20 Jul 2023 16:32:46 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MPh03rZW; spf=pass (imf02.hostedemail.com: domain of vschneid@redhat.com designates 170.10.129.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=1689870766; 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=07XsHvqnmvZKa7o2IK/zebs5uLAhltI+FwSlNCiWefo=; b=k6TLtE2Cx3WzzBWg5hu9jaA7ku4w5BewJDtlzqBHTLSTtfxRFfbd+U6pAsN5U7ilq4OsBE F2k/04a6Hj//wRe7MUDaCXyk+HyKjdGbMHJ5W3UvBe/d0xeYyFDdV5ykMz8k37wDPlVxvb MYEfYBpKUxxDkdSRJO13Dq2Lc8AMdXs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MPh03rZW; spf=pass (imf02.hostedemail.com: domain of vschneid@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689870766; a=rsa-sha256; cv=none; b=gdqMcFHTbb6W6O5xJb0oGvSCULJFD9H+QD29bFbA+uVR5lws4qICKIIkWr4DOt5IyRjBJD 6xevxHb5Hf4liGKyQoy7Ix29I5QeA2MbVlZWfYF4M2kscdW+bEbm3rdS8DBbN7VCCTFfH2 2Njl2QNkfNs6BtFT7x9RWWlI9ndlhVA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689870765; 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=07XsHvqnmvZKa7o2IK/zebs5uLAhltI+FwSlNCiWefo=; b=MPh03rZWAXlcovDkT2RqEjie7KjpVJMynbLjTazJ7IQBbZi0yni8tpgIEo8x9s1vv/OopJ Tuij0cLeKwVK5I6X0WrxljxkGFyjDMVjRfZ5VbKDBMwsIuJGswFy9qKgxZxIJneGG1qcvS 30OoKDG3SNS1Ha1xZ6UrY6rEheMeQkk= Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-171-KQfh-86JMfWenLLKyFLDqQ-1; Thu, 20 Jul 2023 12:32:41 -0400 X-MC-Unique: KQfh-86JMfWenLLKyFLDqQ-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 A9EAF2812951; Thu, 20 Jul 2023 16:32:38 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E955440C2070; Thu, 20 Jul 2023 16:32:30 +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 05/20] tracing/filters: Optimise cpumask vs cpumask filtering when user mask is a single CPU Date: Thu, 20 Jul 2023 17:30:41 +0100 Message-Id: <20230720163056.2564824-6-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: 408CD8001B X-Rspam-User: X-Stat-Signature: m1145do87ot1e7ztqyaajx1oqbziuh15 X-Rspamd-Server: rspam01 X-HE-Tag: 1689870766-777917 X-HE-Meta: U2FsdGVkX18jLPX6w3o1uJiO9/iMb7vcRN3C9hZ3CDUs7nC2kbsN3vg6K2HLCQR1Fwdyxsq0fet5356Z6uswADXiHDG0uU3UwppoxdJ8OtsR1JRAuDuamflYozEmxRtTrCMD8vXPTiU2wQo5IH88AL/dUGRx9rIQkKKq6SNthV9rYidpyI4Hi/gqUk+2jgM6ozvOlVUNFkbpxcSG5i57IgsHQyjhqgk0wxZM0f/sLEkZq20M4yUSuHb8s6i/N1X4gZbwB+84pdNOwp2rjIYQonZmBbnPXA5Dy1t1vipCmoMbf+7KGlQIg4bSfHNEecNyy9ESl19uNgBAFMNrFq9JRYrZIwnzqchGNtrZ2jI7K7erJkIhW3OOfOJYZ2hirVCFk76QFOhnN0gZrJ5SvDN7N40bydvjXIr907qvkeTfoLxg8ROJ7OhCwOSXRkVkbDo/6zflrbX1Vi82FtbhW25Awx71/xSCcTzReAxFjfKKPdGsbMxT84flLynPT3FevR6TSK1XLL6bj5NCRI1QHHNH/4fe/Im8uAgX0zgvb4H+eQbMnpubSkyyq2p2+Z7CI1hla/BcPcba6lK0N3Ng/YjIbcWzLEaY9AbE11GoXOMypPoqA3TJ9vIOCKgdEWcMpP/8g32rvgnquJLXLPWIRhsL17nLCE3aOsOC0f5YRNrSnt3UaFNT5CU6oeKQp7fGTyXP0HkOWwG0UARBEIHCJhztpG1szLQ89FBCx3H0DIAuIKZU3eTV9y1bcOvfCwLUkCqHOkzLVcVIXrb0Xh2FoLi29LyfcveXV/YN9Aec+LpfzbSI+1InK9z9QW2sz9JeeRop5Qct9knfirjq49uJXFlzYBt7QY5li0NiqV/PfZWI5QgJwGUFjFtMovfIucXUJESl+1OOIKKSutFwQMN1xBfqWAZuqmF0o32JHlc4dbox52QEa1nHSvrpy7dBudNZwfGCHtxLH+H99RzZ1FLMKZR QD764Xy4 9gsWGy37KYQm4jvNgH8oz4FPzAShhqP4ESs9+/YB9wPy6yoF5WaooOi0GTl2oNu4N2DZ6aNwKXwpwxW8ELX0oJ1QtGvPj8CNPUL1j3SMyxAPWxrl6My3n5oNCylm6AI0CMFqriX0Xor75j6S1kih3ETyPiW9CzgrlIiR2RV8T3qOLrw/kKnjVOjhWidahz7823J5bFC64BEABdj8OhDbHneBZm8JV1F3b1BL/EGdDwWptzIr+5G4ahxOLgJCEl3Go7G3+VeBcIY8hCQQ/tPq+GmgKHjS8233OwFCqZ0RfrwxWv+U= 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. Reuse do_filter_scalar_cpumask() when the input mask has a weight of one. Suggested-by: Steven Rostedt Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 3009d0c61b532..2fe65ddeb34ef 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -70,6 +70,7 @@ enum filter_pred_fn { FILTER_PRED_FN_CPU, FILTER_PRED_FN_CPU_CPUMASK, FILTER_PRED_FN_CPUMASK, + FILTER_PRED_FN_CPUMASK_CPU, FILTER_PRED_FN_FUNCTION, FILTER_PRED_FN_, FILTER_PRED_TEST_VISITED, @@ -957,6 +958,22 @@ static int filter_pred_cpumask(struct filter_pred *pred, void *event) return do_filter_cpumask(pred->op, mask, cmp); } +/* Filter predicate for cpumask field vs user-provided scalar */ +static int filter_pred_cpumask_cpu(struct filter_pred *pred, void *event) +{ + u32 item = *(u32 *)(event + pred->offset); + int loc = item & 0xffff; + const struct cpumask *mask = (event + loc); + unsigned int cpu = pred->val; + + /* + * This inverts the usual usage of the function (field is first element, + * user parameter is second), but that's fine because the (scalar, mask) + * operations used are symmetric. + */ + return do_filter_scalar_cpumask(pred->op, cpu, mask); +} + /* Filter predicate for COMM. */ static int filter_pred_comm(struct filter_pred *pred, void *event) { @@ -1453,6 +1470,8 @@ static int filter_pred_fn_call(struct filter_pred *pred, void *event) return filter_pred_cpu_cpumask(pred, event); case FILTER_PRED_FN_CPUMASK: return filter_pred_cpumask(pred, event); + case FILTER_PRED_FN_CPUMASK_CPU: + return filter_pred_cpumask_cpu(pred, event); case FILTER_PRED_FN_FUNCTION: return filter_pred_function(pred, event); case FILTER_PRED_TEST_VISITED: @@ -1666,6 +1685,7 @@ static int parse_pred(const char *str, void *data, } else if (!strncmp(str + i, "CPUS", 4)) { unsigned int maskstart; + bool single; char *tmp; switch (field->filter_type) { @@ -1724,8 +1744,21 @@ static int parse_pred(const char *str, void *data, /* Move along */ i++; + + /* + * Optimisation: if the user-provided mask has a weight of one + * then we can treat it as a scalar input. + */ + single = cpumask_weight(pred->mask) == 1; + if (single && field->filter_type == FILTER_CPUMASK) { + pred->val = cpumask_first(pred->mask); + kfree(pred->mask); + } + if (field->filter_type == FILTER_CPUMASK) { - pred->fn_num = FILTER_PRED_FN_CPUMASK; + pred->fn_num = single ? + FILTER_PRED_FN_CPUMASK_CPU : + FILTER_PRED_FN_CPUMASK; } else if (field->filter_type == FILTER_CPU) { pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK; } else {