Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3753697ybz; Mon, 20 Apr 2020 08:51:01 -0700 (PDT) X-Google-Smtp-Source: APiQypKnZQaX8NIhmX3okfCqqlufWs32DxPnYoxtkdRPuPQ6/HKah1cFUG+hDqhgVCX5qaWat2sk X-Received: by 2002:a05:6402:21d7:: with SMTP id bi23mr14402246edb.176.1587397861438; Mon, 20 Apr 2020 08:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587397861; cv=none; d=google.com; s=arc-20160816; b=hxNtPw8hvBjAM6ORNWN7M62LDiQdWrgMLMXGpUlwkzOuFit9iq76G4iqeK5lWHV9AM h4ndrnR73BNIrW6tyCTTdPj6fHicbSRhr7TQcsImXX1dot7Q51vjiru9tHwZn0Jou2mm IE/E1SBoz0DMHiQ3m3z/CEXSaYb2RpDWu4n6qnr61+Uc9rnhYlFbjU4n0dRy9QlRXvQN IC2FPObAsPKe1sPGv8d6nWkTaXaYvK2KqVMBoVUZQsoPS1Vs6rtR3vSyx6rfxKhXzJ2Y KnbxfLZynyAT8JKINUaZr9mgfsSZeq8zOUcMvVTKaui1YwubFjmq6n4VBjiYJvFrQ6Ym fIKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5V85vgiCd9mxIf03P1bIjT3PfkRKkdphQg14Rf4jnbc=; b=rMZjFm+J948/U7fSDeblxV+yxvy3lVJf22WHwYl1daq2QjdWte8N3JUAoscTEsICdn bgtUQsuKgLrLFuVKqdl0eD5IBXlRVXaLiJ+ZgKNZqNSkQiPJ14UJVooWwMl6CrGJKjk1 sTqeq+fvUznAVdx9B9jKtB3b6FXv7InrdpH428yJpGfWBXZensnCz8z5ePW2YZeXbyCt ZCEsSmwlh7qujDMwPuNKx5atZxbOOyIRzzCpE/bdjiLYUPTH4nv+jRVfy4rzXnzoNCRt pz6Q4g1GhCJqO33b4lSyZ6nXQIDqgw2UXWkgnwIxwgHuv+R9dndcdBuXRDHV/RmAZ536 cNEA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si826543ejl.173.2020.04.20.08.50.38; Mon, 20 Apr 2020 08:51:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbgDTPtf (ORCPT + 99 others); Mon, 20 Apr 2020 11:49:35 -0400 Received: from foss.arm.com ([217.140.110.172]:51398 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbgDTPte (ORCPT ); Mon, 20 Apr 2020 11:49:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 33DC131B; Mon, 20 Apr 2020 08:49:34 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 19F7E3F73D; Mon, 20 Apr 2020 08:49:31 -0700 (PDT) Date: Mon, 20 Apr 2020 16:49:29 +0100 From: Qais Yousef To: Steven Rostedt Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Andrew Morton , Thomas Gleixner , Yury Norov , Paul Turner , Alexey Dobriyan , Josh Don , Pavan Kondeti , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] cpumask: Convert cpumask_any_but() to the new random function Message-ID: <20200420154929.taacfhjyeku4e5bx@e107158-lin.cambridge.arm.com> References: <20200414150556.10920-1-qais.yousef@arm.com> <20200414150556.10920-4-qais.yousef@arm.com> <20200414122810.4b83ddd2@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200414122810.4b83ddd2@gandalf.local.home> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/14/20 12:28, Steven Rostedt wrote: > On Tue, 14 Apr 2020 16:05:55 +0100 > Qais Yousef wrote: > > > +int cpumask_any_but(const struct cpumask *srcp, unsigned int cpu) > > +{ > > + unsigned int i; > > + > > + cpumask_check(cpu); > > + > > + for_each_cpu(i, srcp) { > > + i = cpumask_any(srcp); > > Hmm, if the current CPU is the last CPU in the mask, and cpumask_any() > happens to return it, what happens? cpumask_any() will wrap. > > > + if (i != cpu) > > + return i; > > We loop again, and wouldn't i being the last CPU in the mask cause this > loop to exit, and return nr_cpu_ids? No, because if we happen to start from the last cpu, on the next call, we'll wrap again to the beginning. But this implementation is crap indeed. No matter how unlikely, there's no guarantee that for all the iters cpumask_any() will return a different cpu. So if there are 3 cpus in the mask, cpumask_any() could potentially always return 'cpu' if the planets aligned correctly. I'll open code it instead to guarantee robustness. Thanks! -- Qais Yousef