From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932544AbcITJq5 (ORCPT ); Tue, 20 Sep 2016 05:46:57 -0400 Received: from foss.arm.com ([217.140.101.70]:53026 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932163AbcITJqy (ORCPT ); Tue, 20 Sep 2016 05:46:54 -0400 Subject: Re: [PATCH 1/2] jump_labels: Add API to deal with keys embedded in structures To: Peter Zijlstra References: <1474305688-22553-1-git-send-email-marc.zyngier@arm.com> <1474305688-22553-2-git-send-email-marc.zyngier@arm.com> <20160920094223.GR5012@twins.programming.kicks-ass.net> Cc: linux-kernel@vger.kernel.org, Jason Baron , Jonathan Corbet , Christoffer Dall , Vladimir Murzin , Catalin Marinas From: Marc Zyngier Organization: ARM Ltd Message-ID: <57E1058B.5040800@arm.com> Date: Tue, 20 Sep 2016 10:46:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0 MIME-Version: 1.0 In-Reply-To: <20160920094223.GR5012@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/09/16 10:42, Peter Zijlstra wrote: > On Mon, Sep 19, 2016 at 06:21:27PM +0100, Marc Zyngier wrote: >> It is desirable to allow static keys to be integrated in structures, >> as it can lead do slightly more readable code. But the current API >> only provides DEFINE_STATIC_KEY_TRUE/FALSE, which is not exactly >> nice and leads to the following idiom: >> >> static struct { >> int foo; >> struct static_key_false key; >> } bar = { >> .key = STATIC_KEY_FALSE_INIT, >> }; >> >> [...] >> >> if (static_branch_unlikely(&bar.key)) >> foo = -1; >> >> which doesn't follow the recommended API, and uses the internals >> of the static key implementation. >> >> This patch introduces DECLARE_STATIC_KEY_TRUE/FALSE, as well as >> INIT_STATIC_KEY_TRUE/FALSE, which abstract such construct and >> allow the internals to evolve without having to fix everything else: >> >> static struct { >> int foo; >> DECLARE_STATIC_KEY_FALSE(key); >> } bar = { >> INIT_STATIC_KEY_FALSE(.key), >> }; > > Hurm.. > > I think I like the first better, it looks more like actual C. Either way > around you need to now manually match up the type and initializer. Fair enough, I'll stick to that for the KVM code. Thanks for the quick feedback. M. -- Jazz is not dead. It just smells funny...