Skip to content

Commit

Permalink
core-helper, stress-*: add stress_zero_metrics helper to zero metrics
Browse files Browse the repository at this point in the history
Zero'ing metrics is performed by many stressors, so provide a helper
function to do this and hide the details of all the fields that need
to be zero'd.

Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Oct 22, 2024
1 parent b59ba6d commit 6977840
Show file tree
Hide file tree
Showing 38 changed files with 59 additions and 131 deletions.
16 changes: 16 additions & 0 deletions core-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4948,3 +4948,19 @@ uint64_t stress_get_machine_id(void)
#endif
return id;
}

/*
* stress_zero_metrics()
* initialize metrics array 0..n-1 items
*/
void stress_zero_metrics(stress_metrics_t *metrics, const size_t n)
{
size_t i;

for (i = 0; i < n; i++) {
metrics[i].lock = NULL;
metrics[i].duration = 0.0;
metrics[i].count = 0.0;
metrics[i].t_start = 0.0;
}
}
1 change: 1 addition & 0 deletions core-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@ extern void *stress_mmap_populate(void *addr, size_t length, int prot,
int flags, int fd, off_t offset);
extern bool stress_addr_readable(const void *addr, const size_t len);
extern uint64_t stress_get_machine_id(void);
extern void stress_zero_metrics(stress_metrics_t *metrics, const size_t n);

#endif
6 changes: 1 addition & 5 deletions stress-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,7 @@ static int stress_access(stress_args_t *args)
goto tidy;
}
stress_set_vma_anon_name(metrics, metrics_size, "metrics");

metrics[0].duration = 0.0;
metrics[0].count = 0.0;
metrics[1].duration = 0.0;
metrics[1].count = 0.0;
stress_zero_metrics(metrics, 2);

stress_sync_start_init(&s_pids[0]);
stress_sync_start_init(&s_pids[1]);
Expand Down
5 changes: 1 addition & 4 deletions stress-acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,7 @@ static int stress_acl(stress_args_t *args)
}
(void)close(fd);

for (i = 0; i < SIZEOF_ARRAY(metrics); i++) {
metrics[i].duration = 0.0;
metrics[i].count = 0.0;
}
stress_zero_metrics(metrics, SIZEOF_ARRAY(metrics));

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
3 changes: 1 addition & 2 deletions stress-af-alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,7 @@ static bool stress_af_alg_add_crypto(const stress_crypto_info_t *info)
if (!ci)
return false;
*ci = *info;
ci->metrics.duration = 0.0;
ci->metrics.count = 0.0;
stress_zero_metrics(&ci->metrics, 1);
ci->next = crypto_info_list;
crypto_info_list = ci;

Expand Down
5 changes: 1 addition & 4 deletions stress-atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,7 @@ static int stress_atomic(stress_args_t *args)

for (i = 0; i < n_atomic_procs; i++) {
stress_sync_start_init(&atomic_info[i].s_pid);
for (j = 0; j < STRESS_ATOMIC_MAX_FUNCS; j++) {
atomic_info[i].metrics[j].duration = 0.0;
atomic_info[i].metrics[j].count = 0.0;
}
stress_zero_metrics(atomic_info[i].metrics, STRESS_ATOMIC_MAX_FUNCS);
}

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
Expand Down
5 changes: 1 addition & 4 deletions stress-besselmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,7 @@ static int stress_besselmath(stress_args_t *args)

(void)stress_get_setting("besselmath-method", &besselmath_method);

for (i = 0; i < SIZEOF_ARRAY(stress_besselmath_metrics); i++) {
stress_besselmath_metrics[i].duration = 0.0;
stress_besselmath_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_besselmath_metrics, SIZEOF_ARRAY(stress_besselmath_methods));

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-bitops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,7 @@ static int stress_bitops(stress_args_t *args)
int rc = EXIT_SUCCESS;
size_t i, j;

for (i = 0; i < SIZEOF_ARRAY(metrics); i++) {
metrics[i].duration = 0.0;
metrics[i].count = 0.0;
}
stress_zero_metrics(metrics, SIZEOF_ARRAY(metrics));

(void)stress_get_setting("bitops-method", &bitops_method);

Expand Down
5 changes: 1 addition & 4 deletions stress-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,7 @@ static int stress_cache(stress_args_t *args)
"shared cache writes per second",
};

