Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5589713imm; Tue, 16 Oct 2018 12:41:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV62z+uNg5jSUtZvBUy6bu5hWtCa6uPblZvWLxi3VebjIP7gbJ33Rsr6Iiwn+fP1GeRnENQwq X-Received: by 2002:a63:4952:: with SMTP id y18-v6mr21496126pgk.32.1539718878141; Tue, 16 Oct 2018 12:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539718878; cv=none; d=google.com; s=arc-20160816; b=uso8yOgexDkWzzSov5ltlmXzK3FMvz0jGKgBm9NBMDuOqVrAy9LEnjTe7iPZtRFKE9 wMlBHyTBlmCV42irDHXCbBzKhT4PtKrZXeJ/aa8TW6qmIvFEvmLPHB/ziXlZpuRTW6WO mUtPN8hkbm3YypY8M2+lyLOG2+AJ6GgvnXGEDCRrSHeWT2ZP/KfuZkLPT/MuoKP4MR2/ YFo7BY5ZexIHJfuGTOj6CeSbRv8R5553qwn1Y7X7fqI5q+ivArjsVGKGkxhU/QIXZIj6 42z2cEKuWiPnXP2u/HNc/Rr1/lasrJl1p3u4DWmbKR918vRTzW08Dc9UyCpDmxc+jOY9 xE/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1WhXx1TLKb14F2jiVToxuOPnlwIGb8/olr9mt2DNoyM=; b=yDENiMLlL4wjtZaaU2ipbbAlWsFliuPNIvmqBjpuzVf2NXd2jvinibvmYzLSUsYvsl M0zXxu9ZlJ1d6CY2QgTkk8DzweY32BNZ/MTwFDCUBbioHdsV/E+Q2dIaf+d2x/f88DqP pjRBzyCJVKgsOnUrFeeQCdknS8uzHb2Q7uT2BZzWeV/6vbv3MhT85p6VmM5YPYzLNnLc 5feREh6kDdiYymUY/dvl28GRHQNUiVQzYEPu1frptYBnYhtACXS2MY4C6a20nsR0O5og RBUKColK0eKTReOw22DLCR6ibQiQORI7IniiQCQRN7H9begZBW1L85zhUPq6+o+e+7ea zPgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yNqMNg9c; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si15069918pgp.243.2018.10.16.12.41.02; Tue, 16 Oct 2018 12:41:18 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=yNqMNg9c; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbeJQDcA (ORCPT + 99 others); Tue, 16 Oct 2018 23:32:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:48630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbeJQDcA (ORCPT ); Tue, 16 Oct 2018 23:32:00 -0400 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB7E921479; Tue, 16 Oct 2018 19:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539718801; bh=zqiRn+Fo0rqu+/frEvnOPp5XH/g2c/3+p9id3MqcdhE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=yNqMNg9ccRW0apgVLHLPLp/dLg2SGKrXziQTRZxkgpvku5Rr9BH7K891PVYIbi8AG GgHJJsLZ/wYTk6HklXhIRhu4qqacgoh6VO21oCfPlFVFcXJOQwjz7gDv2j5vv5hNf0 0JaLSdwfFvwpM18udvvfm7nVbHVfKiwGwGhVGMRw= Received: by mail-ed1-f53.google.com with SMTP id z21-v6so22525944edb.11; Tue, 16 Oct 2018 12:40:00 -0700 (PDT) X-Gm-Message-State: ABuFfohQsWxzrwoMbz3OLTtW9PP24wmPHO3BR6LisnbNzNlNACfaD62S E3gsw5bE6tRa44VeYuGngK5FlDCkWjQIFQLJbm0= X-Received: by 2002:a50:92fd:: with SMTP id l58-v6mr32466773eda.200.1539718799151; Tue, 16 Oct 2018 12:39:59 -0700 (PDT) MIME-Version: 1.0 References: <1539567282-1326-1-git-send-email-frowand.list@gmail.com> <3635be33-7301-ecd5-5966-24b0494771ef@gmail.com> In-Reply-To: <3635be33-7301-ecd5-5966-24b0494771ef@gmail.com> From: Alan Tull Date: Tue, 16 Oct 2018 14:39:21 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: overlay: user space synchronization To: Frank Rowand Cc: Geert Uytterhoeven , Rob Herring , Pantelis Antoniou , Pantelis Antoniou , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 15, 2018 at 7:04 PM Frank Rowand wrote: > > On 10/15/18 13:38, Alan Tull wrote: > > On Mon, Oct 15, 2018 at 1:09 PM Frank Rowand wrote: > >> > >> On 10/15/18 01:24, Geert Uytterhoeven wrote: > >>> > >>> Please say explicitly that tree_version contains a 32-bit unsigned > >>> decimal number, which is incremented before and after every change. > >>> I had to deduce that from the code. > >> > >> Good point. I'll add that. > > > > Looking at the code, tree_version being odd or even means something. > > tree_version is incremented every time the of_mutex is locked or > > unlocked, such that: > > * tree_version is odd == of_mutex is locked and the tree is > > currently be in the process of being changed > > * tree_version is even == of_version is unlocked again and the > > changes are finished. > > > > How about making this explicit in the interface by breaking it up into > > two attributes: > > > > /sys/firmware/devicetree/tree_lock == "locked" or "unlocked". If the > > tree is locked, you know that the tree may still be changing and the > > sysfs can't be trusted to be stable yet. Or maybe even more > > specifically tree_overlay_lock? > > > > /sys/firmware/devicetree/tree_version = a u32 that is incremented once > > for every overlay added or removed. > > I like the extra clarity of purpose that having two attributes provides, > but it makes the user space dance more difficult. > > With a single attribute, the shell code is (updated from the patch > to remove the variable "version"): > > done=1 > > while [ $done = 1 ] ; do > > pre_version=$(cat /sys/firmware/devicetree/tree_version) > while [ $(( ${pre_version} & 1 )) != 0 ] ; do > # echo is optional, sleep value can be tuned > echo "${pre_version} tree locked, sleeping" > sleep 2; > pre_version=$(cat /sys/firmware/devicetree/tree_version) > done > > # 'critical region' > # access /proc/device-tree/ one or more times > > post_version=$(cat /sys/firmware/devicetree/tree_version) > > if [ ${post_version} = ${pre_version} ] ; then > done=0 > fi > > done > > With two attributes, the shell code is: > > > done=1 > > while [ $done = 1 ] ; do > > # the order of the next three lines must not change > version=$(cat /sys/firmware/devicetree/tree_version) > pre_version=${version} > tree_lock=$(cat /sys/firmware/devicetree/tree_lock) > while [ tree_lock != "unlocked" ] || > [ ${version} != ${pre_version} ] ; do > # echo is optional, sleep value can be tuned > echo "locked, sleeping" > sleep 2; > # the order of the next two lines must not change > pre_version=${version} > tree_lock=$(cat /sys/firmware/devicetree/tree_lock) > version=$(cat /sys/firmware/devicetree/tree_version) > done > > # 'critical region' > # access /proc/device-tree/ one or more times > > # the order of the next two lines must not change > post_version=$(cat /sys/firmware/devicetree/tree_version) > tree_lock=$(cat /sys/firmware/devicetree/tree_lock) > > if [ ${tree_lock} = "unlocked" ] && > [ ${post_version} = ${pre_version} ] ; then > done=0 > fi > > done > > > The two attribute example is untested, could have syntax errors, etc. > I'm also not sure that the logic is correct. > > My opinion is that the extra shell complexity makes the two attribute > solution worse. Yes, I can see that now and agree with you here. Thanks for giving the idea consideration. I'll review your v2 . Alan > > -Frank > > > > > > Alan > > > > > >> > >> > >>> > >>> IMHO that is more important than having the sample script here. > >>> > >>> Gr{oetje,eeting}s, > >>> > >>> Geert > >>> > >> > >