Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-03-19 Thread Pawel Jakub Dawidek
On Sun, Mar 18, 2012 at 05:56:02PM -0700, Julian Elischer wrote:
 On 3/18/12 11:50 AM, Pawel Jakub Dawidek wrote:
  On Mon, Feb 27, 2012 at 01:38:52PM +, David Xu wrote:
  Author: davidxu
  Date: Mon Feb 27 13:38:52 2012
  New Revision: 232209
  URL: http://svn.freebsd.org/changeset/base/232209
 
  Log:
 Follow changes made in revision 232144, pass absolute timeout to kernel,
 this eliminates a clock_gettime() syscall.
  This or some other change has broken CLOCK_MONOTONIC usage with
  condition variables.
 
  You should be able to reproduce this by something like this:
 
  pthread_cond_t cv;
  pthread_condattr_t attr;
  pthread_mutex_t lock;
  struct timespec ts;
   int error;
 
  (void)pthread_mutex_init(lock, NULL);
 
  (void)pthread_condattr_init(attr);
  (void)pthread_condattr_setclock(attr, CLOCK_MONOTONIC);
 
  (void)pthread_cond_init(cv,attr);
  (void)pthread_condattr_destroy(attr);
 
  (void)clock_gettime(CLOCK_MONOTONIC,ts);
  ts.tv_sec += 10;
  (void)pthread_mutex_lock(lock);
  (void)pthread_cond_timedwait(cv,lock,ts);
  (void)pthread_mutex_unlock(lock);
 
  This should timeout after 10 seconds, but pthread_cond_timedwait(3)
  returns immediately with ETIMEDOUT. CLOCK_REALTIME works properly.
  Bascially pthread_condattr_setclock(attr, CLOCK_MONOTONIC) is no-op.
  If you change CLOCK_MONOTONIC to CLOCK_REALTIME in clock_gettime(2)
  call, it will timeout after 10 seconds.
 
 this has been broken for  a while for  me in fact fixing this was, I 
 thought,
 one of the reasons for this work..  glad I'm not the omnly person 
 seeing it though.
 
 for me it broke sysutils/fio  from ports

For me it breaks sbin/hastd and openbsm/auditdistd, but my feeling is
that it is was broken recently. This stuff use to work not so long ago.

-- 
Pawel Jakub Dawidek   http://www.wheelsystems.com
FreeBSD committer http://www.FreeBSD.org
Am I Evil? Yes, I Am! http://tupytaj.pl


pgpOKwkORW0RY.pgp
Description: PGP signature


Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-03-19 Thread David Xu

On 2012/3/19 15:33, Pawel Jakub Dawidek wrote:

On Sun, Mar 18, 2012 at 05:56:02PM -0700, Julian Elischer wrote:

On 3/18/12 11:50 AM, Pawel Jakub Dawidek wrote:

On Mon, Feb 27, 2012 at 01:38:52PM +, David Xu wrote:

Author: davidxu
Date: Mon Feb 27 13:38:52 2012
New Revision: 232209
URL: http://svn.freebsd.org/changeset/base/232209

Log:
Follow changes made in revision 232144, pass absolute timeout to kernel,
this eliminates a clock_gettime() syscall.

This or some other change has broken CLOCK_MONOTONIC usage with
condition variables.

You should be able to reproduce this by something like this:

pthread_cond_t cv;
pthread_condattr_t attr;
pthread_mutex_t lock;
struct timespec ts;
  int error;

(void)pthread_mutex_init(lock, NULL);

(void)pthread_condattr_init(attr);
(void)pthread_condattr_setclock(attr, CLOCK_MONOTONIC);

(void)pthread_cond_init(cv,attr);
(void)pthread_condattr_destroy(attr);

(void)clock_gettime(CLOCK_MONOTONIC,ts);
ts.tv_sec += 10;
(void)pthread_mutex_lock(lock);
(void)pthread_cond_timedwait(cv,lock,ts);
(void)pthread_mutex_unlock(lock);

