Skip to content

Commit

Permalink
Move more stuff into credit-utils.h
Browse files Browse the repository at this point in the history
These functions will be reused by a new test in a subsequent commit.

Signed-off-by: Matheus Castanho <msc@linux.ibm.com>
  • Loading branch information
mscastanho committed Jun 21, 2022
1 parent 3d08904 commit 8306e4d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
30 changes: 30 additions & 0 deletions test/serial-tests/credit_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ pid_t *children = NULL;
int num_procs = 0;
static int keep_going = 0;

/* TODO: calling system with super-user privileges is not recommended, implement
our own version using fork, exec and wait instead. */
int run(const char *command)
{
return system(command);
}

/* For some reason the number of credits only changes when we alter the number
of virtual processors, even though on shared LPAR they are tied to the number
of processing units (aka Entitled Capactity). Remember credits=proc_units*20,
and drmgr sees 0.01 proc_units as 1 ent_capacity, so reducing ent_capacity by
5 means removing 0.05 units, and thus 1 credit. */
#define PROC_UNITS "15" // -3 credits
#define DLPAR_CPU_COUNT "1"
#define CPU_ARGS "-c cpu -w 5 -d 3"

int reduce_credits(void)
{
run("drmgr " CPU_ARGS " -r -p ent_capacity -q " PROC_UNITS);
run("drmgr " CPU_ARGS " -r -q " DLPAR_CPU_COUNT);

return 0;
}

void restore_credits(void)
{
(void) run("drmgr " CPU_ARGS " -a -p ent_capacity -q " PROC_UNITS);
(void) run("drmgr " CPU_ARGS " -a -q " DLPAR_CPU_COUNT);
}

int read_credits(int *total, int *used) {
if (read_sysfs_entry(SYSFS_VAS_CAPS "nr_total_credits", total) ||
read_sysfs_entry(SYSFS_VAS_CAPS "nr_used_credits", used)) {
Expand Down
9 changes: 9 additions & 0 deletions test/serial-tests/credit_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
extern pid_t *children;
extern int num_procs;

/* Run shell command */
int run(const char *command);

/* Reduce credits in the system by executing a DLPAR remove core operation */
int reduce_credits(void);

/* Restore credits in the system by executing a DLPAR add core operation */
void restore_credits(void);

/* Read credits information from sysfs */
int read_credits(int *total, int *used);

Expand Down
31 changes: 0 additions & 31 deletions test/serial-tests/test_window_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,13 @@
#include "test_utils.h"
#include "credit_utils.h"

#define CPU_ARGS "-c cpu -w 5 -d 3"

Bytef *src, *compr;
const unsigned int src_len = 32000; /* Need something larger than
cache_threshold to avoid deflate
falling back to software by
default. */
const unsigned int compr_len = 64000;

/* TODO: calling system with super-user privileges is not recommended, implement
our own version using fork, exec and wait instead. */
int run(const char *command)
{
return system(command);
}

/* For some reason the number of credits only changes when we alter the number
of virtual processors, even though on shared LPAR they are tied to the number
of processing units (aka Entitled Capactity). Remember credits=proc_units*20,
and drmgr sees 0.01 proc_units as 1 ent_capacity, so reducing ent_capacity by
5 means removing 0.05 units, and thus 1 credit. */
#define PROC_UNITS "15" // -3 credits
#define CPU_COUNT "1"

int reduce_credits(void)
{
run("drmgr " CPU_ARGS " -r -p ent_capacity -q " PROC_UNITS);
run("drmgr " CPU_ARGS " -r -q " CPU_COUNT);

return 0;
}

void restore_credits(void)
{
(void) run("drmgr " CPU_ARGS " -a -p ent_capacity -q " PROC_UNITS);
(void) run("drmgr " CPU_ARGS " -a -q " CPU_COUNT);
}

/* Work for the child */
void child_do(z_stream *stream) {
int rc;
Expand Down

0 comments on commit 8306e4d

Please sign in to comment.