summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2013-01-28 19:38:13 +0000
committerjhb <jhb@FreeBSD.org>2013-01-28 19:38:13 +0000
commit5df972afb615beef2123a19aeca58e473e3d4e95 (patch)
tree380f661c837f03bdedc0e10252427ed4cde7ed7d
parent7756bef786978bd5d07c05b55bc8428454d6837d (diff)
downloadFreeBSD-src-5df972afb615beef2123a19aeca58e473e3d4e95.zip
FreeBSD-src-5df972afb615beef2123a19aeca58e473e3d4e95.tar.gz
Mark 'ticks', 'time_second', and 'time_uptime' as volatile to prevent the
compiler from caching their values in tight loops. Reviewed by: bde MFC after: 1 week
-rw-r--r--sys/dev/usb/net/if_cdce.c4
-rw-r--r--sys/kern/kern_clock.c4
-rw-r--r--sys/kern/kern_tc.c4
-rw-r--r--sys/pci/ncr.c2
-rw-r--r--sys/sys/kernel.h2
-rw-r--r--sys/sys/time.h4
6 files changed, 11 insertions, 9 deletions
diff --git a/sys/dev/usb/net/if_cdce.c b/sys/dev/usb/net/if_cdce.c
index 6e0ce97..e214fe2 100644
--- a/sys/dev/usb/net/if_cdce.c
+++ b/sys/dev/usb/net/if_cdce.c
@@ -500,6 +500,7 @@ cdce_attach(device_t dev)
const struct usb_interface_descriptor *id;
const struct usb_cdc_ethernet_descriptor *ued;
const struct usb_config *pcfg;
+ uint32_t seed;
int error;
uint8_t i;
uint8_t data_iface_no;
@@ -612,8 +613,9 @@ alloc_transfers:
/* fake MAC address */
device_printf(dev, "faking MAC address\n");
+ seed = ticks;
sc->sc_ue.ue_eaddr[0] = 0x2a;
- memcpy(&sc->sc_ue.ue_eaddr[1], &ticks, sizeof(uint32_t));
+ memcpy(&sc->sc_ue.ue_eaddr[1], &seed, sizeof(uint32_t));
sc->sc_ue.ue_eaddr[5] = device_get_unit(dev);
} else {
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index 5e10200..9d62c58 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -382,7 +382,7 @@ static void watchdog_config(void *, u_int, int *);
int stathz;
int profhz;
int profprocs;
-int ticks;
+volatile int ticks;
int psratio;
static DPCPU_DEFINE(int, pcputicks); /* Per-CPU version of ticks. */
@@ -469,7 +469,7 @@ void
hardclock(int usermode, uintfptr_t pc)
{
- atomic_add_int((volatile int *)&ticks, 1);
+ atomic_add_int(&ticks, 1);
hardclock_cpu(usermode);
tc_ticktock(1);
cpu_tick_calibration();
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index a08b218..2ffa2f9 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -103,8 +103,8 @@ static struct timecounter *timecounters = &dummy_timecounter;
int tc_min_ticktock_freq = 1;
-time_t time_second = 1;
-time_t time_uptime = 1;
+volatile time_t time_second = 1;
+volatile time_t time_uptime = 1;
struct bintime boottimebin;
struct timeval boottime;
diff --git a/sys/pci/ncr.c b/sys/pci/ncr.c
index 793ae80..ead7d43 100644
--- a/sys/pci/ncr.c
+++ b/sys/pci/ncr.c
@@ -1386,7 +1386,7 @@ static char *ncr_name (ncb_p np)
* Kernel variables referenced in the scripts.
* THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
*/
-static void *script_kvars[] =
+static volatile void *script_kvars[] =
{ &time_second, &ticks, &ncr_cache };
static struct script script0 = {
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index 441bcb3..c54677a 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -63,7 +63,7 @@ extern int psratio; /* ratio: prof / stat */
extern int stathz; /* statistics clock's frequency */
extern int profhz; /* profiling clock's frequency */
extern int profprocs; /* number of process's profiling */
-extern int ticks;
+extern volatile int ticks;
#endif /* _KERNEL */
diff --git a/sys/sys/time.h b/sys/sys/time.h
index 12d43cf..80878c0 100644
--- a/sys/sys/time.h
+++ b/sys/sys/time.h
@@ -287,8 +287,8 @@ struct clockinfo {
void inittodr(time_t base);
void resettodr(void);
-extern time_t time_second;
-extern time_t time_uptime;
+extern volatile time_t time_second;
+extern volatile time_t time_uptime;
extern struct bintime boottimebin;
extern struct timeval boottime;
OpenPOWER on IntegriCloud