From patchwork Tue Jan 30 23:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13538361 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7C36339AD; Tue, 30 Jan 2024 23:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706657739; cv=none; b=EzL/NGCKPeGLocYXIoMDHJJsERUOTp4LWFJTN9anZw5bJNYXsF4FsIw5jZ9uKLYA5MLBlWVEM4jt99yiW/HLrI9gNMQ7r1ekAIXjJB915lPTS5JEu8Ny16Iol9PvnyHq7k7ukbN9LAL8mVNPkY0Mk/E8wABPPahzF7ip5B1kfo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706657739; c=relaxed/simple; bh=/Epgl74/c5KAbeO1E37tYKhmfe9dldDU3rzD9FU3nSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=APB/9gUxiSh6PxpfXKVnee0Hywp3HEvAzops2JG/Y8M/pawxcLtx8XSAUDIoLea3MP7/OVo1dmU7kkucNMQpWTypH9AMYOB9REAeQDuSuUmb3gJER6Gh8LUUiTSSi7FLc926oobVP/B1+RwOO0HIkN3tqxZKNV8EnSE7YVoGANo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B31BC43390; Tue, 30 Jan 2024 23:35:38 +0000 (UTC) From: Dave Jiang To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: vishal.l.verma@intel.com, Alison Schofield Subject: [NDCTL PATCH v4 2/4] ndctl: cxl: Add QoS class support for the memory device Date: Tue, 30 Jan 2024 16:32:42 -0700 Message-ID: <20240130233526.1031801-3-dave.jiang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130233526.1031801-1-dave.jiang@intel.com> References: <20240130233526.1031801-1-dave.jiang@intel.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add libcxl API to retrieve the QoS class tokens for the memory devices. Two API calls are added. One for 'ram' or 'volatile' mode and another for 'pmem' or 'persistent' mode. Support also added for displaying the QoS class tokens through the 'cxl list' command. Reviewed-by: Alison Schofield Signed-off-by: Dave Jiang --- v4: - Code change to single qos_class due to kernel code change --- cxl/json.c | 14 ++++++++++++++ cxl/lib/libcxl.c | 22 ++++++++++++++++++++++ cxl/lib/libcxl.sym | 2 ++ cxl/lib/private.h | 2 ++ cxl/libcxl.h | 2 ++ 5 files changed, 42 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index 48a43ddf14b0..9d22bdd2188a 100644 --- a/cxl/json.c +++ b/cxl/json.c @@ -791,6 +791,13 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, jobj = util_json_object_size(size, flags); if (jobj) json_object_object_add(jdev, "pmem_size", jobj); + + if (flags & UTIL_JSON_QOS_CLASS) { + jobj = json_object_new_int( + cxl_memdev_get_pmem_qos_class(memdev)); + if (jobj) + json_object_object_add(jdev, "pmem_qos_class", jobj); + } } size = cxl_memdev_get_ram_size(memdev); @@ -798,6 +805,13 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, jobj = util_json_object_size(size, flags); if (jobj) json_object_object_add(jdev, "ram_size", jobj); + + if (flags & UTIL_JSON_QOS_CLASS) { + jobj = json_object_new_int( + cxl_memdev_get_ram_qos_class(memdev)); + if (jobj) + json_object_object_add(jdev, "ram_qos_class", jobj); + } } if (flags & UTIL_JSON_HEALTH) { diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 9a1ac7001803..6c293f1dfc91 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1260,6 +1260,18 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base) goto err_read; memdev->ram_size = strtoull(buf, NULL, 0); + sprintf(path, "%s/pmem/qos_class", cxlmem_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + memdev->pmem_qos_class = CXL_QOS_CLASS_NONE; + else + memdev->pmem_qos_class = atoi(buf); + + sprintf(path, "%s/ram/qos_class", cxlmem_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + memdev->ram_qos_class = CXL_QOS_CLASS_NONE; + else + memdev->ram_qos_class = atoi(buf); + sprintf(path, "%s/payload_max", cxlmem_base); if (sysfs_read_attr(ctx, path, buf) < 0) goto err_read; @@ -1483,6 +1495,16 @@ CXL_EXPORT unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev) return memdev->ram_size; } +CXL_EXPORT int cxl_memdev_get_pmem_qos_class(struct cxl_memdev *memdev) +{ + return memdev->pmem_qos_class; +} + +CXL_EXPORT int cxl_memdev_get_ram_qos_class(struct cxl_memdev *memdev) +{ + return memdev->ram_qos_class; +} + CXL_EXPORT const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev) { return memdev->firmware_version; diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index 384fea2c25e3..465c78dc6c70 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -283,4 +283,6 @@ LIBCXL_8 { global: cxl_memdev_wait_sanitize; cxl_root_decoder_get_qos_class; + cxl_memdev_get_pmem_qos_class; + cxl_memdev_get_ram_qos_class; } LIBCXL_7; diff --git a/cxl/lib/private.h b/cxl/lib/private.h index 4847ff448f71..07dc8c784f1d 100644 --- a/cxl/lib/private.h +++ b/cxl/lib/private.h @@ -47,6 +47,8 @@ struct cxl_memdev { struct list_node list; unsigned long long pmem_size; unsigned long long ram_size; + int ram_qos_class; + int pmem_qos_class; int payload_max; size_t lsa_size; struct kmod_module *module; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index e5c08da77f77..a180f01cb05e 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -72,6 +72,8 @@ int cxl_memdev_get_minor(struct cxl_memdev *memdev); struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev); unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev); unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev); +int cxl_memdev_get_pmem_qos_class(struct cxl_memdev *memdev); +int cxl_memdev_get_ram_qos_class(struct cxl_memdev *memdev); const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev); bool cxl_memdev_fw_update_in_progress(struct cxl_memdev *memdev); size_t cxl_memdev_fw_update_get_remaining(struct cxl_memdev *memdev);