Skip to contentSkip to conversation

support for user space tsc emulation for decrementing counters

PATCH In review Sebastian Smolorz 2 participants 4 messages Jul 20, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support for user space tsc emulation for decrementing counters

Hi,

here comes my patch for user space tsc emulation for decrementing counters. I had to extend the __xn_tscinfo structure because the counter value from the last tsc update is needed to calculate the new tsc value.

I will post a second patch for Adeos which implements the kernel side for s3c24xx platforms on adeos-main.

Signature · 1 line
Sebastian
asm-arm/syscall.h +28 -3
Index: include/asm-arm/syscall.h
===================================================================
@@ -4,6 +4,9 @@
  * ARM port
  *   Copyright (C) 2005 Stelian Pop
  *
+ * Copyright (C) 2007 Sebastian Smolorz <[email protected]>
+ *	Support for TSC emulation in user space for decrementing counters
+ *
  * Xenomai is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
  * by the Free Software Foundation; either version 2 of the License,
@@ -202,6 +205,7 @@
                 struct {
                         volatile unsigned *counter;
                         unsigned mask;
+			volatile unsigned *last_cnt;
                         volatile unsigned long long *tsc;
                 } fr;
                 struct {
@@ -248,6 +252,28 @@
 	if ((counter & mask) < (before & mask))
 		before += mask + 1;
 	return (before & ~mask) | (counter & mask);
+
+#elif CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_DECREMENTER
+	const unsigned long long mask = __xn_tscinfo.u.fr.mask;
+	unsigned long long after, before;
+	unsigned counter, last_cnt;
+
+	do {
+		before = *__xn_tscinfo.u.fr.tsc;
+		counter = *__xn_tscinfo.u.fr.counter;
+		last_cnt = *__xn_tscinfo.u.fr.last_cnt;
+		/* compiler barrier. */
+		asm("" : /* */ : /* */ : "memory");
+
+		after = *__xn_tscinfo.u.fr.tsc;
+	} while (after != before);
+
+	counter &= mask;
+	last_cnt &= mask;
+	if (counter > last_cnt)
+		before += mask + 1;
+	return (before + last_cnt - counter);
+
 #endif /* CONFIG_XENO_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING */
 }
 
@@ -279,8 +305,8 @@
 	page_size = sysconf(_SC_PAGESIZE);
 
 	switch(__xn_tscinfo.type) {
-#if CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING
-	case __XN_TSC_TYPE_FREERUNNING:{
+	case __XN_TSC_TYPE_FREERUNNING:
+	case __XN_TSC_TYPE_DECREMENTER: {
 		unsigned long phys_addr;
 
 		phys_addr = (unsigned long) __xn_tscinfo.u.fr.counter;
@@ -296,7 +322,6 @@
 			 ((char *) addr + (phys_addr & (page_size - 1))));
 		break;
 	}
-#endif /* CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING */
 	case __XN_TSC_TYPE_NONE:
 		goto error;
 		
asm-arm/bits/shadow.h +6 -0
Index: include/asm-arm/bits/shadow.h
===================================================================
@@ -176,6 +176,12 @@
 			info.u.fr.tsc = ipipe_info.archdep.tsc.u.fr.tsc;
 			break;
 		case IPIPE_TSC_TYPE_DECREMENTER:
+			info.type = __XN_TSC_TYPE_DECREMENTER,
+			info.u.fr.counter = ipipe_info.archdep.tsc.u.fr.counter;
+			info.u.fr.mask = ipipe_info.archdep.tsc.u.fr.mask;
+			info.u.fr.last_cnt = ipipe_info.archdep.tsc.u.fr.last_cnt;
+			info.u.fr.tsc = ipipe_info.archdep.tsc.u.fr.tsc;
+			break;
 		case IPIPE_TSC_TYPE_NONE:
 			return -ENOSYS;
 			
configure.in +2 -1
Index: configure.in
===================================================================
@@ -182,7 +182,8 @@
 	ixp4xx|pxa) 	arch=5
 	      		tsc_type=__XN_TSC_TYPE_FREERUNNING;;
 
-	s3c2410) 	arch=4;;
+	s3c2410) 	arch=4
+			tsc_type=__XN_TSC_TYPE_DECREMENTER;;
 
 	sa1100) 	arch=4
 			CONFIG_XENO_ARM_SA1100=y
ChangeLog +5 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,8 @@
+2007-07-19  Sebastian Smolorz  <[email protected]>
+
+	* include/asm-arm/syscall.h: Add user-space access to
+	tsc emulation for decrementing counters.
+
 2007-07-19  Jan Kiszka  <[email protected]>
 
 	* ksrc/nucleus/timer.c (xntimer_tick_aperiodic): Keep processing
#1 lore raw
Quoted 5 lines · Sebastian Smolorz

Hi,

here comes my patch for user space tsc emulation for decrementing counters. I had to extend the __xn_tscinfo structure because the counter value from the last tsc update is needed to calculate the new tsc value.

The struct __xn_tscinfo is a union where "fr" stands for free-running, the idea was that you could add your own structure for decrementer based tsc.

Signature · 1 line
                                              Gilles Chanteperdrix
#2 lore raw
Quoted 10 lines · Gilles Chanteperdrix
Quoted 5 lines · Sebastian Smolorz

Hi,

here comes my patch for user space tsc emulation for decrementing counters. I had to extend the __xn_tscinfo structure because the counter value from the last tsc update is needed to calculate the new tsc value.

The struct __xn_tscinfo is a union where "fr" stands for free-running, the idea was that you could add your own structure for decrementer based tsc.

