From patchwork Fri Nov 1 12:53:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: oscar.mateo@intel.com X-Patchwork-Id: 3124731 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AF9FF9F3C4 for ; Fri, 1 Nov 2013 12:58:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FF242039F for ; Fri, 1 Nov 2013 12:58:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3DDD22049D for ; Fri, 1 Nov 2013 12:58:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6E2E9EE657; Fri, 1 Nov 2013 05:58:24 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 73AD9EE657 for ; Fri, 1 Nov 2013 05:58:23 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 01 Nov 2013 05:58:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,617,1378882800"; d="scan'208";a="426465932" Received: from omateolo-haswell.isw.intel.com ([10.102.226.88]) by fmsmga002.fm.intel.com with ESMTP; 01 Nov 2013 05:58:19 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 1 Nov 2013 12:53:42 +0000 Message-Id: <1383310422-30702-1-git-send-email-oscar.mateo@intel.com> X-Mailer: git-send-email 1.7.9.5 Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH] prime_self_import: Assure no pending requests before object counting X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Mateo We don't want a previously used object to be freed in the middle of a before/after object counting operation (or we would get a "-1 objects leaked" message). We have seen this happening, e.g., when a context from a previous run dies, but its backing object is alive waiting for a retire_work to kick in. Signed-off-by: Oscar Mateo Cc: Ben Widawsky --- tests/prime_self_import.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c index 481a809..e48abd1 100644 --- a/tests/prime_self_import.c +++ b/tests/prime_self_import.c @@ -211,6 +211,25 @@ static void test_with_one_bo(void) check_bo(fd2, handle_import1, fd2, handle_import1); } +static void retire_requests(void) +{ + char fname[FILENAME_MAX]; + int drop_caches_fd; + const char *data = "0x4"; + + snprintf(fname, FILENAME_MAX, "%s/%i/%s", + "/sys/kernel/debug/dri", drm_get_card(), + "i915_gem_drop_caches"); + + drop_caches_fd = open(fname, O_WRONLY); + + if (drop_caches_fd >= 0) + { + write(drop_caches_fd, data, strlen(data) + 1); + close(drop_caches_fd); + } +} + static int get_object_count(void) { FILE *file; @@ -252,10 +271,13 @@ static void test_reimport_close_race(void) pthread_t *threads; int r, i, num_threads; int fds[2]; - int obj_count = get_object_count(); + int obj_count; void *status; uint32_t handle; + retire_requests(); + obj_count = get_object_count(); + num_threads = sysconf(_SC_NPROCESSORS_ONLN); threads = calloc(num_threads, sizeof(pthread_t)); @@ -330,9 +352,12 @@ static void test_export_close_race(void) pthread_t *threads; int r, i, num_threads; int fd; - int obj_count = get_object_count(); + int obj_count; void *status; + retire_requests(); + obj_count = get_object_count(); + num_threads = sysconf(_SC_NPROCESSORS_ONLN); threads = calloc(num_threads, sizeof(pthread_t));