Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3148855imu; Wed, 7 Nov 2018 05:58:41 -0800 (PST) X-Google-Smtp-Source: AJdET5eUqdwUo2v2hanpVEAYdvdfdkCCFFE4+pab04XmXIJ/zU8H3x8vuJs5jAzOnnrLt2zuz7dL X-Received: by 2002:a17:902:e28a:: with SMTP id cf10-v6mr330273plb.81.1541599121612; Wed, 07 Nov 2018 05:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541599121; cv=none; d=google.com; s=arc-20160816; b=q7JLQJ85Iy6NnKw05lW/k3MLgqkBqRLEAxyNSWfvmSEdTwrzfvQBa1IxCNDn6mA6kI IPZfML14lpWVA8lugbF2kjtygs3Opc6y02ul+ymNViP6r/9Kt2zgUwSANAw+iqErnS0f qtUCJYCEf/Opb9cz60ETvxzkGRcZALG+kbANMeNeDpgHcJWE40hIZyKgErqJKGKrfSct tQLL/j00BwNWUndWxuglk9ZkxmER+UaLPKZh26FP93EEI/6oUBgpIzywOH1zovXgSGLE M5FjPHq410V8n6tNrbT32ZNL7LE188xGXyaz2sBOwHKP0dJFsO4DNlOWT9h/kZy66SO8 dlTw== 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=bvxgqvckawPk/Ymr7/4yXiOzUTIMt/O+nsMhKEVah+g=; b=nw8UKOpCov3zJqDo0WX/tsaiEBIip9wRzTB9wFMt7cHWQa1c4lxkYx1fOcG+b26/ip 7EdIeM6RU0fSBSI2Nm2UoJnhJ2iyJ8UCqCl4Rnx+A0MfurT5brCtoFVEql5HkBNWZT4W UUz+9NhA72ThR7OPPAvWDVM2QijsLoel6/CY6Svq2HRsVekQYFjpqqWQUKBx0zaFc/DN hbwQv3w/EwZS1V6wSvwDa6Ui9lpeYZEwsA+tYwcpilcLehibcNwKTjX0ExdDEpQaUTre 1+kaP3CxiFCtKtIIg5DM/87PfaAILlxpIUKYDQh1UVF9gtAogG5M+71nVwtP6c9TwR4W VETA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6-v6si750304pll.30.2018.11.07.05.58.26; Wed, 07 Nov 2018 05:58:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbeKGX2O (ORCPT + 99 others); Wed, 7 Nov 2018 18:28:14 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51264 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727168AbeKGX2N (ORCPT ); Wed, 7 Nov 2018 18:28:13 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 25E41A78; Wed, 7 Nov 2018 05:57:44 -0800 (PST) Received: from e110439-lin (e110439-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 573BA3F5CF; Wed, 7 Nov 2018 05:57:41 -0800 (PST) Date: Wed, 7 Nov 2018 13:57:38 +0000 From: Patrick Bellasi To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v5 03/15] sched/core: uclamp: map TASK's clamp values into CPU's clamp groups Message-ID: <20181107135738.GE14309@e110439-lin> References: <20181029183311.29175-1-patrick.bellasi@arm.com> <20181029183311.29175-4-patrick.bellasi@arm.com> <20181107131632.GP9781@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181107131632.GP9781@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07-Nov 14:16, Peter Zijlstra wrote: > On Mon, Oct 29, 2018 at 06:32:57PM +0000, Patrick Bellasi wrote: > > > +static void uclamp_group_put(unsigned int clamp_id, unsigned int group_id) > > { > > + union uclamp_map *uc_maps = &uclamp_maps[clamp_id][0]; > > + union uclamp_map uc_map_old, uc_map_new; > > + long res; > > + > > +retry: > > + > > + uc_map_old.data = atomic_long_read(&uc_maps[group_id].adata); > > + uc_map_new = uc_map_old; > > + uc_map_new.se_count -= 1; > > + res = atomic_long_cmpxchg(&uc_maps[group_id].adata, > > + uc_map_old.data, uc_map_new.data); > > + if (res != uc_map_old.data) > > + goto retry; > > +} > > Please write cmpxchg loops in the form: > > atomic_long_t *ptr = &uclamp_maps[clamp_id][group_id].adata; > union uclamp_map old, new; > > old.data = atomic_long_read(ptr); > do { > new.data = old.data; > new.se_cound--; > } while (!atomic_long_try_cmpxchg(ptr, &old.data, new.data)); > > > (same for all the others of course) Ok, I did that to save some indentation, but actually it's most commonly used in a while loop... will update in v6. Out of curiosity, apart from code consistency, is that required also specifically for any possible compiler related (mis)behavior ? -- #include Patrick Bellasi