From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A8B66A0547; Thu, 9 Sep 2021 15:45:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 71F814116F; Thu, 9 Sep 2021 15:45:33 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id C8D0941162 for ; Thu, 9 Sep 2021 15:45:30 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10101"; a="243103605" X-IronPort-AV: E=Sophos;i="5.85,280,1624345200"; d="scan'208";a="243103605" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 06:45:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,280,1624345200"; d="scan'208";a="449979532" Received: from silpixa00399952.ir.intel.com ([10.55.129.13]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2021 06:45:29 -0700 From: David Hunt To: dev@dpdk.org Cc: bruce.richardson@intel.com, David Hunt Date: Thu, 9 Sep 2021 14:45:10 +0100 Message-Id: <20210909134511.18871-6-david.hunt@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210909134511.18871-1-david.hunt@intel.com> References: <20210909134511.18871-1-david.hunt@intel.com> Subject: [dpdk-dev] [PATCH v1 5/6] lib/power: reduce memory footprint of channels X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Switch from static memory allocation of channel pkt structs to dynamic allocation. The library used to statically allocate max_lcores number of rte_power_channel_packet structs, so change this to rte_malloc as needed. Reduces static footprint from 236K to 1K. Desirable, especially if we're changing max_lcores default from 128 to 512. Signed-off-by: David Hunt --- lib/power/power_kvm_vm.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/power/power_kvm_vm.c b/lib/power/power_kvm_vm.c index ab7d4b8cee..c60e7acf16 100644 --- a/lib/power/power_kvm_vm.c +++ b/lib/power/power_kvm_vm.c @@ -5,6 +5,7 @@ #include #include +#include #include "rte_power_guest_channel.h" #include "guest_channel.h" @@ -13,7 +14,8 @@ #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent" -static struct rte_power_channel_packet pkt[RTE_MAX_LCORE]; +static struct rte_power_channel_packet + *power_channel_pkt[RTE_MAX_LCORE] = { NULL }; int power_kvm_vm_check_supported(void) @@ -29,8 +31,21 @@ power_kvm_vm_init(unsigned int lcore_id) lcore_id, RTE_MAX_LCORE-1); return -1; } - pkt[lcore_id].command = RTE_POWER_CPU_POWER; - pkt[lcore_id].resource_id = lcore_id; + + if (power_channel_pkt[lcore_id] == NULL) { + power_channel_pkt[lcore_id] = + rte_malloc(NULL, + sizeof(struct rte_power_channel_packet), 0); + if (power_channel_pkt[lcore_id] == NULL) { + RTE_LOG(ERR, POWER, + "Cannot allocate channel for core %u\n", + lcore_id); + return -1; + } + } + + power_channel_pkt[lcore_id]->command = RTE_POWER_CPU_POWER; + power_channel_pkt[lcore_id]->resource_id = lcore_id; return guest_channel_host_connect(FD_PATH, lcore_id); } @@ -38,6 +53,10 @@ int power_kvm_vm_exit(unsigned int lcore_id) { guest_channel_host_disconnect(lcore_id); + + if (power_channel_pkt[lcore_id] != NULL) + rte_free(power_channel_pkt[lcore_id]); + return 0; } @@ -78,8 +97,15 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction) lcore_id, RTE_MAX_LCORE-1); return -1; } - pkt[lcore_id].unit = scale_direction; - ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id); + + if (power_channel_pkt[lcore_id] == NULL) { + RTE_LOG(ERR, POWER, "channel for core %u not initialised\n", + lcore_id); + return -1; + } + + power_channel_pkt[lcore_id]->unit = scale_direction; + ret = guest_channel_send_msg(power_channel_pkt[lcore_id], lcore_id); if (ret == 0) return 1; RTE_LOG(DEBUG, POWER, "Error sending message: %s\n", -- 2.17.1