Skip to content

Commit

Permalink
stress-ng.h: move cacheline stressor fields to struct cacheline
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Jul 28, 2023
1 parent 3231a61 commit 568e6d2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
15 changes: 7 additions & 8 deletions core-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,14 +1935,13 @@ int stress_cache_alloc(const char *name)
return -1;
}

g_shared->cacheline_size = (size_t)STRESS_PROCS_MAX * sizeof(uint8_t) * 2;
g_shared->cacheline =
(uint8_t *)mmap(NULL, g_shared->cacheline_size,
g_shared->cacheline.size = (size_t)STRESS_PROCS_MAX * sizeof(uint8_t) * 2;
g_shared->cacheline.buffer =
(uint8_t *)mmap(NULL, g_shared->cacheline.size,
PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);

if (g_shared->cacheline == MAP_FAILED) {
g_shared->cacheline = NULL;
if (g_shared->cacheline.buffer == MAP_FAILED) {
g_shared->cacheline.buffer = NULL;
pr_err("%s: failed to mmap cacheline buffer, errno=%d (%s)\n",
name, errno, strerror(errno));
return -1;
Expand All @@ -1962,8 +1961,8 @@ void stress_cache_free(void)
{
if (g_shared->mem_cache)
(void)munmap((void *)g_shared->mem_cache, g_shared->mem_cache_size);
if (g_shared->cacheline)
(void)munmap((void *)g_shared->cacheline, g_shared->cacheline_size);
if (g_shared->cacheline.buffer)
(void)munmap((void *)g_shared->cacheline.buffer, g_shared->cacheline.size);
}

/*
Expand Down
70 changes: 35 additions & 35 deletions stress-cacheline.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ static int stress_cacheline_adjacent(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
register uint8_t val8 = *(data8);
volatile uint8_t *data8adjacent = (volatile uint8_t *)(((uintptr_t)data8) ^ 1);

Expand Down Expand Up @@ -154,8 +154,8 @@ static int stress_cacheline_copy(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
const volatile uint8_t *data8adjacent = (volatile uint8_t *)(((uintptr_t)data8) ^ 1);

(void)parent;
Expand Down Expand Up @@ -190,8 +190,8 @@ static int stress_cacheline_inc(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
register uint8_t val8 = *(data8);

(void)parent;
Expand Down Expand Up @@ -230,8 +230,8 @@ static int stress_cacheline_rdwr(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
register uint8_t val8 = *(data8);

(void)parent;
Expand Down Expand Up @@ -305,8 +305,8 @@ static int stress_cacheline_mix(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)(uintptr_t)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)(uintptr_t)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
static uint8_t tmp = 0xa5;

(void)parent;
Expand Down Expand Up @@ -336,10 +336,10 @@ static int stress_cacheline_rdrev64(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
const ssize_t cacheline_size = (ssize_t)g_shared->cacheline_size;
uintptr_t aligned_cacheline = (uintptr_t)cacheline & ~(l1_cacheline_size - 1);
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
const ssize_t cacheline_size = (ssize_t)g_shared->cacheline.size;
uintptr_t aligned_cacheline = (uintptr_t)buffer & ~(l1_cacheline_size - 1);

(void)parent;
(void)l1_cacheline_size;
Expand Down Expand Up @@ -374,10 +374,10 @@ static int stress_cacheline_rdfwd64(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
const size_t cacheline_size = g_shared->cacheline_size;
uintptr_t aligned_cacheline = (uintptr_t)cacheline & ~(l1_cacheline_size - 1);
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
const size_t cacheline_size = g_shared->cacheline.size;
uintptr_t aligned_cacheline = (uintptr_t)buffer & ~(l1_cacheline_size - 1);

(void)parent;
(void)l1_cacheline_size;
Expand Down Expand Up @@ -412,8 +412,8 @@ static int stress_cacheline_rdints(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
volatile uint16_t *data16 = (uint16_t *)(((uintptr_t)data8) & ~(uintptr_t)1);
volatile uint32_t *data32 = (uint32_t *)(((uintptr_t)data8) & ~(uintptr_t)3);
volatile uint64_t *data64 = (uint64_t *)(((uintptr_t)data8) & ~(uintptr_t)7);
Expand Down Expand Up @@ -465,8 +465,8 @@ static int stress_cacheline_bits(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;

(void)parent;
(void)l1_cacheline_size;
Expand Down Expand Up @@ -505,8 +505,8 @@ static int stress_cacheline_atomicinc(
const size_t l1_cacheline_size)
{
register int i;
volatile uint8_t *cacheline = (volatile uint8_t *)g_shared->cacheline;
volatile uint8_t *data8 = cacheline + index;
volatile uint8_t *buffer = (volatile uint8_t *)g_shared->cacheline.buffer;
volatile uint8_t *data8 = buffer + index;
register uint8_t val8 = *(data8);

(void)parent;
Expand Down Expand Up @@ -661,8 +661,8 @@ static int stress_cacheline_child(
*/
static void stress_cacheline_init(void)
{
g_shared->cacheline_index = 0;
g_shared->cacheline_lock = stress_lock_create();
g_shared->cacheline.index = 0;
g_shared->cacheline.lock = stress_lock_create();
}

/*
Expand All @@ -671,24 +671,24 @@ static void stress_cacheline_init(void)
*/
static void stress_cacheline_deinit(void)
{
if (g_shared->cacheline_lock) {
stress_lock_destroy(g_shared->cacheline_lock);
g_shared->cacheline_lock = NULL;
g_shared->cacheline_index = 0;
if (g_shared->cacheline.lock) {
stress_lock_destroy(g_shared->cacheline.lock);
g_shared->cacheline.lock = NULL;
g_shared->cacheline.index = 0;
}
}

static int stress_cacheline_next_index(void)
{
int ret;

if (stress_lock_acquire(g_shared->cacheline_lock) < 0)
if (stress_lock_acquire(g_shared->cacheline.lock) < 0)
return -1;

ret = g_shared->cacheline_index;
g_shared->cacheline_index++;
ret = g_shared->cacheline.index;
g_shared->cacheline.index++;

if (stress_lock_release(g_shared->cacheline_lock) < 0)
if (stress_lock_release(g_shared->cacheline.lock) < 0)
return -1;

return ret * 2;
Expand All @@ -711,7 +711,7 @@ static int stress_cacheline(const stress_args_t *args)
if (stress_sigchld_set_handler(args) < 0)
return EXIT_NO_RESOURCE;

if (!g_shared->cacheline_lock) {
if (!g_shared->cacheline.lock) {
pr_inf("%s: failed to initialized cacheline lock, skipping stressor\n", args->name);
return EXIT_NO_RESOURCE;
}
Expand Down
10 changes: 6 additions & 4 deletions stress-ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,12 @@ typedef struct shared_heap {
/* The stress-ng global shared memory segment */
typedef struct {
size_t length; /* Size of segment */
void *cacheline_lock; /* Cacheline stressor lock */
int cacheline_index; /* Cacheline stressor index */
uint8_t *cacheline; /* Cacheline stressor buffer */
size_t cacheline_size; /* Cacheline buffer size */
struct {
void *lock; /* Cacheline stressor lock */
int index; /* Cacheline stressor index */
uint8_t *buffer; /* Cacheline stressor buffer */
size_t size; /* Cacheline buffer size */
} cacheline;
uint32_t stressors_started; /* Number of stressors started */
uint32_t stressors_exited; /* Number of stressors exited */
uint32_t stressors_reaped; /* Number of stressors reaped */
Expand Down

0 comments on commit 568e6d2

Please sign in to comment.