From owner-svn-src-all@FreeBSD.ORG Mon Sep 15 08:51:28 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E2C0FDAA; Mon, 15 Sep 2014 08:51:28 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 691CE12E; Mon, 15 Sep 2014 08:51:28 +0000 (UTC) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s8F8pMin002947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 15 Sep 2014 11:51:23 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua s8F8pMin002947 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s8F8pMXL002946; Mon, 15 Sep 2014 11:51:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 15 Sep 2014 11:51:22 +0300 From: Konstantin Belousov To: Alexander Motin Subject: Re: svn commit: r271604 - head/sys/kern Message-ID: <20140915085122.GF2737@kib.kiev.ua> References: <201409142213.s8EMDJdM065051@svn.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="is+cnpcw8PTJCzZO" Content-Disposition: inline In-Reply-To: <201409142213.s8EMDJdM065051@svn.freebsd.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Sep 2014 08:51:29 -0000 --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--