From patchwork Wed Jul 19 18:22:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 791184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xCQQj0Q9fz9s3w for ; Thu, 20 Jul 2017 04:23:57 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xCQQh5v3bzDrF8 for ; Thu, 20 Jul 2017 04:23:56 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xCQPh6p3bzDrCr for ; Thu, 20 Jul 2017 04:23:04 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6JIJHd5005529 for ; Wed, 19 Jul 2017 14:23:03 -0400 Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) by mx0a-001b2d01.pphosted.com with ESMTP id 2btahpwaca-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 19 Jul 2017 14:23:03 -0400 Received: from localhost by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Jul 2017 04:23:00 +1000 Received: from d23relay10.au.ibm.com (202.81.31.229) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 20 Jul 2017 04:22:58 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6JIMwix28442716 for ; Thu, 20 Jul 2017 04:22:58 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v6JIMva8024159 for ; Thu, 20 Jul 2017 04:22:58 +1000 Received: from oc4502181600.ibm.com ([9.79.196.140]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v6JIMhIv023876; Thu, 20 Jul 2017 04:22:52 +1000 From: Shilpasri G Bhat To: stewart@linux.vnet.ibm.com, cyrilbur@gmail.com Date: Wed, 19 Jul 2017 23:52:36 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500488561-22489-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1500488561-22489-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17071918-0016-0000-0000-0000025E5863 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071918-0017-0000-0000-000006DF275C Message-Id: <1500488561-22489-4-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-19_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707190286 Subject: [Skiboot] [PATCH V7 3/8] occ: Add support to change power-shifting-ratio X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: skiboot@lists.ozlabs.org, ego@linux.vnet.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Add support to set the CPU-GPU power shifting ratio which is used by the OCC power capping algorithm. PSR value of 100 takes all power away from CPU first and a PSR value of 0 caps GPU first. Signed-off-by: Shilpasri G Bhat --- hw/occ.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/opal-api.h | 4 ++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/hw/occ.c b/hw/occ.c index d166fe5..907cf6e 100644 --- a/hw/occ.c +++ b/hw/occ.c @@ -1217,6 +1217,7 @@ exit: } static void occ_add_powercap_sensors(struct dt_node *power_mgt); +static void occ_add_psr_sensors(struct dt_node *power_mgt); static void occ_cmd_interface_init(void) { @@ -1262,6 +1263,9 @@ static void occ_cmd_interface_init(void) /* Add powercap sensors to DT */ occ_add_powercap_sensors(power_mgt); + + /* Add power-shifting-ratio CPU-GPU sensors to DT */ + occ_add_psr_sensors(power_mgt); } /* Powercap interface */ @@ -1362,6 +1366,98 @@ int occ_set_powercap(int token, u32 pcap) return opal_occ_command(&chips[i], token, &pcap_data); }; +/* Power-Shifting Ratio */ +enum psr_type { + PSR_TYPE_CPU_TO_GPU, /* 0% Cap GPU first, 100% Cap CPU first */ +}; + +static int opal_get_power_shifting_ratio(u32 handle, int token __unused, + int *ratio) +{ + struct occ_dynamic_data *ddata; + struct proc_chip *chip; + int type = (handle >> 24) & 0xF; + int i = handle & 0xF; + + if (type != PSR_TYPE_CPU_TO_GPU) + return OPAL_UNSUPPORTED; + + if (i > nr_occs || i < 0) + return OPAL_PARAMETER; + + if (!(*chips[i].valid)) + return OPAL_WRONG_STATE; + + chip = get_chip(chips[i].chip_id); + ddata = get_occ_dynamic_data(chip); + *ratio = ddata->pwr_shifting_ratio; + return OPAL_SUCCESS; +} + +static u8 psr_cdata; +static struct opal_occ_cmd_data psr_data = { + .data = &psr_cdata, + .cmd = OCC_CMD_SET_POWER_SHIFTING_RATIO, +}; + +static int opal_set_power_shifting_ratio(u32 handle, int token, int ratio) +{ + struct occ_dynamic_data *ddata; + struct proc_chip *chip; + int type = (handle >> 24) & 0xF; + int i = handle & 0xF; + + if (type != PSR_TYPE_CPU_TO_GPU) + return OPAL_UNSUPPORTED; + + if (ratio < 0 || ratio > 100) + return OPAL_PARAMETER; + + if (i > nr_occs || i < 0) + return OPAL_PARAMETER; + + if (!(*chips[i].valid)) + return OPAL_WRONG_STATE; + + chip = get_chip(chips[i].chip_id); + ddata = get_occ_dynamic_data(chip); + if (ratio == ddata->pwr_shifting_ratio) + return OPAL_SUCCESS; + + psr_cdata = ratio; + return opal_occ_command(&chips[i], token, &psr_data); +} + +static void occ_add_psr_sensors(struct dt_node *power_mgt) +{ + struct dt_node *node, *cnode; + int i; + + node = dt_new(power_mgt, "psr"); + if (!node) { + prerror("OCC: Failed to create power-shifting-ratio node\n"); + return; + } + + for (i = 0; i < nr_occs; i++) { + char name[20]; + u32 handle = (PSR_TYPE_CPU_TO_GPU << 24) | i; + + cnode = dt_new_addr(node, "cpu-to-gpu", handle); + if (!cnode) { + prerror("OCC: Failed to create power-shifting-ratio node\n"); + return; + } + + snprintf(name, 20, "cpu_to_gpu_%d", chips[i].chip_id); + dt_add_property_string(cnode, "label", name); + dt_add_property_cells(cnode, "handle", handle); + } + + opal_register(OPAL_GET_PSR, opal_get_power_shifting_ratio, 3); + opal_register(OPAL_SET_PSR, opal_set_power_shifting_ratio, 3); +} + /* CPU-OCC PState init */ /* Called after OCC init on P8 and P9 */ void occ_pstates_init(void) diff --git a/include/opal-api.h b/include/opal-api.h index 3ad4898..2717a0d 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -210,7 +210,9 @@ #define OPAL_IMC_COUNTERS_STOP 151 #define OPAL_GET_POWERCAP 152 #define OPAL_SET_POWERCAP 153 -#define OPAL_LAST 153 +#define OPAL_GET_PSR 154 +#define OPAL_SET_PSR 155 +#define OPAL_LAST 155 /* Device tree flags */