This should timeout after 10 seconds, but pthread_cond_timedwait(3)
returns immediately with ETIMEDOUT. CLOCK_REALTIME works properly.
Bascially pthread_condattr_setclock(attr, CLOCK_MONOTONIC) is no-op.
If you change CLOCK_MONOTONIC to CLOCK_REALTIME in clock_gettime(2)
call, it will timeout after 10 seconds.

this has been broken for  a while for  me in fact fixing this was, I
thought,
one of the reasons for this work..  glad I'm not the omnly person
seeing it though.

for me it broke sysutils/fio  from ports

For me it breaks sbin/hastd and openbsm/auditdistd, but my feeling is
that it is was broken recently. This stuff use to work not so long ago.

Hi,

Revision 233134 should have fixed the problem.

http://svn.freebsd.org/changeset/base/233134


___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-03-19 Thread Pawel Jakub Dawidek
On Mon, Mar 19, 2012 at 04:16:58PM +0800, David Xu wrote:
 Revision 233134 should have fixed the problem.
 
 http://svn.freebsd.org/changeset/base/233134

Works now, thanks for the quick fix.

-- 
Pawel Jakub Dawidek   http://www.wheelsystems.com
FreeBSD committer http://www.FreeBSD.org
Am I Evil? Yes, I Am! http://tupytaj.pl


pgpYEhdhNTPFI.pgp
Description: PGP signature


Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-03-18 Thread Pawel Jakub Dawidek
On Mon, Feb 27, 2012 at 01:38:52PM +, David Xu wrote:
 Author: davidxu
 Date: Mon Feb 27 13:38:52 2012
 New Revision: 232209
 URL: http://svn.freebsd.org/changeset/base/232209
 
 Log:
   Follow changes made in revision 232144, pass absolute timeout to kernel,
   this eliminates a clock_gettime() syscall.

This or some other change has broken CLOCK_MONOTONIC usage with
condition variables.

You should be able to reproduce this by something like this:

pthread_cond_t cv;
pthread_condattr_t attr;
pthread_mutex_t lock;
struct timespec ts;
int error;

(void)pthread_mutex_init(lock, NULL);

(void)pthread_condattr_init(attr);
(void)pthread_condattr_setclock(attr, CLOCK_MONOTONIC);

(void)pthread_cond_init(cv, attr);
(void)pthread_condattr_destroy(attr);

(void)clock_gettime(CLOCK_MONOTONIC, ts);
ts.tv_sec += 10;
(void)pthread_mutex_lock(lock);
(void)pthread_cond_timedwait(cv, lock, ts);
(void)pthread_mutex_unlock(lock);

This should timeout after 10 seconds, but pthread_cond_timedwait(3)
returns immediately with ETIMEDOUT. CLOCK_REALTIME works properly.
Bascially pthread_condattr_setclock(attr, CLOCK_MONOTONIC) is no-op.
If you change CLOCK_MONOTONIC to CLOCK_REALTIME in clock_gettime(2)
call, it will timeout after 10 seconds.

-- 
Pawel Jakub Dawidek   http://www.wheelsystems.com
FreeBSD committer http://www.FreeBSD.org
Am I Evil? Yes, I Am! http://tupytaj.pl


pgp18JNvAfgtP.pgp
Description: PGP signature


Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-03-18 Thread Julian Elischer

On 3/18/12 11:50 AM, Pawel Jakub Dawidek wrote:

On Mon, Feb 27, 2012 at 01:38:52PM +, David Xu wrote:

Author: davidxu
Date: Mon Feb 27 13:38:52 2012
New Revision: 232209
URL: http://svn.freebsd.org/changeset/base/232209

Log:
   Follow changes made in revision 232144, pass absolute timeout to kernel,
   this eliminates a clock_gettime() syscall.

This or some other change has broken CLOCK_MONOTONIC usage with
condition variables.

You should be able to reproduce this by something like this:

pthread_cond_t cv;
pthread_condattr_t attr;
pthread_mutex_t lock;
struct timespec ts;
 int error;

(void)pthread_mutex_init(lock, NULL);

