Skip to contentSkip to conversation

sys_time: use barrier() instead of smp_rmb()

PATCH RESEND New Oleg Nesterov 1 participant 1 message Jul 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sys_time: use barrier() instead of smp_rmb()

Quoted 6 lines

From the recent 4e44f3497d41db4c3b9051c61410dee8ae4fb49c commit,

asmlinkage long sys_time(time_t __user * tloc)
{

(quoted diff) +0 -2
-	time_t i;
-	struct timeval tv;

Review

Quoted 10 lines
(quoted diff) +7 -2
+	/*
+	 * We read xtime.tv_sec atomically - it's updated
+	 * atomically by update_wall_time(), so no need to
+	 * even read-lock the xtime seqlock:
+	 */
+	time_t i = xtime.tv_sec;
 
-	do_gettimeofday(&tv);
-	i = tv.tv_sec;
+	smp_rmb(); /* sys_time() results are coherent */

The is no reason to use rmb(), we don't do any LOADs which could be reordered. What we need is a simple compiler barrier, to prevent the reading of the "volatile" xtime.tv_sec twice.

kernel/time.c renamed from kernel/time.c~ +1 -1
@@ -64,7 +64,7 @@ asmlinkage long sys_time(time_t __user *
 	 */
 	time_t i = xtime.tv_sec;
 
-	smp_rmb(); /* sys_time() results are coherent */
+	barrier(); /* sys_time() results are coherent */
 
 	if (tloc) {
 		if (put_user(i, tloc))