for (j = 0; j < SIZEOF_ARRAY(metrics); j++) {
metrics[j].duration = 0.0;
metrics[j].count = 0.0;
}
stress_zero_metrics(metrics, SIZEOF_ARRAY(metrics));

disabled_flags = 0;

Expand Down
1 change: 1 addition & 0 deletions stress-chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ static int stress_chroot(stress_args_t *args)
return EXIT_FAILURE;
}
stress_set_vma_anon_name(data, sizeof(*data), "metrics");
stress_zero_metrics(&data->metrics, 1);
data->args = args;
data->rootpath_inode = chroot_inode("/");

Expand Down
4 changes: 1 addition & 3 deletions stress-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,8 @@ static int stress_clone(stress_args_t *args)
return EXIT_NO_RESOURCE;
}
stress_set_vma_anon_name(shared, sizeof(*shared), "clone-state");
stress_zero_metrics(&shared->metrics, 1);
shared->metrics.lock = stress_lock_create("metrics");
shared->metrics.duration = 0.0;
shared->metrics.count = 0.0;
shared->metrics.t_start = 0.0;

flag_count = stress_flag_permutation((int)all_flags, &flag_perms);

Expand Down
5 changes: 1 addition & 4 deletions stress-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ static int stress_crypt(stress_args_t *args)
args->name);
return EXIT_NO_RESOURCE;
}
for (i = 0; i < SIZEOF_ARRAY(crypt_methods); i++) {
crypt_metrics[i].duration = 0.0;
crypt_metrics[i].count = 0.0;
}
stress_zero_metrics(crypt_metrics, SIZEOF_ARRAY(crypt_methods));
#if defined(HAVE_CRYPT_R)
(void)memset(&data, 0, sizeof(data));
#endif
Expand Down
3 changes: 3 additions & 0 deletions stress-dekker.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ static int stress_dekker(stress_args_t *args)
}

stress_set_vma_anon_name(dekker, sz, "dekker-mutex");
stress_zero_metrics(&dekker->p0, 1);
stress_zero_metrics(&dekker->p1, 1);

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
stress_set_proc_state(args->name, STRESS_STATE_RUN);
Expand Down
5 changes: 1 addition & 4 deletions stress-eigen.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ static inline int stress_eigen_exercise(
register size_t i, j;
method_all_index = 1;

for (i = 0; i < NUM_EIGEN_METHODS; i++) {
eigen_metrics[i].duration = 0.0;
eigen_metrics[i].count = 0.0;
}
stress_zero_metrics(eigen_metrics, NUM_EIGEN_METHODS);

current_method = eigen_methods[eigen_method].name;

Expand Down
5 changes: 1 addition & 4 deletions stress-expmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,7 @@ static int stress_expmath(stress_args_t *args)

(void)stress_get_setting("expmath-method", &expmath_method);

for (i = 0; i < NUM_EXPMATH_METHODS; i++) {
stress_expmath_metrics[i].duration = 0.0;
stress_expmath_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_expmath_metrics, NUM_EXPMATH_METHODS);

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
4 changes: 1 addition & 3 deletions stress-fd-fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ static int stress_fd_fork(stress_args_t *args)
return EXIT_NO_RESOURCE;
}
stress_set_vma_anon_name(info, sizeof(*info), "state");

info->metrics.count = 0.0;
info->metrics.duration = 0.0;
stress_zero_metrics(&info->metrics, 1);
info->use_close_range = true;

for (i = 1; i < fd_fork_fds; i++)
Expand Down
4 changes: 1 addition & 3 deletions stress-forkheavy.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ static int stress_forkheavy(stress_args_t *args)
return EXIT_NO_RESOURCE;
}
stress_set_vma_anon_name(metrics, sizeof(*metrics), "metrics");
stress_zero_metrics(metrics, 1);
metrics->lock = stress_lock_create("metrics");
metrics->duration = 0.0;
metrics->count = 0.0;
metrics->t_start = 0.0;

forkheavy_args.metrics = metrics;

Expand Down
5 changes: 1 addition & 4 deletions stress-funccall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,7 @@ static int stress_funccall(stress_args_t *args)

size_t i, j;

for (i = 0; i < NUM_STRESS_FUNCCALL_METHODS; i++) {
stress_funccall_metrics[i].duration = 0.0;
stress_funccall_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_funccall_metrics, NUM_STRESS_FUNCCALL_METHODS);

