From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> To: igt-dev@lists.freedesktop.org Cc: Intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Support exiting the tool by pressing 'q' Date: Thu, 17 Dec 2020 10:38:10 +0000 [thread overview] Message-ID: <20201217103812.1174024-1-tvrtko.ursulin@linux.intel.com> (raw) From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Analoguous to top(1) we can enable the user to exit from the tool by pressing 'q' on the console. v2: * Fix sleep period with closed stdin. (Chris) Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- man/intel_gpu_top.rst | 6 ++++ tools/intel_gpu_top.c | 80 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst index 5552e9699d26..2e0c3a05acc1 100644 --- a/man/intel_gpu_top.rst +++ b/man/intel_gpu_top.rst @@ -48,6 +48,12 @@ OPTIONS -d Select a specific GPU using supported filter. +RUNTIME CONTROL +=============== + +Supported keys: + + 'q' Exit from the tool. DEVICE SELECTION ================ diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index dbd353673e55..46221c9543eb 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -23,24 +23,26 @@ #include "igt_device_scan.h" -#include <stdio.h> -#include <sys/types.h> -#include <dirent.h> -#include <stdint.h> #include <assert.h> -#include <string.h> #include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> #include <fcntl.h> #include <inttypes.h> -#include <sys/ioctl.h> -#include <errno.h> -#include <math.h> -#include <locale.h> #include <limits.h> +#include <locale.h> +#include <math.h> +#include <poll.h> #include <signal.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <termios.h> #include "igt_perf.h" @@ -1246,6 +1248,54 @@ static char *tr_pmu_name(struct igt_device_card *card) return device; } +static void interactive_stdin(void) +{ + struct termios termios = { }; + int ret; + + ret = fcntl(0, F_GETFL, NULL); + ret |= O_NONBLOCK; + ret = fcntl(0, F_SETFL, ret); + assert(ret == 0); + + ret = tcgetattr(0, &termios); + assert(ret == 0); + + termios.c_lflag &= ~ICANON; + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 0; /* Deciseconds only - we'll use poll. */ + + ret = tcsetattr(0, TCSAFLUSH, &termios); + assert(ret == 0); +} + +static void process_stdin(unsigned int timeout_us) +{ + struct pollfd p = { .fd = 0, .events = POLLIN }; + int ret; + + ret = poll(&p, 1, timeout_us / 1000); + if (ret <= 0) { + if (ret < 0) + stop_top = true; + return; + } + + for (;;) { + char c; + + ret = read(0, &c, 1); + if (ret <= 0) + break; + + switch (c) { + case 'q': + stop_top = true; + break; + }; + } +} + int main(int argc, char **argv) { unsigned int period_us = DEFAULT_PERIOD_MS * 1000; @@ -1315,6 +1365,7 @@ int main(int argc, char **argv) switch (output_mode) { case INTERACTIVE: pops = &term_pops; + interactive_stdin(); break; case STDOUT: pops = &stdout_pops; @@ -1427,7 +1478,10 @@ int main(int argc, char **argv) if (stop_top) break; - usleep(period_us); + if (output_mode == INTERACTIVE) + process_stdin(period_us); + else + usleep(period_us); } free(codename); -- 2.25.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> To: igt-dev@lists.freedesktop.org Cc: Intel-gfx@lists.freedesktop.org, Tvrtko Ursulin <tvrtko.ursulin@intel.com> Subject: [igt-dev] [PATCH i-g-t 1/3] intel_gpu_top: Support exiting the tool by pressing 'q' Date: Thu, 17 Dec 2020 10:38:10 +0000 [thread overview] Message-ID: <20201217103812.1174024-1-tvrtko.ursulin@linux.intel.com> (raw) From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Analoguous to top(1) we can enable the user to exit from the tool by pressing 'q' on the console. v2: * Fix sleep period with closed stdin. (Chris) Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- man/intel_gpu_top.rst | 6 ++++ tools/intel_gpu_top.c | 80 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst index 5552e9699d26..2e0c3a05acc1 100644 --- a/man/intel_gpu_top.rst +++ b/man/intel_gpu_top.rst @@ -48,6 +48,12 @@ OPTIONS -d Select a specific GPU using supported filter. +RUNTIME CONTROL +=============== + +Supported keys: + + 'q' Exit from the tool. DEVICE SELECTION ================ diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index dbd353673e55..46221c9543eb 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -23,24 +23,26 @@ #include "igt_device_scan.h" -#include <stdio.h> -#include <sys/types.h> -#include <dirent.h> -#include <stdint.h> #include <assert.h> -#include <string.h> #include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> #include <fcntl.h> #include <inttypes.h> -#include <sys/ioctl.h> -#include <errno.h> -#include <math.h> -#include <locale.h> #include <limits.h> +#include <locale.h> +#include <math.h> +#include <poll.h> #include <signal.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <termios.h> #include "igt_perf.h" @@ -1246,6 +1248,54 @@ static char *tr_pmu_name(struct igt_device_card *card) return device; } +static void interactive_stdin(void) +{ + struct termios termios = { }; + int ret; + + ret = fcntl(0, F_GETFL, NULL); + ret |= O_NONBLOCK; + ret = fcntl(0, F_SETFL, ret); + assert(ret == 0); + + ret = tcgetattr(0, &termios); + assert(ret == 0); + + termios.c_lflag &= ~ICANON; + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 0; /* Deciseconds only - we'll use poll. */ + + ret = tcsetattr(0, TCSAFLUSH, &termios); + assert(ret == 0); +} + +static void process_stdin(unsigned int timeout_us) +{ + struct pollfd p = { .fd = 0, .events = POLLIN }; + int ret; + + ret = poll(&p, 1, timeout_us / 1000); + if (ret <= 0) { + if (ret < 0) + stop_top = true; + return; + } + + for (;;) { + char c; + + ret = read(0, &c, 1); + if (ret <= 0) + break; + + switch (c) { + case 'q': + stop_top = true; + break; + }; + } +} + int main(int argc, char **argv) { unsigned int period_us = DEFAULT_PERIOD_MS * 1000; @@ -1315,6 +1365,7 @@ int main(int argc, char **argv) switch (output_mode) { case INTERACTIVE: pops = &term_pops; + interactive_stdin(); break; case STDOUT: pops = &stdout_pops; @@ -1427,7 +1478,10 @@ int main(int argc, char **argv) if (stop_top) break; - usleep(period_us); + if (output_mode == INTERACTIVE) + process_stdin(period_us); + else + usleep(period_us); } free(codename); -- 2.25.1 _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2020-12-17 10:38 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-17 10:38 Tvrtko Ursulin [this message] 2020-12-17 10:38 ` [igt-dev] [PATCH i-g-t 1/3] intel_gpu_top: Support exiting the tool by pressing 'q' Tvrtko Ursulin 2020-12-17 10:38 ` [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Aggregate engine busyness per class Tvrtko Ursulin 2020-12-17 10:38 ` [igt-dev] " Tvrtko Ursulin 2020-12-17 10:38 ` [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Fix interactive mode on serial console Tvrtko Ursulin 2020-12-17 12:14 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/3] intel_gpu_top: Support exiting the tool by pressing 'q' Patchwork
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201217103812.1174024-1-tvrtko.ursulin@linux.intel.com \ --to=tvrtko.ursulin@linux.intel.com \ --cc=Intel-gfx@lists.freedesktop.org \ --cc=igt-dev@lists.freedesktop.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.