From mboxrd@z Thu Jan 1 00:00:00 1970 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 BDABEC43334 for ; Mon, 18 Jul 2022 21:36:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53F6A6B0071; Mon, 18 Jul 2022 17:36:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EE8F6B0088; Mon, 18 Jul 2022 17:36:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B68D8E0001; Mon, 18 Jul 2022 17:36:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2C8D06B0071 for ; Mon, 18 Jul 2022 17:36:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 01593120D5D for ; Mon, 18 Jul 2022 21:36:35 +0000 (UTC) X-FDA: 79701529992.15.66AAF3B Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf23.hostedemail.com (Postfix) with ESMTP id 03726140071 for ; Mon, 18 Jul 2022 21:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658180195; x=1689716195; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=mNR9fZW5L/31bvz/gFxJvxCNXCRVmXZ4lg+FbtpuMEs=; b=oI9qWMYJSXrj4neTt/wioboYUA+jbH4owczEa4LsZQ7cKmHdAr0VmRLT +O+r2EwV0+eg5tIDHY6ZoSVdw9X1jLMC4+Xgkwf5XQe30oKrX2nR8HLRf xm8nEOG/px9DebChq4DUQbuNrxQ35RG1Lo1Bli54kxnpDajNIPOjQxOLc gXPr5oWHivn5V+egc90kfHc+03zhwg7guEooWLv4b4CfUiGwUFk5fzapV 4Z9r391QjThE1iabSHBGOLlZwl6LCjbvafZoiE0KSKOHIohLJWchxUBxC G9V43a6r/y89P/TDH1l2FRTnPN6ZkqVzB14NnZAQKyp0CtYZ7uIIOvOGR Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10412"; a="286344678" X-IronPort-AV: E=Sophos;i="5.92,282,1650956400"; d="scan'208";a="286344678" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 14:36:33 -0700 X-IronPort-AV: E=Sophos;i="5.92,282,1650956400"; d="scan'208";a="597406476" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 14:36:23 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1oDYPa-001OZo-1y; Tue, 19 Jul 2022 00:36:18 +0300 Date: Tue, 19 Jul 2022 00:36:18 +0300 From: Andy Shevchenko To: Yury Norov Cc: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Ben Segall , Christoph Lameter , Dan Williams , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , Dietmar Eggemann , Eric Dumazet , Frederic Weisbecker , Guenter Roeck , Ingo Molnar , Isabella Basso , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Kees Cook , Martin KaFai Lau , Mel Gorman , Miroslav Benes , Nathan Chancellor , "Paul E . McKenney" , Peter Zijlstra , Randy Dunlap , Rasmus Villemoes , Sebastian Andrzej Siewior , Song Liu , Steven Rostedt , Tejun Heo , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vlastimil Babka , Yonghong Song , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH 07/16] smp: optimize smp_call_function_many_cond() Message-ID: References: <20220718192844.1805158-1-yury.norov@gmail.com> <20220718192844.1805158-8-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220718192844.1805158-8-yury.norov@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=oI9qWMYJ; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf23.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=andriy.shevchenko@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658180195; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=N0Y+BbR0o7q5vypEY0YtXnxFVXODOAXd6anfXFN8+o4=; b=Lu5rH8YnbcG1dw0Nx2JqX0yw/vDBSHASs0EwXXlG1hW6B5dfp9QsvLSS7C8XU23rCCWfM7 uUYE1bXNuTOrc6hgP24qSp9/x/BuuhGdWL55SBOXa8/bUp+wmxtqOVjOxwbMWgOG4lR1B9 RyU9ziSla2VesfbAywkFQNpkXdXubuM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658180195; a=rsa-sha256; cv=none; b=cYjXKx5ZvfqJR7180zN4cS22KRc28XTU81Qif6sx2fQ3ms1YgGyJKDvW7i+vb9syaOJT2k uwm7PXhvC+6W2n2I3iJumUfKcyUu4uT52/S1ZP9zPPOGNxWTkp4Eym0DyQYDz/qK4JRxt1 2+HRhTQfFTdB8e69r+4GybmsoiVMYc4= X-Rspamd-Queue-Id: 03726140071 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=oI9qWMYJ; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf23.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=andriy.shevchenko@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: m1njxi3axjj4xmmu8t4y5np6ucxd9rja X-HE-Tag: 1658180194-619352 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: On Mon, Jul 18, 2022 at 12:28:35PM -0700, Yury Norov wrote: > smp_call_function_many_cond() is often passed with cpu_online_mask. > If this is the case, we can use num_online_cpus(), which is O(1) > instead of cpumask_{first,next}(), which is O(N). > > It can be optimized further: if cpu_online_mask has 0 or single bit > set (depending on cpu_online(this_cpu), we can return result without > AND'ing with user's mask. > Caught with CONFIG_DEBUG_BITMAP: > [ 7.830337] Call trace: > [ 7.830397] __bitmap_check_params+0x1d8/0x260 > [ 7.830499] smp_call_function_many_cond+0x1e8/0x45c > [ 7.830607] kick_all_cpus_sync+0x44/0x80 > [ 7.830698] bpf_int_jit_compile+0x34c/0x5cc > [ 7.830796] bpf_prog_select_runtime+0x118/0x190 > [ 7.830900] bpf_prepare_filter+0x3dc/0x51c > [ 7.830995] __get_filter+0xd4/0x170 > [ 7.831145] sk_attach_filter+0x18/0xb0 > [ 7.831236] sock_setsockopt+0x5b0/0x1214 > [ 7.831330] __sys_setsockopt+0x144/0x170 > [ 7.831431] __arm64_sys_setsockopt+0x2c/0x40 > [ 7.831541] invoke_syscall+0x48/0x114 > [ 7.831634] el0_svc_common.constprop.0+0x44/0xfc > [ 7.831745] do_el0_svc+0x30/0xc0 > [ 7.831825] el0_svc+0x2c/0x84 > [ 7.831899] el0t_64_sync_handler+0xbc/0x140 > [ 7.831999] el0t_64_sync+0x18c/0x190 > [ 7.832086] ---[ end trace 0000000000000000 ]--- > [ 7.832375] b1: ffff24d1ffd98a48 > [ 7.832385] b2: ffffa65533a29a38 > [ 7.832393] b3: ffffa65533a29a38 > [ 7.832400] nbits: 256 > [ 7.832407] start: 0 > [ 7.832412] off: 0 > [ 7.832418] smp: Bitmap: parameters check failed > [ 7.832432] smp: include/linux/bitmap.h [363]: bitmap_and Documentation specifically says: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-mesages ... > + default: > + if (mask == cpu_online_mask) > + return true; Instead, put (missed) break; here and do "default" case together below. > + cpu = cpumask_first_and(mask, cpu_online_mask); > + if (cpu == this_cpu) > + cpu = cpumask_next_and(cpu, mask, cpu_online_mask); > + > + return cpu < nr_cpu_ids; ... > + run_remote = __need_remote_exec(mask, this_cpu); > Now you may remove this blank line. > if (run_remote) { -- With Best Regards, Andy Shevchenko