From patchwork Thu Jul 20 16:30:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 13320792 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 6FD07EB64DA for ; Thu, 20 Jul 2023 16:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CA14280136; Thu, 20 Jul 2023 12:33:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 052E828004C; Thu, 20 Jul 2023 12:33:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE860280136; Thu, 20 Jul 2023 12:33:14 -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 CE9B528004C for ; Thu, 20 Jul 2023 12:33:14 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 78CEF1401E2 for ; Thu, 20 Jul 2023 16:33:14 +0000 (UTC) X-FDA: 81032535108.23.77DE031 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 8A766140028 for ; Thu, 20 Jul 2023 16:33:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VjOWU8+5; spf=pass (imf26.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689870792; a=rsa-sha256; cv=none; b=FA8QQPE7L/wcmF2X+rADioVECHIe0g006LFCsgidk2v9kPXKxsyI6X45cXt/ikxNE5QTlT CyBSFw0ZECoaBPa1ZVTfEfmiuSzistcchHjTrZKdvviZvu3FuN5XaLoT8rwXsF6HntBmcw MPqcvLeICxumWWNmtZSA3Z2jeVRn6sE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VjOWU8+5; spf=pass (imf26.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=1689870792; 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=v3SClOtTb5K9y8gZXjCHv42uNQ6hcmWjrBQMdqu658k=; b=omG2W0+EsUqxXNuJAOSXtL4SLytGcqcyAdOO7/+7xN17dosewmbxcFispodSS/zg3AGMHl 5sPcxs5paPZY1XQd+mQshk4K8a2njslBBBkO7ACch9tcngrrjZVRq6ozOlwRoK1C+oe6Zn wGoeOk7vSJV42FB9Nf5GoYlVFkMLDrc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689870791; 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=v3SClOtTb5K9y8gZXjCHv42uNQ6hcmWjrBQMdqu658k=; b=VjOWU8+5G/fcqAtYwAKheLjCO12nLiYDfWnEIvKWEVeMGzWBaNUdGl0lcbHNhPtrU12Wrn yuQU828CaPz3mg8inFGV1sL1eHekPTBX08fnaPFOAK5egiubw0qs182Z24Je/Qo+56e5uZ hemdks6HFz6C9m8Ul5Hb1fGZAK512fg= 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-6-SbuvRRjOPo6HLoecNE0CHQ-1; Thu, 20 Jul 2023 12:33:05 -0400 X-MC-Unique: SbuvRRjOPo6HLoecNE0CHQ-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 6DD1A101156F; Thu, 20 Jul 2023 16:33:02 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.42.28.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1270F40C206F; Thu, 20 Jul 2023 16:32:54 +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 08/20] tracing/filters: Further optimise scalar vs cpumask comparison Date: Thu, 20 Jul 2023 17:30:44 +0100 Message-Id: <20230720163056.2564824-9-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-Server: rspam08 X-Rspamd-Queue-Id: 8A766140028 X-Stat-Signature: 6nhh9dkabfsedh9whor1m4q4j4sz9j8a X-Rspam-User: X-HE-Tag: 1689870792-736188 X-HE-Meta: U2FsdGVkX18h2pNLMez+cMtdqiv2af8p/f+X7hAquMEYjJezKy1gUtyZZDrBwbXzu76UBFOzrwHXJX/njPzDEiFldoj39knWK36eJxo5i0O6EkHLKGhpIPG/DiQyyDZZv0vC0eL5cbeLdD5df97nwF4Xxaeemu/6ZsZF4JkfJhVA4rTFYbD04ZGFHItVewmYS3bCq6+MHHTORQNagpfsfwaJ/4pZHEGlfBM6GEXnieioWa9thQT5wweP3t+rSZTkM7O560dtABNrHoFvoLUiJIqJBK7Bc/K6ZiEbU11jUwFUNVoRUpdfYgLtyGcEeCiguBXtQ/R4bf6oij4KReD2o3bHwPrWJ8a/nSct2f5xj9WINycI376clvxrpS2/G/luJNoH6i3uru9C0/Ny8L8X2Fjd7WH3Awf0NT4q0HWlHqQ3e1/ipck+27fRYA567WajCJiZdme2ivZnyPQdLlYX88pwZ3FAodikVnUrg91D4VFCdnR7QW37IxxEPdaq4wf+Iy+5sjl3xtjSREWXRjrcHP8132qBwwW1kcUz4tZTb8wnjYGtx1fUkA6tz0fgvtR4MiryKXUSD3Iy/+u6tHY0iP9cSaya3P+Oj+9RnJS382/F1tGJKDMnNvea+Ncwc/B7CILZNiHkNh2qgGOXBIQTzwQ1n3efcLfIk7KvscdwtPQlo2vY1tEvYCMd9Q4fMHaodPEuoJGesfszEFlPWDN93AbpSjYkgqZf1yw5kBaZ5lPPu4gIwuUhehV+QHH/LW+0U8FvUj7zQn6PURfG6v6nuevkXFHRVfEXdgEx0C944CnZ57Qn2C8vU65d42baRWAPjPE+XbEKjiYoNndvE6SSxOsVtYAhoxyY3ly7KlxRuYCCE2EtTipz1haYebomevhY/oo+PjgND/KpP+UxKDniEkP7b1vucjmWznM8pb7LaVWhnfrKkB0pXiNBlFpmyWYknImfyCT5FM+6mgCjjsn 2hEUDWeo gmiRJI6fsXGghPKv4GhiStnM3NteUzSo+AA3cIbiG3boS591wA0/pAhsg2mf0N7doxI+VAu9e1AmxDWXpv+++HMmHwsBcUh80zTEH29HJFiUiOPmHEqQNTsw/yXZuuoq7R6BWQA+ztsDJQ9vWERVZXkPHG97HjPnrOzLh6bhGLMBua518G2F8P9NSvpjXKCAKM5f0yA9k/IOitY4zzxCpdQqD4bDjIfRwN6HykZm2diEw2wF40/8EsjEETboIIR6Nik4jI96U6Zw4sLodbLcxhMitG7RHTW4ZWSl8iUiQHeykMmE= 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: Per the previous commits, we now only enter do_filter_scalar_cpumask() with a mask of weight greater than one. Optimise the equality checks. Suggested-by: Steven Rostedt Signed-off-by: Valentin Schneider --- kernel/trace/trace_events_filter.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index fd72dacc5d1b8..3a529214a21b7 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -667,6 +667,25 @@ do_filter_cpumask(int op, const struct cpumask *mask, const struct cpumask *cmp) /* Optimisation of do_filter_cpumask() for scalar fields */ static inline int do_filter_scalar_cpumask(int op, unsigned int cpu, const struct cpumask *mask) +{ + /* + * Per the weight-of-one cpumask optimisations, the mask passed in this + * function has a weight >= 2, so it is never equal to a single scalar. + */ + switch (op) { + case OP_EQ: + return false; + case OP_NE: + return true; + case OP_BAND: + return cpumask_test_cpu(cpu, mask); + default: + return 0; + } +} + +static inline int +do_filter_cpumask_scalar(int op, const struct cpumask *mask, unsigned int cpu) { switch (op) { case OP_EQ: @@ -966,12 +985,7 @@ static int filter_pred_cpumask_cpu(struct filter_pred *pred, void *event) 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); + return do_filter_cpumask_scalar(pred->op, mask, cpu); } /* Filter predicate for COMM. */