Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2086954lqt; Mon, 22 Apr 2024 00:27:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWy+t4shdRGpSzDfXfvZ8pYouVDNj59LTThCcYwLqhr4lMOKeav2R5BwC/uQEcAh28FcC17OK4j0THYAhFAyk7IDnNT8PqScb6FHGKsAg== X-Google-Smtp-Source: AGHT+IGjh+UovfKSoZAruK3H9gFYH2nRFoybHEZc2wxv44G4RXlEhfy+Ur7w8eo/lwFdxlnTjpIA X-Received: by 2002:a17:903:249:b0:1e1:6850:f823 with SMTP id j9-20020a170903024900b001e16850f823mr9921281plh.13.1713770863926; Mon, 22 Apr 2024 00:27:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713770863; cv=pass; d=google.com; s=arc-20160816; b=ha+x0dwyrOej78bkCrTPi16MKg/Wk2bBbjFfrRhUyiub7GmzE7t4AqA8WxvCaasev7 mbWzQ0NfcuzMUwezT3QD/Rk1zLZ+ZaslyQxJu8Qjm7EzbBn7+Xx7xphpONDildslMhJU EYs7foMacbgkiFCTmE641+BJxahh3uV07iUNBdvlW4ncvQo76mkPToQBgJeDu+MH1U3z Dph1ObeKeNNz2KpZcQvVqaLWz1niCU5sRQW6cvcCl8QR+936A3BhFIBOng3E1Yp2qK8e VOvunVcNzSDIhr4UGkrDsu260cWEFUniLnDChe+WacUQ6AwZJPTfdpnbxC4BLBqMfk0c 5ZXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=dSWKV/i3DST6mGvsPHhxXOiFOckxaI7nSxVUjxZHaSM=; fh=6Eg2udc9X1126viNLBVdecuPiqPLk5gjT6YD4/0ai9Q=; b=VhjEpViI/C2PheOMOAX/KZSyd7YegnSb+lkEgyW93E7Y1Js3rOmGPa3JaNbNhaCeU/ guBoO3u5KPAfL7ol4CcmOSMRzeb1fXLqN6+z8GXXwD1yLd2Dzz2udNvDf70El20PoEjI xxe1ZCd8QuNgO59Q2OC8+i3u3OMlEuBPeELbUxDA+yA/6RfxWlkG/CA2FRsJJe8CXZ90 Q7gsgnwnYuxDYpWmZQJQkT5il3dCdcXfDQx8NaXvGwAZ2DvH6908TgyK71Ar1XhIIunr xgDlRmdDDjfJGa6l/rIByVXPwfeDD+Xi5g8iSID9v7GUWo0Md7VFUN70MFrgsmI80Wge dBVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-152870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l14-20020a170903120e00b001e67732a182si7245286plh.637.2024.04.22.00.27.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:27:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-152870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5D3E52822EC for ; Mon, 22 Apr 2024 07:27:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF698548E7; Mon, 22 Apr 2024 07:24:26 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8E7E51037; Mon, 22 Apr 2024 07:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713770666; cv=none; b=fe1Mq31biu6kpqA+qX48Lf4LLsn81QYo/yuGkXJj8LY798z/lJZF6g+zUJ9U4INxpFSWgN7/z/K902GaGg4THjnARfaP7fEWWrD7IwMoisKP+ldBlAiYJUbnFH7KkR1pXbtRx2PHn4i/MA+qVK/DA9lyrAMfca28ewawradmXqg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713770666; c=relaxed/simple; bh=+jbogwzOl0Cmt21yqpTd7FcQBUl20qerWA4osI69YTk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bHRwzmdQjBRzEhBhWmtr6Z5wvdYdEq6aOEp6vj3B8ziIrziHNerF19exQlmSPslCxFjO1vnInhX9qYf73/bezXNRJ04UWB655QafuMZqUGumV2wH65rOEwYwtA59/gsHB1BdQyacc4VunUxkR39BQifn/jYTW8wlrLI2Nr5yxzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A81D4339; Mon, 22 Apr 2024 00:24:52 -0700 (PDT) Received: from [10.57.75.149] (unknown [10.57.75.149]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B74D3F7BD; Mon, 22 Apr 2024 00:24:22 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 08:24:31 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] PM: EM: Add min/max available performance state limits To: Hongyan Xia Cc: dietmar.eggemann@arm.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com, cristian.marussi@arm.com, linux-samsung-soc@vger.kernel.org, rafael@kernel.org, viresh.kumar@linaro.org, quic_sibis@quicinc.com References: <20240403162315.1458337-1-lukasz.luba@arm.com> <20240403162315.1458337-2-lukasz.luba@arm.com> <08bff6ab-dcdc-42b6-b8ad-5938f0119385@arm.com> Content-Language: en-US From: Lukasz Luba In-Reply-To: <08bff6ab-dcdc-42b6-b8ad-5938f0119385@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 4/9/24 15:47, Hongyan Xia wrote: > On 03/04/2024 17:23, Lukasz Luba wrote: >> [...] >> >> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c >> index 927cc55ba0b3d..1a8b394251cb2 100644 >> --- a/kernel/power/energy_model.c >> +++ b/kernel/power/energy_model.c >> @@ -628,6 +628,8 @@ int em_dev_register_perf_domain(struct device >> *dev, unsigned int nr_states, >>           goto unlock; >>       dev->em_pd->flags |= flags; >> +    dev->em_pd->min_ps = 0; >> +    dev->em_pd->max_ps = nr_states - 1; >>       em_cpufreq_update_efficiencies(dev, dev->em_pd->em_table->state); >> @@ -856,3 +858,49 @@ int em_dev_update_chip_binning(struct device *dev) >>       return em_recalc_and_update(dev, pd, em_table); >>   } >>   EXPORT_SYMBOL_GPL(em_dev_update_chip_binning); >> + >> + >> +/** >> + * em_update_performance_limits() - Update Energy Model with performance >> + *                limits information. >> + * @pd            : Performance Domain with EM that has to be updated. >> + * @freq_min_khz    : New minimum allowed frequency for this device. >> + * @freq_max_khz    : New maximum allowed frequency for this device. >> + * >> + * This function allows to update the EM with information about >> available >> + * performance levels. It takes the minimum and maximum frequency in kHz >> + * and does internal translation to performance levels. >> + * Returns 0 on success or -EINVAL when failed. >> + */ >> +int em_update_performance_limits(struct em_perf_domain *pd, >> +        unsigned long freq_min_khz, unsigned long freq_max_khz) >> +{ >> +    struct em_perf_state *table; >> +    int min_ps = -1; >> +    int max_ps = -1; >> +    int i; >> + >> +    if (!pd) >> +        return -EINVAL; >> + >> +    rcu_read_lock(); >> +    table = em_perf_state_from_pd(pd); >> + >> +    for (i = 0; i < pd->nr_perf_states; i++) { >> +        if (freq_min_khz == table[i].frequency) >> +            min_ps = i; >> +        if (freq_max_khz == table[i].frequency) >> +            max_ps = i; >> +    } >> +    rcu_read_unlock(); >> + >> +    /* Only update when both are found and sane */ >> +    if (min_ps < 0 || max_ps < 0 || max_ps < min_ps) >> +        return -EINVAL; >> + >> +    pd->min_ps = min_ps; >> +    pd->max_ps = max_ps; > > Are we sure we are protected against multiple simultaneous updates? Or > is this a concern for the caller? > > The rest of the patch LGTM. > I've tried to make it running fast for only one caller. Although, if someone would like to use it from many places then locking should be handled under in function (and I will use the existing mutex for it). I'll change it. Thanks for the review.