Date: Mon, 15 Sep 2014 11:51:22 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Alexander Motin <mav@FreeBSD.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r271604 - head/sys/kern Message-ID: <20140915085122.GF2737@kib.kiev.ua> In-Reply-To: <201409142213.s8EMDJdM065051@svn.freebsd.org> References: <201409142213.s8EMDJdM065051@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--is+cnpcw8PTJCzZO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 14, 2014 at 10:13:19PM +0000, Alexander Motin wrote: > Author: mav > Date: Sun Sep 14 22:13:19 2014 > New Revision: 271604 > URL: http://svnweb.freebsd.org/changeset/base/271604 >=20 > Log: > Add couple memory barries to serialize tdq_cpu_idle and tdq_load access= es. Serialize what against what ? It seems what you do is just ensuring that the write to tdq_cpu_idle in sched_idletd() become visible faster than it was before your patch. Memory barrier after the assignment of dq->tdq_cpu_idle =3D 1 flushes write buffers, which makes the tdq_notify() to see the write immediately. Am I right ? If true, this must be commented to explain the stray barriers appearing in the code. > =20 > This change fixes transient performance drops in some of my benchmarks, > vanishing as soon as I am trying to collect any stats from the schedule= r. > It looks like reordered access to those variables sometimes caused loss= of > IPI_PREEMPT, that delayed thread execution until some later interrupt. > =20 > MFC after: 3 days >=20 > Modified: > head/sys/kern/sched_ule.c >=20 > Modified: head/sys/kern/sched_ule.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/kern/sched_ule.c Sun Sep 14 22:10:35 2014 (r271603) > +++ head/sys/kern/sched_ule.c Sun Sep 14 22:13:19 2014 (r271604) > @@ -1037,6 +1037,7 @@ tdq_notify(struct tdq *tdq, struct threa > ctd =3D pcpu_find(cpu)->pc_curthread; > if (!sched_shouldpreempt(pri, ctd->td_priority, 1)) > return; > + mb(); > if (TD_IS_IDLETHREAD(ctd)) { > /* > * If the MD code has an idle wakeup routine try that before > @@ -2640,6 +2641,7 @@ sched_idletd(void *dummy) > =20 > /* Run main MD idle handler. */ > tdq->tdq_cpu_idle =3D 1; > + mb(); > cpu_idle(switchcnt * 4 > sched_idlespinthresh); > tdq->tdq_cpu_idle =3D 0; > =20 I suspect that what you are trying to do could be achieved by using the FreeBSD API, instead of compat shims, in the following way. diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 0a63c01..1ffac22 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -1042,7 +1042,8 @@ tdq_notify(struct tdq *tdq, struct thread *td) * If the MD code has an idle wakeup routine try that before * falling back to IPI. */ - if (!tdq->tdq_cpu_idle || cpu_idle_wakeup(cpu)) + if (!atomic_load_acq_int(&tdq->tdq_cpu_idle) || + cpu_idle_wakeup(cpu)) return; } tdq->tdq_ipipending =3D 1; @@ -2639,7 +2640,7 @@ sched_idletd(void *dummy) continue; =20 /* Run main MD idle handler. */ - tdq->tdq_cpu_idle =3D 1; + atomic_add_rel_int(&tdq->tdq_cpu_idle, 1); cpu_idle(switchcnt * 4 > sched_idlespinthresh); tdq->tdq_cpu_idle =3D 0; =20 --is+cnpcw8PTJCzZO Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJUFqiKAAoJEJDCuSvBvK1BqaIP+wfjWn7DvvXs98lob6RNVXz7 5Qa5RTnhpVzG8Yw9E3MQ+igbi03ZRkZqcQSjHS62AMyzkFDaWu5u1+awy6Q8puzj jKq3DbVTTidNn5C4Hs4DtmsaAjNdPKL8ieyEwb59nWzTD0lUxu8Khldz5afHiCUS IjwBWZMyKQCWUeLWT15P+5XANOTiN6l4AzfU5DRqJGFIztpzXlP8RZI6OtbvswFh c4Zp7yhyLYMNBakyELxgRa+fvkTRklyd1rZ6OEmGtWcawI42l8LqqlSOoHTXS2k0 6Qt0a5Eb0/qtZWrn4CiIUnCRTzv7rIJv6qt13FVb/MuAFAWGNJPaMxINOqvBSQc8 4Z9ctaQ3PdXD2uLgR1m1N4Ci8enrK83FACiw1dWaZcVCKU5b8Z8ZqNF1vdhNlAnx ZofjwE6kebnuDe3+a6VU/2zfn9nps7prayr7eZE+CaB+SK6T/SPqCrOvRpfKQWlc aKKpiSR3Bui6NNYf9iQWpz5h9SNg50MIas3o7TCaSBMGcUz91M5TLQ+pYKh69TKA dfvakdl2uTk29i/jtq7FeH3/CBQYqghSJFpm+sDHDFAAL3/Q9zbUXXhCsbmRqoBx u3RhklLQaoI58qgqCXNUg9Xl8GPLIXPsNQX/4xer+hHrDWzEwsSJXnSslh0HlAea oAiZWoGfeEmWj5/3fdD7 =MXLW -----END PGP SIGNATURE----- --is+cnpcw8PTJCzZO--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140915085122.GF2737>