Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp398760pxu; Wed, 7 Oct 2020 06:11:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwojgT6qBcCj1qQVQHSmvVPijg4aU9B4/X7W0GZEDZz+PlA7UKpdjkH7f/vy4dd11ax1W3L X-Received: by 2002:a17:906:f90a:: with SMTP id lc10mr3398412ejb.272.1602076277231; Wed, 07 Oct 2020 06:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602076277; cv=none; d=google.com; s=arc-20160816; b=pmRoAH3+bbAsO2nHlSyQxLa+9opcJ3+SPbR8bZPxQwA1KmoqpBEchYiS7BXfvFrKWK x3z74RPeWuwBmMxV+fDZ0KRatPrLh34Ii6vxfw4RYYd7k/OWHc5/dlJsqluDBU3hKOpv J5+WW3PONcePaoee9DYyltts0mgS+psuF6HmfduBID2ORZhlQebdRmPe8v/9Sl3BH+L2 ZStXZaobbAHANjHDdgYH8lo3EB8FawdRBzUlFrrpm6WapHcG6MeX5KtHOpHkjDKvSKlD nKlMVbzyFKLwytlVVn+Ny/gAThKn9Rehg+enyzk2Lhs6L5nVBoABfKi9VMOq94+NqBGJ tvSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=fzzYwvnRkrY3q9cauoayqyN5TYt/xYOuYyfAOguTrUY=; b=dFqGCvVj7gEj88oA+XQ09K0jK3zkfsMq5OKGTVYUmsjivJgwezvFNBaa+x9Hq8mFCK mqtq7gf6Kv51onZzNTgsJxhfX4OoGB3MPfXZuU0ILACjxRHaMJYbrDa4m3aghPOLm/YK JxWLFR05pqPpWDz2/UuH0fhfZ7N3VzHA9fk2V8AtmZIc8Pt+4pfByQCm6s22HmObuZ6M q/wbOZ2qkeZsv+UyE0s35gwxOT/KUHzLPd6DCldvqfmP8MPm5j3x2SXDK9I2aW37Ruym +AYQsb1W+Vo7J+/O9QLqDDeZk07OdbWTFKOzMKKyEWsWPeqdwAvfpZCgGIA54vdmGv/I HAyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Os66LS1P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t21si1510171ejr.71.2020.10.07.06.10.48; Wed, 07 Oct 2020 06:11:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Os66LS1P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbgJGNFv (ORCPT + 99 others); Wed, 7 Oct 2020 09:05:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27866 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728177AbgJGNFu (ORCPT ); Wed, 7 Oct 2020 09:05:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602075949; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fzzYwvnRkrY3q9cauoayqyN5TYt/xYOuYyfAOguTrUY=; b=Os66LS1PIR9LVKLI6VZYwO5LAZ0XSo4vbRhbB3smTNyUulu3/nKJw0SHrjOTM6YK4qZkFu N9wiMQuGe45OFMqRE/mBhMyJ68pVMRUOUlVC+77uHA+dFpRI7p8sTOD1/Ug6JXm3mxr6LX Cc3Pua+Bb5S/OkFH6WEH1wDghuCEDAM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-xBoHtIPSM3a9S4XvbTk6nw-1; Wed, 07 Oct 2020 09:05:47 -0400 X-MC-Unique: xBoHtIPSM3a9S4XvbTk6nw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B98A108BD06; Wed, 7 Oct 2020 13:05:45 +0000 (UTC) Received: from ovpn-66-195.rdu2.redhat.com (unknown [10.10.67.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BE3819C4F; Wed, 7 Oct 2020 13:05:43 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 09/11] powerpc/smp: Optimize update_mask_by_l2 From: Qian Cai To: Srikar Dronamraju , Michael Ellerman Cc: Nathan Lynch , Gautham R Shenoy , Michael Neuling , Peter Zijlstra , LKML , Nicholas Piggin , Valentin Schneider , Oliver O'Halloran , Satheesh Rajendran , linuxppc-dev , Ingo Molnar Date: Wed, 07 Oct 2020 09:05:42 -0400 In-Reply-To: <20200921095653.9701-10-srikar@linux.vnet.ibm.com> References: <20200921095653.9701-1-srikar@linux.vnet.ibm.com> <20200921095653.9701-10-srikar@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-09-21 at 15:26 +0530, Srikar Dronamraju wrote: > All threads of a SMT4 core can either be part of this CPU's l2-cache > mask or not related to this CPU l2-cache mask. Use this relation to > reduce the number of iterations needed to find all the CPUs that share > the same l2-cache. > > Use a temporary mask to iterate through the CPUs that may share l2_cache > mask. Also instead of setting one CPU at a time into cpu_l2_cache_mask, > copy the SMT4/sub mask at one shot. > ... > static bool update_mask_by_l2(int cpu) > { > + struct cpumask *(*submask_fn)(int) = cpu_sibling_mask; > struct device_node *l2_cache, *np; > + cpumask_var_t mask; > int i; > > l2_cache = cpu_to_l2cache(cpu); > @@ -1240,22 +1264,37 @@ static bool update_mask_by_l2(int cpu) > return false; > } > > - cpumask_set_cpu(cpu, cpu_l2_cache_mask(cpu)); > - for_each_cpu_and(i, cpu_online_mask, cpu_cpu_mask(cpu)) { > + alloc_cpumask_var_node(&mask, GFP_KERNEL, cpu_to_node(cpu)); Shouldn't this be GFP_ATOMIC? Otherwise, during the CPU hotplugging, we have, (irqs were disabled in do_idle()) [ 335.420001][ T0] BUG: sleeping function called from invalid context at mm/slab.h:494 [ 335.420003][ T0] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/88 [ 335.420005][ T0] no locks held by swapper/88/0. [ 335.420007][ T0] irq event stamp: 18074448 [ 335.420015][ T0] hardirqs last enabled at (18074447): [] tick_nohz_idle_enter+0x9c/0x110 [ 335.420019][ T0] hardirqs last disabled at (18074448): [] do_idle+0x138/0x3b0 do_idle at kernel/sched/idle.c:253 (discriminator 1) [ 335.420023][ T0] softirqs last enabled at (18074440): [] irq_enter_rcu+0x94/0xa0 [ 335.420026][ T0] softirqs last disabled at (18074439): [] irq_enter_rcu+0x70/0xa0 [ 335.420030][ T0] CPU: 88 PID: 0 Comm: swapper/88 Tainted: G W 5.9.0-rc8-next-20201007 #1 [ 335.420032][ T0] Call Trace: [ 335.420037][ T0] [c00020000a4bfcf0] [c000000000649e98] dump_stack+0xec/0x144 (unreliable) [ 335.420043][ T0] [c00020000a4bfd30] [c0000000000f6c34] ___might_sleep+0x2f4/0x310 [ 335.420048][ T0] [c00020000a4bfdb0] [c000000000354f94] slab_pre_alloc_hook.constprop.82+0x124/0x190 [ 335.420051][ T0] [c00020000a4bfe00] [c00000000035e9e8] __kmalloc_node+0x88/0x3a0 slab_alloc_node at mm/slub.c:2817 (inlined by) __kmalloc_node at mm/slub.c:4013 [ 335.420054][ T0] [c00020000a4bfe80] [c0000000006494d8] alloc_cpumask_var_node+0x38/0x80 kmalloc_node at include/linux/slab.h:577 (inlined by) alloc_cpumask_var_node at lib/cpumask.c:116 [ 335.420060][ T0] [c00020000a4bfef0] [c00000000003eedc] start_secondary+0x27c/0x800 update_mask_by_l2 at arch/powerpc/kernel/smp.c:1267 (inlined by) add_cpu_to_masks at arch/powerpc/kernel/smp.c:1387 (inlined by) start_secondary at arch/powerpc/kernel/smp.c:1420 [ 335.420063][ T0] [c00020000a4bff90] [c00000000000c468] start_secondary_resume+0x10/0x14 > + cpumask_and(mask, cpu_online_mask, cpu_cpu_mask(cpu)); > + > + if (has_big_cores) > + submask_fn = cpu_smallcore_mask; > + > + /* Update l2-cache mask with all the CPUs that are part of submask */ > + or_cpumasks_related(cpu, cpu, submask_fn, cpu_l2_cache_mask); > + > + /* Skip all CPUs already part of current CPU l2-cache mask */ > + cpumask_andnot(mask, mask, cpu_l2_cache_mask(cpu)); > + > + for_each_cpu(i, mask) { > /* > * when updating the marks the current CPU has not been marked > * online, but we need to update the cache masks > */ > np = cpu_to_l2cache(i); > - if (!np) > - continue; > > - if (np == l2_cache) > - set_cpus_related(cpu, i, cpu_l2_cache_mask); > + /* Skip all CPUs already part of current CPU l2-cache */ > + if (np == l2_cache) { > + or_cpumasks_related(cpu, i, submask_fn, > cpu_l2_cache_mask); > + cpumask_andnot(mask, mask, submask_fn(i)); > + } else { > + cpumask_andnot(mask, mask, cpu_l2_cache_mask(i)); > + } > > of_node_put(np); > } > of_node_put(l2_cache); > + free_cpumask_var(mask); > > return true; > }