1From 65b545d762100c4012c2f8176f5c296d5bfcbdc4 Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Sat, 15 Dec 2018 12:20:01 +0800 4Subject: [PATCH 2/5] modetest: Speed up dumping info 5 6Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 7--- 8 tests/modetest/modetest.c | 28 +++++++++++++++++++++------- 9 1 file changed, 21 insertions(+), 7 deletions(-) 10 11diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c 12index 8ff6c80..5291ca0 100644 13--- a/tests/modetest/modetest.c 14+++ b/tests/modetest/modetest.c 15@@ -50,6 +50,7 @@ 16 #include <strings.h> 17 #include <errno.h> 18 #include <poll.h> 19+#include <fcntl.h> 20 #include <sys/time.h> 21 #if HAVE_SYS_SELECT_H 22 #include <sys/select.h> 23@@ -71,6 +72,10 @@ 24 static enum util_fill_pattern primary_fill = UTIL_PATTERN_SMPTE; 25 static enum util_fill_pattern secondary_fill = UTIL_PATTERN_TILES; 26 27+int encoders = 0, connectors = 0, crtcs = 0, planes = 0, fbs = 0; 28+int dump_only; 29+#define need_resource(type) (!dump_only || type##s) 30+ 31 struct crtc { 32 drmModeCrtc *crtc; 33 drmModeObjectProperties *props; 34@@ -485,7 +490,7 @@ static void dump_crtcs(struct device *dev) 35 printf("\n"); 36 } 37 38-static void dump_framebuffers(struct device *dev) 39+static void dump_fbs(struct device *dev) 40 { 41 drmModeFB *fb; 42 int i; 43@@ -554,6 +559,7 @@ static void free_resources(struct resources *res) 44 return; 45 46 #define free_resource(_res, type, Type) \ 47+ if (need_resource(type)) \ 48 do { \ 49 if (!(_res)->type##s) \ 50 break; \ 51@@ -566,6 +572,7 @@ static void free_resources(struct resources *res) 52 } while (0) 53 54 #define free_properties(_res, type) \ 55+ if (need_resource(type)) \ 56 do { \ 57 for (i = 0; i < (int)(_res)->count_##type##s; ++i) { \ 58 unsigned int j; \ 59@@ -578,10 +585,10 @@ static void free_resources(struct resources *res) 60 61 free_properties(res, plane); 62 free_resource(res, plane, Plane); 63- 64 free_properties(res, connector); 65 free_properties(res, crtc); 66 67+ if (need_resource(connector)) 68 for (i = 0; i < res->count_connectors; i++) 69 free(res->connectors[i].name); 70 71@@ -630,6 +637,7 @@ static struct resources *get_resources(struct device *dev) 72 } 73 74 #define get_resource(_res, __res, type, Type) \ 75+ if (need_resource(type)) \ 76 do { \ 77 for (i = 0; i < (int)(_res)->count_##type##s; ++i) { \ 78 uint32_t type##id = (__res)->type##s[i]; \ 79@@ -650,6 +658,7 @@ static struct resources *get_resources(struct device *dev) 80 drmModeFreeResources(_res); 81 82 /* Set the name of all connectors based on the type name and the per-type ID. */ 83+ if (need_resource(connector)) 84 for (i = 0; i < res->count_connectors; i++) { 85 struct connector *connector = &res->connectors[i]; 86 drmModeConnector *conn = connector->connector; 87@@ -663,6 +672,7 @@ static struct resources *get_resources(struct device *dev) 88 } 89 90 #define get_properties(_res, type, Type) \ 91+ if (need_resource(type)) \ 92 do { \ 93 for (i = 0; i < (int)(_res)->count_##type##s; ++i) { \ 94 struct type *obj = &res->type##s[i]; \ 95@@ -690,6 +700,7 @@ static struct resources *get_resources(struct device *dev) 96 get_properties(res, crtc, CRTC); 97 get_properties(res, connector, CONNECTOR); 98 99+ if (need_resource(crtc)) 100 for (i = 0; i < res->count_crtcs; ++i) 101 res->crtcs[i].mode = &res->crtcs[i].crtc->mode; 102 103@@ -2026,7 +2037,6 @@ int main(int argc, char **argv) 104 struct device dev; 105 106 int c; 107- int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0; 108 int drop_master = 0; 109 int test_vsync = 0; 110 int test_cursor = 0; 111@@ -2070,7 +2080,7 @@ int main(int argc, char **argv) 112 encoders = 1; 113 break; 114 case 'f': 115- framebuffers = 1; 116+ fbs = 1; 117 break; 118 case 'F': 119 parse_fill_patterns(optarg); 120@@ -2143,7 +2153,7 @@ int main(int argc, char **argv) 121 122 /* Dump all the details when no* arguments are provided. */ 123 if (!args) 124- encoders = connectors = crtcs = planes = framebuffers = 1; 125+ encoders = connectors = crtcs = planes = fbs = 1; 126 127 if (test_vsync && !count) { 128 fprintf(stderr, "page flipping requires at least one -s option.\n"); 129@@ -2159,7 +2169,11 @@ int main(int argc, char **argv) 130 return -1; 131 } 132 133- dev.fd = util_open(device, module); 134+ dump_only = !count && !plane_count && !prop_count; 135+ if (dump_only && !device && !module) 136+ dev.fd = open("/dev/dri/card0", O_RDWR); 137+ else 138+ dev.fd = util_open(device, module); 139 if (dev.fd < 0) 140 return -1; 141 142@@ -2186,7 +2200,7 @@ int main(int argc, char **argv) 143 dump_resource(&dev, connectors); 144 dump_resource(&dev, crtcs); 145 dump_resource(&dev, planes); 146- dump_resource(&dev, framebuffers); 147+ dump_resource(&dev, fbs); 148 149 for (i = 0; i < prop_count; ++i) 150 set_property(&dev, &prop_args[i]); 151-- 1522.20.1 153 154