From owner-freebsd-x11@freebsd.org Mon Mar 6 22:53:41 2017 Return-Path: Delivered-To: freebsd-x11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1BEFDCFB5A5 for ; Mon, 6 Mar 2017 22:53:41 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 00A23145A; Mon, 6 Mar 2017 22:53:41 +0000 (UTC) (envelope-from jbeich@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1354) id 4CC201A28; Mon, 6 Mar 2017 22:53:40 +0000 (UTC) To: davshao@gmail.com, freebsd-x11@freebsd.org Subject: Re: libdrm atomic_add_unless may reverse meaning In-Reply-To: Message-Id: <20170306225340.4CC201A28@freefall.freebsd.org> Date: Mon, 6 Mar 2017 22:53:40 +0000 (UTC) From: jbeich@freebsd.org (Jan Beich) X-BeenThere: freebsd-x11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: X11 on FreeBSD -- maintaining and support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2017 22:53:41 -0000 David Shao writes: > For those who have frustrating glitches with applications > such as glxgears on Intel integrated graphics, the > following libdrm bug report may be of interest. > > https://bugs.freedesktop.org/show_bug.cgi?id=100077 > "libdrm atomic_add_unless() may reverse return value meaning" > > A one character patch allows glxgears to run on > DragonFly using a hacked version of pkgsrc on an > Intel IvyBridge integrated graphics machine. > > --- xf86atomic.h.orig 2015-09-22 04:34:51.000000000 +0000 > +++ xf86atomic.h > @@ -111,7 +111,7 @@ static inline int atomic_add_unless(atom > c = atomic_read(v); > while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c) > c = old; > - return c == unless; > + return c != unless; > } > > #endif glxgears works fine here on drm-next (i915kms, Skylake, SNA) but the patch in question breaks it. Perhaps, DragonFly semantics differ. $ glxgears drm_intel_gem_bo_unreference(): atomic_add_unless(1, -1, 1) drm_intel_gem_bo_unreference(): atomic_add_unless(2, -1, 1) Running synchronized to the vertical refresh. The framerate should be approximately the same as the monitor refresh rate. drm_intel_gem_bo_unreference(): atomic_add_unless(2, -1, 1) drm_intel_gem_bo_unreference(): atomic_add_unless(2, -1, 1) Assertion failed: (atomic_read(&bo_gem->refcount) > 0), function drm_intel_gem_bo_unreference, file intel_bufmgr_gem.c, line 1436. (lldb) bt * thread #1, stop reason = signal SIGABRT * frame #0: libc.so.7`thr_kill at thr_kill.S:3 frame #1: libc.so.7`__raise(s=6) at raise.c:52 frame #2: libc.so.7`abort at abort.c:65 frame #3: libc.so.7`__assert(func=, file=, line=, failedexpr=) at assert.c:51 frame #4: libdrm_intel.so.1`drm_intel_gem_bo_unreference(bo=0x000000080549dd80) at intel_bufmgr_gem.c:1436 frame #5: libdrm_intel.so.1`drm_intel_bo_unreference(bo=0x000000080549dd80) at intel_bufmgr.c:99 frame #6: 0x0000000805aa9ca1 i965_dri.so`intel_miptree_release + 81 frame #7: 0x0000000805aa7b9d i965_dri.so`intel_alloc_private_renderbuffer_storage + 141 frame #8: 0x000000080578dfbf i965_dri.so`_mesa_resize_framebuffer + 79 frame #9: 0x0000000805a70fa3 i965_dri.so`intel_update_renderbuffers + 1507 frame #10: 0x0000000805a708c6 i965_dri.so`intel_prepare_render + 54 frame #11: 0x0000000805a67ba9 i965_dri.so`brw_clear + 153 frame #12: 0x000000000040366e glxgears`draw + 14 frame #13: 0x00000000004027fd glxgears`main + 2909 frame #14: glxgears`_start(ap=, cleanup=) at crt1.c:72 (lldb) f 4 frame #4: libdrm_intel.so.1`drm_intel_gem_bo_unreference(bo=0x000000080549dd80) at intel_bufmgr_gem.c:1436 1433 { 1434 drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; 1435 -> 1436 assert(atomic_read(&bo_gem->refcount) > 0); 1437 1438 if (atomic_add_unless(&bo_gem->refcount, -1, 1)) { 1439 drm_intel_bufmgr_gem *bufmgr_gem =