Skip to contentSkip to conversation

modetest: Use floating vrefresh while dumping mode

PATCH Superseded Devarsh Thakkar 4 participants 6 messages Dec 2, 2019 – Dec 3, 2019

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 modetest: Use floating vrefresh while dumping mode

Add function to derive floating value of vertical
refresh rate from drm mode using pixel clock,
horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +27 -13
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
 	return (int64_t)*((int64_t *)&val);
 }
 
+static float mode_vrefresh(drmModeModeInfo *mode)
+{
+	return  mode->clock * 1000.00
+			/ (mode->htotal * mode->vtotal);
+}
+
 #define bit_name_fn(res)					\
 const char * res##_str(int type) {				\
 	unsigned int i;						\
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d %d",
+	printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
 	       mode->name,
-	       mode->vrefresh,
+	       mode_vrefresh(mode),
 	       mode->hdisplay,
 	       mode->hsync_start,
 	       mode->hsync_end,
@@ -823,12 +829,11 @@ struct plane_arg {
 
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
-	const float vrefresh)
+	float *vrefresh)
 {
 	drmModeConnector *connector;
 	drmModeModeInfo *mode;
 	int i;
-	float mode_vrefresh;
 
 	connector = get_connector_by_id(dev, con_id);
 	if (!connector || !connector->count_modes)
@@ -837,16 +842,19 @@ connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
 	for (i = 0; i < connector->count_modes; i++) {
 		mode = &connector->modes[i];
 		if (!strcmp(mode->name, mode_str)) {
-			/* If the vertical refresh frequency is not specified then return the
-			 * first mode that match with the name. Else, return the mode that match
-			 * the name and the specified vertical refresh frequency.
+			/* If the vertical refresh frequency is not specified
+			 * then return the first mode that match with the name
+			 * and update corresponding vrefresh in pipe_arg.
+			 * Else, return the mode that match the name and
+			 * the specified vertical refresh frequency.
 			 */
-			mode_vrefresh = mode->clock * 1000.00
-					/ (mode->htotal * mode->vtotal);
-			if (vrefresh == 0)
+			if (*vrefresh == 0) {
+				*vrefresh = mode_vrefresh(mode);
 				return mode;
-			else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+			} else if (fabs(mode_vrefresh(mode)
+				   - *vrefresh) < 0.005) {
 				return mode;
+			}
 		}
 	}
 
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct device *dev, struct pipe_arg *pipe)
 
 	for (i = 0; i < (int)pipe->num_cons; i++) {
 		mode = connector_find_mode(dev, pipe->con_ids[i],
-					   pipe->mode_str, pipe->vrefresh);
+					   pipe->mode_str, &pipe->vrefresh);
 		if (mode == NULL) {
-			fprintf(stderr,
+			if (pipe->vrefresh)
+				fprintf(stderr,
+				"failed to find mode "
+				"\"%s-%.2fHz\" for connector %s\n",
+				pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
+			else
+				fprintf(stderr,
 				"failed to find mode \"%s\" for connector %s\n",
 				pipe->mode_str, pipe->cons[i]);
 			return -EINVAL;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 58 lines · Devarsh Thakkar

Add function to derive floating value of vertical
refresh rate from drm mode using pixel clock,
horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +8 -2
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
 	return (int64_t)*((int64_t *)&val);
 }
 
+static float mode_vrefresh(drmModeModeInfo *mode)
+{
+	return  mode->clock * 1000.00
+			/ (mode->htotal * mode->vtotal);
+}
+
 #define bit_name_fn(res)					\
 const char * res##_str(int type) {				\
 	unsigned int i;						\
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d %d",
+	printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
 	       mode->name,
-	       mode->vrefresh,
+	       mode_vrefresh(mode),
 	       mode->hdisplay,
 	       mode->hsync_start,
 	       mode->hsync_end,

tests/modetest/modetest.c struct plane_arg { · line 832

Quoted 5 lines
tests/modetest/modetest.c +1 -1
@@ -823,12 +829,11 @@ struct plane_arg {
 
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
-	const float vrefresh)
+	float *vrefresh)

This change still looks pointless.

Quoted 55 lines
tests/modetest/modetest.c +18 -10
 {
 	drmModeConnector *connector;
 	drmModeModeInfo *mode;
 	int i;
-	float mode_vrefresh;
 
 	connector = get_connector_by_id(dev, con_id);
 	if (!connector || !connector->count_modes)
@@ -837,16 +842,19 @@ connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
 	for (i = 0; i < connector->count_modes; i++) {
 		mode = &connector->modes[i];
 		if (!strcmp(mode->name, mode_str)) {
-			/* If the vertical refresh frequency is not specified then return the
-			 * first mode that match with the name. Else, return the mode that match
-			 * the name and the specified vertical refresh frequency.
+			/* If the vertical refresh frequency is not specified
+			 * then return the first mode that match with the name
+			 * and update corresponding vrefresh in pipe_arg.
+			 * Else, return the mode that match the name and
+			 * the specified vertical refresh frequency.
 			 */
-			mode_vrefresh = mode->clock * 1000.00
-					/ (mode->htotal * mode->vtotal);
-			if (vrefresh == 0)
+			if (*vrefresh == 0) {
+				*vrefresh = mode_vrefresh(mode);
 				return mode;
-			else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+			} else if (fabs(mode_vrefresh(mode)
+				   - *vrefresh) < 0.005) {
 				return mode;
+			}
 		}
 	}
 
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct device *dev, struct pipe_arg *pipe)
 
 	for (i = 0; i < (int)pipe->num_cons; i++) {
 		mode = connector_find_mode(dev, pipe->con_ids[i],
-					   pipe->mode_str, pipe->vrefresh);
+					   pipe->mode_str, &pipe->vrefresh);
 		if (mode == NULL) {
-			fprintf(stderr,
+			if (pipe->vrefresh)
+				fprintf(stderr,
+				"failed to find mode "
+				"\"%s-%.2fHz\" for connector %s\n",
+				pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
+			else
+				fprintf(stderr,
 				"failed to find mode \"%s\" for connector %s\n",
 				pipe->mode_str, pipe->cons[i]);
 			return -EINVAL;
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by
#2 lore raw
Quoted 60 lines · Ville Syrjälä
Quoted 59 lines · Devarsh Thakkar

Add function to derive floating value of vertical
refresh rate from drm mode using pixel clock,
horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +8 -2
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
 	return (int64_t)*((int64_t *)&val);
 }
 
+static float mode_vrefresh(drmModeModeInfo *mode)
+{
+	return  mode->clock * 1000.00
+			/ (mode->htotal * mode->vtotal);
+}
+
 #define bit_name_fn(res)					\
 const char * res##_str(int type) {				\
 	unsigned int i;						\
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d %d",
+	printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
 	       mode->name,
-	       mode->vrefresh,
+	       mode_vrefresh(mode),
 	       mode->hdisplay,
 	       mode->hsync_start,
 	       mode->hsync_end,
@@ -823,12 +829,11 @@ struct plane_arg {
 
Quoted 6 lines

tests/modetest/modetest.c struct plane_arg { · line 832

Quoted 4 lines
tests/modetest/modetest.c +1 -1
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
-	const float vrefresh)
+	float *vrefresh)

This change still looks pointless.

Without this, you cannot set 1000/1001 CEA alternate clock modes, so, no this is not pointless.

This is actual something I always wanted to implement !

Quoted 48 lines
Quoted 48 lines
tests/modetest/modetest.c +15 -10
 {
 	drmModeConnector *connector;
 	drmModeModeInfo *mode;
 	int i;
-	float mode_vrefresh;
 
 	connector = get_connector_by_id(dev, con_id);
 	if (!connector || !connector->count_modes)
@@ -837,16 +842,19 @@ connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
 	for (i = 0; i < connector->count_modes; i++) {
 		mode = &connector->modes[i];
 		if (!strcmp(mode->name, mode_str)) {
-			/* If the vertical refresh frequency is not specified then return the
-			 * first mode that match with the name. Else, return the mode that match
-			 * the name and the specified vertical refresh frequency.
+			/* If the vertical refresh frequency is not specified
+			 * then return the first mode that match with the name
+			 * and update corresponding vrefresh in pipe_arg.
+			 * Else, return the mode that match the name and
+			 * the specified vertical refresh frequency.
 			 */
-			mode_vrefresh = mode->clock * 1000.00
-					/ (mode->htotal * mode->vtotal);
-			if (vrefresh == 0)
+			if (*vrefresh == 0) {
+				*vrefresh = mode_vrefresh(mode);
 				return mode;
-			else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+			} else if (fabs(mode_vrefresh(mode)
+				   - *vrefresh) < 0.005) {
 				return mode;
+			}
 		}
 	}
 
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct device *dev, struct pipe_arg *pipe)
 
 	for (i = 0; i < (int)pipe->num_cons; i++) {
 		mode = connector_find_mode(dev, pipe->con_ids[i],
-					   pipe->mode_str, pipe->vrefresh);
+					   pipe->mode_str, &pipe->vrefresh);
 		if (mode == NULL) {
-			fprintf(stderr,
+			if (pipe->vrefresh)
+				fprintf(stderr,
+				"failed to find mode "
+				"\"%s-%.2fHz\" for connector %s\n",
Quoted 9 lines
Quoted 8 lines
tests/modetest/modetest.c +3 -0
+				pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
+			else
+				fprintf(stderr,
 				"failed to find mode \"%s\" for connector %s\n",
 				pipe->mode_str, pipe->cons[i]);
 			return -EINVAL;
Signature · 1 line
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 61 lines · Neil Armstrong
Quoted 60 lines · Ville Syrjälä
Quoted 59 lines · Devarsh Thakkar

Add function to derive floating value of vertical
refresh rate from drm mode using pixel clock,
horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +8 -2
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
 	return (int64_t)*((int64_t *)&val);
 }
 
+static float mode_vrefresh(drmModeModeInfo *mode)
+{
+	return  mode->clock * 1000.00
+			/ (mode->htotal * mode->vtotal);
+}
+
 #define bit_name_fn(res)					\
 const char * res##_str(int type) {				\
 	unsigned int i;						\
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d %d",
+	printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
 	       mode->name,
-	       mode->vrefresh,
+	       mode_vrefresh(mode),
 	       mode->hdisplay,
 	       mode->hsync_start,
 	       mode->hsync_end,
@@ -823,12 +829,11 @@ struct plane_arg {
 
Quoted 8 lines
Quoted 6 lines

tests/modetest/modetest.c struct plane_arg { · line 832

Quoted 4 lines
tests/modetest/modetest.c +1 -1
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
-	const float vrefresh)
+	float *vrefresh)

This change still looks pointless.

Without this, you cannot set 1000/1001 CEA alternate clock modes, so, no this is not pointless.

I'm talking about this specific s/float/float*/ change. That is pointless. Are you talking about the whole patch or what?

Quoted 62 lines

This is actual something I always wanted to implement !

Quoted 57 lines
Quoted 56 lines
tests/modetest/modetest.c +18 -10
 {
 	drmModeConnector *connector;
 	drmModeModeInfo *mode;
 	int i;
-	float mode_vrefresh;
 
 	connector = get_connector_by_id(dev, con_id);
 	if (!connector || !connector->count_modes)
@@ -837,16 +842,19 @@ connector_find_mode(struct device *dev, uint32_t con_id, const char *mode_str,
 	for (i = 0; i < connector->count_modes; i++) {
 		mode = &connector->modes[i];
 		if (!strcmp(mode->name, mode_str)) {
-			/* If the vertical refresh frequency is not specified then return the
-			 * first mode that match with the name. Else, return the mode that match
-			 * the name and the specified vertical refresh frequency.
+			/* If the vertical refresh frequency is not specified
+			 * then return the first mode that match with the name
+			 * and update corresponding vrefresh in pipe_arg.
+			 * Else, return the mode that match the name and
+			 * the specified vertical refresh frequency.
 			 */
-			mode_vrefresh = mode->clock * 1000.00
-					/ (mode->htotal * mode->vtotal);
-			if (vrefresh == 0)
+			if (*vrefresh == 0) {
+				*vrefresh = mode_vrefresh(mode);
 				return mode;
-			else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+			} else if (fabs(mode_vrefresh(mode)
+				   - *vrefresh) < 0.005) {
 				return mode;
+			}
 		}
 	}
 
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct device *dev, struct pipe_arg *pipe)
 
 	for (i = 0; i < (int)pipe->num_cons; i++) {
 		mode = connector_find_mode(dev, pipe->con_ids[i],
-					   pipe->mode_str, pipe->vrefresh);
+					   pipe->mode_str, &pipe->vrefresh);
 		if (mode == NULL) {
-			fprintf(stderr,
+			if (pipe->vrefresh)
+				fprintf(stderr,
+				"failed to find mode "
+				"\"%s-%.2fHz\" for connector %s\n",
+				pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
+			else
+				fprintf(stderr,
 				"failed to find mode \"%s\" for connector %s\n",
 				pipe->mode_str, pipe->cons[i]);
 			return -EINVAL;
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Thanks for the review Ville and Neil, response inline.

Quoted 11 lines

-----Original Message-----
From: Ville Syrjälä <[email protected]>
Sent: 02 December 2019 09:43
To: Neil Armstrong <[email protected]>
Cc: Devarsh Thakkar <[email protected]>; Ranganathan Sk <[email protected]>; vcu-team <[email protected]>; Dhaval Rajeshbhai Shah <[email protected]>; [email protected]; Varunkumar Allagadapa <[email protected]>
Subject: Re: [PATCH libdrm v3] modetest: Use floating vrefresh while dumping mode

Quoted 68 lines

EXTERNAL EMAIL

Quoted 65 lines · Neil Armstrong
Quoted 63 lines · Ville Syrjälä
Quoted 54 lines · Devarsh Thakkar

Add function to derive floating value of vertical refresh rate from drm mode using pixel clock, horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40
+++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +6 -2
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
   return (int64_t)*((int64_t *)&val);  }
 
+static float mode_vrefresh(drmModeModeInfo *mode) {
+  return  mode->clock * 1000.00
+                  / (mode->htotal * mode->vtotal); }
+
 #define bit_name_fn(res)                                  \
 const char * res##_str(int type) {                                \
   unsigned int i;                                         \
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)  {
-  printf("  %s %d %d %d %d %d %d %d %d %d %d",
+  printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
          mode->name,
-         mode->vrefresh,
+         mode_vrefresh(mode),
          mode->hdisplay,
          mode->hsync_start,
          mode->hsync_end,

tests/modetest/modetest.c struct plane_arg { · line 833

Quoted 6 lines
tests/modetest/modetest.c +1 -1
@@ -823,12 +829,11 @@ struct plane_arg {
 
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const
 char *mode_str,
-  const float vrefresh)
+  float *vrefresh)

This change still looks pointless.

The only small advantage it offers is that it backs up the vrefresh from mode in pipe_args in connector_find_mode and I don't have to call mode_vrefresh again while printing below :
printf("setting mode %s-%.2fHz on connectors ",

                       pipe->mode_str, pipe->vrefresh);

If this is not preferable then it's not mandatory either, then instead of doing this I can call mode_vrefresh again while printing the mode as below :
printf("setting mode %s-%.2fHz on connectors ",

                       pipe->mode_str, mode_vrefresh(pipe->mode))

Kindly let me know your opinion.

Quoted 12 lines
Quoted 1 line

Without this, you cannot set 1000/1001 CEA alternate clock modes, so, no

this is not pointless.

I'm talking about this specific s/float/float*/ change. That is pointless. Are you talking about the whole patch or what?

Quoted 5 lines

This is actual something I always wanted to implement !

Thanks for the review Neil.

Quoted 64 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tests/modetest/modetest.c +0 -1
 {
   drmModeConnector *connector;
   drmModeModeInfo *mode;
   int i;
-  float mode_vrefresh;
 
   connector = get_connector_by_id(dev, con_id);
   if (!connector || !connector->count_modes) @@ -837,16 +842,19

@@

Quoted 1 line
Quoted 1 line
Quoted 1 line

connector_find_mode(struct device *dev, uint32_t con_id, const char

*mode_str,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
   for (i = 0; i < connector->count_modes; i++) {
           mode = &connector->modes[i];
           if (!strcmp(mode->name, mode_str)) {

- /* If the vertical refresh frequency is not specified then

return the

Quoted 1 line
Quoted 1 line
Quoted 1 line

- * first mode that match with the name. Else, return the mode

that match

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
tests/modetest/modetest.c +17 -7
-                   * the name and the specified vertical refresh frequency.
+                  /* If the vertical refresh frequency is not specified
+                   * then return the first mode that match with the name
+                   * and update corresponding vrefresh in pipe_arg.
+                   * Else, return the mode that match the name and
+                   * the specified vertical refresh frequency.
                    */
-                  mode_vrefresh = mode->clock * 1000.00
-                                  / (mode->htotal * mode->vtotal);
-                  if (vrefresh == 0)
+                  if (*vrefresh == 0) {
+                          *vrefresh = mode_vrefresh(mode);
                           return mode;
-                  else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+                  } else if (fabs(mode_vrefresh(mode)
+                             - *vrefresh) < 0.005) {
                           return mode;
+                  }
           }
   }
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct
 device *dev, struct pipe_arg *pipe)
 
   for (i = 0; i < (int)pipe->num_cons; i++) {
           mode = connector_find_mode(dev, pipe->con_ids[i],
-                                     pipe->mode_str, pipe->vrefresh);
+                                     pipe->mode_str,
+ &pipe->vrefresh);
           if (mode == NULL) {
-                  fprintf(stderr,
+                  if (pipe->vrefresh)
+                          fprintf(stderr,
+                          "failed to find mode "
+                          "\"%s-%.2fHz\" for connector %s\n",
+                          pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
tests/modetest/modetest.c +2 -1
+                  else
+                          fprintf(stderr,
                           "failed to find mode \"%s\" for connector %s\n",
                           pipe->mode_str, pipe->cons[i]);
                   return -EINVAL;
--

2.7.4

Quoted 3 lines

--
Ville Syrjälä
Intel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 82 lines · Devarsh Thakkar

Thanks for the review Ville and Neil, response inline.

Quoted 11 lines

-----Original Message-----
From: Ville Syrjälä <[email protected]>
Sent: 02 December 2019 09:43
To: Neil Armstrong <[email protected]>
Cc: Devarsh Thakkar <[email protected]>; Ranganathan Sk <[email protected]>; vcu-team <[email protected]>; Dhaval Rajeshbhai Shah <[email protected]>; [email protected]; Varunkumar Allagadapa <[email protected]>
Subject: Re: [PATCH libdrm v3] modetest: Use floating vrefresh while dumping mode

Quoted 68 lines

EXTERNAL EMAIL

Quoted 65 lines · Neil Armstrong
Quoted 63 lines · Ville Syrjälä
Quoted 54 lines · Devarsh Thakkar

Add function to derive floating value of vertical refresh rate from drm mode using pixel clock, horizontal total size and vertical total size.

Use this function to find suitable mode having vrefresh value which is matching with user provided vrefresh value.

If user doesn't provide any vrefresh value in args then update vertical refresh rate value in pipe args using this function.

Also use this function for printing floating vrefresh while dumping all available modes.

This will give more accurate picture to user for available modes differentiated by floating vertical refresh rate and help user select more appropriate mode using suitable refresh rate value.

V3: Change name of function used to derive refresh rate.
V2: 1) Don't use inline function for deriving refresh rate from mode.
2) If requested mode not found, print refresh rate only if user had provided it in args.

---
 tests/modetest/modetest.c | 40
+++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
tests/modetest/modetest.c +6 -2
index b4edfcb..19ce20f 100644
@@ -133,6 +133,12 @@ static inline int64_t U642I64(uint64_t val)
   return (int64_t)*((int64_t *)&val);  }
 
+static float mode_vrefresh(drmModeModeInfo *mode) {
+  return  mode->clock * 1000.00
+                  / (mode->htotal * mode->vtotal); }
+
 #define bit_name_fn(res)                                  \
 const char * res##_str(int type) {                                \
   unsigned int i;                                         \
@@ -210,9 +216,9 @@ static void dump_encoders(struct device *dev)
 
 static void dump_mode(drmModeModeInfo *mode)  {
-  printf("  %s %d %d %d %d %d %d %d %d %d %d",
+  printf("  %s %.2f %d %d %d %d %d %d %d %d %d",
          mode->name,
-         mode->vrefresh,
+         mode_vrefresh(mode),
          mode->hdisplay,
          mode->hsync_start,
          mode->hsync_end,

tests/modetest/modetest.c struct plane_arg { · line 833

Quoted 6 lines
tests/modetest/modetest.c +1 -1
@@ -823,12 +829,11 @@ struct plane_arg {
 
 static drmModeModeInfo *
 connector_find_mode(struct device *dev, uint32_t con_id, const
 char *mode_str,
-  const float vrefresh)
+  float *vrefresh)

This change still looks pointless.

Quoted 7 lines

The only small advantage it offers is that it backs up the vrefresh from mode in pipe_args in connector_find_mode and I don't have to call mode_vrefresh again while printing below :
printf("setting mode %s-%.2fHz on connectors ",

                       pipe->mode_str, pipe->vrefresh);

If this is not preferable then it's not mandatory either, then instead of doing this I can call mode_vrefresh again while printing the mode as below :
printf("setting mode %s-%.2fHz on connectors ",

                       pipe->mode_str, mode_vrefresh(pipe->mode))

I would change that to to use mode_vrefres(), and also IMO better to replace the pipe->mode_str with mode->name as well. That way the code doesn't have to care at all how the mode was chosen.

Quoted 85 lines

Kindly let me know your opinion.

Quoted 12 lines
Quoted 1 line

Without this, you cannot set 1000/1001 CEA alternate clock modes, so, no

this is not pointless.

I'm talking about this specific s/float/float*/ change. That is pointless. Are you talking about the whole patch or what?

Quoted 5 lines

This is actual something I always wanted to implement !

Thanks for the review Neil.

Quoted 67 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tests/modetest/modetest.c +0 -1
 {
   drmModeConnector *connector;
   drmModeModeInfo *mode;
   int i;
-  float mode_vrefresh;
 
   connector = get_connector_by_id(dev, con_id);
   if (!connector || !connector->count_modes) @@ -837,16 +842,19

@@

Quoted 1 line
Quoted 1 line
Quoted 1 line

connector_find_mode(struct device *dev, uint32_t con_id, const char

*mode_str,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
   for (i = 0; i < connector->count_modes; i++) {
           mode = &connector->modes[i];
           if (!strcmp(mode->name, mode_str)) {

- /* If the vertical refresh frequency is not specified then

return the

Quoted 1 line
Quoted 1 line
Quoted 1 line

- * first mode that match with the name. Else, return the mode

that match

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
tests/modetest/modetest.c +17 -7
-                   * the name and the specified vertical refresh frequency.
+                  /* If the vertical refresh frequency is not specified
+                   * then return the first mode that match with the name
+                   * and update corresponding vrefresh in pipe_arg.
+                   * Else, return the mode that match the name and
+                   * the specified vertical refresh frequency.
                    */
-                  mode_vrefresh = mode->clock * 1000.00
-                                  / (mode->htotal * mode->vtotal);
-                  if (vrefresh == 0)
+                  if (*vrefresh == 0) {
+                          *vrefresh = mode_vrefresh(mode);
                           return mode;
-                  else if (fabs(mode_vrefresh - vrefresh) < 0.005)
+                  } else if (fabs(mode_vrefresh(mode)
+                             - *vrefresh) < 0.005) {
                           return mode;
+                  }
           }
   }
@@ -909,9 +917,15 @@ static int pipe_find_crtc_and_mode(struct
 device *dev, struct pipe_arg *pipe)
 
   for (i = 0; i < (int)pipe->num_cons; i++) {
           mode = connector_find_mode(dev, pipe->con_ids[i],
-                                     pipe->mode_str, pipe->vrefresh);
+                                     pipe->mode_str,
+ &pipe->vrefresh);
           if (mode == NULL) {
-                  fprintf(stderr,
+                  if (pipe->vrefresh)
+                          fprintf(stderr,
+                          "failed to find mode "
+                          "\"%s-%.2fHz\" for connector %s\n",
+                          pipe->mode_str, pipe->vrefresh, pipe->cons[i]);
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
tests/modetest/modetest.c +2 -1
+                  else
+                          fprintf(stderr,
                           "failed to find mode \"%s\" for connector %s\n",
                           pipe->mode_str, pipe->cons[i]);
                   return -EINVAL;
--

2.7.4

--
Ville Syrjälä
Intel

Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel