lib: move prefault helpers to igt_debugfs.c
PATCH 1/5 lib: move prefault helpers to igt_debugfs.c
This way all debugfs library code is in one place, ready for some api documentation care.
--- lib/drmtest.c | 38 ---------------------------------- lib/drmtest.h | 4 ---- lib/igt_debugfs.c | 45 +++++++++++++++++++++++++++++++++++++++++ lib/igt_debugfs.h | 8 ++++++++ tests/gem_exec_faulting_reloc.c | 1 + tests/gem_mmap_gtt.c | 1 + 6 files changed, 55 insertions(+), 42 deletions(-)
lib/drmtest.c +0 -38
@@ -425,44 +425,6 @@ void igt_cleanup_aperture_trashers(void)free (trash_bos); } -#define PREFAULT_DEBUGFS "/sys/module/i915/parameters/prefault_disable" -static void igt_prefault_control (bool enable) -{ -const char *name =PREFAULT_DEBUGFS ; -int fd; -char buf[2 ] = {'Y' ,'N' }; -int index; - - fd =open (name,O_RDWR ); -igt_require (fd >=0 ); - -if (enable) - index =1 ; -else - index =0 ; - -igt_require (write (fd, &buf[index],1 ) ==1 ); - -close (fd); -} - -static void enable_prefault_at_exit (int sig) -{ -igt_enable_prefault (); -} - -void igt_disable_prefault (void ) -{ -igt_prefault_control (false); - -igt_install_exit_handler (enable_prefault_at_exit); -} - -void igt_enable_prefault (void ) -{ -igt_prefault_control (true); -} -void igt_system_suspend_autoresume (void ) {int ret;
lib/drmtest.h +0 -4
@@ -77,10 +77,6 @@ void igt_cleanup_aperture_trashers(void);/* set vt into graphics mode, required to prevent fbcon from interfering */ void igt_set_vt_graphics_mode (void ); -/* prefault disabling, needs the corresponding debugfs interface */ -void igt_disable_prefault (void ); -void igt_enable_prefault (void ); -/* suspend and auto-resume system */ void igt_system_suspend_autoresume (void );
lib/igt_debugfs.c +45 -0
54 lines not on this page · raw message
lib/igt_debugfs.h +8 -0
@@ -96,4 +96,12 @@ void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);void igt_drop_caches_set (uint64_t val); +/* +* Prefault control +*/ + +void igt_disable_prefault (void ); +void igt_enable_prefault (void ); + +#endif /* __IGT_DEBUGFS_H__ */
tests/gem_exec_faulting_reloc.c +1 -0
@@ -41,6 +41,7 @@#include "drmtest.h" #include "intel_chipset.h" #include "intel_gpu_tools.h" +#include "igt_debugfs.h" /* Testcase: Submit patches with relocations in memory that will fault *
tests/gem_mmap_gtt.c +1 -0
@@ -38,6 +38,7 @@#include "drm.h" #include "i915_drm.h" #include "drmtest.h" +#include "igt_debugfs.h" static int OBJECT_SIZE =16 *1024 *1024 ;
Signature · 1 line
1.8.5.2
PATCH 2/5 lib/ioctl_wrappers: api doc fixup
Oops.
--- lib/ioctl_wrappers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ioctl_wrappers.c +1 -1
@@ -785,7 +785,7 @@ void gem_require_caching(int fd)/** * gem_require_ring: * @fd: open i915 drm file descriptor -* @id: ring flag bit as used in gem_execbuf() +* @ring_id: ring flag bit as used in gem_execbuf() * * Feature test macro to query whether a specific ring is available. * In contrast to gem_has_enable_ring() this automagically skips if the ring
Signature · 1 line
1.8.5.2
PATCH 3/5 lib: make igt_debugfs_open infallible
In reply to Daniel Vetter(Almost) no one cared anyway.
--- lib/igt_debugfs.c | 13 ++++++------- lib/igt_debugfs.h | 2 +- tests/gem_reset_stats.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)
lib/igt_debugfs.c +6 -7
@@ -37,7 +37,7 @@/* * General debugfs helpers */ -int igt_debugfs_init (igt_debugfs_t *debugfs) +void igt_debugfs_init (igt_debugfs_t *debugfs) {const char *path ="/sys/kernel/debug" ;struct stat st;
@@ -51,11 +51,9 @@ int igt_debugfs_init(igt_debugfs_t *debugfs)if (stat ("/sys/kernel/debug/dri" , &st) ==0 ) goto find_minor; -if (stat ("/sys/kernel/debug" , &st)) -return errno; +igt_assert (stat ("/sys/kernel/debug" , &st) ==0 ); -if (mount ("debug" ,"/sys/kernel/debug" ,"debugfs" ,0 ,0 )) -return errno; +igt_assert (mount ("debug" ,"/sys/kernel/debug" ,"debugfs" ,0 ,0 ) ==0 ); find_minor:strcpy (debugfs->root, path);
@@ -64,12 +62,13 @@ find_minor:sprintf (debugfs->dri_path + len,"/i915_error_state" );if (stat (debugfs->dri_path, &st) ==0 ) { debugfs->dri_path[len] ='\0' ; -return 0 ; +return ; } } debugfs->dri_path[0 ] ='\0' ; -return ENOENT ; + +igt_fail (4 ); }int igt_debugfs_open (igt_debugfs_t *debugfs,const char *filename,int mode)
lib/igt_debugfs.h +1 -1
@@ -36,7 +36,7 @@ typedef struct {char dri_path[128 ]; } igt_debugfs_t; -int igt_debugfs_init (igt_debugfs_t *debugfs); +void igt_debugfs_init (igt_debugfs_t *debugfs);int igt_debugfs_open (igt_debugfs_t *debugfs,const char *filename,int mode);FILE *igt_debugfs_fopen (igt_debugfs_t *debugfs,const char *filename,const char *mode);
tests/gem_reset_stats.c +1 -1
@@ -1041,7 +1041,7 @@ igt_main"Kernel is too old, or contexts not supported: %s\n" , strerror(errno)); -assert (igt_debugfs_init (&dfs) ==0 ); +igt_debugfs_init (&dfs); }igt_subtest ("params" )
Signature · 1 line
1.8.5.2
PATCH 4/5 lib/igt_debugfs: drop drm_fd argument from igt_pipe_crc_new
In reply to Daniel VetterIt's nowhere used and removing it gives us a cleaner, more orthogonal interface.
--- lib/igt_debugfs.c | 5 +---- lib/igt_debugfs.h | 2 +- tests/kms_cursor_crc.c | 2 +- tests/kms_fbc_crc.c | 2 +- tests/kms_pipe_crc_basic.c | 2 +- tests/kms_plane.c | 2 +- 6 files changed, 6 insertions(+), 9 deletions(-)
lib/igt_debugfs.c +1 -4
@@ -136,8 +136,6 @@ char *igt_crc_to_string(igt_crc_t *crc)#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)struct _igt_pipe_crc { -int drm_fd; -int ctl_fd;int crc_fd;int line_len;
@@ -226,7 +224,7 @@ void igt_pipe_crc_check(igt_debugfs_t *debugfs) }igt_pipe_crc_t * -igt_pipe_crc_new (igt_debugfs_t *debugfs,int drm_fd,enum pipe pipe, +igt_pipe_crc_new (igt_debugfs_t *debugfs,enum pipe pipe,enum intel_pipe_crc_source source) {igt_pipe_crc_t *pipe_crc;
@@ -246,7 +244,6 @@ igt_pipe_crc_new(igt_debugfs_t *debugfs, int drm_fd, enum pipe pipe, pipe_crc->line_len =PIPE_CRC_LINE_LEN ; pipe_crc->buffer_len =PIPE_CRC_BUFFER_LEN ; - pipe_crc->drm_fd = drm_fd; pipe_crc->pipe = pipe; pipe_crc->source = source;
lib/igt_debugfs.h +1 -1
@@ -72,7 +72,7 @@ char *igt_crc_to_string(igt_crc_t *crc);void igt_pipe_crc_check (igt_debugfs_t *debugfs);igt_pipe_crc_t * -igt_pipe_crc_new (igt_debugfs_t *debugfs,int drm_fd,enum pipe pipe, +igt_pipe_crc_new (igt_debugfs_t *debugfs,enum pipe pipe,enum intel_pipe_crc_source source);void igt_pipe_crc_free (igt_pipe_crc_t *pipe_crc);void igt_pipe_crc_start (igt_pipe_crc_t *pipe_crc);
tests/kms_cursor_crc.c +1 -1
@@ -63,7 +63,7 @@ static igt_pipe_crc_t *create_crc(data_t *data, enum pipe pipe) {igt_pipe_crc_t *crc; - crc =igt_pipe_crc_new (&data->debugfs, data->drm_fd, pipe, + crc =igt_pipe_crc_new (&data->debugfs, pipe,INTEL_PIPE_CRC_SOURCE_AUTO );return crc; }
tests/kms_fbc_crc.c +1 -1
@@ -352,7 +352,7 @@ static bool prepare_crtc(data_t *data, uint32_t connector_id, enum test_mode mod data->pipe_crc[data->crtc_idx] =NULL ; pipe_crc =igt_pipe_crc_new (&data->debugfs, - data->drm_fd, data->crtc_idx, + data->crtc_idx,INTEL_PIPE_CRC_SOURCE_AUTO );if (!pipe_crc) { printf("auto crc not supported on this connector with crtc %i\n",
tests/kms_pipe_crc_basic.c +1 -1
@@ -88,7 +88,7 @@ static void test_read_crc(data_t *data, int pipe, unsigned flags)igt_display_commit (display); - pipe_crc =igt_pipe_crc_new (&data->debugfs, data->drm_fd, + pipe_crc =igt_pipe_crc_new (&data->debugfs, pipe,INTEL_PIPE_CRC_SOURCE_AUTO );if (!pipe_crc)
tests/kms_plane.c +1 -1
@@ -92,7 +92,7 @@ test_position_init(test_position_t *test, igt_output_t *output, enum pipe pipe)drmModeModeInfo *mode;igt_plane_t *primary; - test->pipe_crc =igt_pipe_crc_new (&data->debugfs, data->drm_fd, + test->pipe_crc =igt_pipe_crc_new (&data->debugfs, pipe,INTEL_PIPE_CRC_SOURCE_AUTO );igt_output_set_pipe (output, pipe);
Signature · 1 line
1.8.5.2
PATCH 5/5 lib/igt_debugfs: api docs
In reply to Daniel VetterAgain issues with an enum, this time intel_pipe_crc_source. The typedefs seem to work better here though.
--- lib/igt_debugfs.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/igt_debugfs.h | 65 +++++++++++++++++--- 2 files changed, 225 insertions(+), 13 deletions(-)
lib/igt_debugfs.c +167 -6
@@ -34,9 +34,54 @@#include "igt_display.h" #include "igt_debugfs.h" +/** +* SECTION:igt_debugfs +* @short_description: Support code for debugfs features +* @title: i-g-t debugfs +* +* This library provides helpers to access debugfs features. On top of some +* basic functions to access debugfs files with e.g. igt_debugfs_open() it also +* provides higher-level wrappers for some debugfs features +* +* # Pipe CRC Support +* +* This library wraps up the kernel's support for capturing pipe CRCs into a +* neat and tidy package. For the datailed usage see all the functions which +* work on #igt_pipe_crc_t. This is supported on all platforms and outputs. +* +* Actually using pipe CRCs to write modeset tests is a bit tricky though, so +* there is no way to directly check a CRC: Both the details of the plane +* blending, color correction and other hardware and how exactly the CRC is +* computed at each tap point vary by hardware generation and are not disclosed. +* +* The only way to use #igt_crc_t CRCs therefors is to compare CRCs among each +* another either for equality or difference. Otherwise CRCs must be treated as +* completely opaque values. Note that not even CRCs from different pipes or tap +* points on the same platform can be compared. Hence only use igt_crc_is_null() +* and igt_crc_equal() to insepct CRC values captured by the same +* #igt_pipe_crc_t object. +* +* # Other debugfs interface wrappers +* +* This covers the miscellaneous debugfs interface wrappers: +* +* - drm/i915 supports interfaces to evict certain clases of gem buffer objects, +* see igt_drop_caches_set(). +* +* - drm/i915 supports an interface to disable prefaulting, useful to test +* slowpaths in ioctls. See igt_disable_prefault(). +*/ +/* * General debugfs helpers */ + +/** +* igt_debugfs_init: +* @debugfs: debugfs access structure to initialize +* +* Initializes the debugfs access helper library. +*/ void igt_debugfs_init (igt_debugfs_t *debugfs) {const char *path ="/sys/kernel/debug" ;
@@ -71,6 +116,15 @@ find_minor:igt_fail (4 ); } +/** +* igt_debugfs_open: +* @debugfs: debugfs access structure +* @filename: name of the debugfs node to open +* @mode: mode bits as used by open() +* +* This opens a debugfs file as a Unix file descriptor. The filename should be +* relative to the drm device's root, i.e without "drm/<minor>". +*/ int igt_debugfs_open (igt_debugfs_t *debugfs,const char *filename,int mode) {char buf[1024 ];
@@ -79,6 +133,15 @@ int igt_debugfs_open(igt_debugfs_t *debugfs, const char *filename, int mode)return open (buf, mode); } +/** +* igt_debugfs_fopen: +* @debugfs: debugfs access structure +* @filename: name of the debugfs node to open +* @mode: mode string as used by fopen() +* +* This opens a debugfs file as a libc FILE. The filename should be +* relative to the drm device's root, i.e without "drm/<minor>". +*/ FILE *igt_debugfs_fopen (igt_debugfs_t *debugfs,const char *filename,const char *mode) {
@@ -92,6 +155,13 @@ FILE *igt_debugfs_fopen(igt_debugfs_t *debugfs, const char *filename,* Pipe CRC */ +/** +* igt_crc_is_null: +* @crc: pipe CRC value to check +* +* Returns: True if the CRC is null/invalid, false if it represents a captured +* valid CRC. +*/ bool igt_crc_is_null (igt_crc_t *crc) {int i;
@@ -103,6 +173,15 @@ bool igt_crc_is_null(igt_crc_t *crc)return true; } +/** +* igt_crc_equal: +* @a: first pipe CRC value +* @b: second pipe CRC value +* +* Compares two CRC values. +* +* Returns: Retruns true if the two CRCs match, false otherwise. +*/ bool igt_crc_equal (igt_crc_t *a,igt_crc_t *b) {int i;
@@ -117,6 +196,16 @@ bool igt_crc_equal(igt_crc_t *a, igt_crc_t *b)return true; } +/** +* igt_crc_to_string: +* @crc: pipe CRC value to print +* +* This formats @crc into a string buffer which is owned by igt_crc_to_string(). +* The next call will override the buffer again, which makes this multithreading +* unsafe. +* +* This should only ever be used for diagnostic debug output. +*/ char *igt_crc_to_string (igt_crc_t *crc) {char buf[128 ];
@@ -205,6 +294,14 @@ static void pipe_crc_exit_handler(int sig)igt_pipe_crc_reset (); } +/** +* igt_pipe_crc_check: +* @debugfs: debugfs access structure +* +* Convenience helper to check whether pipe CRC capturing is supported by the +* kernel. Uses igt_skip to automatically skip the test/subtest if this isn't +* the case. +*/ void igt_pipe_crc_check (igt_debugfs_t *debugfs) {const char *cmd ="pipe A none" ;
@@ -223,6 +320,18 @@ void igt_pipe_crc_check(igt_debugfs_t *debugfs)fclose (ctl); } +/** +* igt_pipe_crc_new: +* @debugfs: debugfs access structure +* @pipe: display pipe to use as source +* @source: CRC tap point to use as source +* +* This sets up a new pipe CRC capture object for the given @pipe and @source. +* +* Returns: A pipe CRC object if the given @pipe and @source is available, NULL +* otherwise. Tests can use this to intelligently skip if they require a +* specific pipe CRC source to function properly. +*/ igt_pipe_crc_t *igt_pipe_crc_new (igt_debugfs_t *debugfs,enum pipe pipe,enum intel_pipe_crc_source source)
@@ -258,6 +367,12 @@ igt_pipe_crc_new(igt_debugfs_t *debugfs, enum pipe pipe,return pipe_crc; } +/** +* igt_pipe_crc_free: +* @pipe_crc: pipe CRC object +* +* Frees all resources associated with @pipe_crc. +*/ void igt_pipe_crc_free (igt_pipe_crc_t *pipe_crc) {if (!pipe_crc)
@@ -268,6 +383,12 @@ void igt_pipe_crc_free(igt_pipe_crc_t *pipe_crc)free (pipe_crc); } +/** +* igt_pipe_crc_start: +* @pipe_crc: pipe CRC object +* +* Starts the CRC capture process on @pipe_crc. +*/ void igt_pipe_crc_start (igt_pipe_crc_t *pipe_crc) {igt_crc_t *crcs =NULL ;
@@ -282,6 +403,12 @@ void igt_pipe_crc_start(igt_pipe_crc_t *pipe_crc)free (crcs); } +/** +* igt_pipe_crc_stop: +* @pipe_crc: pipe CRC object +* +* Stops the CRC capture process on @pipe_crc. +*/ void igt_pipe_crc_stop (igt_pipe_crc_t *pipe_crc) {char buf[32 ];
@@ -315,9 +442,18 @@ static bool read_one_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out)return true; } -/* -* Read @n_crcs from the @pipe_crc. This function blocks until @n_crcs are -* retrieved. +/** +* igt_pipe_crc_get_crcs: +* @pipe_crc: pipe CRC object +* @n_crcs: number of CRCs to capture +* @out_crcs: buffer pointer for the captured CRC values +* +* Read @n_crcs from @pipe_crc. This function blocks until @n_crcs are +* retrieved. @out_crcs is alloced by this function and must be released with +* free() by the caller. +* +* Callers must start and stop the capturing themselves by calling +* igt_pipe_crc_start() and igt_pipe_crc_stop(). */ void igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
@@ -340,9 +476,13 @@ igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs, *out_crcs = crcs; } -/* -* Read 1 CRC from @pipe_crc. This function blocks until the CRC is retrieved. -* @out_crc must be allocated by the caller. +/** +* igt_pipe_crc_collect_crc: +* @pipe_crc: pipe CRC object +* @out_crc: buffer for the captured CRC values +* +* Read a single CRC from @pipe_crc. This function blocks until the CRC is +* retrieved. @out_crc must be allocated by the caller. * * This function takes care of the pipe_crc book-keeping, it will start/stop * the collection of the CRC.
@@ -358,6 +498,13 @@ void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc)* Drop caches */ +/** +* igt_drop_caches_set: +* @val: bitmask for DROP_* values +* +* This calls the debugfs interface the drm/i915 GEM driver exposes to drop or +* evict certain classes of gem buffer objects. +*/ void igt_drop_caches_set (uint64_t val) {igt_debugfs_t debugfs;
@@ -406,6 +553,15 @@ static void enable_prefault_at_exit(int sig)igt_enable_prefault (); } +/** +* igt_disable_prefault: +* +* Disable prefaulting in certain gem ioctls through the debugfs interface. As +* usual this installs an exit handler to clean up and re-enable prefaulting +* even when the test exited abnormally. +* +* igt_enable_prefault() will enable normale operation again. +*/ void igt_disable_prefault (void ) {igt_prefault_control (false);
@@ -413,6 +569,11 @@ void igt_disable_prefault(void)igt_install_exit_handler (enable_prefault_at_exit); } +/** +* igt_enable_prefault: +* +* Enable prefault (again) through the debugfs interface. +*/ void igt_enable_prefault (void ) {igt_prefault_control (true);
lib/igt_debugfs.h +58 -7
92 lines not on this page · raw message
Signature · 1 line
1.8.5.2