(void)pthread_condattr_init(attr);
(void)pthread_condattr_setclock(attr, CLOCK_MONOTONIC);

(void)pthread_cond_init(cv,attr);
(void)pthread_condattr_destroy(attr);

(void)clock_gettime(CLOCK_MONOTONIC,ts);
ts.tv_sec += 10;
(void)pthread_mutex_lock(lock);
(void)pthread_cond_timedwait(cv,lock,ts);
(void)pthread_mutex_unlock(lock);

This should timeout after 10 seconds, but pthread_cond_timedwait(3)
returns immediately with ETIMEDOUT. CLOCK_REALTIME works properly.
Bascially pthread_condattr_setclock(attr, CLOCK_MONOTONIC) is no-op.
If you change CLOCK_MONOTONIC to CLOCK_REALTIME in clock_gettime(2)
call, it will timeout after 10 seconds.


this has been broken for  a while for  me in fact fixing this was, I 
thought,
one of the reasons for this work..  glad I'm not the omnly person 
seeing it though.


for me it broke sysutils/fio  from ports


___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-02-27 Thread David Xu
Author: davidxu
Date: Mon Feb 27 13:38:52 2012
New Revision: 232209
URL: http://svn.freebsd.org/changeset/base/232209

Log:
  Follow changes made in revision 232144, pass absolute timeout to kernel,
  this eliminates a clock_gettime() syscall.

Modified:
  head/lib/libthr/thread/thr_rwlock.c
  head/lib/libthr/thread/thr_umtx.c
  head/lib/libthr/thread/thr_umtx.h
  head/sys/kern/kern_umtx.c

