"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stress-context.c" between
stress-ng-0.13.04.tar.xz and stress-ng-0.13.05.tar.xz

About: stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.

stress-context.c  (stress-ng-0.13.04.tar.xz):stress-context.c  (stress-ng-0.13.05.tar.xz)
skipping to change at line 57 skipping to change at line 57
} chk_canary_t; } chk_canary_t;
typedef struct { typedef struct {
chk_ucontext_t cu; /* check ucontext */ chk_ucontext_t cu; /* check ucontext */
uint8_t stack[CONTEXT_STACK_SIZE + STACK_ALIGNMENT]; /* stack */ uint8_t stack[CONTEXT_STACK_SIZE + STACK_ALIGNMENT]; /* stack */
chk_canary_t canary; /* copy of canary */ chk_canary_t canary; /* copy of canary */
} context_info_t; } context_info_t;
static context_info_t context[3]; static context_info_t context[3];
static ucontext_t uctx_main; static ucontext_t uctx_main;
static uint64_t __counter, __max_ops; static uint64_t context_counter;
static uint64_t stress_max_ops;
static void thread1(void) static void thread1(void)
{ {
do { do {
__counter++; context_counter++;
(void)swapcontext(&context[0].cu.uctx, &context[1].cu.uctx); (void)swapcontext(&context[0].cu.uctx, &context[1].cu.uctx);
} while (keep_stressing_flag() && (!__max_ops || (__counter < __max_ops)) } while (keep_stressing_flag() && (!stress_max_ops || (context_counter <
); stress_max_ops)));
(void)swapcontext(&context[0].cu.uctx, &uctx_main); (void)swapcontext(&context[0].cu.uctx, &uctx_main);
} }
static void thread2(void) static void thread2(void)
{ {
do { do {
__counter++; context_counter++;
(void)swapcontext(&context[1].cu.uctx, &context[2].cu.uctx); (void)swapcontext(&context[1].cu.uctx, &context[2].cu.uctx);
} while (keep_stressing_flag() && (!__max_ops || (__counter < __max_ops)) ); } while (keep_stressing_flag() && (!stress_max_ops || (context_counter < stress_max_ops)));
(void)swapcontext(&context[1].cu.uctx, &uctx_main); (void)swapcontext(&context[1].cu.uctx, &uctx_main);
} }
static void thread3(void) static void thread3(void)
{ {
do { do {
__counter++; context_counter++;
(void)swapcontext(&context[2].cu.uctx, &context[0].cu.uctx); (void)swapcontext(&context[2].cu.uctx, &context[0].cu.uctx);
} while (keep_stressing_flag() && (!__max_ops || (__counter < __max_ops)) ); } while (keep_stressing_flag() && (!stress_max_ops || (context_counter < stress_max_ops)));
(void)swapcontext(&context[2].cu.uctx, &uctx_main); (void)swapcontext(&context[2].cu.uctx, &uctx_main);
} }
static int stress_context_init( static int stress_context_init(
const stress_args_t *args, const stress_args_t *args,
void (*func)(void), void (*func)(void),
ucontext_t *uctx_link, ucontext_t *uctx_link,
context_info_t *context_info) context_info_t *context_info)
{ {
(void)memset(context_info, 0, sizeof(*context_info));
if (getcontext(&context_info->cu.uctx) < 0) { if (getcontext(&context_info->cu.uctx) < 0) {
pr_err("%s: getcontext failed: %d (%s)\n", pr_err("%s: getcontext failed: %d (%s)\n",
args->name, errno, strerror(errno)); args->name, errno, strerror(errno));
return -1; return -1;
} }
context_info->canary.check0 = stress_mwc32(); context_info->canary.check0 = stress_mwc32();
context_info->canary.check1 = stress_mwc32(); context_info->canary.check1 = stress_mwc32();
context_info->cu.check0 = context_info->canary.check0; context_info->cu.check0 = context_info->canary.check0;
skipping to change at line 119 skipping to change at line 121
return 0; return 0;
} }
/* /*
* stress_context() * stress_context()
* stress that exercises CPU context save/restore * stress that exercises CPU context save/restore
*/ */
static int stress_context(const stress_args_t *args) static int stress_context(const stress_args_t *args)
{ {
uint8_t *stack_sig;
size_t i; size_t i;
stack_sig = (uint8_t *)mmap(NULL, STRESS_SIGSTKSZ, PROT_READ | PROT_WRITE (void)memset(&uctx_main, 0, sizeof(uctx_main));
,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (stack_sig == MAP_FAILED) {
pr_inf("%s: cannot allocate signal stack, errno=%d (%s)\n",
args->name, errno, strerror(errno));
return EXIT_NO_RESOURCE;
}
if (stress_sigaltstack(stack_sig, STRESS_SIGSTKSZ) < 0)
return EXIT_FAILURE;
__counter = 0; context_counter = 0;
__max_ops = args->max_ops * 1000; stress_max_ops = args->max_ops * 1000;
/* Create 3 micro threads */ /* Create 3 micro threads */
if (stress_context_init(args, thread1, &uctx_main, &context[0]) < 0) if (stress_context_init(args, thread1, &uctx_main, &context[0]) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
if (stress_context_init(args, thread2, &uctx_main, &context[1]) < 0) if (stress_context_init(args, thread2, &uctx_main, &context[1]) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
if (stress_context_init(args, thread3, &uctx_main, &context[2]) < 0) if (stress_context_init(args, thread3, &uctx_main, &context[2]) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
/* And start.. */ /* And start.. */
if (swapcontext(&uctx_main, &context[0].cu.uctx) < 0) { if (swapcontext(&uctx_main, &context[0].cu.uctx) < 0) {
pr_err("%s: swapcontext failed: %d (%s)\n", pr_err("%s: swapcontext failed: %d (%s)\n",
args->name, errno, strerror(errno)); args->name, errno, strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
set_counter(args, __counter / 1000); set_counter(args, context_counter / 1000);
stress_set_proc_state(args->name, STRESS_STATE_RUN); stress_set_proc_state(args->name, STRESS_STATE_RUN);
for (i = 0; i < SIZEOF_ARRAY(context); i++) { for (i = 0; i < SIZEOF_ARRAY(context); i++) {
if (context[i].canary.check0 != context[i].cu.check0) { if (context[i].canary.check0 != context[i].cu.check0) {
pr_fail("%s: swapcontext clobbered data before context re gion\n", pr_fail("%s: swapcontext clobbered data before context re gion\n",
args->name); args->name);
} }
if (context[i].canary.check1 != context[i].cu.check1) { if (context[i].canary.check1 != context[i].cu.check1) {
pr_fail("%s: swapcontext clobbered data after context reg ion\n", pr_fail("%s: swapcontext clobbered data after context reg ion\n",
args->name); args->name);
} }
} }
stress_set_proc_state(args->name, STRESS_STATE_DEINIT); stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
(void)munmap((void *)stack_sig, STRESS_SIGSTKSZ);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
stressor_info_t stress_context_info = { stressor_info_t stress_context_info = {
.stressor = stress_context, .stressor = stress_context,
.class = CLASS_MEMORY | CLASS_CPU, .class = CLASS_MEMORY | CLASS_CPU,
.help = help .help = help
}; };
#else #else
 End of changes. 13 change blocks. 
25 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)