All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp
@ 2021-09-03  4:33 Hongzhan Chen
  2021-09-03  7:08 ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Hongzhan Chen @ 2021-09-03  4:33 UTC (permalink / raw)
  To: xenomai

Provide choices to switch clock between MONO and REALTIME for getting
different timestamp since gpio driver already provide choosable service.

Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>

diff --git a/testsuite/gpiobench/gpiobench.c b/testsuite/gpiobench/gpiobench.c
index 0f099b0e8..04c694639 100644
--- a/testsuite/gpiobench/gpiobench.c
+++ b/testsuite/gpiobench/gpiobench.c
@@ -85,6 +85,7 @@ struct test_info {
 	unsigned long total_cycles;
 	unsigned long max_histogram;
 	int mode;
+	int clockid;
 	int prio;
 	int quiet;
 	int tracelimit;
@@ -121,7 +122,10 @@ static void display_help(void)
 	       "                            must be specified\n"
 	       "-m       --testmode         0 is loopback mode\n"
 	       "                            1 is react mode which works with a latency box,\n"
-	       "                            default=0\n\n"
+	       "                            default=0\n"
+	       "-k       --clockid          0 is CLOCK_REALTIME\n"
+	       "                            1 is CLOCK_MONOTONIC,\n"
+	       "                            default=1\n\n"
 
 	       "e.g.     gpiobench -o 20 -i 21 -c pinctrl-bcm2835\n"
 		);
@@ -130,7 +134,7 @@ static void display_help(void)
 static void process_options(int argc, char *argv[])
 {
 	int c = 0;
-	static const char optstring[] = "h:p:m:l:c:b:i:o:q";
+	static const char optstring[] = "h:p:m:l:c:b:i:o:k:q";
 
 	struct option long_options[] = {
 		{ "bracetrace", required_argument, 0, 'b'},
@@ -142,6 +146,7 @@ static void process_options(int argc, char *argv[])
 		{ "intr", required_argument, 0, 'i'},
 		{ "pinctrl", required_argument, 0, 'c'},
 		{ "testmode", required_argument, 0, 'm'},
+		{ "clockid", required_argument, 0, 'k'},
 		{ 0, 0, 0, 0},
 	};
 
@@ -185,6 +190,11 @@ static void process_options(int argc, char *argv[])
 				MODE_REACT ? MODE_REACT : MODE_LOOPBACK;
 			break;
 
+		case 'k':
+			ti.clockid = atoi(optarg) >= CLOCK_MONOTONIC ?
+				CLOCK_MONOTONIC : CLOCK_REALTIME;
+			break;
+
 		default:
 			display_help();
 			exit(2);
@@ -291,7 +301,7 @@ static int rw_gpio(int value, int index)
 	struct rtdm_gpio_readout rdo;
 	long long gpio_write, gpio_read, inner_diff, outer_diff;
 
-	clock_gettime(CLOCK_MONOTONIC, &timestamp);
+	clock_gettime(ti.clockid, &timestamp);
 	gpio_write = calc_us(timestamp);
 
 	ret = write(ti.fd_dev_out, &value, sizeof(value));
@@ -306,7 +316,7 @@ static int rw_gpio(int value, int index)
 		return ret;
 	}
 
-	clock_gettime(CLOCK_MONOTONIC, &timestamp);
+	clock_gettime(ti.clockid, &timestamp);
 	gpio_read = calc_us(timestamp);
 
 	inner_diff = (rdo.timestamp - gpio_write) / 1000;
@@ -472,6 +482,7 @@ static void init_ti(void)
 	ti.gpio_out = -1;
 	ti.gpio_intr = -1;
 	ti.mode = MODE_LOOPBACK;
+	ti.clockid = CLOCK_MONOTONIC;
 
 	ti.ts.inner_min = ti.ts.outer_min = DEFAULT_LIMIT;
 	ti.ts.inner_max = ti.ts.outer_max = 0;
@@ -632,7 +643,9 @@ int main(int argc, char **argv)
 			goto out;
 		}
 
