Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2467759ybm; Thu, 23 May 2019 18:03:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeIAvdhQ8wGun5pkuPhqcKj91frZbN0p2EXMPTVFMto77EL94pQd3cOgakqICtDXaky7Cq X-Received: by 2002:aa7:9104:: with SMTP id 4mr78390005pfh.66.1558659820123; Thu, 23 May 2019 18:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558659820; cv=none; d=google.com; s=arc-20160816; b=g90VDBhaZ141qjDdl7UkgqMILLA9DoHBJZg9zPygw1z4pcjmc65XP9W0lcv4cdOH7G LlE6Q9de/Rhi9VX2CoVgkQGzOSwHlQGfymj4Qiq5AdSjk8P8VKn1KloTNWAPN10yrD1i VXX6Ze7C4cOmAEwQvl56uPx02R0h3Z6/zjwOhcB7cfT+6G+ONIEAseNUUnHlfEqeZzm5 vTShnQ9n6cV/LILRs40PeHGT8Rt+wuCFYX0dRi7As0iy0qRaCwqiIxonWPdrcNA4ANxq optLt3VgQNGhtkh7/ns3SApKW2I81RDL+oX5d36r7nL94HQv7uYs6UO4wSPlGGJ8ZWoV 4v7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=DkFNL0Lxas2CTOjiDN2hgVYuR42qb65M2nUWhRx2AoU=; b=cbGvb9Wbkl8lYv5OI6xzs72o6yqOYwb0vcSNpnMdIP7gmqGHJwLePadXTXFUe92A0o 6eKMvVmSuYF88FGT6/Kl3FGoLr4uuEK1x64BRwKEnwMBPAB+Rh/BhBwapu5DedCno1ua QO2OjM1Q4U5fjAZqP/+yBVhh6nfHhswBRAD6l2gwbEPZJLd2QvjTnJJovgTvPNXJb9mS peLilHD3zjhzu/D6WPx1KwiAdK6eQ06VoBxlsUjLsulUC5sDysnqqW+e5r9hOkx9UYsm 7xBRpgeSTeO/iPSnSP38yDpN/Kxx7nGLVUusik/jTeEYphvNLooxELlOKoIc2czdrDxi hqfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=naestgbM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l27si1835932pgm.172.2019.05.23.18.03.18; Thu, 23 May 2019 18:03:40 -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=@google.com header.s=20161025 header.b=naestgbM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731703AbfEXBBb (ORCPT + 99 others); Thu, 23 May 2019 21:01:31 -0400 Received: from mail-oi1-f202.google.com ([209.85.167.202]:40147 "EHLO mail-oi1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731608AbfEXBBb (ORCPT ); Thu, 23 May 2019 21:01:31 -0400 Received: by mail-oi1-f202.google.com with SMTP id l63so3065892oia.7 for ; Thu, 23 May 2019 18:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=DkFNL0Lxas2CTOjiDN2hgVYuR42qb65M2nUWhRx2AoU=; b=naestgbM/OBAVNz1Xr0RTA3sfhmM/mtWyEzsKef0nniKmd4+t3sffScnviOf+ToOj6 tOIX9Jge830iP/Qx3nWIBsT8gyLyq4siWX5dSrDzdKj7S0sovydIwoRpms5YDKIf0pfy Gfw6wg0xhvM5vCghXWxI3jyAGUQjQNf8Ntyyl+EpioqdjVPKohz9Oq7Sk2BdKxtAatvj ZNfUn9e16UZMg6/VenRWfxWqJQpFpfVP18gBAZbTlH0PjloOC7QPwAKxqfbnpg7zL8Li uf77Up71hdyzInQEJZGuBaGhLPHn294TJ4vkoyLWorucJzEFC5rlxbYimg8mt6U0Gily eqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=DkFNL0Lxas2CTOjiDN2hgVYuR42qb65M2nUWhRx2AoU=; b=iUlZ5dL5zYHdPYSgTFqXqmav1TGJ9N6FeLT9sdg/VQvYhIPZLpY+RGwXVoP5KgO5OL k4rIFt209NAxkpboDSWws1sJP/SmkNXHpRNvCtvs3KrzVeU19sYf4Y3R/Ln6yiRtbR32 lfiolAITK31/dAni0FwttoOiMIHLamqZ6bJ4lskp1mlrRGOekhXiW5OfJAovG9vpJ1Lv wLyjYZKcPVMydtLV1nT4by9cKlBB04r0+G0iWVo4PSHm6Uf+TZAPrSkBxQ5pcvUO89RX 7ly8iyRsr2zBR1+SLHLcsqwb4FwvfvdmAC9eyYeff85VaHISkNIptI+JqfMQDqLwuT+I pACw== X-Gm-Message-State: APjAAAXNk5kVR73XMt+1bIFeMyQL/q4BP+HzzKJ9ootypj8KESHnUX9c MLf3VmG2q7ip+BADvfzXjPH1zTJPa9oYqaI= X-Received: by 2002:a9d:7acd:: with SMTP id m13mr12297317otn.336.1558659690736; Thu, 23 May 2019 18:01:30 -0700 (PDT) Date: Thu, 23 May 2019 18:01:11 -0700 Message-Id: <20190524010117.225219-1-saravanak@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.rc1.257.g3120a18244-goog Subject: [PATCH v1 0/5] Solve postboot supplier cleanup and optimize probe ordering From: Saravana Kannan To: Rob Herring , Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand Cc: Saravana Kannan , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com 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 Add a generic "depends-on" property that allows specifying mandatory functional dependencies between devices. Add device-links after the devices are created (but before they are probed) by looking at this "depends-on" property. This property is used instead of existing DT properties that specify phandles of other devices (Eg: clocks, pinctrl, regulators, etc). This is because not all resources referred to by existing DT properties are mandatory functional dependencies. Some devices/drivers might be able to operate with reduced functionality when some of the resources aren't available. For example, a device could operate in polling mode if no IRQ is available, a device could skip doing power management if clock or voltage control isn't available and they are left on, etc. So, adding mandatory functional dependency links between devices by looking at referred phandles in DT properties won't work as it would prevent probing devices that could be probed. By having an explicit depends-on property, we can handle these cases correctly. Having functional dependencies explicitly called out in DT and automatically added before the devices are probed, provides the following benefits: - Optimizes device probe order and avoids the useless work of attempting probes of devices that will not probe successfully (because their suppliers aren't present or haven't probed yet). For example, in a commonly available mobile SoC, registering just one consumer device's driver at an initcall level earlier than the supplier device's driver causes 11 failed probe attempts before the consumer device probes successfully. This was with a kernel with all the drivers statically compiled in. This problem gets a lot worse if all the drivers are loaded as modules without direct symbol dependencies. - Supplier devices like clock providers, regulators providers, etc need to keep the resources they provide active and at a particular state(s) during boot up even if their current set of consumers don't request the resource to be active. This is because the rest of the consumers might not have probed yet and turning off the resource before all the consumers have probed could lead to a hang or undesired user experience. Some frameworks (Eg: regulator) handle this today by turning off "unused" resources at late_initcall_sync and hoping all the devices have probed by then. This is not a valid assumption for systems with loadable modules. Other frameworks (Eg: clock) just don't handle this due to the lack of a clear signal for when they can turn off resources. This leads to downstream hacks to handle cases like this that can easily be solved in the upstream kernel. By linking devices before they are probed, we give suppliers a clear count of the number of dependent consumers. Once all of the consumers are active, the suppliers can turn off the unused resources without making assumptions about the number of consumers. By default we just add device-links to track "driver presence" (probe succeeded) of the supplier device. If any other functionality provided by device-links are needed, it is left to the consumer/supplier devices to change the link when they probe. Saravana Kannan (5): of/platform: Speed up of_find_device_by_node() driver core: Add device links support for pending links to suppliers dt-bindings: Add depends-on property of/platform: Add functional dependency link from "depends-on" property driver core: Add sync_state driver/bus callback .../devicetree/bindings/depends-on.txt | 26 +++++ drivers/base/core.c | 106 ++++++++++++++++++ drivers/of/platform.c | 75 ++++++++++++- include/linux/device.h | 24 ++++ include/linux/of.h | 3 + 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/depends-on.txt -- 2.22.0.rc1.257.g3120a18244-goog