Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Use req_max_processed_len from sysfs NX capabilities

On PowerVM, the hypervisor defines the maximum buffer length for
each NX request and the kernel exported this value via sysfs.

This patch reads this value if the sysfs entry is available and
is used to limit the request length.

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/ed908341b1eb7ca0183c028a4ed4a0cf48bfe0f6.camel@linux.ibm.com

authored by

Haren Myneni and committed by
Michael Ellerman
c6c27e3d 20ccb004

+17 -4
+2 -2
tools/testing/selftests/powerpc/nx-gzip/Makefile
··· 1 - CFLAGS = -O3 -m64 -I./include 1 + CFLAGS = -O3 -m64 -I./include -I../include 2 2 3 3 TEST_GEN_FILES := gzfht_test gunz_test 4 4 TEST_PROGS := nx-gzip-test.sh 5 5 6 6 include ../../lib.mk 7 7 8 - $(TEST_GEN_FILES): gzip_vas.c 8 + $(TEST_GEN_FILES): gzip_vas.c ../utils.c
+15 -2
tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
··· 60 60 #include <assert.h> 61 61 #include <errno.h> 62 62 #include <signal.h> 63 + #include "utils.h" 63 64 #include "nxu.h" 64 65 #include "nx.h" 65 66 ··· 70 69 #define NX_MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) 71 70 #define FNAME_MAX 1024 72 71 #define FEXT ".nx.gz" 72 + 73 + #define SYSFS_MAX_REQ_BUF_PATH "devices/vio/ibm,compression-v1/nx_gzip_caps/req_max_processed_len" 73 74 74 75 /* 75 76 * LZ counts returned in the user supplied nx_gzip_crb_cpb_t structure. ··· 247 244 struct nx_gzip_crb_cpb_t *cmdp; 248 245 uint32_t pagelen = 65536; 249 246 int fault_tries = NX_MAX_FAULTS; 247 + char buf[32]; 250 248 251 249 cmdp = (void *)(uintptr_t) 252 250 aligned_alloc(sizeof(struct nx_gzip_crb_cpb_t), ··· 267 263 assert(NULL != (outbuf = (char *)malloc(outlen))); 268 264 nxu_touch_pages(outbuf, outlen, pagelen, 1); 269 265 270 - /* Compress piecemeal in smallish chunks */ 271 - chunk = 1<<22; 266 + /* 267 + * On PowerVM, the hypervisor defines the maximum request buffer 268 + * size is defined and this value is available via sysfs. 269 + */ 270 + if (!read_sysfs_file(SYSFS_MAX_REQ_BUF_PATH, buf, sizeof(buf))) { 271 + chunk = atoi(buf); 272 + } else { 273 + /* sysfs entry is not available on PowerNV */ 274 + /* Compress piecemeal in smallish chunks */ 275 + chunk = 1<<22; 276 + } 272 277 273 278 /* Write the gzip header to the stream */ 274 279 num_hdr_bytes = gzip_header_blank(outbuf);