(void)stress_get_setting("funccall-method", &funccall_method);

Expand Down
5 changes: 1 addition & 4 deletions stress-funcret.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,7 @@ static int stress_funcret(stress_args_t *args)

(void)stress_get_setting("funcret-method", &funcret_method);

for (i = 0; i < NUM_STRESS_FUNCRET_METHODS; i++) {
stress_funcret_metrics[i].duration = 0.0;
stress_funcret_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_funcret_metrics, NUM_STRESS_FUNCRET_METHODS);

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-hyperbolic.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ static int stress_hyperbolic(stress_args_t *args)

(void)stress_get_setting("hyperbolic-method", &hyperbolic_method);

for (i = 0; i < SIZEOF_ARRAY(stress_hyperbolic_metrics); i++) {
stress_hyperbolic_metrics[i].duration = 0.0;
stress_hyperbolic_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_hyperbolic_metrics, SIZEOF_ARRAY(stress_hyperbolic_metrics));

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-intmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,7 @@ static int stress_intmath(stress_args_t *args)

(void)memset(stress_intmath_initialized, 0, sizeof(stress_intmath_initialized));

for (i = 0; i < STRESS_INTMATH_MAX_METHODS; i++) {
stress_intmath_metrics[i].duration = 0.0;
stress_intmath_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_intmath_metrics, STRESS_INTMATH_MAX_METHODS);

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,7 @@ static int stress_list(stress_args_t *args)
stress_metrics_t *metrics, list_metrics[SIZEOF_ARRAY(list_methods)];
stress_list_func func;

for (i = 0; i < SIZEOF_ARRAY(list_metrics); i++) {
list_metrics[i].duration = 0.0;
list_metrics[i].count = 0.0;
}
stress_zero_metrics(list_metrics, SIZEOF_ARRAY(list_metrics));

(void)stress_get_setting("list-method", &list_method);
func = list_methods[list_method].func;
Expand Down
5 changes: 1 addition & 4 deletions stress-logmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,7 @@ static int stress_logmath(stress_args_t *args)

(void)stress_get_setting("logmath-method", &logmath_method);

