From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lina Iyer Subject: Re: [PATCH 1/8] PM / Domains: Make genpd state allocation dynamic Date: Thu, 6 Oct 2016 14:57:24 -0600 Message-ID: <20161006205724.GA41480@linaro.org> References: <1475699519-109623-1-git-send-email-lina.iyer@linaro.org> <1475699519-109623-2-git-send-email-lina.iyer@linaro.org> <20161006154052.GB28930@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Return-path: Received: from mail-pf0-f172.google.com ([209.85.192.172]:35092 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935025AbcJFU52 (ORCPT ); Thu, 6 Oct 2016 16:57:28 -0400 Received: by mail-pf0-f172.google.com with SMTP id s13so14353986pfd.2 for ; Thu, 06 Oct 2016 13:57:28 -0700 (PDT) Content-Disposition: inline In-Reply-To: Sender: linux-arm-msm-owner@vger.kernel.org List-Id: linux-arm-msm@vger.kernel.org To: Ulf Hansson Cc: Kevin Hilman , "Rafael J. Wysocki" , "linux-pm@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , Andy Gross , Stephen Boyd , "linux-arm-msm@vger.kernel.org" , Brendan Jackman , Lorenzo Pieralisi , Sudeep Holla , Juri Lelli , Axel Haslam On Thu, Oct 06 2016 at 13:45 -0600, Ulf Hansson wrote: >On 6 October 2016 at 17:40, Lina Iyer wrote: >> On Thu, Oct 06 2016 at 02:37 -0600, Ulf Hansson wrote: >>> >>> On 5 October 2016 at 22:31, Lina Iyer wrote: >>>> >>>> Allow PM Domain states to be defined dynamically by the drivers. This >>>> removes the limitation on the maximum number of states possible for a >>>> domain. >>>> >>>> Cc: Axel Haslam >>>> Suggested-by: Ulf Hansson >>>> Signed-off-by: Lina Iyer >> >> <...> >>>> >>>> -#define GENPD_MAX_NUM_STATES 8 /* Number of possible low power states >>>> */ >>>> - >>>> enum gpd_status { >>>> GPD_STATE_ACTIVE = 0, /* PM domain is active */ >>>> GPD_STATE_POWER_OFF, /* PM domain is off */ >>>> @@ -70,7 +68,7 @@ struct generic_pm_domain { >>>> void (*detach_dev)(struct generic_pm_domain *domain, >>>> struct device *dev); >>>> unsigned int flags; /* Bit field of configs for genpd >>>> */ >>>> - struct genpd_power_state states[GENPD_MAX_NUM_STATES]; >>>> + struct genpd_power_state *states; >>>> unsigned int state_count; /* number of states */ >>>> unsigned int state_idx; /* state that genpd will go to when off >>>> */ >>>> >>>> -- >>>> 2.7.4 >>>> >>> >>> In general I like the improvement, but.. >>> >>> This change implies that ->states may very well be NULL. This isn't >>> validated by genpd's internal logic when power off/on the domain >>> (genpd_power_on|off(), __default_power_down_ok()). You need to fix >>> this, somehow. >>> >> Good point. >> >>> Perhaps the easiest solutions is, when pm_genpd_init() finds that >>> ->state is NULL, that we allocate a struct genpd_power_state with >>> array size of 1 and assign it to ->states. Although, doing this also >>> means you need to track that genpd was responsible for the the >>> allocation, so it must also free the data from within genpd_remove(). >>> >>> Unless you have other ideas!? >>> >> I can think of some hacks, but they are uglier than the problem we are >> trying to solve. We could drop this patch. Real world situations would >> not have more than 8 states and if there is one, we can think about it >> then. > >The problem with the current approach is that we waste some memory as >we always have an array of 8 states per genpd. In the worst case, >which currently is the most common case, only 1 out of 8 states is >being used. > >So, let's not be lazy here and instead take the opportunity to fix >this, and especially I think this makes sense, before we go on and add >the DT parsing of the domain-idle-states. > Hmm.. We are not wasting much memory in comparison, but if you insist, sure. >The more sophisticated method would probably be to use kobject/kref, >but let's not go there for now. Instead let's try an easy method of >just tracking whether the allocations had been made internally by >genpd, via adding a "bool state_allocated to the struct >generic_pm_domain. Would that work? > It would work. i. How about an additional static state by default in the domain structure, if the platform does not provide a state then the default structure is used. That way we dont have to track it. But it does waste memory eqivalent to a state, when there are states provided by the platform. ii. I could add a void *free to the domain structure and save the memory allocated by default in the *free. At domain remove, we just do a kfree on free. iii. Use a boolean flag. Thanks, Lina