Ah, ok, will change the patch. The abbreviation was not immediately clear to me. ;-)

Signature · 1 line
Sebastian
#3 lore raw
In reply to Gilles Chanteperdrix
Quoted 10 lines · Gilles Chanteperdrix
Quoted 5 lines · Sebastian Smolorz

Hi,

here comes my patch for user space tsc emulation for decrementing counters. I had to extend the __xn_tscinfo structure because the counter value from the last tsc update is needed to calculate the new tsc value.

The struct __xn_tscinfo is a union where "fr" stands for free-running, the idea was that you could add your own structure for decrementer based tsc.

Ok. Here is version 2 of the patch.

Signature · 1 line
Sebastian
asm-arm/syscall.h +47 -1
Index: include/asm-arm/syscall.h
===================================================================
@@ -4,6 +4,9 @@
  * ARM port
  *   Copyright (C) 2005 Stelian Pop
  *
+ * Copyright (C) 2007 Sebastian Smolorz <[email protected]>
+ *	Support for TSC emulation in user space for decrementing counters
+ *
  * Xenomai is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
  * by the Free Software Foundation; either version 2 of the License,
@@ -205,6 +208,10 @@
                         volatile unsigned long long *tsc;
                 } fr;
                 struct {
+			volatile unsigned *counter;
+			unsigned mask;
+			volatile unsigned *last_cnt;
+			volatile unsigned long long *tsc;
                 } dec;
         } u;
 };
@@ -248,6 +255,28 @@
 	if ((counter & mask) < (before & mask))
 		before += mask + 1;
 	return (before & ~mask) | (counter & mask);
+
+#elif CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_DECREMENTER
+	const unsigned mask = __xn_tscinfo.u.dec.mask;
+	unsigned long long after, before;
+	unsigned counter, last_cnt;
+
+	do {
+		before = *__xn_tscinfo.u.dec.tsc;
+		counter = *__xn_tscinfo.u.dec.counter;
+		last_cnt = *__xn_tscinfo.u.dec.last_cnt;
+		/* compiler barrier. */
+		asm("" : /* */ : /* */ : "memory");
+
+		after = *__xn_tscinfo.u.dec.tsc;
+	} while (after != before);
+
+	counter &= mask;
+	last_cnt &= mask;
+	if (counter > last_cnt)
+		before += mask + 1;
+	return (before + last_cnt - counter);
+
 #endif /* CONFIG_XENO_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING */
 }
 
@@ -280,7 +309,7 @@
 
 	switch(__xn_tscinfo.type) {
 #if CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING
-	case __XN_TSC_TYPE_FREERUNNING:{
+	case __XN_TSC_TYPE_FREERUNNING: {
 		unsigned long phys_addr;
 
 		phys_addr = (unsigned long) __xn_tscinfo.u.fr.counter;
@@ -296,6 +325,23 @@
 			 ((char *) addr + (phys_addr & (page_size - 1))));
 		break;
 	}
+#elif CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_DECREMENTER
+	case __XN_TSC_TYPE_DECREMENTER: {
+		unsigned long phys_addr;
+
+		phys_addr = (unsigned long) __xn_tscinfo.u.dec.counter;
+		addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED,
+			    fd, phys_addr & ~(page_size - 1));
+		if (addr == MAP_FAILED) {
+			perror("Xenomai init: mmap(/dev/mem)");
+			exit(EXIT_FAILURE);
+		}
+
+		__xn_tscinfo.u.dec.counter = 
+			((volatile unsigned *)
+			 ((char *) addr + (phys_addr & (page_size - 1))));
+		break;
+	}
 #endif /* CONFIG_XENO_ARM_HW_DIRECT_TSC == __XN_TSC_TYPE_FREERUNNING */
 	case __XN_TSC_TYPE_NONE:
 		goto error;
asm-arm/bits/shadow.h +6 -0
Index: include/asm-arm/bits/shadow.h
===================================================================
@@ -176,6 +176,12 @@
 			info.u.fr.tsc = ipipe_info.archdep.tsc.u.fr.tsc;
 			break;
 		case IPIPE_TSC_TYPE_DECREMENTER:
+			info.type = __XN_TSC_TYPE_DECREMENTER,
+			info.u.dec.counter = ipipe_info.archdep.tsc.u.dec.counter;
+			info.u.dec.mask = ipipe_info.archdep.tsc.u.dec.mask;
+			info.u.dec.last_cnt = ipipe_info.archdep.tsc.u.dec.last_cnt;
+			info.u.dec.tsc = ipipe_info.archdep.tsc.u.dec.tsc;
+			break;
 		case IPIPE_TSC_TYPE_NONE:
 			return -ENOSYS;
 			
configure.in +2 -1
Index: configure.in
===================================================================
@@ -182,7 +182,8 @@
 	ixp4xx|pxa) 	arch=5
 	      		tsc_type=__XN_TSC_TYPE_FREERUNNING;;
 
-	s3c2410) 	arch=4;;
+	s3c2410) 	arch=4
+			tsc_type=__XN_TSC_TYPE_DECREMENTER;;
 
 	sa1100) 	arch=4
 			CONFIG_XENO_ARM_SA1100=y
ChangeLog +5 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,8 @@
+2007-07-19  Sebastian Smolorz  <[email protected]>
+
+	* include/asm-arm/syscall.h: Add user-space access to
+	tsc emulation for decrementing counters.
+
 2007-07-19  Jan Kiszka  <[email protected]>
 
 	* ksrc/nucleus/timer.c (xntimer_tick_aperiodic): Keep processing