From patchwork Mon Jul 18 19:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12921670 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 2571AC43334 for ; Mon, 18 Jul 2022 19:29:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C12C594000E; Mon, 18 Jul 2022 15:29:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC2A094000D; Mon, 18 Jul 2022 15:29:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8CBB94000E; Mon, 18 Jul 2022 15:29:00 -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 9362694000D for ; Mon, 18 Jul 2022 15:29:00 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 706063480B for ; Mon, 18 Jul 2022 19:29:00 +0000 (UTC) X-FDA: 79701208440.05.E8A1EE3 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf17.hostedemail.com (Postfix) with ESMTP id F322340089 for ; Mon, 18 Jul 2022 19:28:59 +0000 (UTC) Received: by mail-qk1-f169.google.com with SMTP id c3so3807761qko.1 for ; Mon, 18 Jul 2022 12:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=D0vGYuUrWK1A1pC+aGb2diJW4SXv6dDhykR2E3SvFc8=; b=acjdcKpDdV2PdvNi+eoEwihWKcpSrRAsrDHiFJG9tElETVBRpRl1BHIlBTcqTpJ1PZ dqPhoWLauRERrZA0j1cq0xNk0IkyjS+bk910OJd6v3ZC939j06bzpOv+oySvXXxzwccG DuquVnf7VDRuglTdL1A81oCQPyP9OiRPuTo9rV8rvvWPSirAXqZUVdJ9cVJF+N/tZAut cn4mvdBOyL7FeaLStoJT+VMKK5o0ToUzvTPwDDD4B5R4znOjfgPiLRfaP8jZoSwV2fdJ sN1KlbxFCs/ArEXTCRiHuBowwklPVPJUzv5nXSPFafZGnOR76aQqVOuKje8NqcNeZoVw N+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D0vGYuUrWK1A1pC+aGb2diJW4SXv6dDhykR2E3SvFc8=; b=nK5r55Fy4ydkGjPOaXVxlbg6XOSBOylm3j+KWc8hytv0DACe/wGpFxXQ+25k9QhYTo KvLSr+e6PN2vdROwceGDpO3gIhEPeMrQZaI1lk4a9705kM1LRQAPpAwvI/kh0OPI4cd/ pR4Yf3u/AYybPOVJcFxVIRQcHPNqFv/5yNYf7npSYNyGPzWzj9hhnhssb4MB1m+pkcVd DALmn7yzB/OmEsxwGoFGcjOhHQAru6WXg/3WRdeYoa+qvi0SXW8kwlMIylcawf39Jw5t 4bIzRRU6uU8JBg/Mt2cnOZXuuqr3ogT6SQtwidZzJrL2Ui32QLI3cpiX1VdOKhfrbvdp QjrA== X-Gm-Message-State: AJIora+xxNjSfalzXCoRrQyF2xNOhSLKUlpFGeZN8pgwdElL7Q9CzsBB ZcXWLshkb+zV29RCILBiMhM= X-Google-Smtp-Source: AGRyM1sfjfCy0QR9NsI2tMcO46D+TGA9UPgSgzjARo5pB7cKyOwUWXXbOFws+xYx88TQYg8ZRSCfgg== X-Received: by 2002:a37:648f:0:b0:6b5:ccd2:3ff9 with SMTP id y137-20020a37648f000000b006b5ccd23ff9mr11422805qkb.139.1658172539175; Mon, 18 Jul 2022 12:28:59 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:ab01:d009:465a:5ab1]) by smtp.gmail.com with ESMTPSA id ez12-20020a05622a4c8c00b0031eb0bb5c3csm9878869qtb.28.2022.07.18.12.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:28:58 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Andy Shevchenko , 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 , Yury Norov , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 11/16] time: optimize tick_check_preferred() Date: Mon, 18 Jul 2022 12:28:39 -0700 Message-Id: <20220718192844.1805158-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718192844.1805158-1-yury.norov@gmail.com> References: <20220718192844.1805158-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658172540; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D0vGYuUrWK1A1pC+aGb2diJW4SXv6dDhykR2E3SvFc8=; b=x6p9tOwXO4l3x2wPe6rBQQLi1e0F2NXwgFrBE2D7JP5ews11bbjwEkw3J+D3QwU/fi0u4o mZEOBgYcgxzFUUtW9NcsGlaslhb5By1hb1nAJo9ioS9WbxbKiXO0EOIz5XWHBme1BlKJHz TEx8LDtX5Jc0tI5rKq4lD+Mrz/AEGPc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658172540; a=rsa-sha256; cv=none; b=JJ1E7kaGF37qs5QexyZRXLIL2R9oDqr2TxcTVUtP4OGBq4c8/MvsoHXzRoD/AzkXH0au9n TjFoFxLRNqHr5DtH+e24oW7eoDHBFSt9kYqGLLOMgvkVmc5YfSIL/t9rEhVtbL/CpMRmpD 26zK0KBaZMT3+CTMgn3hZgVuRLGROqI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=acjdcKpD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Stat-Signature: gja9sm5cmx3f6jz5kb3h6qntnadw4j9t X-Rspamd-Queue-Id: F322340089 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=acjdcKpD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Server: rspam06 X-HE-Tag: 1658172539-308806 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: tick_check_preferred() calls cpumask_equal() even if curdev->cpumask == newdev->cpumask. Fix it. Caught with CONFIG_DEBUG_BITMAP: [ 0.079109] Call trace: [ 0.079124] __bitmap_check_params+0x144/0x250 [ 0.079161] tick_check_replacement+0x1a4/0x320 [ 0.079203] tick_check_new_device+0x50/0x110 [ 0.079237] clockevents_register_device+0x74/0x1c0 [ 0.079268] dummy_timer_starting_cpu+0x6c/0x80 [ 0.079310] cpuhp_invoke_callback+0x104/0x20c [ 0.079353] cpuhp_invoke_callback_range+0x70/0xf0 [ 0.079401] notify_cpu_starting+0xac/0xcc [ 0.079434] secondary_start_kernel+0xe4/0x154 [ 0.079471] __secondary_switched+0xa0/0xa4 [ 0.079516] ---[ end trace 0000000000000000 ]--- [ 0.079542] b1: ffffbfec4703b890 [ 0.079553] b2: ffffbfec4703b890 [ 0.079566] b3: 0 [ 0.079576] nbits: 256 [ 0.079588] start: 0 [ 0.079598] off: 0 [ 0.079609] Bitmap: parameters check failed [ 0.079619] include/linux/bitmap.h [419]: bitmap_equal Signed-off-by: Yury Norov --- kernel/time/tick-common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 46789356f856..fdd5ae1a074b 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -316,9 +316,13 @@ static bool tick_check_preferred(struct clock_event_device *curdev, * Use the higher rated one, but prefer a CPU local device with a lower * rating than a non-CPU local device */ - return !curdev || - newdev->rating > curdev->rating || - !cpumask_equal(curdev->cpumask, newdev->cpumask); + if (!curdev || newdev->rating > curdev->rating) + return true; + + if (newdev->cpumask == curdev->cpumask) + return false; + + return !cpumask_equal(curdev->cpumask, newdev->cpumask); } /*