From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932436AbbJ1Ae1 (ORCPT ); Tue, 27 Oct 2015 20:34:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:48873 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932125AbbJ1Ae0 (ORCPT ); Tue, 27 Oct 2015 20:34:26 -0400 Date: Wed, 28 Oct 2015 01:34:18 +0100 From: Borislav Petkov To: Huang Rui Cc: Guenter Roeck , Peter Zijlstra , Jean Delvare , Andy Lutomirski , Andreas Herrmann , Thomas Gleixner , Ingo Molnar , "Rafael J. Wysocki" , Len Brown , John Stultz , =?utf-8?B?RnLDqWTDqXJpYw==?= Weisbecker , lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org, x86@kernel.org, Andreas Herrmann , Aravind Gopalakrishnan , Fengguang Wu , Aaron Lu , Tony Li Subject: Re: [PATCH v2 05/10] hwmon: (fam15h_power) Add compute unit accumulated power Message-ID: <20151028003418.GA7802@nazgul.tnic> References: <1445308109-17970-1-git-send-email-ray.huang@amd.com> <1445308109-17970-6-git-send-email-ray.huang@amd.com> <20151023132702.GC2844@pd.tnic> <20151027025339.GF8036@hr-amur2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20151027025339.GF8036@hr-amur2> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 27, 2015 at 10:53:40AM +0800, Huang Rui wrote: > Preemption must be disabled when calling smp_call_function_many, > get_cpu would did that. Will get_online_cpus have the same behavior > like that? Well, get_online_cpus() protects you against CPU hotplug operations in general. If you want to protect yourself against CPUs going away only, then I guess get_cpu()/put_cpu() is fine. But since we're going to work with the masks as below, prohibiting any changes to cpu_online_mask is probably the better/safe thing to do, i.e. get_online_cpus(); preempt_disable(); smp_call_function_many( ... ); preempt_enable(); put_online_cpus(); > That means "the value(cu_acc_power) of the compute unit", which does > not represent the value of one CPU core. No, I mean this: "This behavior can decrease IPI numbers between the unit's." I'm wondering whether it is really needed at all ... > OK, how about below codes: > > --- > for (i = 0; i <= cores_per_cu / BITS_PER_LONG; i++) { > offset = cores_per_cu % BITS_PER_LONG; > if (i == cores_per_cu / BITS_PER_LONG) { > cpumask_bits(src_mask)[i] = GENMASK(offset -1, 0); > break; > } > cpumask_bits(src_mask)[i] = GENMASK(BITS_PER_LONG - 1, 0); > } > > for (i = 0; i < cu_num; i++) { > cpumask_shift_left(dst, src_mask, cores_per_cu * i); > cpumask_and(res, dst, cpu_online_mask); > cpumask_set_cpu(cpumask_any(res), mask); > } I think you can make it even simpler: /* prepare CU temp mask */ for (i = 0; i < cores_per_cu; i++) cpumask_set_cpu(i, tmp_mask); for (i = 0; i < cu_num; i++) { /* WARN_ON for empty CU masks */ WARN_ON(!cpumask_and(res_mask, tmp_mask, cpu_online_mask)); cpumask_set(cpumask_any(res_mask), call_mask); cpumask_shift_right(tmp_mask, tmp_mask, cores_per_cu); } smp_call_function_many(call_mask, .... ); Something like that... -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --