Date: Tue, 2 Oct 2007 01:14:20 -0700 (PDT) From: Jeff Roberson <jroberson@chesapeake.net> To: NIIMI Satoshi <sa2c@sa2c.net> Cc: freebsd-current@freebsd.org, freebsd-threads@freebsd.org Subject: Re: sched_yield() is very slow when other threads are busy on FreeBSD-current Message-ID: <20071002011337.Q6669@10.0.0.1> In-Reply-To: <46FD4B09.20006@sa2c.net> References: <46FD4B09.20006@sa2c.net>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
On Sat, 29 Sep 2007, NIIMI Satoshi wrote:
> Hi,
>
> I experienced sched_yield() is very slow when other threads are busy
> on FreeBSD-current.
Hello,
Can you please try the enclosed patch and tell me if it addresses your
problem?
Thanks,
Jeff
>
> When I run the program:
> ------------------------------------------------
> #include <assert.h>
> #include <stdio.h>
> #include <pthread.h>
>
> #define NUM_THREAD (10)
>
> volatile int run = 0;
>
> void *start(void *p)
> {
> while (!run)
> ;
> return p;
> }
>
> int main()
> {
> pthread_t th[NUM_THREAD];
> int i;
> for (i = 0; i < NUM_THREAD; i++) {
> assert(pthread_create(&th[i], NULL, start, NULL) == 0);
> sched_yield();
> }
> run = 1;
> for (i = 0; i < NUM_THREAD; i++)
> assert(pthread_join(th[i], NULL) == 0);
> return 0;
> }
> ------------------------------------------------
> The output of /usr/bin/time:
>
> FreeBSD 6.2-RELEASE, libthr, HZ=100, GENERIC kernel:
> 0.55 real 0.55 user 0.00 sys
>
> FreeBSD 7-CURRENT, libthr, HZ=100, kernel
> include GENERIC
> nooptions INVARIANTS, INVARIANT_SUPPORT, WITNESS, WITNESS_SKIPSPIN:
> 164.16 real 162.80 user 0.00 sys
>
> I tried SCHED_ULE too, but does not help so much.
>
> Increasing HZ helps to perform better, but still very slower than FreeBSD-6.
>
> Thanks,
> --
> NIIMI Satoshi
> _______________________________________________
> freebsd-threads@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org"
>
[-- Attachment #2 --]
Index: sched_4bsd.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/sched_4bsd.c,v
retrieving revision 1.105
diff -u -r1.105 sched_4bsd.c
--- sched_4bsd.c 21 Sep 2007 04:10:23 -0000 1.105
+++ sched_4bsd.c 2 Oct 2007 08:08:36 -0000
@@ -1324,8 +1324,6 @@
sched_relinquish(struct thread *td)
{
thread_lock(td);
- if (td->td_pri_class == PRI_TIMESHARE)
- sched_prio(td, PRI_MAX_TIMESHARE);
SCHED_STAT_INC(switch_relinquish);
mi_switch(SW_VOL, NULL);
thread_unlock(td);
Index: sched_ule.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/sched_ule.c,v
retrieving revision 1.209
diff -u -r1.209 sched_ule.c
--- sched_ule.c 24 Sep 2007 00:28:54 -0000 1.209
+++ sched_ule.c 2 Oct 2007 08:08:45 -0000
@@ -2502,8 +2502,6 @@
sched_relinquish(struct thread *td)
{
thread_lock(td);
- if (td->td_pri_class == PRI_TIMESHARE)
- sched_prio(td, PRI_MAX_TIMESHARE);
SCHED_STAT_INC(switch_relinquish);
mi_switch(SW_VOL, NULL);
thread_unlock(td);
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071002011337.Q6669>
