Skip to content

Commit

Permalink
selftests/powerpc: Use req_max_processed_len from sysfs NX capabilities
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Haren Myneni authored and Michael Ellerman committed Jun 25, 2021
1 parent 20ccb00 commit c6c27e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tools/testing/selftests/powerpc/nx-gzip/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CFLAGS = -O3 -m64 -I./include
CFLAGS = -O3 -m64 -I./include -I../include

TEST_GEN_FILES := gzfht_test gunz_test
TEST_PROGS := nx-gzip-test.sh

include ../../lib.mk

$(TEST_GEN_FILES): gzip_vas.c
$(TEST_GEN_FILES): gzip_vas.c ../utils.c
17 changes: 15 additions & 2 deletions tools/testing/selftests/powerpc/nx-gzip/gzfht_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include "utils.h"
#include "nxu.h"
#include "nx.h"

Expand All @@ -70,6 +71,8 @@ FILE *nx_gzip_log;
#define FNAME_MAX 1024
#define FEXT ".nx.gz"

#define SYSFS_MAX_REQ_BUF_PATH "devices/vio/ibm,compression-v1/nx_gzip_caps/req_max_processed_len"

/*
* LZ counts returned in the user supplied nx_gzip_crb_cpb_t structure.
*/
Expand Down Expand Up @@ -244,6 +247,7 @@ int compress_file(int argc, char **argv, void *handle)
struct nx_gzip_crb_cpb_t *cmdp;
uint32_t pagelen = 65536;
int fault_tries = NX_MAX_FAULTS;
char buf[32];

cmdp = (void *)(uintptr_t)
aligned_alloc(sizeof(struct nx_gzip_crb_cpb_t),
Expand All @@ -263,8 +267,17 @@ int compress_file(int argc, char **argv, void *handle)
assert(NULL != (outbuf = (char *)malloc(outlen)));
nxu_touch_pages(outbuf, outlen, pagelen, 1);

/* Compress piecemeal in smallish chunks */
chunk = 1<<22;
/*
* On PowerVM, the hypervisor defines the maximum request buffer
* size is defined and this value is available via sysfs.
*/
if (!read_sysfs_file(SYSFS_MAX_REQ_BUF_PATH, buf, sizeof(buf))) {
chunk = atoi(buf);
} else {
/* sysfs entry is not available on PowerNV */
/* Compress piecemeal in smallish chunks */
chunk = 1<<22;
}

/* Write the gzip header to the stream */
num_hdr_bytes = gzip_header_blank(outbuf);
Expand Down

0 comments on commit c6c27e3

Please sign in to comment.