-		ret = ioctl(ti.fd_dev_intr, GPIO_RTIOC_TS_MONO, &value);
+		ret = ioctl(ti.fd_dev_intr,
+			ti.clockid == CLOCK_MONOTONIC ?
+			GPIO_RTIOC_TS_MONO : GPIO_RTIOC_TS_REAL, &value);
 		if (ret) {
 			printf("ioctl gpio port ts, failed\n");
 			goto out;
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp
  2021-09-03  4:33 [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp Hongzhan Chen
@ 2021-09-03  7:08 ` Jan Kiszka
  2021-09-07  0:55   ` Chen, Hongzhan
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2021-09-03  7:08 UTC (permalink / raw)
  To: Hongzhan Chen, xenomai

On 03.09.21 06:33, Hongzhan Chen via Xenomai wrote:
> Provide choices to switch clock between MONO and REALTIME for getting
> different timestamp since gpio driver already provide choosable service.
> 
> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
> 
> diff --git a/testsuite/gpiobench/gpiobench.c b/testsuite/gpiobench/gpiobench.c
> index 0f099b0e8..04c694639 100644
> --- a/testsuite/gpiobench/gpiobench.c
> +++ b/testsuite/gpiobench/gpiobench.c
> @@ -85,6 +85,7 @@ struct test_info {
>  	unsigned long total_cycles;
>  	unsigned long max_histogram;
>  	int mode;
> +	int clockid;
>  	int prio;
>  	int quiet;
>  	int tracelimit;
> @@ -121,7 +122,10 @@ static void display_help(void)
>  	       "                            must be specified\n"
>  	       "-m       --testmode         0 is loopback mode\n"
>  	       "                            1 is react mode which works with a latency box,\n"
> -	       "                            default=0\n\n"
> +	       "                            default=0\n"
> +	       "-k       --clockid          0 is CLOCK_REALTIME\n"
> +	       "                            1 is CLOCK_MONOTONIC,\n"
> +	       "                            default=1\n\n"
>  
>  	       "e.g.     gpiobench -o 20 -i 21 -c pinctrl-bcm2835\n"
>  		);
> @@ -130,7 +134,7 @@ static void display_help(void)
>  static void process_options(int argc, char *argv[])
>  {
>  	int c = 0;
> -	static const char optstring[] = "h:p:m:l:c:b:i:o:q";
> +	static const char optstring[] = "h:p:m:l:c:b:i:o:k:q";
>  
>  	struct option long_options[] = {
>  		{ "bracetrace", required_argument, 0, 'b'},
> @@ -142,6 +146,7 @@ static void process_options(int argc, char *argv[])
>  		{ "intr", required_argument, 0, 'i'},
>  		{ "pinctrl", required_argument, 0, 'c'},
>  		{ "testmode", required_argument, 0, 'm'},
> +		{ "clockid", required_argument, 0, 'k'},
>  		{ 0, 0, 0, 0},
>  	};
>  
> @@ -185,6 +190,11 @@ static void process_options(int argc, char *argv[])
>  				MODE_REACT ? MODE_REACT : MODE_LOOPBACK;
>  			break;
>  
> +		case 'k':
> +			ti.clockid = atoi(optarg) >= CLOCK_MONOTONIC ?
> +				CLOCK_MONOTONIC : CLOCK_REALTIME;
> +			break;
> +
>  		default:
>  			display_help();
>  			exit(2);
> @@ -291,7 +301,7 @@ static int rw_gpio(int value, int index)
>  	struct rtdm_gpio_readout rdo;
>  	long long gpio_write, gpio_read, inner_diff, outer_diff;
>  
> -	clock_gettime(CLOCK_MONOTONIC, &timestamp);
> +	clock_gettime(ti.clockid, &timestamp);
>  	gpio_write = calc_us(timestamp);
>  
>  	ret = write(ti.fd_dev_out, &value, sizeof(value));
> @@ -306,7 +316,7 @@ static int rw_gpio(int value, int index)
>  		return ret;
>  	}
>  
> -	clock_gettime(CLOCK_MONOTONIC, &timestamp);
> +	clock_gettime(ti.clockid, &timestamp);
>  	gpio_read = calc_us(timestamp);
>  
>  	inner_diff = (rdo.timestamp - gpio_write) / 1000;
> @@ -472,6 +482,7 @@ static void init_ti(void)
>  	ti.gpio_out = -1;
>  	ti.gpio_intr = -1;
>  	ti.mode = MODE_LOOPBACK;
> +	ti.clockid = CLOCK_MONOTONIC;
>  
>  	ti.ts.inner_min = ti.ts.outer_min = DEFAULT_LIMIT;
>  	ti.ts.inner_max = ti.ts.outer_max = 0;
> @@ -632,7 +643,9 @@ int main(int argc, char **argv)
>  			goto out;
>  		}
>  
> -		ret = ioctl(ti.fd_dev_intr, GPIO_RTIOC_TS_MONO, &value);
> +		ret = ioctl(ti.fd_dev_intr,
> +			ti.clockid == CLOCK_MONOTONIC ?
> +			GPIO_RTIOC_TS_MONO : GPIO_RTIOC_TS_REAL, &value);
>  		if (ret) {
>  			printf("ioctl gpio port ts, failed\n");
>  			goto out;
> 

Merged to next, thanks.

May I assume that both modes work fine now?

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp
  2021-09-03  7:08 ` Jan Kiszka
@ 2021-09-07  0:55   ` Chen, Hongzhan
  0 siblings, 0 replies; 3+ messages in thread
From: Chen, Hongzhan @ 2021-09-07  0:55 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

>                                                                                       
>                                                                                              
>-----Original Message-----                                                                    
>From: Jan Kiszka <jan.kiszka@siemens.com>                                                     
>Sent: Friday, September 3, 2021 3:09 PM                                                       
>To: Chen, Hongzhan <hongzhan.chen@intel.com>; xenomai@xenomai.org                             
>Subject: Re: [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp
>                                                                                              
>On 03.09.21 06:33, Hongzhan Chen via Xenomai wrote:                                           
>> Provide choices to switch clock between MONO and REALTIME for getting                       
>> different timestamp since gpio driver already provide choosable service.                    
>>                                                                                             
>> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>                                      
>>                                                                                             
>> diff --git a/testsuite/gpiobench/gpiobench.c b/testsuite/gpiobench/gpiobench.c              
>> index 0f099b0e8..04c694639 100644                                                           
>> --- a/testsuite/gpiobench/gpiobench.c                                                       
>> +++ b/testsuite/gpiobench/gpiobench.c                                                       
>> @@ -85,6 +85,7 @@ struct test_info {                                                        
>>  	unsigned long total_cycles;                                                               
>>  	unsigned long max_histogram;                                                              
>>  	int mode;                                                                                 
>> +	int clockid;                                                                              
>>  	int prio;                                                                                 
>>  	int quiet;                                                                                
>>  	int tracelimit;                                                                           
>> @@ -121,7 +122,10 @@ static void display_help(void)                                         
>>  	       "                            must be specified\n"                                  
>>  	       "-m       --testmode         0 is loopback mode\n"                                 
>>  	       "                            1 is react mode which works with a latency box,\n"    
>> -	       "                            default=0\n\n"                                        
>> +	       "                            default=0\n"                                          
>> +	       "-k       --clockid          0 is CLOCK_REALTIME\n"                                
>> +	       "                            1 is CLOCK_MONOTONIC,\n"                              
>> +	       "                            default=1\n\n"                                        
>>                                                                                             
>>  	       "e.g.     gpiobench -o 20 -i 21 -c pinctrl-bcm2835\n"                              
>>  		);                                                                                      
>> @@ -130,7 +134,7 @@ static void display_help(void)                                          
>>  static void process_options(int argc, char *argv[])                                        
>>  {                                                                                          
>>  	int c = 0;                                                                                
>> -	static const char optstring[] = "h:p:m:l:c:b:i:o:q";                                      
>> +	static const char optstring[] = "h:p:m:l:c:b:i:o:k:q";                                    
>>                                                                                             
>>  	struct option long_options[] = {                                                          
>>  		{ "bracetrace", required_argument, 0, 'b'},                                             
>> @@ -142,6 +146,7 @@ static void process_options(int argc, char *argv[])                     
>>  		{ "intr", required_argument, 0, 'i'},                                                   
>>  		{ "pinctrl", required_argument, 0, 'c'},                                                
>>  		{ "testmode", required_argument, 0, 'm'},                                               
>> +		{ "clockid", required_argument, 0, 'k'},                                                
>>  		{ 0, 0, 0, 0},                                                                          
>>  	};                                                                                        
>>                                                                                             
>> @@ -185,6 +190,11 @@ static void process_options(int argc, char *argv[])                    
>>  				MODE_REACT ? MODE_REACT : MODE_LOOPBACK;                                            
>>  			break;                                                                                
>>                                                                                             
>> +		case 'k':                                                                               
>> +			ti.clockid = atoi(optarg) >= CLOCK_MONOTONIC ?                                        
>> +				CLOCK_MONOTONIC : CLOCK_REALTIME;                                                   
>> +			break;                                                                                
>> +                                                                                           
>>  		default:                                                                                
>>  			display_help();                                                                       
>>  			exit(2);                                                                              
>> @@ -291,7 +301,7 @@ static int rw_gpio(int value, int index)                                
>>  	struct rtdm_gpio_readout rdo;                                                             
>>  	long long gpio_write, gpio_read, inner_diff, outer_diff;                                  
>>                                                                                             
>> -	clock_gettime(CLOCK_MONOTONIC, &timestamp);                                               
>> +	clock_gettime(ti.clockid, &timestamp);                                                    
>>  	gpio_write = calc_us(timestamp);                                                          
>>                                                                                             
>>  	ret = write(ti.fd_dev_out, &value, sizeof(value));                                        
>> @@ -306,7 +316,7 @@ static int rw_gpio(int value, int index)                                
>>  		return ret;                                                                             
>>  	}                                                                                         
>>                                                                                             
>> -	clock_gettime(CLOCK_MONOTONIC, &timestamp);                                               
>> +	clock_gettime(ti.clockid, &timestamp);                                                    
>>  	gpio_read = calc_us(timestamp);                                                           
>>                                                                                             
>>  	inner_diff = (rdo.timestamp - gpio_write) / 1000;                                         
>> @@ -472,6 +482,7 @@ static void init_ti(void)                                               
>>  	ti.gpio_out = -1;                                                                         
>>  	ti.gpio_intr = -1;                                                                        
>>  	ti.mode = MODE_LOOPBACK;                                                                  
>> +	ti.clockid = CLOCK_MONOTONIC;                                                             
>>                                                                                             
>>  	ti.ts.inner_min = ti.ts.outer_min = DEFAULT_LIMIT;                                        
>>  	ti.ts.inner_max = ti.ts.outer_max = 0;                                                    
>> @@ -632,7 +643,9 @@ int main(int argc, char **argv)                                         
>>  			goto out;                                                                             
>>  		}                                                                                       
>>                                                                                             
>> -		ret = ioctl(ti.fd_dev_intr, GPIO_RTIOC_TS_MONO, &value);                                
>> +		ret = ioctl(ti.fd_dev_intr,                                                             
>> +			ti.clockid == CLOCK_MONOTONIC ?                                                       
>> +			GPIO_RTIOC_TS_MONO : GPIO_RTIOC_TS_REAL, &value);                                     
>>  		if (ret) {                                                                              
>>  			printf("ioctl gpio port ts, failed\n");                                               
>>  			goto out;                                                                             
>>                                                                                             
>                                                                                              
>Merged to next, thanks.	                                                                      
>                                                                                              
>May I assume that both modes work fine now?  

According to my test on rockipx board, both work fine.

Regards

Hongzhan Chen                                                 
>                                                                                              
>Jan                                                                                           
>                                                                                              
>--                                                                                            
Siemens AG, T RDA IOT                                                                         
Corporate Competence Center Embedded Linux                                                    

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-07  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03  4:33 [PATCH] testsuite/gpiobench: Provide choice to switch clock for getting timestamp Hongzhan Chen
2021-09-03  7:08 ` Jan Kiszka
2021-09-07  0:55   ` Chen, Hongzhan

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.