From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757348AbdJKI5J (ORCPT ); Wed, 11 Oct 2017 04:57:09 -0400 Received: from mail-cys01nam02on0080.outbound.protection.outlook.com ([104.47.37.80]:65152 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756774AbdJKI5F (ORCPT ); Wed, 11 Oct 2017 04:57:05 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=George.Cherian@cavium.com; Subject: Re: [PATCH v4 2/2] ACPI / CPPC: Make cppc acpi driver aware of pcc subspace ids To: "Prakash, Prashanth" , George Cherian , devel@acpica.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Cc: lv.zheng@intel.com, robert.moore@intel.com, jassisinghbrar@gmail.com, lenb@kernel.org, rjw@rjwysocki.net References: <1505885087-5112-1-git-send-email-george.cherian@cavium.com> <1505885087-5112-3-git-send-email-george.cherian@cavium.com> <929b30f2-03d1-269c-8672-72577a4e5a46@codeaurora.org> <54c0a799-0cf6-3ba3-c137-7a5c35012654@codeaurora.org> From: George Cherian Message-ID: Date: Wed, 11 Oct 2017 14:26:42 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <54c0a799-0cf6-3ba3-c137-7a5c35012654@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0078.INDPRD01.PROD.OUTLOOK.COM (10.174.208.146) To CY1PR0701MB1709.namprd07.prod.outlook.com (10.163.21.11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72bac887-945c-4bbe-3c8d-08d510860a8e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:CY1PR0701MB1709; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1709;3:EPC4+UDQdAudFTJBBrjOILhNMFVX/NpCna/5rSbctwLeUpVbytqu7iPFJCwb5d5jP9AoSzv7sw1ua2S0blr0dqpWSwABojhRhGonf76S8vGVNe2Br8QTfprYZmjtMJa0lbUodjtmgN/2W8fbx9HRc9jBhSION2yPIqg0NPRQhD/kS/4FvJLScCRgnRrTWlnGQmzv/Q1Nfgg4GOkTwQGLJWA3d7ALPLepTtBfnPdtwJtKtZEGE3UzmTMxxrJTq/k5;25:mrEJSTkrRWYG+/DK/jJs6lSIddXl0OEnjh+unxv3ocyToo8yg9aGLAV8JPsDsf3JrkVd8DaZu8zcCdrhg6hEgHIRd1ZBKSYxiTaRkI7s4oXYYUNJFI4c88OUL4qluvEB02hdC8NgwcKbOj7Yz03AMHB55cmDgx99q5UANfQo1xOoVM1kQWR0JE3Ap1CRuPn1OeN5eHN/dHtcHo4F3A3SCyMg4a+cJt0F3DkWT97jh/VpYbPwley0zID4Yv/+BmJH+JkMxZo8hNlJCG//laLDOrtCj1NiQHhiSDc7e4s9YVkfMmtTyXHt1xKSUSTygba8NEMjsLbAcrbQllZMe+LIFg==;31:CDDMDIT9lbNxX9abQ4K9+nGoizQcviJwwlpEc/TZlNYesYf+XedgCic6hgddQu8MPZH2jS/Nl5rHY1V1o1kfpp2D6YbjSCQPEDRW7TtJJcmjof2ru0Jgg+Nk2js9hiSpgUGG8vCr0s0UYQ+f22YSUIk3tuuEnC30WCp6GXSE7yVIFVL/AZoHeoFiVN5q32eD1kN56rINR8w9WiZ7ArBGugy8OqtcrlFKfZ5ZQDQhJEg= X-MS-TrafficTypeDiagnostic: CY1PR0701MB1709: X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1709;20:D86z8zh0LrdPdXrNo+qW4/QRve2wsq74t6FrKyYo2AbXp1dlyUZHSAqs6d2tm8Lj19VMHObc9AbRbB55BrQIK7m3JiYAdsk8MqHxm+zAksUebj0guoCFx6uvUv55P+LcLeo9FhoX0tonQqiMV/b3acSs8DpsKNTRd3ZTLN2qaJtYBT3Synzm/QnuKV02iX7HTiT+nca9ge7QSQUJ+sG9NBWGwCXI1ia1Mpqo3XFTUq0RBJmxDRYcdLOkQT2JPXl/sWeULV9Jme6QH14Tyt6Ya32819Y48YGIOFdnrNswyGH/0lOIJyW60zfSDsuImg3yYs4yQgdO9PmUE79N2KHOQTugw6FH6HM+YNZNWtaJ5DyRseUFOkRvK/5xi/5MhbRpyEBAUzl1BGZbkazEqoIS787QwzU2QUq26SrLVMX9XgfDklYFws95QcRIiFsY4NUVzU8Q5/SlMTzHKQJEo8FS1jsA8hZIbcwsNgilnUmb1nbXWbQuoPyFkl8W9z1AK//uA3c01McTasIUvmym2zK7f4VpnI8ixlK03PA1Rxuobpm7ReXcYe+tXMGGEfUtoRf/kEPIRvDld++tnMJahyt2muE+WJuZkQm2rY+QF5sEPL8= X-Exchange-Antispam-Report-Test: UriScan:(60795455431006)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3002001)(93006095)(100000703101)(100105400095)(10201501046)(6041248)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR0701MB1709;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR0701MB1709; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1709;4:/o+F6mND6G5KPt1jGGzBawtDWV8Ivi8FMMxabUSiQUNqaa1lYD4dgpvpa7atQ5qKjBL6zGOdWkgcAY1FAzeKZjhYgoys19tWG8pwyKB2r0c/lDBWFBeR9lCpeXEfDoKjIafPE1xtj1czS9ndHC75bDGqij4BfvpLIAaajLRMuFJnInipRoSJKuyolySSWol5g7PD0easelAjFVoTXu/vHUNv/a/V4br6MO8gJ+8wB7wBmqoJtMr98OmM2JquzkISxhaXF0dWvy7ZAfbI0WTo+/M3Ymq4K6hTAmO5JTYKVZbVLfilyO45Af/b6z6yumk6LUH44IEANr0zaSFYC7ahRQ== X-Forefront-PRVS: 0457F11EAF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6049001)(346002)(376002)(24454002)(199003)(189002)(57704003)(377454003)(58126008)(110136005)(6116002)(31696002)(2870700001)(5009440100003)(76176999)(50986999)(65806001)(93886005)(54356999)(106356001)(53936002)(316002)(66066001)(105586002)(16526018)(6246003)(65956001)(47776003)(2906002)(6666003)(3846002)(23676002)(16576012)(101416001)(5660300001)(65826007)(189998001)(33646002)(53546010)(83506001)(68736007)(42882006)(478600001)(2950100002)(305945005)(50466002)(31686004)(25786009)(7736002)(39060400002)(4326008)(72206003)(64126003)(229853002)(90366009)(8936002)(97736004)(81156014)(6486002)(36756003)(8676002)(77096006)(81166006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0701MB1709;H:[10.167.103.249];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjA3MDFNQjE3MDk7MjM6Y01zZFZqSFBWNEhOQzJiazl6OVpsL0Rt?= =?utf-8?B?R1dJVVl0VHV4RDVsMHQ4QW1VV3V3MW9MWC9wdHRBNTFjYkhmZEkyOUJsSXRO?= =?utf-8?B?bDJVcGl3TWtoMWNRRXN5ZDRWdGMrTGxzdzdtK24ySEtyTitHbXo4Nkh6WGpn?= =?utf-8?B?RWhqTjdBbEMwZU5uMWxKcTFIVmVRUnZQekx2TGJMYkVqVVJzNVN3c3YyRD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VJJODJITGUvTUdKOUJhQXE5dFhRPT0=?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1709;6:fzSI0JP6rqJCB0F8hPZ0bRpdRbp+BLc3X8GUk8TWv6aw1fItsplIdV1ISSwTI0PKkc9TbQX1o+/y0A8nmqiAy+uUIi3QV7anksLrYGrxQo2fVSB4KU4WYLm7b3ByHMDxUp07ZGRBY27NQYyJQfc4UwpSCS7PCf/OAmK/aKUxM7nTYfVKzXFU/sDLArx7/NoetuPyWJg9HBokHGfryVYjIfGbnpsAzeKNuVzvPh31sp4iqRMzgRXpcKEWzdU6gSbQpDA+WhoCc6+gTa6aHiYvfEal3LDeKeuAyAO1/k1j4SONAh5AQeQzimqinOpkNE7VvQ6m7dq4o7mD9dhKvZ2gOQ==;5:D9OKDHqTDURiYP4zNc194WQw2hb5zbiizRjc+bg2PYpcK+mjXPAdimtIbqOEwS6nF/tLwv60i1CMGeEY3ebTTRBnX+az/8tuAM8+e+EfDpO5ECd4O9FHkWizt50Vj2E54VcWnh1aq2VCRDkIrG2FiA==;24:4KsEJ0cCVmh31YHOX20GtVEq44Z4lZoazTHMCYRPLBeDOtrIc1yVU+H+NEIpIznJGeS88Uj40XT20Ecb5FD+f17u3HruLgLdLN7Hw5cniUo=;7:eYfsXjNjH6a8rGfJhodlbrxbOqQWB9wtoqTot06ZcL2qahYcuJSSOiT1pPiXteRAspJUbTHJfPRkf9/kSnxWjvn+DhEOauaTxWl6kYbZPqbTwTkpbc26xP4HG+No3rq5qZFwFPvCuoJItjdwWA8HuX/1j44djh1TIS6ZGQNHEvfFP2rKt6m8nxv6k7LOkb+SYxBdQJpVHoQMpH2Q+kcMh2+iXtKhWqGdypfBrxkMTIk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2017 08:56:59.3891 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1709 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Prakash for the clarifications. I have updated the patch set incorporating your comments and posted v5. Regards -George On 10/07/2017 02:40 AM, Prakash, Prashanth wrote: > > On 10/3/2017 5:01 AM, George Cherian wrote: >> Hi Prakash, >> >> On 09/29/2017 04:49 AM, Prakash, Prashanth wrote: >>> Hi George, >>> >>> On 9/19/2017 11:24 PM, George Cherian wrote: >>>> Based on ACPI 6.2 Section 8.4.7.1.9 If the PCC register space is used, >>>> all PCC registers, for all processors in the same performance >>>> domain (as defined by _PSD), must be defined to be in the same subspace. >>>> Based on Section 14.1 of ACPI specification, it is possible to have a >>>> maximum of 256 PCC subspace ids. Add support of multiple PCC subspace id >>>> instead of using a single global pcc_data structure. >>>> >>>> While at that fix the time_delta check in send_pcc_cmd() so that last_mpar_reset >>>> and mpar_count is initialized properly. >>>> >>>> Signed-off-by: George Cherian >>>> --- >>>>   drivers/acpi/cppc_acpi.c | 243 +++++++++++++++++++++++++++++------------------ >>>>   1 file changed, 153 insertions(+), 90 deletions(-) >>>> >>>> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c >>>> index e5b47f0..3ae79ef 100644 >>>> --- a/drivers/acpi/cppc_acpi.c >>>> +++ b/drivers/acpi/cppc_acpi.c >>>> @@ -75,13 +75,16 @@ struct cppc_pcc_data { >>>>         /* Wait queue for CPUs whose requests were batched */ >>>>       wait_queue_head_t pcc_write_wait_q; >>>> +    ktime_t last_cmd_cmpl_time; >>>> +    ktime_t last_mpar_reset; >>>> +    int mpar_count; >>>> +    int refcount; >>>>   }; >>>>   -/* Structure to represent the single PCC channel */ >>>> -static struct cppc_pcc_data pcc_data = { >>>> -    .pcc_subspace_idx = -1, >>>> -    .platform_owns_pcc = true, >>>> -}; >>>> +/* Array  to represent the PCC channel per subspace id */ >>>> +static struct cppc_pcc_data *pcc_data[MAX_PCC_SUBSPACES]; >>>> +/* The cpu_pcc_subspace_idx containsper CPU subspace id */ >>>> +static DEFINE_PER_CPU(int, cpu_pcc_subspace_idx); >>>>     /* >>>>    * The cpc_desc structure contains the ACPI register details >>>> @@ -93,7 +96,8 @@ static struct cppc_pcc_data pcc_data = { >>>>   static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr); >>>>     /* pcc mapped address + header size + offset within PCC subspace */ >>>> -#define GET_PCC_VADDR(offs) (pcc_data.pcc_comm_addr + 0x8 + (offs)) >>>> +#define GET_PCC_VADDR(offs, pcc_ss_id) (pcc_data[pcc_ss_id]->pcc_comm_addr + \ >>>> +                        0x8 + (offs)) >>>>     /* Check if a CPC register is in PCC */ >>>>   #define CPC_IN_PCC(cpc) ((cpc)->type == ACPI_TYPE_BUFFER &&        \ >>>> @@ -188,13 +192,16 @@ static struct kobj_type cppc_ktype = { >>>>       .default_attrs = cppc_attrs, >>>>   }; >>>>   -static int check_pcc_chan(bool chk_err_bit) >>>> +static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit) >>>>   { >>>>       int ret = -EIO, status = 0; >>>> -    struct acpi_pcct_shared_memory __iomem *generic_comm_base = pcc_data.pcc_comm_addr; >>>> -    ktime_t next_deadline = ktime_add(ktime_get(), pcc_data.deadline); >>>> +    struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id]; >>>> +    struct acpi_pcct_shared_memory __iomem *generic_comm_base = >>>> +        pcc_ss_data->pcc_comm_addr; >>>> +    ktime_t next_deadline = ktime_add(ktime_get(), >>>> +                      pcc_ss_data->deadline); >>>>   -    if (!pcc_data.platform_owns_pcc) >>>> +    if (!pcc_ss_data->platform_owns_pcc) >>>>           return 0; >>>>         /* Retry in case the remote processor was too slow to catch up. */ >>>> @@ -219,7 +226,7 @@ static int check_pcc_chan(bool chk_err_bit) >>>>       } >>>>         if (likely(!ret)) >>>> -        pcc_data.platform_owns_pcc = false; >>>> +        pcc_ss_data->platform_owns_pcc = false; >>>>       else >>>>           pr_err("PCC check channel failed. Status=%x\n", status); >>>>   @@ -230,13 +237,12 @@ static int check_pcc_chan(bool chk_err_bit) >>>>    * This function transfers the ownership of the PCC to the platform >>>>    * So it must be called while holding write_lock(pcc_lock) >>>>    */ >>>> -static int send_pcc_cmd(u16 cmd) >>>> +static int send_pcc_cmd(int pcc_ss_id, u16 cmd) >>>>   { >>>>       int ret = -EIO, i; >>>> +    struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id]; >>>>       struct acpi_pcct_shared_memory *generic_comm_base = >>>> -        (struct acpi_pcct_shared_memory *) pcc_data.pcc_comm_addr; >>>> -    static ktime_t last_cmd_cmpl_time, last_mpar_reset; >>>> -    static int mpar_count; >>>> +        (struct acpi_pcct_shared_memory *)pcc_ss_data->pcc_comm_addr; >>>>       unsigned int time_delta; >>>>         /* >>>> @@ -249,24 +255,25 @@ static int send_pcc_cmd(u16 cmd) >>>>            * before write completion, so first send a WRITE command to >>>>            * platform >>>>            */ >>>> -        if (pcc_data.pending_pcc_write_cmd) >>>> -            send_pcc_cmd(CMD_WRITE); >>>> +        if (pcc_ss_data->pending_pcc_write_cmd) >>>> +            send_pcc_cmd(pcc_ss_id, CMD_WRITE); >>>>   -        ret = check_pcc_chan(false); >>>> +        ret = check_pcc_chan(pcc_ss_id, false); >>>>           if (ret) >>>>               goto end; >>>>       } else /* CMD_WRITE */ >>>> -        pcc_data.pending_pcc_write_cmd = FALSE; >>>> +        pcc_ss_data->pending_pcc_write_cmd = FALSE; >>>>         /* >>>>        * Handle the Minimum Request Turnaround Time(MRTT) >>>>        * "The minimum amount of time that OSPM must wait after the completion >>>>        * of a command before issuing the next command, in microseconds" >>>>        */ >>>> -    if (pcc_data.pcc_mrtt) { >>>> -        time_delta = ktime_us_delta(ktime_get(), last_cmd_cmpl_time); >>>> -        if (pcc_data.pcc_mrtt > time_delta) >>>> -            udelay(pcc_data.pcc_mrtt - time_delta); >>>> +    if (pcc_ss_data->pcc_mrtt) { >>>> +        time_delta = ktime_us_delta(ktime_get(), >>>> +                        pcc_ss_data->last_cmd_cmpl_time); >>>> +        if (pcc_ss_data->pcc_mrtt > time_delta) >>>> +            udelay(pcc_ss_data->pcc_mrtt - time_delta); >>>>       } >>>>         /* >>>> @@ -280,18 +287,19 @@ static int send_pcc_cmd(u16 cmd) >>>>        * not send the request to the platform after hitting the MPAR limit in >>>>        * any 60s window >>>>        */ >>>> -    if (pcc_data.pcc_mpar) { >>>> -        if (mpar_count == 0) { >>>> -            time_delta = ktime_ms_delta(ktime_get(), last_mpar_reset); >>>> -            if (time_delta < 60 * MSEC_PER_SEC) { >>>> +    if (pcc_ss_data->pcc_mpar) { >>>> +        if (pcc_ss_data->mpar_count == 0) { >>>> +            time_delta = ktime_ms_delta(ktime_get(), >>>> +                            pcc_ss_data->last_mpar_reset); >>>> +            if ((time_delta < 60 * MSEC_PER_SEC) && pcc_ss_data->last_mpar_reset) { >>>>                   pr_debug("PCC cmd not sent due to MPAR limit"); >>>>                   ret = -EIO; >>>>                   goto end; >>>>               } >>>> -            last_mpar_reset = ktime_get(); >>>> -            mpar_count = pcc_data.pcc_mpar; >>>> +            pcc_ss_data->last_mpar_reset = ktime_get(); >>>> +            pcc_ss_data->mpar_count = pcc_ss_data->pcc_mpar; >>>>           } >>>> -        mpar_count--; >>>> +        pcc_ss_data->mpar_count--; >>>>       } >>>>         /* Write to the shared comm region. */ >>>> @@ -300,10 +308,10 @@ static int send_pcc_cmd(u16 cmd) >>>>       /* Flip CMD COMPLETE bit */ >>>>       writew_relaxed(0, &generic_comm_base->status); >>>>   -    pcc_data.platform_owns_pcc = true; >>>> +    pcc_ss_data->platform_owns_pcc = true; >>>>         /* Ring doorbell */ >>>> -    ret = mbox_send_message(pcc_data.pcc_channel, &cmd); >>>> +    ret = mbox_send_message(pcc_ss_data->pcc_channel, &cmd); >>>>       if (ret < 0) { >>>>           pr_err("Err sending PCC mbox message. cmd:%d, ret:%d\n", >>>>                   cmd, ret); >>>> @@ -311,15 +319,15 @@ static int send_pcc_cmd(u16 cmd) >>>>       } >>>>         /* wait for completion and check for PCC errro bit */ >>>> -    ret = check_pcc_chan(true); >>>> +    ret = check_pcc_chan(pcc_ss_id, true); >>>>   -    if (pcc_data.pcc_mrtt) >>>> -        last_cmd_cmpl_time = ktime_get(); >>>> +    if (pcc_ss_data->pcc_mrtt) >>>> +        pcc_ss_data->last_cmd_cmpl_time = ktime_get(); >>>>   -    if (pcc_data.pcc_channel->mbox->txdone_irq) >>>> -        mbox_chan_txdone(pcc_data.pcc_channel, ret); >>>> +    if (pcc_ss_data->pcc_channel->mbox->txdone_irq) >>>> +        mbox_chan_txdone(pcc_ss_data->pcc_channel, ret); >>>>       else >>>> -        mbox_client_txdone(pcc_data.pcc_channel, ret); >>>> +        mbox_client_txdone(pcc_ss_data->pcc_channel, ret); >>>>     end: >>>>       if (cmd == CMD_WRITE) { >>>> @@ -329,12 +337,12 @@ static int send_pcc_cmd(u16 cmd) >>>>                   if (!desc) >>>>                       continue; >>>>   -                if (desc->write_cmd_id == pcc_data.pcc_write_cnt) >>>> +                if (desc->write_cmd_id == pcc_ss_data->pcc_write_cnt) >>>>                       desc->write_cmd_status = ret; >>>>               } >>>>           } >>>> -        pcc_data.pcc_write_cnt++; >>>> -        wake_up_all(&pcc_data.pcc_write_wait_q); >>>> +        pcc_ss_data->pcc_write_cnt++; >>>> +        wake_up_all(&pcc_ss_data->pcc_write_wait_q); >>>>       } >>>>         return ret; >>>> @@ -536,16 +544,16 @@ int acpi_get_psd_map(struct cppc_cpudata **all_cpu_data) >>>>   } >>>>   EXPORT_SYMBOL_GPL(acpi_get_psd_map); >>>>   -static int register_pcc_channel(int pcc_subspace_idx) >>>> +static int register_pcc_channel(int pcc_ss_idx) >>>>   { >>>>       struct acpi_pcct_hw_reduced *cppc_ss; >>>>       u64 usecs_lat; >>>>   -    if (pcc_subspace_idx >= 0) { >>>> -        pcc_data.pcc_channel = pcc_mbox_request_channel(&cppc_mbox_cl, >>>> -                pcc_subspace_idx); >>>> +    if (pcc_ss_idx >= 0) { >>>> +        pcc_data[pcc_ss_idx]->pcc_channel = >>>> +            pcc_mbox_request_channel(&cppc_mbox_cl,    pcc_ss_idx); >>>>   -        if (IS_ERR(pcc_data.pcc_channel)) { >>>> +        if (IS_ERR(pcc_data[pcc_ss_idx]->pcc_channel)) { >>>>               pr_err("Failed to find PCC communication channel\n"); >>>>               return -ENODEV; >>>>           } >>>> @@ -556,7 +564,7 @@ static int register_pcc_channel(int pcc_subspace_idx) >>>>            * PCC channels) and stored pointers to the >>>>            * subspace communication region in con_priv. >>>>            */ >>>> -        cppc_ss = (pcc_data.pcc_channel)->con_priv; >>>> +        cppc_ss = (pcc_data[pcc_ss_idx]->pcc_channel)->con_priv; >>>>             if (!cppc_ss) { >>>>               pr_err("No PCC subspace found for CPPC\n"); >>>> @@ -569,19 +577,20 @@ static int register_pcc_channel(int pcc_subspace_idx) >>>>            * So add an arbitrary amount of wait on top of Nominal. >>>>            */ >>>>           usecs_lat = NUM_RETRIES * cppc_ss->latency; >>>> -        pcc_data.deadline = ns_to_ktime(usecs_lat * NSEC_PER_USEC); >>>> -        pcc_data.pcc_mrtt = cppc_ss->min_turnaround_time; >>>> -        pcc_data.pcc_mpar = cppc_ss->max_access_rate; >>>> -        pcc_data.pcc_nominal = cppc_ss->latency; >>>> - >>>> -        pcc_data.pcc_comm_addr = acpi_os_ioremap(cppc_ss->base_address, cppc_ss->length); >>>> -        if (!pcc_data.pcc_comm_addr) { >>>> +        pcc_data[pcc_ss_idx]->deadline = ns_to_ktime(usecs_lat * NSEC_PER_USEC); >>>> +        pcc_data[pcc_ss_idx]->pcc_mrtt = cppc_ss->min_turnaround_time; >>>> +        pcc_data[pcc_ss_idx]->pcc_mpar = cppc_ss->max_access_rate; >>>> +        pcc_data[pcc_ss_idx]->pcc_nominal = cppc_ss->latency; >>>> + >>>> +        pcc_data[pcc_ss_idx]->pcc_comm_addr = >>>> +            acpi_os_ioremap(cppc_ss->base_address, cppc_ss->length); >>>> +        if (!pcc_data[pcc_ss_idx]->pcc_comm_addr) { >>>>               pr_err("Failed to ioremap PCC comm region mem\n"); >>>>               return -ENOMEM; >>>>           } >>>>             /* Set flag so that we dont come here for each CPU. */ >>>> -        pcc_data.pcc_channel_acquired = true; >>>> +        pcc_data[pcc_ss_idx]->pcc_channel_acquired = true; >>>>       } >>>>         return 0; >>>> @@ -600,6 +609,39 @@ bool __weak cpc_ffh_supported(void) >>>>       return false; >>>>   } >>>>   + >>>> +/** >>>> + * pcc_data_alloc() - Allocate the pcc_data memory for pcc subspace >>>> + * >>>> + * Check and allocate the cppc_pcc_data memory. >>>> + * In some processor configurations it is possible that same subspace >>>> + * is shared between multiple CPU's. This is seen especially in CPU's >>>> + * with hardware multi-threading support. >>>> + * >>>> + * Return: 0 for success, errno for failure >>>> + */ >>>> +int pcc_data_alloc(int pcc_ss_id) >>>> +{ >>>> +    int loop; >>>> + >>>> +    if (pcc_ss_id < 0) >>> Above should be (pcc_ss_id < 0 || pcc_ss_id >= MAX_PCC_SUBSPACES) >> Yes we can have this additional check. >>>> +        return -EINVAL; >>>> + >>>> +    for (loop = 0; pcc_data[loop] != NULL; loop++) { >>>> +        if (pcc_data[loop]->pcc_subspace_idx == pcc_ss_id) { >>>> +            pcc_data[loop]->refcount++; >>>> +            return 0; >>>> +        } >>>> +    } >>> Why do we need the above for loop? can't it be direct array lookup? >>> if (pcc_data[pcc_ss_id]) { >>>      //increment ref_count and return >>> } >> Yes, we could get rid of the loop and increment the reference directly if already allocated. >> >>> >>> Also, we should remove the pcc_subspace_idx from cppc_pcc_data structure, >>> it is no longer useful and probably adds to confusion. >> Please see below >>>> + >>>> +    pcc_data[pcc_ss_id] = kzalloc(sizeof(struct cppc_pcc_data), GFP_KERNEL); >>>> +    if (!pcc_data[pcc_ss_id]) >>>> +        return -ENOMEM; >>>> +    pcc_data[pcc_ss_id]->pcc_subspace_idx = pcc_ss_id; >>>> +    pcc_data[pcc_ss_id]->refcount++; >>>> + >>>> +    return 0; >>>> +} >>>>   /* >>>>    * An example CPC table looks like the following. >>>>    * >>>> @@ -661,6 +703,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) >>>>       struct device *cpu_dev; >>>>       acpi_handle handle = pr->handle; >>>>       unsigned int num_ent, i, cpc_rev; >>>> +    int pcc_subspace_id = -1; >>>>       acpi_status status; >>>>       int ret = -EFAULT; >>>>   @@ -733,12 +776,9 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) >>>>                * so extract it only once. >>>>                */ >>>>               if (gas_t->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) { >>>> -                if (pcc_data.pcc_subspace_idx < 0) >>>> -                    pcc_data.pcc_subspace_idx = gas_t->access_width; >>>> -                else if (pcc_data.pcc_subspace_idx != gas_t->access_width) { >>>> -                    pr_debug("Mismatched PCC ids.\n"); >>> We need to retain the above checks to make sure all PCC registers >>> within a _CPC package is under same subspace. The Spec still requires: >>> "If the PCC register space is used, all PCC registers, for all processors in >>> the same performance domain (as defined by _PSD), must be defined >>> to be in the same subspace." >> >> So that means we need to maintain the pcc_subspace_idx in cppc_pcc_data. >> If so, then I can move the check inside pcc_data_alloc(). > We need the pcc_subspace_idx for checking only withing the context of this > function, so tracking that data in a local variable will be sufficient. >>> >>>> +                pcc_subspace_id = gas_t->access_width; >>>> +                if (pcc_data_alloc(pcc_subspace_id)) >>>>                       goto out_free; >>> We need to call pcc_data_alloc(to increment the reference) only once per CPU, >>> otherwise acpi_cppc_processor_exit( ) will never free the memory allocated in >>> pcc_data. >> >> It is infact called only once per CPU, The refcounting was added in case if multiple CPU's share the same domain for eg: >> In instances, where CPU have hardware multi-threading support. >> or in cases where all CPU's are controlled using single subspace (as earlier). > No, it is getting called for every PCC registers within a _CPC package, instead it > needs to be called only once per _CPC package irrespective of number of PCC > registers within the_CPC  package. >> >> Do you see any issue with acpi_cppc_processor_exit() in the earlier cases, where refcount remains > 0 and the memory not getting freed-up? >>> >>> >>> -- >>> Thanks, >>> Prashanth >>> >