Modified: head/lib/libthr/thread/thr_rwlock.c
==
--- head/lib/libthr/thread/thr_rwlock.c Mon Feb 27 13:04:09 2012
(r232208)
+++ head/lib/libthr/thread/thr_rwlock.c Mon Feb 27 13:38:52 2012
(r232209)
@@ -123,7 +123,6 @@ rwlock_rdlock_common(pthread_rwlock_t *r
 {
struct pthread *curthread = _get_curthread();
pthread_rwlock_t prwlock;
-   struct timespec ts, ts2, *tsp;
int flags;
int ret;
 
@@ -162,18 +161,8 @@ rwlock_rdlock_common(pthread_rwlock_t *r
return (EINVAL);
 
for (;;) {
-   if (abstime) {
-   clock_gettime(CLOCK_REALTIME, ts);
-   TIMESPEC_SUB(ts2, abstime, ts);
-   if (ts2.tv_sec  0 || 
-   (ts2.tv_sec == 0  ts2.tv_nsec = 0))
-   return (ETIMEDOUT);
-   tsp = ts2;
-   } else
-   tsp = NULL;
-
/* goto kernel and lock it */
-   ret = __thr_rwlock_rdlock(prwlock-lock, flags, tsp);
+   ret = __thr_rwlock_rdlock(prwlock-lock, flags, abstime);
if (ret != EINTR)
break;
 
@@ -255,7 +244,6 @@ rwlock_wrlock_common (pthread_rwlock_t *
 {
struct pthread *curthread = _get_curthread();
pthread_rwlock_t prwlock;
-   struct timespec ts, ts2, *tsp;
int ret;
 
CHECK_AND_INIT_RWLOCK
@@ -275,18 +263,8 @@ rwlock_wrlock_common (pthread_rwlock_t *
return (EINVAL);
 
for (;;) {
-   if (abstime != NULL) {
-   clock_gettime(CLOCK_REALTIME, ts);
-   TIMESPEC_SUB(ts2, abstime, ts);
-   if (ts2.tv_sec  0 || 
-   (ts2.tv_sec == 0  ts2.tv_nsec = 0))
-   return (ETIMEDOUT);
-   tsp = ts2;
-   } else
-   tsp = NULL;
-
/* goto kernel and lock it */
-   ret = __thr_rwlock_wrlock(prwlock-lock, tsp);
+   ret = __thr_rwlock_wrlock(prwlock-lock, abstime);
if (ret == 0) {
prwlock-owner = curthread;
break;

Modified: head/lib/libthr/thread/thr_umtx.c
==
--- head/lib/libthr/thread/thr_umtx.c   Mon Feb 27 13:04:09 2012
(r232208)
+++ head/lib/libthr/thread/thr_umtx.c   Mon Feb 27 13:38:52 2012
(r232209)
@@ -265,15 +265,42 @@ _thr_ucond_broadcast(struct ucond *cv)
 }
 
 int
-__thr_rwlock_rdlock(struct urwlock *rwlock, int flags, struct timespec *tsp)
+__thr_rwlock_rdlock(struct urwlock *rwlock, int flags,
+   const struct timespec *tsp)
 {
-   return _umtx_op_err(rwlock, UMTX_OP_RW_RDLOCK, flags, NULL, tsp);
+   struct _umtx_time timeout, *tm_p;
+   size_t tm_size;
+
+   if (tsp == NULL) {
+   tm_p = NULL;
+   tm_size = 0;
+   } else {
+   timeout._timeout = *tsp;
+   timeout._flags = UMTX_ABSTIME;
+   timeout._clockid = CLOCK_REALTIME;
+   tm_p = timeout;
+   tm_size = sizeof(timeout);
+   }
+   return _umtx_op_err(rwlock, UMTX_OP_RW_RDLOCK, flags, (void *)tm_size, 
tm_p);
 }
 
 int
-__thr_rwlock_wrlock(struct urwlock *rwlock, struct timespec *tsp)
+__thr_rwlock_wrlock(struct urwlock *rwlock, const struct timespec *tsp)
 {
-   return _umtx_op_err(rwlock, UMTX_OP_RW_WRLOCK, 0, NULL, tsp);
+   struct _umtx_time timeout, *tm_p;
+   size_t tm_size;
+
+   if (tsp == NULL) {
+   tm_p = NULL;
+   tm_size = 0;
+   } else {
+   timeout._timeout = *tsp;
+   timeout._flags = UMTX_ABSTIME;
+   timeout._clockid = CLOCK_REALTIME;
+   tm_p = timeout;
+   tm_size = sizeof(timeout);
+   }
+   return _umtx_op_err(rwlock, UMTX_OP_RW_WRLOCK, 0, (void *)tm_size, 
tm_p);
 }
 
 int

Modified: head/lib/libthr/thread/thr_umtx.h
==
--- head/lib/libthr/thread/thr_umtx.h   Mon Feb 27 13:04:09 2012
(r232208)
+++ head/lib/libthr/thread/thr_umtx.h   Mon Feb 27 13:38:52 2012
(r232209)
@@ -60,8 +60,10 @@ void _thr_ucond_init(struct ucond *cv) _
 int _thr_ucond_signal(struct ucond *cv) __hidden;
 int _thr_ucond_broadcast(struct ucond *cv) __hidden;

Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-02-27 Thread Ivan Voras
On 27 February 2012 14:38, David Xu davi...@freebsd.org wrote:
 Author: davidxu
 Date: Mon Feb 27 13:38:52 2012
 New Revision: 232209
 URL: http://svn.freebsd.org/changeset/base/232209

 Log:
  Follow changes made in revision 232144, pass absolute timeout to kernel,
  this eliminates a clock_gettime() syscall.

Any chance of a MFC?

I use rwlocks a lot; removing a syscall from all operations looks like
a nice improvement.
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r232209 - in head: lib/libthr/thread sys/kern

2012-02-27 Thread David Xu

On 2012/2/27 22:29, Ivan Voras wrote:

On 27 February 2012 14:38, David Xudavi...@freebsd.org  wrote:

Author: davidxu
Date: Mon Feb 27 13:38:52 2012
New Revision: 232209
URL: http://svn.freebsd.org/changeset/base/232209

Log:
  Follow changes made in revision 232144, pass absolute timeout to kernel,
  this eliminates a clock_gettime() syscall.

Any chance of a MFC?

I use rwlocks a lot; removing a syscall from all operations looks like
a nice improvement.


Yes, I will do a MFC when it is ready. ;-)


___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org