for (i = 0; i < SIZEOF_ARRAY(stress_logmath_metrics); i++) {
stress_logmath_metrics[i].duration = 0.0;
stress_logmath_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_logmath_metrics, SIZEOF_ARRAY(stress_logmath_metrics));

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-matrix-3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,7 @@ static inline int stress_matrix_3d_exercise(
method_all_index = 1;
current_method = matrix_3d_methods[matrix_3d_method].name;

for (i = 0; i < num_matrix_3d_methods; i++) {
matrix_3d_metrics[i].duration = 0.0;
matrix_3d_metrics[i].count = 0.0;
}
stress_zero_metrics(matrix_3d_metrics, num_matrix_3d_methods);

a = (matrix_3d_ptr_t)stress_mmap_populate(NULL, matrix_3d_mmap_size,
PROT_READ | PROT_WRITE, flags, -1, 0);
Expand Down
5 changes: 1 addition & 4 deletions stress-matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,7 @@ static inline int stress_matrix_exercise(

current_method = matrix_methods[matrix_method].name;

for (i = 0; i < num_matrix_methods; i++) {
matrix_metrics[i].duration = 0.0;
matrix_metrics[i].count = 0.0;
}
stress_zero_metrics(matrix_metrics, num_matrix_methods);

a = (matrix_ptr_t)stress_mmap_populate(NULL, matrix_mmap_size,
PROT_READ | PROT_WRITE, flags, -1, 0);
Expand Down
7 changes: 1 addition & 6 deletions stress-monte-carlo.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,7 @@ static int stress_monte_carlo(stress_args_t *args)
}

for (i = 0; i < METHODS_MAX; i++) {
for (j = 0; j < RANDS_MAX; j++) {
metrics[i][j].duration = 0.0;
metrics[i][j].count = 0.0;
results[i][j].sum = 0.0;
results[i][j].count = 0.0;
}
stress_zero_metrics(metrics[i], RANDS_MAX);
}

monte_carlo_samples = 100000;
Expand Down
5 changes: 1 addition & 4 deletions stress-mpfr.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,7 @@ static int stress_mpfr(stress_args_t *args)
static stress_metrics_t metrics[SIZEOF_ARRAY(stress_mpfr_methods)];
int rc = EXIT_SUCCESS;

for (i = 0; i < SIZEOF_ARRAY(metrics); i++) {
metrics[i].count = 0.0;
metrics[i].duration = 0.0;
}
stress_zero_metrics(metrics, SIZEOF_ARRAY(metrics));

(void)stress_get_setting("mpfr-precision", &mpfr_precision);
precision = (mpfr_prec_t)mpfr_precision;
Expand Down
7 changes: 2 additions & 5 deletions stress-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ static void stress_pci_info_get_by_name(stress_pci_info_t **pci_info_list, const
pci_info = (stress_pci_info_t *)calloc(1, sizeof(*pci_info));
if (pci_info) {
char pci_path[PATH_MAX];
int i;

(void)snprintf(pci_path, sizeof(pci_path),
"%s/%s", sys_pci_devices, name);
Expand All @@ -125,10 +124,8 @@ static void stress_pci_info_get_by_name(stress_pci_info_t **pci_info_list, const
free(pci_info);
return;
}
for (i = 0; i < PCI_METRICS_MAX; i++) {
pci_info->metrics[i].duration = 0.0;
pci_info->metrics[i].count = 0.0;
}

stress_zero_metrics(pci_info->metrics, PCI_METRICS_MAX);
pci_info->ignore = false;
pci_info->next = *pci_info_list;
*pci_info_list = pci_info;
Expand Down
3 changes: 3 additions & 0 deletions stress-peterson.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static int stress_peterson(stress_args_t *args)
return EXIT_NO_RESOURCE;
}

stress_zero_metrics(&peterson->p0, 1);
stress_zero_metrics(&peterson->p1, 1);

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
stress_set_proc_state(args->name, STRESS_STATE_RUN);
Expand Down
5 changes: 1 addition & 4 deletions stress-powmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,7 @@ static int stress_powmath(stress_args_t *args)

(void)stress_get_setting("powmath-method", &powmath_method);

for (i = 0; i < SIZEOF_ARRAY(stress_powmath_metrics); i++) {
stress_powmath_metrics[i].duration = 0.0;
stress_powmath_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_powmath_metrics, SIZEOF_ARRAY(stress_powmath_metrics));

stress_set_proc_state(args->name, STRESS_STATE_SYNC_WAIT);
stress_sync_start_wait(args);
Expand Down
5 changes: 1 addition & 4 deletions stress-rawdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ static int stress_rawdev(stress_args_t *args)
return EXIT_NO_RESOURCE;
}

for (i = 0; i < SIZEOF_ARRAY(rawdev_methods); i++) {
metrics[i].duration = 0.0;
metrics[i].count = 0.0;
}
stress_zero_metrics(metrics, SIZEOF_ARRAY(rawdev_methods));

if (!path) {
pr_inf("%s: cannot determine temporary path\n",
Expand Down
5 changes: 1 addition & 4 deletions stress-rotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ static int stress_rotate(stress_args_t *args)
bool success = true;
const bool verify = !!(g_opt_flags & OPT_FLAGS_VERIFY);

for (i = 1; i < SIZEOF_ARRAY(stress_rotate_metrics); i++) {
stress_rotate_metrics[i].duration = 0.0;
stress_rotate_metrics[i].count = 0.0;
}
stress_zero_metrics(stress_rotate_metrics, SIZEOF_ARRAY(stress_rotate_metrics));

(void)stress_get_setting("rotate-method", &rotate_method);

Expand Down
4 changes: 1 addition & 3 deletions stress-sigrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ static int stress_sigrt(stress_args_t *args)
return EXIT_NO_RESOURCE;
}

stress_zero_metrics(stress_sigrt_metrics, MAX_RTPIDS);
for (i = 0; i < MAX_RTPIDS; i++) {
stress_sigrt_metrics[i].duration = 0.0;
stress_sigrt_metrics[i].count = 0.0;

if (stress_sighandler(args->name, i + SIGRTMIN, stress_sighandler_nop, NULL) < 0) {
free(pids);
(void)munmap((void *)stress_sigrt_metrics, stress_sigrt_metrics_size);
Expand Down
Loading

0 comments on commit 6977840

Please sign in to comment.