Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3788501imw; Mon, 18 Jul 2022 14:39:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sY7J5aK6LIYxV4IfNMCry9wi33BdX1lNhHCNiJQOMAACLM5A+AeqvBg4J8UK0MsIDGBD/6 X-Received: by 2002:aa7:cdd3:0:b0:43a:1b7d:dce3 with SMTP id h19-20020aa7cdd3000000b0043a1b7ddce3mr40440470edw.359.1658180352511; Mon, 18 Jul 2022 14:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658180352; cv=none; d=google.com; s=arc-20160816; b=D2uFvKbrtB2v/xUIDzfr8rE9zngLLHti3DzJg3NbKW5Yl3xmYpOoQqWfld9JAZMP+4 C70CJGy9u1z2bj3K71hm+Wq1jsMuQ1rxlDWNWiXmpvkLSVBBssceUjpwJk9wiNpi3rgc 5Sc+U1nC0StQYQzpeNCG+hGIs7y2A0MlfFUFeGh99Dl2xanVKc9xMXqs3XVSwosRQQcE PHx3CU2/nt+CJgfqkNk0bGEgNYMhvredDf83cdIT43Iw56Prn14z9BXnWPf9Frc91RE5 eyFryg6s6jL5RK1XnDZQc5FP0gOzu0ebbind+y6xOxlEj4X2ugDlILJ+Ubzo7PNsRYOM mPBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=N0Y+BbR0o7q5vypEY0YtXnxFVXODOAXd6anfXFN8+o4=; b=o5TnBRXj6Qk/T22k0qTDuko+Prkuwip2OguYXfhLPCN4/CLzCWtHIvQcWMDDwEI0zp /xGY4lM8m29hIiRlE65P26lbhG698ydvmUYTknk39tPR6PmYArMCcAzPUvqShz945TxW f0BRWNA/vZvmvshI1S3tO+2okWJuZf8XkIV7vswcj3PgVXrnAKDRBpz+tBYXkEesi6U9 3ePa5p650EvyltU6NadL8xhB9JS5DBLyWBl7dQrx/z4wY9AwSDDG2KxwInEqveOCVAxE WQ9xJOf9PQElkWROHZO8LRKQeeeoVcxh2bxWmiK60GG5i3r6Q041lB/Mcogbk+8bUvM9 Betg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HMNBf9Xf; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb40-20020a1709071ca800b0072eead0cb58si16800829ejc.717.2022.07.18.14.38.47; Mon, 18 Jul 2022 14:39:12 -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=@intel.com header.s=Intel header.b=HMNBf9Xf; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235706AbiGRVgj (ORCPT + 99 others); Mon, 18 Jul 2022 17:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232009AbiGRVge (ORCPT ); Mon, 18 Jul 2022 17:36:34 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 858E03245B; Mon, 18 Jul 2022 14:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658180193; x=1689716193; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=mNR9fZW5L/31bvz/gFxJvxCNXCRVmXZ4lg+FbtpuMEs=; b=HMNBf9Xf716PcEy00NePo/c/6d45CmzWz9qd/HdOmFyOcAJ8xCCfQuLk EKW0VMz3WtyF+PRuLKFavrzeZS0dmzroPQZBoem06mn3RvqTQH3TYuDMo +Epk0tuQCxnTLO8Q+zOKC6ntLCa9FFdqJwqWAoSfphKOPkAki5KbvqbAR WlRnL61w6/0zX2Y6bO86rhdv/j5kD8AItBtA4JrxIPHfmLFqg1wqmwBZQ MeO6B6FCfifeTCXGs0TZNIkUDbVzGSaOU0OgKy4yXlCXUdBFPZDhRq/tx kT/MvTi+2VyJnYaJzXqZO8wO3pWMTfpQMmQXhA+SoMkUY71gBhtLEsRwI Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10412"; a="287068744" X-IronPort-AV: E=Sophos;i="5.92,282,1650956400"; d="scan'208";a="287068744" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.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 X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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: X-Mailing-List: linux-kernel@vger.kernel.org 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