mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-10 17:36:11 +00:00
lib/drmtest: extract helpers for signal interruptions
Also add some hackish stat to check it works. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
36d25cc744
commit
cbaa8a389e
@ -31,6 +31,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "drmtest.h"
|
||||
#include "i915_drm.h"
|
||||
#include "intel_chipset.h"
|
||||
@ -219,3 +221,44 @@ void *gem_mmap(int fd, uint32_t handle, int size, int prot)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static pid_t signal_helper = -1;
|
||||
long long int sig_stat;
|
||||
static void signal_helper_process(pid_t pid)
|
||||
{
|
||||
/* Interrupt the parent process at 500Hz, just to be annoying */
|
||||
while (1) {
|
||||
usleep(1000 * 1000 / 500);
|
||||
if (kill(pid, SIGUSR1)) /* Parent has died, so must we. */
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void sig_handler(int i)
|
||||
{
|
||||
sig_stat++;
|
||||
}
|
||||
|
||||
void drmtest_fork_signal_helper(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
signal(SIGUSR1, sig_handler);
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
signal_helper_process(getppid());
|
||||
return;
|
||||
}
|
||||
|
||||
signal_helper = pid;
|
||||
}
|
||||
|
||||
void drmtest_stop_signal_helper(void)
|
||||
{
|
||||
if (signal_helper != -1)
|
||||
kill(signal_helper, SIGQUIT);
|
||||
|
||||
if (sig_stat)
|
||||
fprintf(stderr, "signal handler called %llu times\n", sig_stat);
|
||||
|
||||
signal_helper = -1;
|
||||
}
|
||||
|
@ -46,3 +46,6 @@ void gem_set_domain(int fd, uint32_t handle,
|
||||
void gem_sync(int fd, uint32_t handle);
|
||||
uint32_t gem_create(int fd, int size);
|
||||
void *gem_mmap(int fd, uint32_t handle, int size, int prot);
|
||||
|
||||
void drmtest_fork_signal_helper(void);
|
||||
void drmtest_stop_signal_helper(void);
|
||||
|
@ -51,8 +51,6 @@
|
||||
|
||||
#include "gem_stress.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#define CMD_POLY_STIPPLE_OFFSET 0x7906
|
||||
|
||||
/** TODO:
|
||||
@ -102,29 +100,6 @@ struct {
|
||||
unsigned max_failed_reads;
|
||||
} stats;
|
||||
|
||||
static void signal_helper_process(pid_t pid)
|
||||
{
|
||||
/* Interrupt the parent process at 500Hz, just to be annoying */
|
||||
while (1) {
|
||||
usleep(1000 * 1000 / 500);
|
||||
if (kill(pid, SIGUSR1)) /* Parent has died, so must we. */
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static pid_t fork_signal_helper(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
signal_helper_process(getppid());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
static void tile2xy(struct scratch_buf *buf, unsigned tile, unsigned *x, unsigned *y)
|
||||
{
|
||||
assert(tile < buf->num_tiles);
|
||||
@ -883,7 +858,6 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
unsigned *current_permutation, *tmp_permutation;
|
||||
pid_t signal_helper = -1;
|
||||
|
||||
drm_fd = drm_open_any();
|
||||
devid = intel_get_drm_devid(drm_fd);
|
||||
@ -891,9 +865,8 @@ int main(int argc, char **argv)
|
||||
parse_options(argc, argv);
|
||||
|
||||
/* start our little helper early before too may allocations occur */
|
||||
signal(SIGUSR1, SIG_IGN);
|
||||
if (options.use_signal_helper)
|
||||
signal_helper = fork_signal_helper();
|
||||
drmtest_fork_signal_helper();
|
||||
|
||||
init();
|
||||
|
||||
@ -943,8 +916,7 @@ int main(int argc, char **argv)
|
||||
|
||||
close(drm_fd);
|
||||
|
||||
if (signal_helper != -1)
|
||||
kill(signal_helper, SIGQUIT);
|
||||
drmtest_stop_signal_helper();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user